/** * 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; } }
@Inject public SystemMessageServiceImpl(MongoConnection mongoConnection) { super(mongoConnection); final DBCollection collection = this.collection(SystemMessageImpl.class); collection.createIndex(DBSort.desc("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)); }
sortBuilder = DBSort.desc(sort); } else { sortBuilder = DBSort.asc(sort);
sortBuilder = DBSort.desc(sort); } else { sortBuilder = DBSort.asc(sort);
@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()); }
sortBuilder = DBSort.desc(sort); } else { sortBuilder = DBSort.asc(sort);
@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)); }
@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()); }
@Inject public SystemMessageServiceImpl(MongoConnection mongoConnection) { super(mongoConnection); final DBCollection collection = this.collection(SystemMessageImpl.class); collection.createIndex(DBSort.desc("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)); }
sortBuilder = DBSort.desc(sort); } else { sortBuilder = DBSort.asc(sort);
sortBuilder = DBSort.desc(sort); } else { sortBuilder = DBSort.asc(sort);
sortBuilder = DBSort.desc(sort); } else { sortBuilder = DBSort.asc(sort);
@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)); }
@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()); }