public class Query extends AbstractMessage implements CursorableMessage
struct OP_QUERY {
MsgHeader header; // standard message header
int32 flags; // bit vector of query options. See below for details.
cstring fullCollectionName; // "dbname.collectionname"
int32 numberToSkip; // number of documents to skip
int32 numberToReturn; // number of documents to return
// in the first OP_REPLY batch
document query; // query object.
[ document returnFieldSelector; ] // Optional. Selector indicating the fields
// to return.
}
Modifier and Type | Field and Description |
---|---|
static int |
AWAIT_DATA_FLAG_BIT
Flag bit for the await data.
|
static int |
DEFAULT_BATCH_SIZE
The default batch size for a MongoDB query.
|
static int |
EXHAUST_FLAG_BIT
Flag bit for the exhaust results.
|
static int |
NO_CURSOR_TIMEOUT_FLAG_BIT
Flag bit for the no cursor timeout.
|
static int |
OPLOG_REPLAY_FLAG_BIT
Flag bit for the OPLOG_REPLAY.
|
static int |
PARTIAL_FLAG_BIT
Flag bit for the partial results.
|
static int |
REPLICA_OK_FLAG_BIT
Flag bit for the replica OK.
|
static int |
TAILABLE_CURSOR_FLAG_BIT
Flag bit for the tailable cursors.
|
HEADER_SIZE, myCollectionName, myDatabaseName
Constructor and Description |
---|
Query(Header header,
BsonInputStream in)
Creates a new Query.
|
Query(String databaseName,
String collectionName,
Document query,
Document returnFields,
int batchSize,
int limit,
int numberToSkip,
boolean tailable,
ReadPreference readPreference,
boolean noCursorTimeout,
boolean awaitData,
boolean exhaust,
boolean partial)
Creates a new Query.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object object)
Determines if the passed object is of this same type as this object and
if so that its fields are equal.
|
int |
getBatchSize()
Returns the number of documents to be returned in each batch of results.
|
int |
getLimit()
Returns the total number of documents to be returned.
|
int |
getNumberToReturn()
Returns the number of documents to be returned.
|
int |
getNumberToSkip()
Returns the number of documents to skip before starting to return
documents.
|
String |
getOperationName()
Returns a short name for the operation.
|
Document |
getQuery()
Returns the query document containing the expression to select documents
from the collection.
|
Document |
getReturnFields()
Returns the optional document containing the fields to be returned.
|
int |
hashCode()
Computes a reasonable hash code.
|
boolean |
isAwaitData()
Returns true and if using a tailable cursor then the connection will
block waiting for more data.
|
boolean |
isBatchSizeSet()
Returns true if the batch size is greater than zero.
|
boolean |
isExhaust()
Returns true if all results should be returned in multiple results.
|
boolean |
isLimitSet()
Returns true if the limit is greater than zero.
|
boolean |
isNoCursorTimeout()
Returns true if marking the cursor as not having a timeout.
|
boolean |
isPartial()
Returns true if return the results found and suppress shard down errors.
|
boolean |
isTailable()
Returns true if the cursor created should follow additional documents
being inserted.
|
int |
size()
Returns the total size of the message on the wire.
|
void |
validateSize(SizeOfVisitor visitor,
int maxDocumentSize)
Validates that the documents with the message do not exceed the maximum
document size specified.
|
void |
write(int messageId,
BsonOutputStream out)
Writes the message from the stream.
|
void |
write(int messageId,
BufferingBsonOutputStream out)
Writes the message from the stream.
|
finishHeader, getCollectionName, getDatabaseName, getReadPreference, getRequiredVersionRange, init, writeHeader, writeHeader
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getCollectionName
getDatabaseName, getReadPreference, getRequiredVersionRange
public static final int AWAIT_DATA_FLAG_BIT
public static final int DEFAULT_BATCH_SIZE
public static final int EXHAUST_FLAG_BIT
public static final int NO_CURSOR_TIMEOUT_FLAG_BIT
public static final int OPLOG_REPLAY_FLAG_BIT
public static final int PARTIAL_FLAG_BIT
public static final int REPLICA_OK_FLAG_BIT
public static final int TAILABLE_CURSOR_FLAG_BIT
public Query(Header header, BsonInputStream in) throws IOException
header
- The header for the query message.in
- The stream to read the kill_cursors message from.IOException
- On a failure reading the kill_cursors message.public Query(String databaseName, String collectionName, Document query, Document returnFields, int batchSize, int limit, int numberToSkip, boolean tailable, ReadPreference readPreference, boolean noCursorTimeout, boolean awaitData, boolean exhaust, boolean partial)
databaseName
- The name of the database.collectionName
- The name of the collection.query
- The query document containing the expression to select
documents from the collection.returnFields
- Optional document containing the fields to be returned.batchSize
- The number of documents to be returned in each batch.limit
- The limit on the number of documents to return.numberToSkip
- The number of documents to skip before starting to return
documents.tailable
- If true, then the cursor created should follow additional
documents being inserted.readPreference
- The preference for which servers to use to retrieve the
results.noCursorTimeout
- If true, marks the cursor as not having a timeout.awaitData
- If true and if using a tailable cursor then the connection
will block waiting for more data.exhaust
- If true, all results should be returned in multiple results.partial
- If true, return the results found and suppress shard down
errors.public boolean equals(Object object)
equals
in class AbstractMessage
object
- The object to compare to.Object.equals(java.lang.Object)
public int getBatchSize()
getBatchSize
in interface CursorableMessage
public int getLimit()
getLimit
in interface CursorableMessage
public int getNumberToReturn()
public int getNumberToSkip()
public String getOperationName()
Overridden to return the name of the operation: "QUERY".
getOperationName
in interface Message
public Document getQuery()
public Document getReturnFields()
null
.public int hashCode()
hashCode
in class AbstractMessage
public boolean isAwaitData()
public boolean isBatchSizeSet()
public boolean isExhaust()
public boolean isLimitSet()
public boolean isNoCursorTimeout()
public boolean isPartial()
public boolean isTailable()
public int size()
Overridden to return the size of the Query
.
public void validateSize(SizeOfVisitor visitor, int maxDocumentSize) throws DocumentToLargeException
Overridden to ensure the inserted documents are not too large in aggregate.
validateSize
in interface Message
visitor
- The SizeOfVisitor
to compute the size of the document.maxDocumentSize
- The maximum document size to validate against.DocumentToLargeException
- If one of the documents in the message is too large or the
documents in aggregate are too large.public void write(int messageId, BsonOutputStream out) throws IOException
Overridden to write the query message.
write
in interface Message
messageId
- The id to be assigned to the message.out
- The sink for data written.IOException
- On an error writing to the stream.Message.write(int, BsonOutputStream)
public void write(int messageId, BufferingBsonOutputStream out) throws IOException
Overridden to write the query message.
write
in interface Message
messageId
- The id to be assigned to the message.out
- The sink for data written.IOException
- On an error writing to the stream.Message.write(int, BsonOutputStream)
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.