mongodb/mongo-java-driver — pull request #260 by mskott (2014-09-26 23:55:06+00:00)
Title: Utility functions to view state of BulkWriteOperation objects

BulkWriteOperation.execute() will throw an exception if the operations have all ready been executed or no operations have been added to the object, but it doesn't provide any way to test if this is the case. I have added two simple methods which make it possible.

For me the practical use-case is that we often create have thousands of operations to run in bulk, but would like to run execute when n have been added. We can easily do this by adding an external counter, but it makes much more sense for the BulkWriteOperation to make this information available. This also removes the need for code like the one below when no operations have been added to the object.

try {
bulkOp.execute();
} catch (IllegalStateException ise) {
//Do nothing
}