com.atlassian.crowd.util.persistence.hibernate.batch
Interface BatchProcessor

All Known Implementing Classes:
BatchProcessorImpl

public interface BatchProcessor

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. For more information on the implementation details, please see the javadoc for BatchProcessorImpl.


Method Summary
<E extends DirectoryEntity>
java.util.Collection<E>
find(long directoryID, java.util.Collection<java.lang.String> names, java.lang.Class<E> persistentClass)
          Find a set of entities by batching SQL disjunction queries.
<E extends java.io.Serializable>
BatchResult<E>
merge(java.util.Collection<E> objects)
          Merge (almost SaveOrUpdate) a set of entities using Hibernate/JDBC batching.
<E extends java.io.Serializable>
BatchResult<E>
replicate(java.util.Collection<E> objects, org.hibernate.ReplicationMode replicationMode)
          Replicate a set of entities using Hibernate/JDBC batching.
<E extends java.io.Serializable>
BatchResult<E>
saveOrUpdate(java.util.Collection<E> objects)
          Merge (almost SaveOrUpdate) a set of entities using Hibernate/JDBC batching.
 

Method Detail

replicate

<E extends java.io.Serializable> BatchResult<E> replicate(java.util.Collection<E> objects,
                                                          org.hibernate.ReplicationMode replicationMode)
Replicate a set of entities using Hibernate/JDBC batching. If some entities fail replication, the rest can still succeed.

Parameters:
objects - entities to replicate.
replicationMode - how to perform the replication, eg. ReplicationMode.OVERWRITE.
Returns:
a BatchResult indicating the number of total entities that were attempted to be processed and the collection of entities that failed to be processed.

merge

<E extends java.io.Serializable> BatchResult<E> merge(java.util.Collection<E> objects)
Merge (almost SaveOrUpdate) a set of entities using Hibernate/JDBC batching. If some entities fail saving/updating, the rest can still succeed. The reason why we need to 'merge' as opposed to 'saveOrUpdate' is because the 'saveOrUpdate' sets the identifier on an object and a subsequent operation on the object results in a StaleStateException. Further reading: http://www.jroller.com/hasant/entry/hibernate_saveorupdate_trap_for_web Use this method ONLY if the objects have Hibernate (Hi-Lo) generated identifiers, ie. a Long id field. NOTE: this method can handle TransactionGroups.

Parameters:
objects - entities to save or update. These objects can be wrapped in TransactionGroups to ensure that a group of objects are added inserted together.
Returns:
a BatchResult indicating the number of total entities that were attempted to be processed and the collection of entities that failed to be processed. Of an TransactionGroup, only the primary object will be reported in the collection of failed entities.

saveOrUpdate

<E extends java.io.Serializable> BatchResult<E> saveOrUpdate(java.util.Collection<E> objects)
Merge (almost SaveOrUpdate) a set of entities using Hibernate/JDBC batching. If some entities fail saving/updating, the rest can still succeed. Use this method ONLY if the objects DO NOT have Hibernate (Hi-Lo) generated identifiers, ie. pojo does not have a Long id field. NOTE: this method cannot handle TransactionGroups. WARNING: this is currently NOT used in Crowd.

Parameters:
objects - entities to save or update. These objects can be wrapped in TransactionGroups to ensure that a group of objects are added inserted together.
Returns:
a BatchResult indicating the number of total entities that were attempted to be processed and the collection of entities that failed to be processed. Of an TransactionGroup, only the primary object will be reported in the collection of failed entities.

find

<E extends DirectoryEntity> java.util.Collection<E> find(long directoryID,
                                                         java.util.Collection<java.lang.String> names,
                                                         java.lang.Class<E> persistentClass)
Find a set of entities by batching SQL disjunction queries. If some entities are not found in the database, they are not present in the returned collection.

Parameters:
directoryID - 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.
Returns:
a collection of the DirectoryEntities that exist matching any of the supplied names.


Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.