[JAVA-1692] Suggest adding #size and/or #isEmpty method to BulkWriteOperation Created: 16/Mar/15 Updated: 08/Nov/17 Resolved: 08/Nov/17 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | 2.13.0 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Andy Lowry | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 1 |
| Labels: | bulk_api | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7 64-bit, Java 1.7, MongoDB v3.0 |
||
| Backwards Compatibility: | Fully Compatible |
| Description |
|
BulkWriteOperation does not provide any means of detecting how many operations have been posted to it. Given that attempting to execute an empty BWO throws an exception, this makes it slightly more complicated than it ought to be to implement, say, a class that provides a single-record #insert() method and internally buffers operations for bulk execution. A private #flush() method in such a class (invoked by #insert() and by #close() when the client is finished inserting records) would need to explicitly coordinate with #insert to know whether or not to submit the BWO for execution. This could be alleviated by providing #size() and/or #isEmpty() methods on BWO. Either could be used by #flush() to decide whether to execute the BWO. And they're very natural operations regardless. Alternatively, one could take the JDBC approach, and make execution of any empty BWO a no-op, just as Statement#execBatch() on a statement object whose #addBatch() method has not been invoked is a no-op in JDBC. In my opinion, that's a more sensible design than throwing an exception, but it would potentially break existing appplications. |
| Comments |
| Comment by Jeffrey Yemin [ 08/Nov/17 ] |
|
Closing this as Won't Fix, as the new CRUD API does not suffer from this deficiency. |
| Comment by Jeffrey Yemin [ 15/Oct/15 ] |
|
It may not help you, but just so you know the new CRUD API in the 3.x driver series will allow you to do this, since a bulk write is just a method that takes a List of write requests. See the Quick Tour for an example. |
| Comment by Simon Chan [X] [ 15/Oct/15 ] |
|
I was looking for just the thing and I'm glad you have raised a jira for this feature. |