public abstract class AbstractBatchProcessor extends Object implements BatchProcessor
batchSize
defaults to batchSize and can
be manually set (via Spring, for example) using the appropriate
setter method. The batchSize
should match the
hibernate.jdbc.batch_size
property defined in the
Hibernate configuration.
Each batch operation is first divided into smaller sets of
batchSize
. If there is an error in processing the batch,
the batched JDBC call is rolled-back and the batch is
processed individually.
This mechanism ensures very fast (JDBC-batched) inserts and
updates and follows it up with a fail-over retry for the
failing batches.
Callback methods are provided to allow you include the session
and transaction management you desire. The processing flow is:
call beforeProcessCollection()
For each item in the collection
Add the item to the batch collection
If the batch collection size >= the batch size
call beforeProcessBatch()
For each item in the batch collection
perform the operation on the item
call afterProcessBatch() or rollbackProcessBatch() if an error occured
clear the batch collection
If there are unprocessed items in the Batch Collcetion
call beforeProcessBatch()
For each item in the batch collection
perform the operation on the item
call afterProcessBatch() or rollbackProcessBatch() if an error occured
call beforeProcessCollection()
If an error occured during the processing of a batch collection then:
For each item in the batch collection
call beforeProcessIndividual()
perform the operation on the item
call afterProcessIndividual() or rollbackProcessIndividual() if an error occured
NOTE 1: Do not use this if you're database is not transactional,
*stab* MySQL ISAM.Constructor and Description |
---|
AbstractBatchProcessor() |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
afterProcessBatch()
Called after successfully processing each batch.
|
protected abstract void |
afterProcessCollection()
Called when processing the collection has completed successfully.
|
protected abstract void |
afterProcessIndividual()
Called after successully processing an item individually.
|
protected abstract void |
beforeProcessBatch()
Called before processing each batch.
|
protected abstract void |
beforeProcessCollection()
Called before the collection is processed into a batch.
|
protected abstract void |
beforeProcessIndividual()
Called before processing an individual item.
|
<E extends Serializable> |
execute(HibernateOperation op,
Collection<E> objects)
The set is first divided into smaller sets of
batchSize . |
protected abstract void |
rollbackProcessBatch()
Called after processing each batch where an exception was encountered.
|
protected abstract void |
rollbackProcessIndividual()
Called after processing an individual item where an exception was encountered.
|
void |
setBatchSize(int batchSize)
The
batchSize value should be the same
as the hibernate.jdbc.batch_size
Hibernate property. |
public final <E extends Serializable> BatchResult<E> execute(HibernateOperation op, Collection<E> objects)
batchSize
.
Each batchSet is added via a batched JDBC call (using Hibernate's
batching mechanism). If there is an error in processing the batch,
the batched JDBC call is rolled-back and the batchSet is processed
individually.
This mechanism ensures very fast (JDBC-batched) inserts and
updates and follows it up with a fail-over retry for the
failing batches.
NOTE: do not use this if you're database is not transactional,
*stab* MySQL ISAM.execute
in interface BatchProcessor
op
- Hibernate operation to perform (eg. replicate, saveOrUpdate).objects
- set of DirectoryEntity
objectst to
batch add.public void setBatchSize(int batchSize)
batchSize
value should be the same
as the hibernate.jdbc.batch_size
Hibernate property.batchSize
- batch size used to group batches.protected abstract void beforeProcessCollection()
protected abstract void afterProcessCollection()
protected abstract void beforeProcessBatch()
protected abstract void afterProcessBatch()
protected abstract void rollbackProcessBatch()
protected abstract void beforeProcessIndividual()
protected abstract void afterProcessIndividual()
protected abstract void rollbackProcessIndividual()
Copyright © 2013 Atlassian. All Rights Reserved.