org.mongojack.DBCursor - java examples

Here are the examples of the java api org.mongojack.DBCursor taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

57 Examples 7

19 View Complete Implementation : DBDataAdapterService.java
Copyright GNU General Public License v3.0
Author : Graylog2
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);
    }
}

19 View Complete Implementation : DBLookupTableService.java
Copyright GNU General Public License v3.0
Author : Graylog2
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);
    }
}

19 View Complete Implementation : SearchDbService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public PaginatedList<Search> findPaginated(DBQuery.Query search, DBSort.SortBuilder sort, int page, int perPage) {
    final DBCursor<Search> cursor = db.find(search).sort(sort).limit(perPage).skip(perPage * Math.max(0, page - 1));
    return new PaginatedList<>(Streams.stream((Iterable<Search>) cursor).map(this::requirementsForSearch).collect(Collectors.toList()), cursor.count(), page, perPage);
}

19 View Complete Implementation : DBCacheService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Collection<CacheDto> findAll() {
    try (DBCursor<CacheDto> cursor = db.find()) {
        return asImmutableList(cursor);
    }
}

19 View Complete Implementation : PaginatedDbService.java
Copyright GNU General Public License v3.0
Author : Graylog2
/**
 * Returns a {@link PaginatedList<DTO>} for the given query and pagination parameters.
 * <p>
 * This method is only accessible by subclreplacedes 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, 0 is unlimited
 * @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))) {
        final long grandTotal = db.count();
        return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage, grandTotal);
    }
}

19 View Complete Implementation : MongoDbRuleService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Collection<RuleDao> loadAll() {
    try (DBCursor<RuleDao> ruleDaos = dbCollection.find().sort(DBSort.asc("replacedle"))) {
        return ImmutableSet.copyOf((Iterable<RuleDao>) ruleDaos);
    } catch (MongoException e) {
        log.error("Unable to load processing rules", e);
        return Collections.emptySet();
    }
}

19 View Complete Implementation : DBDataAdapterService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Collection<DataAdapterDto> findAll() {
    try (DBCursor<DataAdapterDto> cursor = db.find()) {
        return asImmutableList(cursor);
    }
}

19 View Complete Implementation : DBNotificationGracePeriodService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public List<EventNotificationStatus> getAllStatuses() {
    List<EventNotificationStatus> result = new ArrayList<>();
    try (DBCursor<EventNotificationStatus> eventNotificationStatuses = db.find()) {
        for (EventNotificationStatus status : eventNotificationStatuses) {
            result.add(status);
        }
    }
    return result;
}

19 View Complete Implementation : DBLookupTableService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Collection<LookupTableDto> findByNames(Collection<String> names) {
    final DBQuery.Query query = DBQuery.in("name", names);
    final DBCursor<LookupTableDto> dbCursor = db.find(query);
    return asImmutableList(dbCursor);
}

19 View Complete Implementation : MongoDbPipelineService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Collection<PipelineDao> loadAll() {
    try {
        final DBCursor<PipelineDao> daos = dbCollection.find();
        return Sets.newHashSet(daos.iterator());
    } catch (MongoException e) {
        log.error("Unable to load pipelines", e);
        return Collections.emptySet();
    }
}

19 View Complete Implementation : DBCacheService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Collection<CacheDto> findByIds(Set<String> idSet) {
    final DBQuery.Query query = DBQuery.in("_id", idSet.stream().map(ObjectId::new).collect(Collectors.toList()));
    try (DBCursor<CacheDto> cursor = db.find(query)) {
        return asImmutableList(cursor);
    }
}

19 View Complete Implementation : PaginatedDbService.java
Copyright GNU General Public License v3.0
Author : Graylog2
/**
 * Returns an unordered stream of database entries for the given {@link DBQuery.Query}.
 * <p>
 * The returned stream needs to be closed to free the underlying database resources.
 *
 * @param query the query to execute
 * @return stream of database entries that match the query
 */
protected Stream<DTO> streamQuery(DBQuery.Query query) {
    final DBCursor<DTO> cursor = db.find(query);
    return Streams.stream((Iterable<DTO>) cursor).onClose(cursor::close);
}

19 View Complete Implementation : MongoDbPipelineStreamConnectionsService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Set<PipelineConnections> loadByPipelineId(String pipelineId) {
    // Thanks, MongoJack!
    // https://github.com/mongojack/mongojack/issues/12
    final DBObject query = new BasicDBObject("pipeline_ids", new BasicDBObject("$in", Collections.singleton(pipelineId)));
    try (DBCursor<PipelineConnections> pipelineConnections = dbCollection.find(query)) {
        return ImmutableSet.copyOf((Iterable<PipelineConnections>) pipelineConnections);
    } catch (MongoException e) {
        log.error("Unable to load pipeline connections for pipeline ID " + pipelineId, e);
        return Collections.emptySet();
    }
}

19 View Complete Implementation : DBCacheService.java
Copyright GNU General Public License v3.0
Author : Graylog2
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);
    }
}

19 View Complete Implementation : MongoDbRuleService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Collection<RuleDao> loadNamed(Collection<String> ruleNames) {
    try {
        final DBCursor<RuleDao> ruleDaos = dbCollection.find(DBQuery.in("replacedle", ruleNames));
        return Sets.newHashSet(ruleDaos.iterator());
    } catch (MongoException e) {
        log.error("Unable to bulk load rules", e);
        return Collections.emptySet();
    }
}

19 View Complete Implementation : DBDataAdapterService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Collection<DataAdapterDto> findByIds(Set<String> idSet) {
    final DBQuery.Query query = DBQuery.in("_id", idSet.stream().map(ObjectId::new).collect(Collectors.toList()));
    try (DBCursor<DataAdapterDto> cursor = db.find(query)) {
        return asImmutableList(cursor);
    }
}

19 View Complete Implementation : MongoDbRuleService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Collection<RuleDao> loadNamed(Collection<String> ruleNames) {
    try (DBCursor<RuleDao> ruleDaos = dbCollection.find(DBQuery.in("replacedle", ruleNames))) {
        return ImmutableSet.copyOf((Iterable<RuleDao>) ruleDaos);
    } catch (MongoException e) {
        log.error("Unable to bulk load rules", e);
        return Collections.emptySet();
    }
}

19 View Complete Implementation : DBLookupTableService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Collection<LookupTableDto> findByCacheIds(Collection<String> cacheIds) {
    final DBQuery.Query query = DBQuery.in("cache", cacheIds.stream().map(ObjectId::new).collect(Collectors.toList()));
    try (DBCursor<LookupTableDto> cursor = db.find(query)) {
        return asImmutableList(cursor);
    }
}

19 View Complete Implementation : MongoDbPipelineStreamConnectionsService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Set<PipelineConnections> loadAll() {
    try {
        final DBCursor<PipelineConnections> connections = dbCollection.find();
        return Sets.newHashSet(connections.iterator());
    } catch (MongoException e) {
        log.error("Unable to load pipeline connections", e);
        return Collections.emptySet();
    }
}

19 View Complete Implementation : DBLookupTableService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Collection<LookupTableDto> findByDataAdapterIds(Collection<String> dataAdapterIds) {
    final DBQuery.Query query = DBQuery.in("data_adapter", dataAdapterIds.stream().map(ObjectId::new).collect(Collectors.toList()));
    try (DBCursor<LookupTableDto> cursor = db.find(query)) {
        return asImmutableList(cursor);
    }
}

19 View Complete Implementation : AlarmCallbackConfigurationServiceImpl.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Map<String, Long> countPerType() {
    final HashMap<String, Long> result = Maps.newHashMap();
    try (DBCursor<AlarmCallbackConfigurationImpl> avs = coll.find()) {
        for (AlarmCallbackConfigurationImpl av : avs) {
            Long count = result.get(av.getType());
            if (count == null) {
                count = 0L;
            }
            result.put(av.getType(), count + 1);
        }
    }
    return result;
}

19 View Complete Implementation : RoleServiceImpl.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Set<Role> loadAll() throws NotFoundException {
    try (DBCursor<RoleImpl> rolesCursor = dbCollection.find()) {
        return ImmutableSet.copyOf((Iterable<? extends Role>) rolesCursor);
    }
}

19 View Complete Implementation : MongoDbRuleService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Collection<RuleDao> loadAll() {
    try {
        final DBCursor<RuleDao> ruleDaos = dbCollection.find().sort(DBSort.asc("replacedle"));
        return ruleDaos.toArray();
    } catch (MongoException e) {
        log.error("Unable to load processing rules", e);
        return Collections.emptySet();
    }
}

19 View Complete Implementation : MongoDbPipelineService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Collection<PipelineDao> loadAll() {
    try (DBCursor<PipelineDao> daos = dbCollection.find()) {
        return ImmutableSet.copyOf((Iterator<PipelineDao>) daos);
    } catch (MongoException e) {
        log.error("Unable to load pipelines", e);
        return Collections.emptySet();
    }
}

19 View Complete Implementation : MongoDbPipelineStreamConnectionsService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Set<PipelineConnections> loadAll() {
    try (DBCursor<PipelineConnections> connections = dbCollection.find()) {
        return ImmutableSet.copyOf((Iterable<PipelineConnections>) connections);
    } catch (MongoException e) {
        log.error("Unable to load pipeline connections", e);
        return Collections.emptySet();
    }
}

19 View Complete Implementation : PaginatedDbService.java
Copyright GNU General Public License v3.0
Author : Graylog2
/**
 * 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);
}

18 View Complete Implementation : AlarmCallbackConfigurationServiceImpl.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public List<AlarmCallbackConfiguration> getForStreamId(String streamId) {
    try (DBCursor<AlarmCallbackConfigurationImpl> dbCursor = coll.find(DBQuery.is("stream_id", streamId))) {
        return ImmutableList.copyOf((Iterable<AlarmCallbackConfigurationImpl>) dbCursor);
    }
}

18 View Complete Implementation : ContentPackInstallationPersistenceService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Set<ContentPackInstallation> loadAll() {
    try (final DBCursor<ContentPackInstallation> installations = dbCollection.find()) {
        return ImmutableSet.copyOf((Iterator<ContentPackInstallation>) installations);
    }
}

18 View Complete Implementation : ContentPackPersistenceService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Set<ContentPack> loadAll() {
    final DBCursor<ContentPack> contentPacks = dbCollection.find();
    return ImmutableSet.copyOf((Iterable<ContentPack>) contentPacks);
}

18 View Complete Implementation : DBLookupTableService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public void forEach(Consumer<? super LookupTableDto> action) {
    try (DBCursor<LookupTableDto> dbCursor = db.find()) {
        dbCursor.forEachRemaining(action);
    }
}

18 View Complete Implementation : TrafficCounterService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public TrafficHistogram clusterTrafficOfLastDays(Duration duration, Interval interval) {
    final ImmutableMap.Builder<DateTime, Long> inputBuilder = ImmutableMap.builder();
    final ImmutableMap.Builder<DateTime, Long> outputBuilder = ImmutableMap.builder();
    final ImmutableMap.Builder<DateTime, Long> decodedBuilder = ImmutableMap.builder();
    final DateTime to = getDayBucket(Tools.nowUTC());
    final DateTime from = to.minus(duration);
    final DBQuery.Query query = DBQuery.and(DBQuery.lessThanEquals(BUCKET, to), DBQuery.greaterThan(BUCKET, from));
    try (DBCursor<TrafficDto> cursor = db.find(query)) {
        cursor.forEach(trafficDto -> {
            inputBuilder.put(trafficDto.bucket(), trafficDto.input().values().stream().mapToLong(Long::valueOf).sum());
            outputBuilder.put(trafficDto.bucket(), trafficDto.output().values().stream().mapToLong(Long::valueOf).sum());
            decodedBuilder.put(trafficDto.bucket(), trafficDto.decoded().values().stream().mapToLong(Long::valueOf).sum());
        });
        Map<DateTime, Long> inputHistogram = inputBuilder.build();
        Map<DateTime, Long> outputHistogram = outputBuilder.build();
        Map<DateTime, Long> decodedHistogram = decodedBuilder.build();
        // we might need to aggregate the hourly database values to their UTC daily buckets
        if (interval == Interval.DAILY) {
            inputHistogram = aggregateToDaily(inputHistogram);
            outputHistogram = aggregateToDaily(outputHistogram);
            decodedHistogram = aggregateToDaily(decodedHistogram);
        }
        return TrafficHistogram.create(from, to, inputHistogram, outputHistogram, decodedHistogram);
    }
}

17 View Complete Implementation : FreemarkerRenderer.java
Copyright GNU General Public License v3.0
Author : 20n
public PathwayDoc generatePathDoc(Reachable target, ReactionPath path, File pathDestination, File sequenceDestination) throws IOException, TemplateException {
    DBCursor<ReactionPath> cursor = Cascade.get_pathway_collection().find(new BasicDBObject("target", target.getId()));
    String sourceDocName = makeSourceDocName(target);
    if (sourceDocName == null) {
        LOGGER.error("Target %d does not have inchiKey", path.getTarget());
        return null;
    }
    String pathwayDocName = String.format("Pathway_%s_%d", sourceDocName, path.getRank());
    List<DnaDesignTableProperties> designDocsAndSummaries = path.getDnaDesignRef() != null ? renderSequences(sequenceDestination, pathwayDocName, path.getDnaDesignRef()) : Collections.emptyList();
    Pair<Object, String> model = buildPathModel(path, designDocsAndSummaries);
    if (model != null) {
        pathwayTemplate.process(model.getLeft(), new FileWriter(new File(pathDestination, pathwayDocName)));
    }
    return new PathwayDoc(pathwayDocName, model.getRight(), designDocsAndSummaries != null && designDocsAndSummaries.size() > 0);
}

17 View Complete Implementation : DashboardsService.java
Copyright GNU General Public License v3.0
Author : Graylog2
Stream<Dashboard> streamAll() {
    final DBCursor<Dashboard> cursor = db.find(DBQuery.empty());
    return Streams.stream((Iterable<Dashboard>) cursor).onClose(cursor::close);
}

17 View Complete Implementation : ContentPackInstallationPersistenceService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Set<ContentPackInstallation> findByContentPackIds(Set<ModelId> ids) {
    final Set<String> stringIds = ids.stream().map(x -> x.toString()).collect(Collectors.toSet());
    final DBObject query = BasicDBObjectBuilder.start().push(ContentPackInstallation.FIELD_CONTENT_PACK_ID).append("$in", stringIds).get();
    final DBCursor<ContentPackInstallation> result = dbCollection.find(query);
    return ImmutableSet.copyOf((Iterable<ContentPackInstallation>) result);
}

17 View Complete Implementation : MongoDbGrokPatternService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Set<GrokPattern> loadAll() {
    try (DBCursor<GrokPattern> grokPatterns = dbCollection.find()) {
        return ImmutableSet.copyOf((Iterator<GrokPattern>) grokPatterns);
    }
}

17 View Complete Implementation : MongoDbGrokPatternService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Set<GrokPattern> bulkLoad(Collection<String> patternIds) {
    final DBCursor<GrokPattern> dbCursor = dbCollection.find(DBQuery.in("_id", patternIds));
    return ImmutableSet.copyOf((Iterator<GrokPattern>) dbCursor);
}

16 View Complete Implementation : SavedSearchService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Stream<SavedSearch> streamAll() {
    final DBCursor<SavedSearch> cursor = db.find(DBQuery.empty());
    return Streams.stream(cursor.iterator()).onClose(cursor::close);
}

16 View Complete Implementation : ContentPackInstallationPersistenceService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Set<ContentPackInstallation> findByContentPackId(ModelId id) {
    final DBQuery.Query query = DBQuery.is(ContentPackInstallation.FIELD_CONTENT_PACK_ID, id);
    try (final DBCursor<ContentPackInstallation> installations = dbCollection.find(query)) {
        return ImmutableSet.copyOf((Iterator<ContentPackInstallation>) installations);
    }
}

16 View Complete Implementation : ContentPackPersistenceService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Set<ContentPack> findAllById(ModelId id) {
    final DBCursor<ContentPack> result = dbCollection.find(DBQuery.is(Identified.FIELD_META_ID, id));
    return ImmutableSet.copyOf((Iterable<ContentPack>) result);
}

16 View Complete Implementation : MongoDBKnowledgeBase.java
Copyright MIT License
Author : jenkinsci
@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();
}

15 View Complete Implementation : FreemarkerRenderer.java
Copyright GNU General Public License v3.0
Author : 20n
public void generatePages(List<Long> idsToRender) throws IOException, TemplateException {
    // Limit iteration to only molecules we care about if any are specified.
    DBCursor<ReactionPath> cascadeCursor = idsToRender == null || idsToRender.size() == 0 ? Cascade.get_pathway_collection().find() : Cascade.get_pathway_collection().find(DBQuery.in("target", idsToRender));
    int i = 0;
    while (cascadeCursor.hasNext()) {
        // Hacked cursor munging to only consider targets of pathways.
        ReactionPath thisPath = cascadeCursor.next();
        Reachable r = getReachable(thisPath.getTarget());
        /* Don't generate any pathway pages if we're instructed to skip pathways.  We still have to make sure the
       * Reachable objects are constructed, however, so allow the loop to progress to this point before continuing. */
        if (this.hidePathways) {
            continue;
        }
        String inchiKey = r.getInchiKey();
        if (inchiKey != null) {
            PathwayDoc pathwayDoc = generatePathDoc(r, thisPath, this.pathsDest, this.seqsDest);
            List<PathwayDoc> attributions = completedPathways.get(thisPath.getTarget());
            if (attributions == null) {
                attributions = new ArrayList<>();
                completedPathways.put(thisPath.getTarget(), attributions);
            }
            attributions.add(pathwayDoc);
            i++;
            if (i % 100 == 0) {
                LOGGER.info("Completed %d pathways", i);
            }
        } else {
            LOGGER.error("page does not have an inchiKey");
        }
    }
    LOGGER.info("Done generating pathway pages, moving on to reachables");
    // No iterate over all the reachable doreplacedents we've created and generate pages for each using our pathway links.
    DBCursor<Reachable> reachableCursor = idsToRender == null || idsToRender.size() == 0 ? loader.getJacksonReachablesCollection().find() : loader.getJacksonReachablesCollection().find(DBQuery.in("_id", idsToRender));
    i = 0;
    while (reachableCursor.hasNext()) {
        Reachable r = reachableCursor.next();
        if (r.getInchiKey() == null || r.getInchiKey().isEmpty()) {
            LOGGER.error("Found reachable %d with no InChI key--skipping", r.getId());
            continue;
        }
        try (Writer w = new PrintWriter(new File(this.reachablesDest, r.getInchiKey()))) {
            List<PathwayDoc> pathwayDocs = completedPathways.getOrDefault(r.getId(), new ArrayList<>());
            Object model = buildReachableModel(r, pathwayDocs);
            reachableTemplate.process(model, w);
        }
        i++;
        if (i % 100 == 0) {
            LOGGER.info("Completed %d reachables", i);
        }
    }
    LOGGER.info("Page generation complete");
}

15 View Complete Implementation : DBJobTriggerService.java
Copyright GNU General Public License v3.0
Author : Graylog2
/**
 * Returns all job triggers for the given job definition ID.
 *
 * TODO: Don't throw exception when there is more than one trigger for a job definition.
 *       To be able to do this, we need some kind of label system to make sure we can differentiate between
 *       automatically created triggers (e.g. by event definition) and manually created ones.
 *
 * @param jobDefinitionId the job definition ID
 * @return list of found job triggers
 */
public List<JobTriggerDto> getForJob(String jobDefinitionId) {
    if (isNullOrEmpty(jobDefinitionId)) {
        throw new IllegalArgumentException("jobDefinitionId cannot be null or empty");
    }
    final DBQuery.Query query = DBQuery.is(FIELD_JOB_DEFINITION_ID, jobDefinitionId);
    try (final DBCursor<JobTriggerDto> cursor = db.find(query)) {
        final ImmutableList<JobTriggerDto> triggers = ImmutableList.copyOf(cursor.iterator());
        // We are currently expecting only one trigger per job definition. This will most probably change in the
        // future once we extend our scheduler usage.
        if (triggers.size() > 1) {
            throw new IllegalStateException("More than one trigger for job definition <" + jobDefinitionId + ">");
        }
        return triggers;
    }
}

15 View Complete Implementation : ClusterConfigServiceImpl.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public Set<Clreplaced<?>> list() {
    final ImmutableSet.Builder<Clreplaced<?>> clreplacedes = ImmutableSet.builder();
    try (DBCursor<ClusterConfig> clusterConfigs = dbCollection.find()) {
        for (ClusterConfig clusterConfig : clusterConfigs) {
            final String type = clusterConfig.type();
            try {
                final Clreplaced<?> cls = chainingClreplacedLoader.loadClreplaced(type);
                clreplacedes.add(cls);
            } catch (ClreplacedNotFoundException e) {
                LOG.debug("Couldn't find configuration clreplaced \"{}\"", type, e);
            }
        }
    }
    return clreplacedes.build();
}

15 View Complete Implementation : ContentPackInstallationPersistenceService.java
Copyright GNU General Public License v3.0
Author : Graylog2
public Set<ContentPackInstallation> findByContentPackIdAndRevision(ModelId id, int revision) {
    final DBQuery.Query query = DBQuery.is(ContentPackInstallation.FIELD_CONTENT_PACK_ID, id).is(ContentPackInstallation.FIELD_CONTENT_PACK_REVISION, revision);
    try (final DBCursor<ContentPackInstallation> installations = dbCollection.find(query)) {
        return ImmutableSet.copyOf((Iterator<ContentPackInstallation>) installations);
    }
}

15 View Complete Implementation : ClusterEventPeriodical.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public void doRun() {
    LOG.debug("Opening MongoDB cursor on \"{}\"", COLLECTION_NAME);
    try (DBCursor<ClusterEvent> cursor = eventCursor(nodeId)) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("MongoDB query plan: {}", cursor.explain());
        }
        while (cursor.hasNext()) {
            ClusterEvent clusterEvent = cursor.next();
            LOG.trace("Processing cluster event: {}", clusterEvent);
            Object payload = extractPayload(clusterEvent.payload(), clusterEvent.eventClreplaced());
            if (payload != null) {
                serverEventBus.post(payload);
            } else {
                LOG.warn("Couldn't extract payload of cluster event with ID <{}>", clusterEvent.id());
                LOG.debug("Invalid payload in cluster event: {}", clusterEvent);
            }
            updateConsumers(clusterEvent.id(), nodeId);
        }
    } catch (Exception e) {
        LOG.warn("Error while reading cluster events from MongoDB, retrying.", e);
    }
}

15 View Complete Implementation : MongoDBKnowledgeBase.java
Copyright MIT License
Author : jenkinsci
/**
 * @see KnowledgeBase#getCauseNames()
 * Can throw MongoException if unknown fields exist in the database.
 * @return the full list of the names and ids of the causes..
 */
@Override
public Collection<FailureCause> getCauseNames() {
    List<FailureCause> list = new LinkedList<FailureCause>();
    DBObject keys = new BasicDBObject();
    keys.put("name", 1);
    DBCursor<FailureCause> dbCauses = getJacksonCollection().find(NOT_REMOVED_QUERY, keys);
    while (dbCauses.hasNext()) {
        list.add(dbCauses.next());
    }
    return list;
}

15 View Complete Implementation : MongoDBKnowledgeBase.java
Copyright MIT License
Author : jenkinsci
@Override
public Collection<FailureCause> getShallowCauses() {
    List<FailureCause> list = new LinkedList<>();
    DBObject keys = new BasicDBObject();
    keys.put("name", 1);
    keys.put("description", 1);
    keys.put("categories", 1);
    keys.put("comment", 1);
    keys.put("modifications", 1);
    keys.put("lastOccurred", 1);
    BasicDBObject orderBy = new BasicDBObject("name", 1);
    DBCursor<FailureCause> dbCauses = getJacksonCollection().find(NOT_REMOVED_QUERY, keys);
    dbCauses = dbCauses.sort(orderBy);
    while (dbCauses.hasNext()) {
        list.add(dbCauses.next());
    }
    return list;
}

14 View Complete Implementation : WikiWebServicesExporter.java
Copyright GNU General Public License v3.0
Author : 20n
public static void main(String[] args) throws Exception {
    CLIUtil cliUtil = new CLIUtil(WikiWebServicesExporter.clreplaced, HELP_MESSAGE, OPTION_BUILDERS);
    CommandLine cl = cliUtil.parseCommandLine(args);
    String host = cl.getOptionValue(OPTION_INPUT_DB_HOST, DEFAULT_HOST);
    Integer port = Integer.parseInt(cl.getOptionValue(OPTION_INPUT_DB_PORT, DEFAULT_PORT));
    String dbName = cl.getOptionValue(OPTION_INPUT_DB, DEFAULT_DB);
    String collection = cl.getOptionValue(OPTION_INPUT_DB_COLLECTION, DEFAULT_COLLECTION);
    String sequenceCollection = cl.getOptionValue(OPTION_INPUT_SEQUENCE_COLLECTION, DEFAULT_SEQUENCES_COLLECTION);
    LOGGER.info("Attempting to connect to DB %s:%d/%s, collection %s", host, port, dbName, collection);
    Loader loader = new Loader(host, port, UNUSED_SOURCE_DB, dbName, collection, sequenceCollection, DEFAULT_RENDERING_CACHE);
    JacksonDBCollection<Reachable, String> reachables = loader.getJacksonReachablesCollection();
    LOGGER.info("Connected to DB, reading reachables");
    List<Long> exportIds = !cl.hasOption(OPTION_EXPORT_SOME) ? Collections.emptyList() : Arrays.stream(cl.getOptionValues(OPTION_EXPORT_SOME)).map(Long::valueOf).collect(Collectors.toList());
    TSVWriter<String, String> tsvWriter = new TSVWriter<>(HEADER);
    tsvWriter.open(new File(cl.getOptionValue(OPTION_OUTPUT_FILE)));
    try {
        DBCursor<Reachable> cursor = exportIds.isEmpty() ? reachables.find() : reachables.find(DBQuery.in("_id", exportIds));
        int written = 0;
        while (cursor.hasNext()) {
            final Reachable r = cursor.next();
            Map<String, String> row = new HashMap<String, String>() {

                {
                    put("inchi", r.getInchi());
                    put("inchi_key", r.getInchiKey());
                    put("display_name", r.getPageName());
                    put("image_name", r.getStructureFilename());
                }
            };
            tsvWriter.append(row);
            tsvWriter.flush();
            written++;
        }
        LOGGER.info("Wrote %d reachables to output TSV", written);
    } finally {
        tsvWriter.close();
    }
}

14 View Complete Implementation : MongoIndexRangeService.java
Copyright GNU General Public License v3.0
Author : Graylog2
@Override
public SortedSet<IndexRange> findAll() {
    try (DBCursor<MongoIndexRange> cursor = collection.find(DBQuery.notExists("start"))) {
        return ImmutableSortedSet.copyOf(IndexRange.COMPARATOR, (Iterator<? extends IndexRange>) cursor);
    }
}

12 View Complete Implementation : CollectionIdsResource.java
Copyright Apache License 2.0
Author : eeb
@GET
public List<MongoDoreplacedent> fetch(@PathParam("collection") String collection) {
    final JacksonDBCollection<MongoDoreplacedent, String> coll = JacksonDBCollection.wrap(mongoDB.getCollection(collection), MongoDoreplacedent.clreplaced, String.clreplaced);
    final DBCursor<MongoDoreplacedent> cursor = coll.find();
    final List<MongoDoreplacedent> l = new ArrayList<>();
    try {
        while (cursor.hasNext()) {
            l.add(cursor.next());
        }
    } finally {
        cursor.close();
    }
    return l;
}