org.springframework.orm.jpa
Class ExtendedEntityManagerCreator.ExtendedEntityManagerSynchronization

java.lang.Object
  extended by org.springframework.transaction.support.ResourceHolderSynchronization<EntityManagerHolder,EntityManager>
      extended by org.springframework.orm.jpa.ExtendedEntityManagerCreator.ExtendedEntityManagerSynchronization
All Implemented Interfaces:
Ordered, TransactionSynchronization
Enclosing class:
ExtendedEntityManagerCreator

private static class ExtendedEntityManagerCreator.ExtendedEntityManagerSynchronization
extends ResourceHolderSynchronization<EntityManagerHolder,EntityManager>
implements Ordered

TransactionSynchronization enlisting an extended EntityManager with a current Spring transaction.


Field Summary
private  EntityManager entityManager
           
private  PersistenceExceptionTranslator exceptionTranslator
           
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Fields inherited from interface org.springframework.transaction.support.TransactionSynchronization
STATUS_COMMITTED, STATUS_ROLLED_BACK, STATUS_UNKNOWN
 
Constructor Summary
ExtendedEntityManagerCreator.ExtendedEntityManagerSynchronization(EntityManager em, PersistenceExceptionTranslator exceptionTranslator)
           
 
Method Summary
 void afterCommit()
          Invoked after transaction commit.
 void afterCompletion(int status)
          Invoked after transaction commit/rollback.
private  java.lang.RuntimeException convertException(java.lang.RuntimeException ex)
           
protected  void flushResource(EntityManagerHolder resourceHolder)
          Flush callback for the given resource holder.
 int getOrder()
          Return the order value of this object, with a higher value meaning greater in terms of sorting.
protected  boolean shouldReleaseBeforeCompletion()
          Return whether this holder's resource should be released before transaction completion (true) or rather after transaction completion (false).
 
Methods inherited from class org.springframework.transaction.support.ResourceHolderSynchronization
beforeCommit, beforeCompletion, cleanupResource, flush, processResourceAfterCommit, releaseResource, resume, shouldUnbindAtCompletion, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityManager

private final EntityManager entityManager

exceptionTranslator

private final PersistenceExceptionTranslator exceptionTranslator
Constructor Detail

ExtendedEntityManagerCreator.ExtendedEntityManagerSynchronization

public ExtendedEntityManagerCreator.ExtendedEntityManagerSynchronization(EntityManager em,
                                                                         PersistenceExceptionTranslator exceptionTranslator)
Method Detail

getOrder

public int getOrder()
Description copied from interface: Ordered
Return the order value of this object, with a higher value meaning greater in terms of sorting.

Normally starting with 0, with Integer.MAX_VALUE indicating the greatest value. Same order values will result in arbitrary positions for the affected objects.

Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).

Specified by:
getOrder in interface Ordered
Returns:
the order value

flushResource

protected void flushResource(EntityManagerHolder resourceHolder)
Description copied from class: ResourceHolderSynchronization
Flush callback for the given resource holder.

Overrides:
flushResource in class ResourceHolderSynchronization<EntityManagerHolder,EntityManager>
Parameters:
resourceHolder - the resource holder to flush

shouldReleaseBeforeCompletion

protected boolean shouldReleaseBeforeCompletion()
Description copied from class: ResourceHolderSynchronization
Return whether this holder's resource should be released before transaction completion (true) or rather after transaction completion (false).

Note that resources will only be released when they are unbound from the thread (ResourceHolderSynchronization.shouldUnbindAtCompletion()).

The default implementation returns true.

Overrides:
shouldReleaseBeforeCompletion in class ResourceHolderSynchronization<EntityManagerHolder,EntityManager>
See Also:
ResourceHolderSynchronization.releaseResource(H, K)

afterCommit

public void afterCommit()
Description copied from interface: TransactionSynchronization
Invoked after transaction commit. Can perform further operations right after the main transaction has successfully committed.

Can e.g. commit further operations that are supposed to follow on a successful commit of the main transaction, like confirmation messages or emails.

NOTE: The transaction will have been committed already, but the transactional resources might still be active and accessible. As a consequence, any data access code triggered at this point will still "participate" in the original transaction, allowing to perform some cleanup (with no commit following anymore!), unless it explicitly declares that it needs to run in a separate transaction. Hence: Use PROPAGATION_REQUIRES_NEW for any transactional operation that is called from here.

Specified by:
afterCommit in interface TransactionSynchronization
Overrides:
afterCommit in class ResourceHolderSynchronization<EntityManagerHolder,EntityManager>

afterCompletion

public void afterCompletion(int status)
Description copied from interface: TransactionSynchronization
Invoked after transaction commit/rollback. Can perform resource cleanup after transaction completion.

NOTE: The transaction will have been committed or rolled back already, but the transactional resources might still be active and accessible. As a consequence, any data access code triggered at this point will still "participate" in the original transaction, allowing to perform some cleanup (with no commit following anymore!), unless it explicitly declares that it needs to run in a separate transaction. Hence: Use PROPAGATION_REQUIRES_NEW for any transactional operation that is called from here.

Specified by:
afterCompletion in interface TransactionSynchronization
Overrides:
afterCompletion in class ResourceHolderSynchronization<EntityManagerHolder,EntityManager>
Parameters:
status - completion status according to the STATUS_* constants
See Also:
TransactionSynchronization.STATUS_COMMITTED, TransactionSynchronization.STATUS_ROLLED_BACK, TransactionSynchronization.STATUS_UNKNOWN, TransactionSynchronization.beforeCompletion()

convertException

private java.lang.RuntimeException convertException(java.lang.RuntimeException ex)