Class BatchControl

java.lang.Object
io.ebeaninternal.server.persist.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 Details

    • BatchControl

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

    • 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

    • executeStatementOrBatch

      public int executeStatementOrBatch(PersistRequest request, boolean batch, boolean addBatch) throws BatchedSqlException
      Execute a Orm Update, SqlUpdate or CallableSql.

      These all go straight to jdbc and use addBatch(). Entity beans goto a queue and wait there so that the jdbc is executed in the correct order according to the depth.

      Throws:
      BatchedSqlException
    • 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
    • pstmtHolder

      public BatchedPstmtHolder pstmtHolder()
      Return the actual batch of PreparedStatements.
    • isEmpty

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

      public void flushOnCommit() throws BatchedSqlException
      Throws:
      BatchedSqlException
    • flush

      public void flush() throws BatchedSqlException
      Flush without resetting the depth info.
      Throws:
      BatchedSqlException
    • flushReset

      public void flushReset() throws BatchedSqlException
      Flush with a reset of the depth info.
      Throws:
      BatchedSqlException
    • clear

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

      public int[] execute(String key, boolean getGeneratedKeys) throws SQLException
      Execute a batched statement.
      Throws:
      SQLException
    • addToFlushQueue

      public void addToFlushQueue(PersistRequestUpdateSql request, int pos)
      Add a SqlUpdate request to execute after flush.