@Nullable @Override public ObjectId apply(String input) { return new ObjectId(input); } }
protected <T extends Persisted> void removeEmbedded(T model, String key, String searchId) { BasicDBObject aryQry = new BasicDBObject("id", searchId); BasicDBObject qry = new BasicDBObject("_id", new ObjectId(model.getId())); BasicDBObject update = new BasicDBObject("$pull", new BasicDBObject(key, aryQry)); // http://docs.mongodb.org/manual/reference/operator/pull/ collection(model).update(qry, update); }
@Override public void addOutput(Stream stream, Output output) { collection(stream).update( new BasicDBObject("_id", new ObjectId(stream.getId())), new BasicDBObject("$addToSet", new BasicDBObject(StreamImpl.FIELD_OUTPUTS, new ObjectId(output.getId()))) ); clusterEventBus.post(StreamsChangedEvent.create(stream.getId())); }
@Override public Input findForThisNodeOrGlobal(String nodeId, String id) throws NotFoundException { final List<BasicDBObject> forThisNodeOrGlobal = ImmutableList.of( new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId), new BasicDBObject(MessageInput.FIELD_GLOBAL, true)); final List<BasicDBObject> query = ImmutableList.of( new BasicDBObject(InputImpl.FIELD_ID, new ObjectId(id)), new BasicDBObject("$or", forThisNodeOrGlobal)); final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query)); return new InputImpl((ObjectId) o.get(InputImpl.FIELD_ID), o.toMap()); }
@Override public List<StreamRule> loadForStreamId(String streamId) { ObjectId id = new ObjectId(streamId); final List<StreamRule> streamRules = new ArrayList<>(); final List<DBObject> respStreamRules = query(StreamRuleImpl.class, new BasicDBObject(StreamRuleImpl.FIELD_STREAM_ID, id) ); for (DBObject streamRule : respStreamRules) { streamRules.add(toStreamRule(streamRule)); } return streamRules; }
private static Object translateValue(Object source, Type type) { if (source instanceof Slice) { if (type instanceof ObjectIdType) { return new ObjectId(((Slice) source).getBytes()); } else { return ((Slice) source).toStringUtf8(); } } return source; }
@Override public List<SystemMessage> all(int page) { List<SystemMessage> messages = Lists.newArrayList(); DBObject sort = new BasicDBObject(); sort.put("timestamp", -1); List<DBObject> results = query(SystemMessageImpl.class, new BasicDBObject(), sort, PER_PAGE, PER_PAGE * page); for (DBObject o : results) { messages.add(new SystemMessageImpl(new ObjectId(o.get("_id").toString()), o.toMap())); } return messages; }
public static CollectorActions create(String sidecar_id, DateTime created, List<CollectorAction> action) { return create( new org.bson.types.ObjectId().toHexString(), sidecar_id, created, action); } }
@Override public Role loadById(String roleId) throws NotFoundException { final Role role = dbCollection.findOneById(new ObjectId(roleId)); if (role == null) { throw new NotFoundException("No role found with id " + roleId); } return role; }
@Override public GrokPattern load(String patternId) throws NotFoundException { final GrokPattern pattern = dbCollection.findOneById(new ObjectId(patternId)); if (pattern == null) { throw new NotFoundException("Couldn't find Grok pattern with ID " + patternId); } return pattern; }
public Optional<LookupTableDto> get(String idOrName) { try { return Optional.ofNullable(db.findOneById(new ObjectId(idOrName))); } catch (IllegalArgumentException e) { // not an ObjectId, try again with name return Optional.ofNullable(db.findOne(DBQuery.is("name", idOrName))); } }
public Optional<IndexFieldTypesDTO> get(String idOrIndexName) { try { return Optional.ofNullable(db.findOneById(new ObjectId(idOrIndexName))); } catch (IllegalArgumentException e) { // Not an ObjectId, try again with index_name return Optional.ofNullable(db.findOne(DBQuery.is(IndexFieldTypesDTO.FIELD_INDEX_NAME, idOrIndexName))); } }
@Override public Stream load(String id) throws NotFoundException { try { return load(new ObjectId(id)); } catch (IllegalArgumentException e) { throw new NotFoundException("Stream <" + id + "> not found!"); } }
public Optional<CacheDto> get(String idOrName) { try { return Optional.ofNullable(db.findOneById(new ObjectId(idOrName))); } catch (IllegalArgumentException e) { // not an ObjectId, try again with name return Optional.ofNullable(db.findOne(DBQuery.is("name", idOrName))); } }
public static ConfigurationVariable create(String name, String description, String content) { return create(new org.bson.types.ObjectId().toHexString(), name, description, content); }
@Description("mongodb ObjectId") @ScalarFunction("objectid") @SqlType("ObjectId") public static Slice ObjectId() { return Slices.wrappedBuffer(new ObjectId().toByteArray()); }
@ScalarOperator(HASH_CODE) @SqlType(StandardTypes.BIGINT) public static long hashCode(@SqlType("ObjectId") Slice value) { return new ObjectId(value.getBytes()).hashCode(); }
public static AlertImpl fromCheckResult(AlertCondition.CheckResult checkResult) { return create(new org.bson.types.ObjectId().toHexString(), checkResult.getTriggeredCondition().getStream().getId(), checkResult.getTriggeredCondition().getId(), checkResult.getTriggeredAt(), null, checkResult.getResultDescription(), ImmutableMap.copyOf(checkResult.getTriggeredCondition().getParameters()), true); }
@Description("mongodb ObjectId from the given string") @ScalarFunction("objectid") @SqlType("ObjectId") public static Slice ObjectId(@SqlType(StandardTypes.VARCHAR) Slice value) { return Slices.wrappedBuffer(new ObjectId(CharMatcher.is(' ').removeFrom(value.toStringUtf8())).toByteArray()); }