/** * Returns a sort builder for the given order and field name. * * @param order the order. either "asc" or "desc" * @param field the field to sort on * @return the sort builder */ protected DBSort.SortBuilder getSortBuilder(String order, String field) { DBSort.SortBuilder sortBuilder; if ("desc".equalsIgnoreCase(order)) { sortBuilder = DBSort.desc(field); } else { sortBuilder = DBSort.asc(field); } return sortBuilder; } }
@Override public Collection<RuleDao> loadAll() { try(DBCursor<RuleDao> ruleDaos = dbCollection.find().sort(DBSort.asc("title"))) { return ImmutableSet.copyOf((Iterable<RuleDao>) ruleDaos); } catch (MongoException e) { log.error("Unable to load processing rules", e); return Collections.emptySet(); } }
/** * {@inheritDoc} */ @Override public List<IndexSetConfig> findAll() { return ImmutableList.copyOf((Iterator<? extends IndexSetConfig>) collection.find().sort(DBSort.asc("title"))); }
@VisibleForTesting protected MongoIndexSetService(JacksonDBCollection<IndexSetConfig, ObjectId> collection, StreamService streamService, ClusterConfigService clusterConfigService, ClusterEventBus clusterEventBus) { this.collection = requireNonNull(collection); this.streamService = streamService; this.clusterConfigService = clusterConfigService; this.clusterEventBus = requireNonNull(clusterEventBus); this.collection.getDbCollection().createIndex(DBSort.asc(IndexSetConfig.FIELD_INDEX_PREFIX), null, true); this.collection.getDbCollection().createIndex(DBSort.desc(IndexSetConfig.FIELD_CREATION_DATE)); }
private DBCursor<ClusterEvent> eventCursor(NodeId nodeId) { // Resorting to ugly MongoDB Java Client because of https://github.com/devbliss/mongojack/issues/88 final BasicDBList consumersList = new BasicDBList(); consumersList.add(nodeId.toString()); final DBObject query = new BasicDBObject("consumers", new BasicDBObject("$nin", consumersList)); return dbCollection.find(query).sort(DBSort.asc("timestamp")); }
/** * {@inheritDoc} */ @Override public List<IndexSetConfig> findPaginated(Set<String> indexSetIds, int limit, int skip) { final List<DBQuery.Query> idQuery = indexSetIds.stream() .map(id -> DBQuery.is("_id", id)) .collect(Collectors.toList()); final DBQuery.Query query = DBQuery.or(idQuery.toArray(new DBQuery.Query[0])); return ImmutableList.copyOf(collection.find(query) .sort(DBSort.asc("title")) .skip(skip) .limit(limit) .toArray()); }
@Inject public MongoDbPipelineService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, ClusterEventBus clusterBus) { this.dbCollection = JacksonDBCollection.wrap( mongoConnection.getDatabase().getCollection(COLLECTION), PipelineDao.class, String.class, mapper.get()); this.clusterBus = clusterBus; dbCollection.createIndex(DBSort.asc("title"), new BasicDBObject("unique", true)); }
@Inject public MongoDbPipelineStreamConnectionsService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, ClusterEventBus clusterBus) { this.dbCollection = JacksonDBCollection.wrap( mongoConnection.getDatabase().getCollection(COLLECTION), PipelineConnections.class, String.class, mapper.get()); this.clusterBus = clusterBus; dbCollection.createIndex(DBSort.asc("stream_id"), new BasicDBObject("unique", true)); }
sortBuilder = DBSort.desc(sort); } else { sortBuilder = DBSort.asc(sort);
sortBuilder = DBSort.desc(sort); } else { sortBuilder = DBSort.asc(sort);
@VisibleForTesting static DBCollection prepareCollection(final MongoConnection mongoConnection) { DBCollection coll = mongoConnection.getDatabase().getCollection(COLLECTION_NAME); coll.createIndex(DBSort.asc("type"), "unique_type", true); coll.setWriteConcern(WriteConcern.JOURNALED); return coll; }
@Inject public MongoDbRuleService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, ClusterEventBus clusterBus) { this.dbCollection = JacksonDBCollection.wrap( mongoConnection.getDatabase().getCollection(COLLECTION), RuleDao.class, String.class, mapper.get()); this.clusterBus = clusterBus; dbCollection.createIndex(DBSort.asc("title"), new BasicDBObject("unique", true)); }
sortBuilder = DBSort.desc(sort); } else { sortBuilder = DBSort.asc(sort);
@VisibleForTesting static DBCollection prepareCollection(final MongoConnection mongoConnection) { final DB db = mongoConnection.getDatabase(); DBCollection coll = db.getCollection(COLLECTION_NAME); coll.createIndex(DBSort .asc("timestamp") .asc("producer") .asc("consumers")); coll.setWriteConcern(WriteConcern.JOURNALED); return coll; }
/** * {@inheritDoc} */ @Override public List<IndexSetConfig> findAll() { return ImmutableList.copyOf((Iterator<? extends IndexSetConfig>) collection.find().sort(DBSort.asc("title"))); }
private DBCursor<ClusterEvent> eventCursor(NodeId nodeId) { // Resorting to ugly MongoDB Java Client because of https://github.com/devbliss/mongojack/issues/88 final BasicDBList consumersList = new BasicDBList(); consumersList.add(nodeId.toString()); final DBObject query = new BasicDBObject("consumers", new BasicDBObject("$nin", consumersList)); return dbCollection.find(query).sort(DBSort.asc("timestamp")); }
@VisibleForTesting protected MongoIndexSetService(JacksonDBCollection<IndexSetConfig, ObjectId> collection, StreamService streamService, ClusterConfigService clusterConfigService, ClusterEventBus clusterEventBus) { this.collection = requireNonNull(collection); this.streamService = streamService; this.clusterConfigService = clusterConfigService; this.clusterEventBus = requireNonNull(clusterEventBus); this.collection.getDbCollection().createIndex(DBSort.asc(IndexSetConfig.FIELD_INDEX_PREFIX), null, true); this.collection.getDbCollection().createIndex(DBSort.desc(IndexSetConfig.FIELD_CREATION_DATE)); }
/** * {@inheritDoc} */ @Override public List<IndexSetConfig> findPaginated(Set<String> indexSetIds, int limit, int skip) { final List<DBQuery.Query> idQuery = indexSetIds.stream() .map(id -> DBQuery.is("_id", id)) .collect(Collectors.toList()); final DBQuery.Query query = DBQuery.or(idQuery.toArray(new DBQuery.Query[0])); return ImmutableList.copyOf(collection.find(query) .sort(DBSort.asc("title")) .skip(skip) .limit(limit) .toArray()); }
@VisibleForTesting static DBCollection prepareCollection(final MongoConnection mongoConnection) { DBCollection coll = mongoConnection.getDatabase().getCollection(COLLECTION_NAME); coll.createIndex(DBSort.asc("type"), "unique_type", true); coll.setWriteConcern(WriteConcern.JOURNALED); return coll; }
@VisibleForTesting static DBCollection prepareCollection(final MongoConnection mongoConnection) { final DB db = mongoConnection.getDatabase(); DBCollection coll = db.getCollection(COLLECTION_NAME); coll.createIndex(DBSort .asc("timestamp") .asc("producer") .asc("consumers")); coll.setWriteConcern(WriteConcern.JOURNALED); return coll; }