public final class BatchControl extends Object
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 and Description |
|---|
BatchControl(SpiTransaction t,
int batchSize,
boolean getGenKeys)
Create for a given transaction, PersistExecute, default size and
getGeneratedKeys.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
executeNow(ArrayList<PersistRequest> list)
Execute all the requests contained in the list.
|
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()
execute all the requests currently queued or batched.
|
protected void |
flushPstmtHolder()
Flush any batched PreparedStatements.
|
int |
getBatchSize()
Return the batchSize.
|
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.
|
public BatchControl(SpiTransaction t, int batchSize, boolean getGenKeys)
public void setBatchFlushOnMixed(boolean flushBatchOnMixed)
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).
public int getBatchSize()
public void setBatchSize(int batchSize)
The user can set this via the Transaction.
public void setGetGeneratedKeys(Boolean getGeneratedKeys)
The user can set this via the transaction
public int executeStatementOrBatch(PersistRequest request, boolean batch)
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.
public int executeOrQueue(PersistRequestBean<?> request, boolean batch)
public BatchedPstmtHolder getPstmtHolder()
public boolean isEmpty()
protected void flushPstmtHolder()
protected void executeNow(ArrayList<PersistRequest> list)
public void flush()
throws javax.persistence.PersistenceException
javax.persistence.PersistenceExceptionCopyright © 2014. All Rights Reserved.