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
ConstructorsConstructorDescriptionBatchControl(SpiTransaction t, int batchSize, boolean getGenKeys) Create for a given transaction, PersistExecute, default size and getGeneratedKeys. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToFlushQueue(PersistRequestUpdateSql request, int pos) Add a SqlUpdate request to execute after flush.voidclear()Clears the batch, discarding all batched statements.int[]Execute a batched statement.intexecuteOrQueue(PersistRequestBean<?> request, boolean batch) Entity Bean insert, update or delete.intexecuteStatementOrBatch(PersistRequest request, boolean batch, boolean addBatch) Execute a Orm Update, SqlUpdate or CallableSql.voidflush()Flush without resetting the depth info.voidvoidFlush with a reset of the depth info.booleanisEmpty()Return true if the queue is empty.Return the actual batch of PreparedStatements.voidsetBatchFlushOnMixed(boolean flushBatchOnMixed) Set this flag to false to allow batching of a mix of Beans and UpdateSql (or CallableSql).voidsetBatchSize(int batchSize) Set the size of batch execution.voidsetGetGeneratedKeys(Boolean getGeneratedKeys) Set whether or not to use getGeneratedKeys for this batch execution.
-
Constructor Details
-
BatchControl
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
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
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
Return the actual batch of PreparedStatements. -
isEmpty
public boolean isEmpty()Return true if the queue is empty. -
flushOnCommit
- Throws:
BatchedSqlException
-
flush
Flush without resetting the depth info.- Throws:
BatchedSqlException
-
flushReset
Flush with a reset of the depth info.- Throws:
BatchedSqlException
-
clear
public void clear()Clears the batch, discarding all batched statements. -
execute
Execute a batched statement.- Throws:
SQLException
-
addToFlushQueue
Add a SqlUpdate request to execute after flush.
-