T
- the operations result type.public class FindAndReplaceOperation<T> extends Object implements AsyncWriteOperation<T>, WriteOperation<T>
Constructor and Description |
---|
FindAndReplaceOperation(MongoNamespace namespace,
Decoder<T> decoder,
BsonDocument replacement)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
T |
execute(WriteBinding binding)
General execute which can return anything of type T
|
void |
executeAsync(AsyncWriteBinding binding,
SingleResultCallback<T> callback)
General execute which can return anything of type T
|
FindAndReplaceOperation<T> |
filter(BsonDocument filter)
Sets the query filter to apply to the query.
|
Decoder<T> |
getDecoder()
Gets the decoder used to decode the result documents.
|
BsonDocument |
getFilter()
Gets the query filter.
|
long |
getMaxTime(TimeUnit timeUnit)
Gets the maximum execution time on the server for this operation.
|
MongoNamespace |
getNamespace()
Gets the namespace.
|
BsonDocument |
getProjection()
Gets a document describing the fields to return for all matching documents.
|
BsonDocument |
getReplacement()
Gets the document which will replace the document matching the query filter.
|
BsonDocument |
getSort()
Gets the sort criteria to apply to the query.
|
boolean |
isReturnOriginal()
When false, returns the replaced document rather than the original.
|
boolean |
isUpsert()
Returns true if a new document should be inserted if there are no matches to the query filter.
|
FindAndReplaceOperation<T> |
maxTime(long maxTime,
TimeUnit timeUnit)
Sets the maximum execution time on the server for this operation.
|
FindAndReplaceOperation<T> |
projection(BsonDocument projection)
Sets a document describing the fields to return for all matching documents.
|
FindAndReplaceOperation<T> |
returnOriginal(boolean returnOriginal)
Set to false to return the replaced document rather than the original.
|
FindAndReplaceOperation<T> |
sort(BsonDocument sort)
Sets the sort criteria to apply to the query.
|
FindAndReplaceOperation<T> |
upsert(boolean upsert)
Set to true if a new document should be inserted if there are no matches to the query filter.
|
public FindAndReplaceOperation(MongoNamespace namespace, Decoder<T> decoder, BsonDocument replacement)
namespace
- the database and collection namespace for the operation.decoder
- the decoder for the result documents.replacement
- the document that will replace the found document.public MongoNamespace getNamespace()
public Decoder<T> getDecoder()
public BsonDocument getReplacement()
public BsonDocument getFilter()
public FindAndReplaceOperation<T> filter(BsonDocument filter)
filter
- the query filter, which may be null.public BsonDocument getProjection()
public FindAndReplaceOperation<T> projection(BsonDocument projection)
projection
- the project document, which may be null.public long getMaxTime(TimeUnit timeUnit)
timeUnit
- the time unit to return the result inpublic FindAndReplaceOperation<T> maxTime(long maxTime, TimeUnit timeUnit)
maxTime
- the max timetimeUnit
- the time unit, which may not be nullpublic BsonDocument getSort()
public FindAndReplaceOperation<T> sort(BsonDocument sort)
sort
- the sort criteria, which may be null.public boolean isReturnOriginal()
public FindAndReplaceOperation<T> returnOriginal(boolean returnOriginal)
returnOriginal
- set to false to return the replaced document rather than the originalpublic boolean isUpsert()
public FindAndReplaceOperation<T> upsert(boolean upsert)
upsert
- true if a new document should be inserted if there are no matches to the query filterpublic T execute(WriteBinding binding)
WriteOperation
execute
in interface WriteOperation<T>
binding
- the binding to execute in the context ofpublic void executeAsync(AsyncWriteBinding binding, SingleResultCallback<T> callback)
AsyncWriteOperation
executeAsync
in interface AsyncWriteOperation<T>
binding
- the binding to execute in the context ofcallback
- the callback to be called when the operation has been executed