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 Summary
Constructors Constructor Description BatchControl(SpiTransaction t, int batchSize, boolean getGenKeys)
Create for a given transaction, PersistExecute, default size and getGeneratedKeys.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addToFlushQueue(PersistRequestUpdateSql request, boolean early)
Add a SqlUpdate request to execute after flush.void
clear()
Clears the batch, discarding all batched statements.int[]
execute(String key, boolean getGeneratedKeys)
Execute a batched statement.int
executeOrQueue(PersistRequestBean<?> request, boolean batch)
Entity Bean insert, update or delete.int
executeStatementOrBatch(PersistRequest request, boolean batch)
Execute a Orm Update, SqlUpdate or CallableSql.void
flush()
Flush without resetting the depth info.void
flushReset()
Flush with a reset of the depth info.BatchedPstmtHolder
getPstmtHolder()
Return the actual batch of PreparedStatements.boolean
isEmpty()
Return true if the queue is empty.void
setBatchFlushOnMixed(boolean flushBatchOnMixed)
Set this flag to false to allow batching of a mix of Beans and UpdateSql (or CallableSql).void
setBatchSize(int batchSize)
Set the size of batch execution.void
setGetGeneratedKeys(Boolean getGeneratedKeys)
Set whether or not to use getGeneratedKeys for this batch execution.
-
-
-
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
-
executeStatementOrBatch
public int executeStatementOrBatch(PersistRequest request, boolean batch) 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
-
getPstmtHolder
public BatchedPstmtHolder getPstmtHolder()
Return the actual batch of PreparedStatements.
-
isEmpty
public boolean isEmpty()
Return true if the queue is empty.
-
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, boolean early)
Add a SqlUpdate request to execute after flush.
-
-