CountOperation count(final Bson filter, final CountOptions options, final CountStrategy countStrategy) { CountOperation operation = new CountOperation(namespace, countStrategy) .filter(toBsonDocument(filter)) .skip(options.getSkip()) .limit(options.getLimit()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .collation(options.getCollation()); if (options.getHint() != null) { operation.hint(toBsonDocument(options.getHint())); } else if (options.getHintString() != null) { operation.hint(new BsonString(options.getHintString())); } return operation; }
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public ReadOperation<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) { if (countStrategy.equals(CountStrategy.COMMAND)) { return createExplainableOperation(explainVerbosity); } else { return getAggregateOperation().asExplainableOperation(explainVerbosity); } }
private CommandReadOperation<BsonDocument> createExplainableOperation(final ExplainVerbosity explainVerbosity) { return new CommandReadOperation<BsonDocument>(namespace.getDatabaseName(), asExplainCommand(getCommand(NoOpSessionContext.INSTANCE), explainVerbosity), new BsonDocumentCodec()); }
@Override public Long execute(final ReadBinding binding) { if (countStrategy.equals(CountStrategy.COMMAND)) { return withConnection(binding, new CallableWithConnection<Long>() { @Override public Long call(final Connection connection) { validateReadConcernAndCollation(connection, binding.getSessionContext().getReadConcern(), collation); return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), DECODER, connection, transformer()); } }); } else { BatchCursor<BsonDocument> cursor = getAggregateOperation().execute(binding); return cursor.hasNext() ? getCountFromAggregateResults(cursor.next()) : 0; } }
getAggregateOperation().executeAsync(binding, new SingleResultCallback<AsyncBatchCursor<BsonDocument>>(){ @Override public void onResult(final AsyncBatchCursor<BsonDocument> result, final Throwable t) {
@Override public Long execute(final ReadBinding binding) { if (countStrategy.equals(CountStrategy.COMMAND)) { return withConnection(binding, new CallableWithConnection<Long>() { @Override public Long call(final Connection connection) { validateReadConcernAndCollation(connection, binding.getSessionContext().getReadConcern(), collation); return executeWrappedCommandProtocol(binding, namespace.getDatabaseName(), getCommand(binding.getSessionContext()), DECODER, connection, transformer()); } }); } else { BatchCursor<BsonDocument> cursor = getAggregateOperation().execute(binding); return cursor.hasNext() ? getCountFromAggregateResults(cursor.next()) : 0; } }
getAggregateOperation().executeAsync(binding, new SingleResultCallback<AsyncBatchCursor<BsonDocument>>(){ @Override public void onResult(final AsyncBatchCursor<BsonDocument> result, final Throwable t) {
CountOperation operation = new CountOperation(getNamespace()) .skip(options.getSkip()) .limit(options.getLimit()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .collation(options.getCollation()); if (query != null) { operation.filter(wrap(query)); operation.hint(wrap(hint)); } else { String hintString = options.getHintString(); if (hintString != null) { operation.hint(new BsonString(hintString));
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public AsyncReadOperation<BsonDocument> asExplainableOperationAsync(final ExplainVerbosity explainVerbosity) { if (countStrategy.equals(CountStrategy.COMMAND)) { return createExplainableOperation(explainVerbosity); } else { return getAggregateOperation().asExplainableOperationAsync(explainVerbosity); } }
private CommandReadOperation<BsonDocument> createExplainableOperation(final ExplainVerbosity explainVerbosity) { return new CommandReadOperation<BsonDocument>(namespace.getDatabaseName(), asExplainCommand(getCommand(NoOpSessionContext.INSTANCE), explainVerbosity), new BsonDocumentCodec()); }
CountOperation count(final Bson filter, final CountOptions options, final CountStrategy countStrategy) { CountOperation operation = new CountOperation(namespace, countStrategy) .filter(toBsonDocument(filter)) .skip(options.getSkip()) .limit(options.getLimit()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .collation(options.getCollation()); if (options.getHint() != null) { operation.hint(toBsonDocument(options.getHint())); } else if (options.getHintString() != null) { operation.hint(new BsonString(options.getHintString())); } return operation; }
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public AsyncReadOperation<BsonDocument> asExplainableOperationAsync(final ExplainVerbosity explainVerbosity) { if (countStrategy.equals(CountStrategy.COMMAND)) { return createExplainableOperation(explainVerbosity); } else { return getAggregateOperation().asExplainableOperationAsync(explainVerbosity); } }
CountOperation operation = new CountOperation(getNamespace()) .skip(options.getSkip()) .limit(options.getLimit()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .collation(options.getCollation()); if (query != null) { operation.filter(wrap(query)); operation.hint(wrap(hint)); } else { String hintString = options.getHintString(); if (hintString != null) { operation.hint(new BsonString(hintString));
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public ReadOperation<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) { if (countStrategy.equals(CountStrategy.COMMAND)) { return createExplainableOperation(explainVerbosity); } else { return getAggregateOperation().asExplainableOperation(explainVerbosity); } }