Class BatchControl


  • public final class BatchControl
    extends Object
    Controls the batch ordering of persist requests.

    Persist requests include bean inserts updates deletes and UpdateSql and CallableSql requests.

    This object queues up the requests into appropriate entries according to the 'depth' and the 'type' of the requests. The depth relates to how saves and deletes cascade following the associations of a bean. For saving Associated One cascades reduce the depth (-1) and associated many's increase the depth. The initial depth of a request is 0.

    • Constructor Detail

      • BatchControl

        public BatchControl​(SpiTransaction t,
                            int batchSize,
                            boolean getGenKeys)
        Create for a given transaction, PersistExecute, default size and getGeneratedKeys.
    • Method Detail

      • setBatchFlushOnMixed

        public void setBatchFlushOnMixed​(boolean flushBatchOnMixed)
        Set this flag to false to allow batching of a mix of Beans and UpdateSql (or CallableSql). Normally if you mix the two this will result in an automatic flush.

        Note that UpdateSql and CallableSql will ALWAYS flush first. This is due to it already having been bound to a PreparedStatement where as the Beans go through a 2 step process when they are flushed (delayed binding).

      • setBatchSize

        public void setBatchSize​(int batchSize)
        Set the size of batch execution.

        The user can set this via the Transaction.

      • setGetGeneratedKeys

        public void setGetGeneratedKeys​(Boolean getGeneratedKeys)
        Set whether or not to use getGeneratedKeys for this batch execution.

        The user can set this via the transaction

      • executeOrQueue

        public int executeOrQueue​(PersistRequestBean<?> request,
                                  boolean batch)
                           throws BatchedSqlException
        Entity Bean insert, update or delete. This will either execute the request immediately or queue it for batch processing later. The queue is flushedIntercept according to the depth (object graph depth).
        Throws:
        BatchedSqlException
      • isEmpty

        public boolean isEmpty()
        Return true if the queue is empty.
      • clear

        public void clear()
        Clears the batch, discarding all batched statements.