T
- the operations result type.public class FindOperation<T> extends java.lang.Object implements AsyncReadOperation<AsyncBatchCursor<T>>, ReadOperation<BatchCursor<T>>
Modifier and Type | Class and Description |
---|---|
private static class |
FindOperation.ExplainResultCallback |
Modifier and Type | Field and Description |
---|---|
private int |
batchSize |
private Collation |
collation |
private CursorType |
cursorType |
private Decoder<T> |
decoder |
private BsonDocument |
filter |
private static java.lang.String |
FIRST_BATCH |
private int |
limit |
private long |
maxAwaitTimeMS |
private long |
maxTimeMS |
private static java.util.Map<java.lang.String,java.lang.String> |
META_OPERATOR_TO_COMMAND_FIELD_MAP |
private BsonDocument |
modifiers |
private MongoNamespace |
namespace |
private boolean |
noCursorTimeout |
private boolean |
oplogReplay |
private boolean |
partial |
private BsonDocument |
projection |
private ReadConcern |
readConcern |
private int |
skip |
private boolean |
slaveOk |
private BsonDocument |
sort |
Constructor and Description |
---|
FindOperation(MongoNamespace namespace,
Decoder<T> decoder)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
private BsonDocument |
asDocument(ConnectionDescription connectionDescription,
ReadPreference readPreference) |
ReadOperation<BsonDocument> |
asExplainableOperation(ExplainVerbosity explainVerbosity)
Gets an operation whose execution explains this operation.
|
AsyncReadOperation<BsonDocument> |
asExplainableOperationAsync(ExplainVerbosity explainVerbosity)
Gets an operation whose execution explains this operation.
|
private CommandOperationHelper.CommandTransformer<BsonDocument,AsyncBatchCursor<T>> |
asyncTransformer(AsyncConnectionSource source,
AsyncConnection connection) |
FindOperation<T> |
batchSize(int batchSize)
Sets the number of documents to return per batch.
|
FindOperation<T> |
collation(Collation collation)
Sets the collation options
|
private FindOperation<BsonDocument> |
createExplainableQueryOperation() |
FindOperation<T> |
cursorType(CursorType cursorType)
Sets the cursor type.
|
private QueryResult<T> |
documentToQueryResult(BsonDocument result,
ServerAddress serverAddress) |
private static <T> SingleResultCallback<T> |
exceptionTransformingCallback(SingleResultCallback<T> callback) |
BatchCursor<T> |
execute(ReadBinding binding)
General execute which can return anything of type T
|
void |
executeAsync(AsyncReadBinding binding,
SingleResultCallback<AsyncBatchCursor<T>> callback)
General execute which can return anything of type T
|
FindOperation<T> |
filter(BsonDocument filter)
Sets the query filter to apply to the query.
|
int |
getBatchSize()
Gets the number of documents to return per batch.
|
Collation |
getCollation()
Returns the collation options
|
private BsonDocument |
getCommand() |
CursorType |
getCursorType()
Get the cursor type.
|
Decoder<T> |
getDecoder()
Gets the decoder used to decode the result documents.
|
BsonDocument |
getFilter()
Gets the query filter.
|
int |
getLimit()
Gets the limit to apply.
|
long |
getMaxAwaitTime(java.util.concurrent.TimeUnit timeUnit)
The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor
query.
|
long |
getMaxTime(java.util.concurrent.TimeUnit timeUnit)
Gets the maximum execution time on the server for this operation.
|
private long |
getMaxTimeForCursor() |
BsonDocument |
getModifiers()
Gets the query modifiers to apply to this operation.
|
MongoNamespace |
getNamespace()
Gets the namespace.
|
BsonDocument |
getProjection()
Gets a document describing the fields to return for all matching documents.
|
ReadConcern |
getReadConcern()
Gets the read concern
|
int |
getSkip()
Gets the number of documents to skip.
|
BsonDocument |
getSort()
Gets the sort criteria to apply to the query.
|
private boolean |
isAwaitData() |
private boolean |
isExplain() |
boolean |
isNoCursorTimeout()
Returns true if cursor timeout has been turned off.
|
boolean |
isOplogReplay()
Internal replication use only.
|
boolean |
isPartial()
Returns true if can get partial results from a mongos if some shards are down.
|
boolean |
isSlaveOk()
Returns true if set to allowed to query non-primary replica set members.
|
private boolean |
isTailableCursor() |
FindOperation<T> |
limit(int limit)
Sets the limit to apply.
|
FindOperation<T> |
maxAwaitTime(long maxAwaitTime,
java.util.concurrent.TimeUnit timeUnit)
Sets the maximum await execution time on the server for this operation.
|
FindOperation<T> |
maxTime(long maxTime,
java.util.concurrent.TimeUnit timeUnit)
Sets the maximum execution time on the server for this operation.
|
FindOperation<T> |
modifiers(BsonDocument modifiers)
Sets the query modifiers to apply to this operation.
|
FindOperation<T> |
noCursorTimeout(boolean noCursorTimeout)
Sets if the cursor timeout should be turned off.
|
FindOperation<T> |
oplogReplay(boolean oplogReplay)
Internal replication use only.
|
FindOperation<T> |
partial(boolean partial)
Sets if partial results from a mongos if some shards are down are allowed
|
FindOperation<T> |
projection(BsonDocument projection)
Sets a document describing the fields to return for all matching documents.
|
FindOperation<T> |
readConcern(ReadConcern readConcern)
Sets the read concern
|
FindOperation<T> |
skip(int skip)
Sets the number of documents to skip.
|
FindOperation<T> |
slaveOk(boolean slaveOk)
Sets if allowed to query non-primary replica set members.
|
FindOperation<T> |
sort(BsonDocument sort)
Sets the sort criteria to apply to the query.
|
private CommandOperationHelper.CommandTransformer<BsonDocument,BatchCursor<T>> |
transformer(ConnectionSource source,
Connection connection) |
private BsonDocument |
wrapInExplainIfNecessary(BsonDocument commandDocument) |
private static final java.lang.String FIRST_BATCH
private final MongoNamespace namespace
private BsonDocument filter
private int batchSize
private int limit
private BsonDocument modifiers
private BsonDocument projection
private long maxTimeMS
private long maxAwaitTimeMS
private int skip
private BsonDocument sort
private CursorType cursorType
private boolean slaveOk
private boolean oplogReplay
private boolean noCursorTimeout
private boolean partial
private ReadConcern readConcern
private Collation collation
private static final java.util.Map<java.lang.String,java.lang.String> META_OPERATOR_TO_COMMAND_FIELD_MAP
public FindOperation(MongoNamespace namespace, Decoder<T> decoder)
namespace
- the database and collection namespace for the operation.decoder
- the decoder for the result documents.public MongoNamespace getNamespace()
public Decoder<T> getDecoder()
public BsonDocument getFilter()
public FindOperation<T> filter(BsonDocument filter)
filter
- the filter, which may be null.public int getBatchSize()
public FindOperation<T> batchSize(int batchSize)
batchSize
- the batch sizepublic int getLimit()
public FindOperation<T> limit(int limit)
limit
- the limit, which may be nullpublic BsonDocument getModifiers()
public FindOperation<T> modifiers(BsonDocument modifiers)
modifiers
- the query modifiers to apply, which may be null.public BsonDocument getProjection()
public FindOperation<T> projection(BsonDocument projection)
projection
- the project document, which may be null.public long getMaxTime(java.util.concurrent.TimeUnit timeUnit)
timeUnit
- the time unit to return the result inpublic FindOperation<T> maxTime(long maxTime, java.util.concurrent.TimeUnit timeUnit)
maxTime
- the max timetimeUnit
- the time unit, which may not be nullpublic long getMaxAwaitTime(java.util.concurrent.TimeUnit timeUnit)
timeUnit
- the time unit to return the result inpublic FindOperation<T> maxAwaitTime(long maxAwaitTime, java.util.concurrent.TimeUnit timeUnit)
maxAwaitTime
- the max await time. A zero value will be ignored, and indicates that the driver should respect the server's
default valuetimeUnit
- the time unit, which may not be nullpublic int getSkip()
public FindOperation<T> skip(int skip)
skip
- the number of documents to skippublic BsonDocument getSort()
public FindOperation<T> sort(BsonDocument sort)
sort
- the sort criteria, which may be null.public CursorType getCursorType()
public FindOperation<T> cursorType(CursorType cursorType)
cursorType
- the cursor typepublic boolean isSlaveOk()
public FindOperation<T> slaveOk(boolean slaveOk)
slaveOk
- true if allowed to query non-primary replica set members.public boolean isOplogReplay()
public FindOperation<T> oplogReplay(boolean oplogReplay)
oplogReplay
- the oplogReplay valuepublic boolean isNoCursorTimeout()
The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use.
public FindOperation<T> noCursorTimeout(boolean noCursorTimeout)
noCursorTimeout
- true if the cursor timeout should be turned off.public boolean isPartial()
public FindOperation<T> partial(boolean partial)
partial
- allow partial results from a mongos if some shards are downpublic ReadConcern getReadConcern()
public FindOperation<T> readConcern(ReadConcern readConcern)
readConcern
- the read concernpublic Collation getCollation()
public FindOperation<T> collation(Collation collation)
A null value represents the server default.
collation
- the collation options to usepublic BatchCursor<T> execute(ReadBinding binding)
ReadOperation
execute
in interface ReadOperation<BatchCursor<T>>
binding
- the binding to execute in the context ofpublic void executeAsync(AsyncReadBinding binding, SingleResultCallback<AsyncBatchCursor<T>> callback)
AsyncReadOperation
executeAsync
in interface AsyncReadOperation<AsyncBatchCursor<T>>
binding
- the binding to execute in the context ofcallback
- the callback to be called when the operation has been executedprivate static <T> SingleResultCallback<T> exceptionTransformingCallback(SingleResultCallback<T> callback)
public ReadOperation<BsonDocument> asExplainableOperation(ExplainVerbosity explainVerbosity)
explainVerbosity
- the explain verbositypublic AsyncReadOperation<BsonDocument> asExplainableOperationAsync(ExplainVerbosity explainVerbosity)
explainVerbosity
- the explain verbosityprivate FindOperation<BsonDocument> createExplainableQueryOperation()
private BsonDocument asDocument(ConnectionDescription connectionDescription, ReadPreference readPreference)
private BsonDocument getCommand()
private BsonDocument wrapInExplainIfNecessary(BsonDocument commandDocument)
private boolean isExplain()
private boolean isTailableCursor()
private boolean isAwaitData()
private CommandOperationHelper.CommandTransformer<BsonDocument,BatchCursor<T>> transformer(ConnectionSource source, Connection connection)
private long getMaxTimeForCursor()
private CommandOperationHelper.CommandTransformer<BsonDocument,AsyncBatchCursor<T>> asyncTransformer(AsyncConnectionSource source, AsyncConnection connection)
private QueryResult<T> documentToQueryResult(BsonDocument result, ServerAddress serverAddress)