|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.atlassian.crowd.util.persistence.hibernate.batch.BatchProcessorImpl
public class BatchProcessorImpl
Threadsafe batch processor. Currently capable of performing
"find", "saveOrUpdate" and "replicate" on a collection of
entities.
This processor is essentially a heavyweight generic DAO for
processing batching inserts or updates to NamedEntities and
for performing finds on DirectoryEntities.
A NamedEntity is just an Object with a getName() method suitable
for logging the names of objects that could not be processed.
It is assumed that all data-cleansing (eg. convert to lower
case, directoryID assigned, etc) is performed prior to calling
methods on the BatchProcessor.
The batchSize defaults to 20 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.
You can use the BatchProcessor in a singleton manner.
There is no need to transaction/Hibernate wrap the
BatchProcessor as transactions and Hibernate sessions
are managed internally by this class.
Each batch operation is first divided into smaller sets of
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 1: do not use this if you're database is not transactional,
*stab* MySQL ISAM.
NOTE 2: if you are experiencing problems with the
BatchProcessor set the log level on this class
to DEBUG via log4j.properties:
log4j.logger.com.atlassian.crowd.util.persistence.hibernate.BatchProcessor=DEBUG
NOTE 3: it is quite is easy to generify this batch processor if
you would like batch processing outside Crowd.
| Constructor Summary | |
|---|---|
BatchProcessorImpl(org.hibernate.SessionFactory sessionFactory)
|
|
| Method Summary | ||
|---|---|---|
|
find(long directoryID,
java.util.Collection<java.lang.String> names,
java.lang.Class<E> persistentClass)
Returns a collection of entities that match the names provided. |
|
|
merge(java.util.Collection<E> objects)
Merge (almost SaveOrUpdate) a set of entities using Hibernate/JDBC batching. |
|
|
processBatchFind(org.hibernate.Session session,
long directoryID,
java.util.Collection<java.lang.String> names,
java.lang.Class<E> persistentClass)
|
|
|
replicate(java.util.Collection<E> objects,
org.hibernate.ReplicationMode replicationMode)
Replicate a set of entities using Hibernate/JDBC batching. |
|
|
saveOrUpdate(java.util.Collection<E> objects)
Merge (almost SaveOrUpdate) a set of entities using Hibernate/JDBC batching. |
|
void |
setBatchSize(int batchSize)
The batchSize value should be the same
as the hibernate.jdbc.batch_size
Hibernate property. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BatchProcessorImpl(org.hibernate.SessionFactory sessionFactory)
| Method Detail |
|---|
public <E extends java.io.Serializable> BatchResult<E> replicate(java.util.Collection<E> objects,
org.hibernate.ReplicationMode replicationMode)
BatchProcessor
replicate in interface BatchProcessorobjects - entities to replicate.replicationMode - how to perform the replication, eg. ReplicationMode.OVERWRITE.
public <E extends java.io.Serializable> BatchResult<E> merge(java.util.Collection<E> objects)
BatchProcessor
merge in interface BatchProcessorobjects - entities to save or update.
These objects can be wrapped in TransactionGroups
to ensure that a group of objects are added inserted together.
public <E extends java.io.Serializable> BatchResult<E> saveOrUpdate(java.util.Collection<E> objects)
BatchProcessor
saveOrUpdate in interface BatchProcessorobjects - entities to save or update.
These objects can be wrapped in TransactionGroups
to ensure that a group of objects are added inserted together.
public <E extends DirectoryEntity> java.util.Collection<E> find(long directoryID,
java.util.Collection<java.lang.String> names,
java.lang.Class<E> persistentClass)
SELECT * FROM entityTable WHERE entityName IN (...)
This is batched such that the size of the IN
clause is at most the batchSize.
find in interface BatchProcessordirectoryID - directory ID of the entities to return.names - collection of entity names. This, along with the directoryID
should form the primary key of the entity.persistentClass - the persistent class to lookup. This must
be a Hibernate-mapped DirectoryEntity.
public <E extends DirectoryEntity> java.util.Collection<E> processBatchFind(org.hibernate.Session session,
long directoryID,
java.util.Collection<java.lang.String> names,
java.lang.Class<E> persistentClass)
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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||