public class BatchedAsyncMongoCollectionImpl extends AbstractAsyncMongoCollection implements BatchedAsyncMongoCollection
BatchedAsyncMongoCollection
.DELETE_SINGLE_DELETE_DEFAULT, EMPTY_INDEX_OPTIONS, ID_FIELD_NAME, INSERT_CONTINUE_ON_ERROR_DEFAULT, myClient, myDatabase, myName, UNIQUE_INDEX_OPTIONS, UPDATE_MULTIUPDATE_DEFAULT, UPDATE_UPSERT_DEFAULT
ALL, NONE
Constructor and Description |
---|
BatchedAsyncMongoCollectionImpl(Client client,
MongoDatabase database,
String name)
Creates a new BatchedAsyncMongoCollectionImpl.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the pending batch of operations without sending them to the
server.
|
void |
close()
Flushes the pending batch and submits all of the pending requests to the
server.
|
void |
flush()
Flushes the pending batch and submits all of the pending requests to the
server.
|
BatchedWriteMode |
getMode()
Returns the mode for the batched writes.
|
boolean |
isBatchDeletes()
Returns true if the deletes should be batched.
|
boolean |
isBatchUpdates()
Returns true if the updates should be batched.
|
void |
setBatchDeletes(boolean batchDeletes)
Sets if deletes should be batched.
|
void |
setBatchUpdates(boolean batchUpdates)
Sets if updates should be batched.
|
void |
setMode(BatchedWriteMode mode)
Sets the default mode for batching of writes.
|
protected boolean |
useWriteCommand()
Extension point for derived classes to force the
AbstractMongoOperations.insertAsync(Callback, boolean, Durability, DocumentAssignable...)
,
AbstractMongoOperations.updateAsync(Callback, DocumentAssignable, DocumentAssignable, boolean, boolean, Durability)
, and
AbstractMongoOperations.deleteAsync(Callback, DocumentAssignable, boolean, Durability)
methods to use the legacy Insert , Update , and
Delete messages regardless of the server version. |
aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, getLockType, groupByAsync, groupByAsync, groupByAsync, groupByAsync, groupByAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, saveAsync, saveAsync, saveAsync, saveAsync, saveAsync, stream, stream, stream, stream, stream, stream, streamingFind, streamingFind, streamingFind, streamingFind, streamingFind, streamingFind, textSearchAsync, textSearchAsync, textSearchAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, writeAsync, writeAsync, writeAsync, writeAsync, writeAsync
aggregateAsync, asGetLastError, countAsync, createQuery, deleteAsync, distinctAsync, doInsertAsync, doWriteAsync, explainAsync, explainAsync, findAndModifyAsync, findAsync, findOneAsync, getDatabaseName, getDurability, getName, getReadPreference, groupByAsync, insertAsync, isWriteCommandsSupported, mapReduceAsync, parallelScanAsync, saveAsync, setDurability, setReadPreference, stream, stream, textSearchAsync, toCommand, updateAsync, updateReadPreference, writeAsync
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, aggregateAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, countAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, distinctAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, explainAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAndModifyAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, findOneAsync, groupByAsync, groupByAsync, groupByAsync, groupByAsync, groupByAsync, groupByAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, insertAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, mapReduceAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, parallelScanAsync, saveAsync, saveAsync, saveAsync, saveAsync, saveAsync, saveAsync, stream, stream, stream, stream, stream, stream, stream, stream, streamingFind, streamingFind, streamingFind, streamingFind, streamingFind, streamingFind, textSearchAsync, textSearchAsync, textSearchAsync, textSearchAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, updateAsync, writeAsync, writeAsync, writeAsync, writeAsync, writeAsync, writeAsync
public BatchedAsyncMongoCollectionImpl(Client client, MongoDatabase database, String name)
client
- The client for interacting with MongoDB.database
- The database we interact with.name
- The name of the collection we interact with.public void cancel()
After canceling the current batch you may continue to accumulate additional operations to be sent in a different batch.
Overridden to clear any pending messages without sending them to MongoDB.
cancel
in interface BatchedAsyncMongoCollection
public void close() throws MongoDbException
This method is equivalent to BatchedAsyncMongoCollection.flush()
and is only provided to
implement the Closeable
interface to support try-with-resource.
Overridden to flush any pending messages to a real serialized client.
close
in interface BatchedAsyncMongoCollection
close
in interface Closeable
close
in interface AutoCloseable
MongoDbException
- If there is an error submitting the batched requests.public void flush() throws MongoDbException
After flushing the current batch you may continue to accumulate additional operations to be sent in a different batch.
Overridden to flush any pending messages to a real serialized client.
flush
in interface BatchedAsyncMongoCollection
MongoDbException
- If there is an error submitting the batched requests.public BatchedWriteMode getMode()
public boolean isBatchDeletes()
public boolean isBatchUpdates()
public void setBatchDeletes(boolean batchDeletes)
Defaults to false since there is no way to determine how many documents each deletes removed when they are batched.
This setting takes effect for a batch when it is closed
or flushed
. Intermediate changes between flushes have no
effect.
setBatchDeletes
in interface BatchedAsyncMongoCollection
batchDeletes
- Set to true to batch deletes.public void setBatchUpdates(boolean batchUpdates)
Defaults to false since there is no way to determine how many documents each update touched when they are batched.
This setting takes effect for a batch when it is closed
or flushed
. Intermediate changes between flushes have no
effect.
setBatchUpdates
in interface BatchedAsyncMongoCollection
batchUpdates
- Set to true to batch updates.public void setMode(BatchedWriteMode mode)
Durability.ACK
and Durability.NONE
writes and
they may be grouped with other writes. Users should be aware that this
may cause unexpected write concern failures in those cases.
The default mode is BatchedWriteMode.SERIALIZE_AND_CONTINUE
. This
provides reasonable performance while maintaining the expected semantics.
Note that this mode has the effect of coalescing sequences of inserts
(where continueOnError is true), updates and deletes into single
operations.
The BatchedWriteMode.SERIALIZE_AND_STOP
will cause each insert,
update, and delete to be sent as independent commands.
The BatchedWriteMode.REORDERED
will cause each sequence of
inserts, updates, and deletes without any other command or query to be
groups together, reordered, and executed together. This includes the
reordering writes within a type (one insert before another to better
packet the messages) as well as reordering the writes across types (a
delete before an insert to build larger batches).
The mode setting takes effect for a batch when it is closed
or flushed
. Intermediate changes between flushes
have no effect.
Warning: In the case of
BatchedWriteMode.SERIALIZE_AND_CONTINUE
and
BatchedWriteMode.REORDERED
it is impossible to determine the
number of documents each update and/or delete touched. In these cases
each update in the batch will be returned the number of documents touched
by the batch as a whole. For this reason the batching of updates and
deletes is disabled. It can be enabled by setting
BatchedAsyncMongoCollection.setBatchUpdates(boolean)
and BatchedAsyncMongoCollection.setBatchDeletes(boolean)
to true. We have written a bug report (SERVER-12858) to
have the additional information added to the responses so we can remove
this restriction.
setMode
in interface BatchedAsyncMongoCollection
mode
- The default mode forprotected boolean useWriteCommand()
AbstractMongoOperations.insertAsync(Callback, boolean, Durability, DocumentAssignable...)
,
AbstractMongoOperations.updateAsync(Callback, DocumentAssignable, DocumentAssignable, boolean, boolean, Durability)
, and
AbstractMongoOperations.deleteAsync(Callback, DocumentAssignable, boolean, Durability)
methods to use the legacy Insert
, Update
, and
Delete
messages regardless of the server version.
This version of the method always returns true.
Overridden to return false to force the AbstractMongoOperations
class to always use the legacy Insert
, Update
, and
Delete
messages. The CaptureClientHandler.optimize()
will
convert those operations to bulk write commands as appropriate.
useWriteCommand
in class AbstractMongoOperations
Insert
,
Update
, and Delete
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.