@SuppressWarnings("deprecation") private <TResult> FindOperation<TResult> createFindOperation(final MongoNamespace findNamespace, final Bson filter, final Class<TResult> resultClass, final FindOptions options) { return new FindOperation<TResult>(findNamespace, codecRegistry.get(resultClass)) .filter(filter == null ? new BsonDocument() : filter.toBsonDocument(documentClass, codecRegistry)) .batchSize(options.getBatchSize()) .skip(options.getSkip()) .limit(options.getLimit()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .maxAwaitTime(options.getMaxAwaitTime(MILLISECONDS), MILLISECONDS) .modifiers(toBsonDocumentOrNull(options.getModifiers())) .projection(toBsonDocumentOrNull(options.getProjection())) .sort(toBsonDocumentOrNull(options.getSort())) .cursorType(options.getCursorType()) .noCursorTimeout(options.isNoCursorTimeout()) .oplogReplay(options.isOplogReplay()) .partial(options.isPartial()) .slaveOk(readPreference.isSlaveOk()) .collation(options.getCollation()) .comment(options.getComment()) .hint(toBsonDocumentOrNull(options.getHint())) .min(toBsonDocumentOrNull(options.getMin())) .max(toBsonDocumentOrNull(options.getMax())) .maxScan(options.getMaxScan()) .returnKey(options.isReturnKey()) .showRecordId(options.isShowRecordId()) .snapshot(options.isSnapshot()); }
private FindOperation<BsonDocument> createExplainableQueryOperation() { FindOperation<BsonDocument> explainFindOperation = new FindOperation<BsonDocument>(namespace, new BsonDocumentCodec()); BsonDocument explainModifiers = new BsonDocument(); if (modifiers != null) { explainModifiers.putAll(modifiers); } explainModifiers.append("$explain", BsonBoolean.TRUE); return explainFindOperation.filter(filter) .projection(projection) .sort(sort) .skip(skip) .limit(Math.abs(limit) * -1) .hint(hint) .min(min) .max(max) .modifiers(explainModifiers); }
/** * Checks if there is another object available. * * <p><em>Note</em>: Automatically adds the {@link Bytes#QUERYOPTION_AWAITDATA} option to any cursors with the * {@link Bytes#QUERYOPTION_TAILABLE} option set. For non blocking tailable cursors see {@link #tryNext }.</p> * * @return true if there is another object available * @mongodb.driver.manual /core/cursors/#cursor-batches Cursor Batches */ @Override public boolean hasNext() { if (closed) { throw new IllegalStateException("Cursor has been closed"); } if (cursor == null) { FindOperation<DBObject> operation = getQueryOperation(decoder); if (operation.getCursorType() == CursorType.Tailable) { operation.cursorType(CursorType.TailableAwait); } initializeCursor(operation); } boolean hasNext = cursor.hasNext(); setServerCursorOnFinalizer(cursor.getServerCursor()); return hasNext; }
private FindOperation<BsonDocument> createExplainableQueryOperation() { FindOperation<BsonDocument> explainFindOperation = new FindOperation<BsonDocument>(namespace, new BsonDocumentCodec()); BsonDocument explainModifiers = new BsonDocument(); if (modifiers != null) { explainModifiers.putAll(modifiers); } explainModifiers.append("$explain", BsonBoolean.TRUE); return explainFindOperation.filter(filter) .projection(projection) .sort(sort) .skip(skip) .limit(Math.abs(limit) * -1) .hint(hint) .min(min) .max(max) .modifiers(explainModifiers); }
/** * Checks if there is another object available. * * <p><em>Note</em>: Automatically adds the {@link Bytes#QUERYOPTION_AWAITDATA} option to any cursors with the * {@link Bytes#QUERYOPTION_TAILABLE} option set. For non blocking tailable cursors see {@link #tryNext }.</p> * * @return true if there is another object available * @mongodb.driver.manual /core/cursors/#cursor-batches Cursor Batches */ @Override public boolean hasNext() { if (closed) { throw new IllegalStateException("Cursor has been closed"); } if (cursor == null) { FindOperation<DBObject> operation = getQueryOperation(decoder); if (operation.getCursorType() == CursorType.Tailable) { operation.cursorType(CursorType.TailableAwait); } initializeCursor(operation); } boolean hasNext = cursor.hasNext(); setServerCursorOnFinalizer(cursor.getServerCursor()); return hasNext; }
@SuppressWarnings("deprecation") private FindOperation<DBObject> getQueryOperation(final Decoder<DBObject> decoder) { FindOperation<DBObject> operation = new FindOperation<DBObject>(collection.getNamespace(), decoder) .filter(collection.wrapAllowNull(filter)) .batchSize(findOptions.getBatchSize()) .skip(findOptions.getSkip()) .limit(findOptions.getLimit()) .maxAwaitTime(findOptions.getMaxAwaitTime(MILLISECONDS), MILLISECONDS) .maxTime(findOptions.getMaxTime(MILLISECONDS), MILLISECONDS) .modifiers(collection.wrapAllowNull(findOptions.getModifiers())) .projection(collection.wrapAllowNull(findOptions.getProjection())) .sort(collection.wrapAllowNull(findOptions.getSort())) .collation(findOptions.getCollation()) .comment(findOptions.getComment()) .hint(collection.wrapAllowNull(findOptions.getHint())) .min(collection.wrapAllowNull(findOptions.getMin())) .max(collection.wrapAllowNull(findOptions.getMax())) .returnKey(findOptions.isReturnKey()) .showRecordId(findOptions.isShowRecordId()); operation.cursorType(CursorType.TailableAwait); } else { operation.cursorType(CursorType.Tailable); operation.cursorType(findOptions.getCursorType()); operation.oplogReplay(true); } else { operation.oplogReplay(findOptions.isOplogReplay());
@SuppressWarnings("deprecation") private <TResult> FindOperation<TResult> createFindOperation(final MongoNamespace findNamespace, final Bson filter, final Class<TResult> resultClass, final FindOptions options) { return new FindOperation<TResult>(findNamespace, codecRegistry.get(resultClass)) .filter(filter == null ? new BsonDocument() : filter.toBsonDocument(documentClass, codecRegistry)) .batchSize(options.getBatchSize()) .skip(options.getSkip()) .limit(options.getLimit()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .maxAwaitTime(options.getMaxAwaitTime(MILLISECONDS), MILLISECONDS) .modifiers(toBsonDocumentOrNull(options.getModifiers())) .projection(toBsonDocumentOrNull(options.getProjection())) .sort(toBsonDocumentOrNull(options.getSort())) .cursorType(options.getCursorType()) .noCursorTimeout(options.isNoCursorTimeout()) .oplogReplay(options.isOplogReplay()) .partial(options.isPartial()) .slaveOk(readPreference.isSlaveOk()) .collation(options.getCollation()) .comment(options.getComment()) .hint(toBsonDocumentOrNull(options.getHint())) .min(toBsonDocumentOrNull(options.getMin())) .max(toBsonDocumentOrNull(options.getMax())) .maxScan(options.getMaxScan()) .returnKey(options.isReturnKey()) .showRecordId(options.isShowRecordId()) .snapshot(options.isSnapshot()); }
@SuppressWarnings("deprecation") private FindOperation<DBObject> getQueryOperation(final Decoder<DBObject> decoder) { FindOperation<DBObject> operation = new FindOperation<DBObject>(collection.getNamespace(), decoder) .filter(collection.wrapAllowNull(filter)) .batchSize(findOptions.getBatchSize()) .skip(findOptions.getSkip()) .limit(findOptions.getLimit()) .maxAwaitTime(findOptions.getMaxAwaitTime(MILLISECONDS), MILLISECONDS) .maxTime(findOptions.getMaxTime(MILLISECONDS), MILLISECONDS) .modifiers(collection.wrapAllowNull(findOptions.getModifiers())) .projection(collection.wrapAllowNull(findOptions.getProjection())) .sort(collection.wrapAllowNull(findOptions.getSort())) .collation(findOptions.getCollation()) .comment(findOptions.getComment()) .hint(collection.wrapAllowNull(findOptions.getHint())) .min(collection.wrapAllowNull(findOptions.getMin())) .max(collection.wrapAllowNull(findOptions.getMax())) .returnKey(findOptions.isReturnKey()) .showRecordId(findOptions.isShowRecordId()); operation.cursorType(CursorType.TailableAwait); } else { operation.cursorType(CursorType.Tailable); operation.cursorType(findOptions.getCursorType()); operation.oplogReplay(true); } else { operation.oplogReplay(findOptions.isOplogReplay());