Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1692

Suggest adding #size and/or #isEmpty method to BulkWriteOperation

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • 2.13.0
    • API
    • Windows 7 64-bit, Java 1.7, MongoDB v3.0
    • 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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            andylowry Andy Lowry
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: