@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"))); }
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()); }
/** * Returns a stream of database entries for the given {@link DBQuery.Query} sorted by the give {@link DBSort.SortBuilder}. * <p> * The returned stream needs to be closed to free the underlying database resources. * * @param query the query to execute * @param sort the sort order for the query * @return stream of database entries that match the query */ protected Stream<DTO> streamQueryWithSort(DBQuery.Query query, DBSort.SortBuilder sort) { final DBCursor<DTO> cursor = db.find(query).sort(sort); return Streams.stream((Iterable<DTO>) cursor).onClose(cursor::close); }
@Override public List<Alert> loadRecentOfStreams(List<String> streamIds, DateTime since, int limit) { if (streamIds == null || streamIds.isEmpty()) { return Collections.emptyList(); } final DateTime effectiveSince = (since == null ? new DateTime(0L, DateTimeZone.UTC) : since); final DBQuery.Query query = DBQuery.and( getFindAnyStreamQuery(streamIds), DBQuery.greaterThanEquals(AlertImpl.FIELD_TRIGGERED_AT, effectiveSince) ); return Collections.unmodifiableList(this.coll.find(query) .limit(limit) .sort(DBSort.desc(AlertImpl.FIELD_TRIGGERED_AT)) .toArray()); }
@Override public Optional<Alert> getLastTriggeredAlert(String streamId, String conditionId) { final List<AlertImpl> alert = this.coll.find( DBQuery.and( DBQuery.is(AlertImpl.FIELD_STREAM_ID, streamId), DBQuery.is(AlertImpl.FIELD_CONDITION_ID, conditionId) ) ) .sort(DBSort.desc(AlertImpl.FIELD_TRIGGERED_AT)) .limit(1) .toArray(); if (alert == null || alert.size() == 0) { return Optional.empty(); } return Optional.of(alert.get(0)); }
public PaginatedList<DataAdapterDto> findPaginated(DBQuery.Query query, DBSort.SortBuilder sort, int page, int perPage) { try (DBCursor<DataAdapterDto> cursor = db.find(query) .sort(sort) .limit(perPage) .skip(perPage * Math.max(0, page - 1))) { return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage); } }
public PaginatedList<LookupTableDto> findPaginated(DBQuery.Query query, DBSort.SortBuilder sort, int page, int perPage) { try (DBCursor<LookupTableDto> cursor = db.find(query) .sort(sort) .limit(perPage) .skip(perPage * Math.max(0, page - 1))) { return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage); } }
public PaginatedList<CacheDto> findPaginated(DBQuery.Query query, DBSort.SortBuilder sort, int page, int perPage) { try (DBCursor<CacheDto> cursor = db.find(query) .sort(sort) .limit(perPage) .skip(perPage * Math.max(0, page - 1))) { return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage); } }
@Override public List<Alert> listForStreamIds(List<String> streamIds, AlertState state, int skip, int limit) { if (streamIds == null || streamIds.isEmpty()) { return Collections.emptyList(); } DBQuery.Query query = getFindAnyStreamQuery(streamIds); if (state != null && state != AlertState.ANY) { query = DBQuery.and(query, getFindByStateQuery(state)); } return Collections.unmodifiableList(this.coll.find(query) .sort(DBSort.desc(AlertImpl.FIELD_TRIGGERED_AT)) .skip(skip) .limit(limit) .toArray()); }
/** * Returns a {@link PaginatedList<DTO>} for the given query and pagination parameters. * <p> * This method is only accessible by subclasses to avoid exposure of the {@link DBQuery} and {@link DBSort} * interfaces to consumers. * * @param query the query to execute * @param sort the sort builder for the query * @param page the page number that should be returned * @param perPage the number of entries per page * @return the paginated list */ protected PaginatedList<DTO> findPaginatedWithQueryAndSort(DBQuery.Query query, DBSort.SortBuilder sort, int page, int perPage) { try (final DBCursor<DTO> cursor = db.find(query) .sort(sort) .limit(perPage) .skip(perPage * Math.max(0, page - 1))) { return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage); } }
/** * {@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")); }
/** * {@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()); }
@Override public List<Statistics> getStatistics(GraphFilterBuilder filter, int limit) { DBObject matchFields = generateMatchFields(filter); DBCursor<Statistics> dbCursor = getJacksonStatisticsCollection().find(matchFields); BasicDBObject buildNumberDescending = new BasicDBObject("buildNumber", -1); dbCursor = dbCursor.sort(buildNumberDescending); if (limit > 0) { dbCursor = dbCursor.limit(limit); } return dbCursor.toArray(); }
public PaginatedList<DataAdapterDto> findPaginated(DBQuery.Query query, DBSort.SortBuilder sort, int page, int perPage) { final DBCursor<DataAdapterDto> cursor = db.find(query) .sort(sort) .limit(perPage) .skip(perPage * Math.max(0, page - 1)); return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage); }
public PaginatedList<LookupTableDto> findPaginated(DBQuery.Query query, DBSort.SortBuilder sort, int page, int perPage) { final DBCursor<LookupTableDto> cursor = db.find(query) .sort(sort) .limit(perPage) .skip(perPage * Math.max(0, page - 1)); return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage); }
public PaginatedList<CacheDto> findPaginated(DBQuery.Query query, DBSort.SortBuilder sort, int page, int perPage) { final DBCursor<CacheDto> cursor = db.find(query) .sort(sort) .limit(perPage) .skip(perPage * Math.max(0, page - 1)); return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage); }
@Override public List<Alert> listForStreamIds(List<String> streamIds, AlertState state, int skip, int limit) { if (streamIds == null || streamIds.isEmpty()) { return Collections.emptyList(); } DBQuery.Query query = getFindAnyStreamQuery(streamIds); if (state != null && state != AlertState.ANY) { query = DBQuery.and(query, getFindByStateQuery(state)); } return Collections.unmodifiableList(this.coll.find(query) .sort(DBSort.desc(AlertImpl.FIELD_TRIGGERED_AT)) .skip(skip) .limit(limit) .toArray()); }