org.spicefactory.pimento.context
Class SpringPersistenceContextPhaseListener

java.lang.Object
  extended by org.spicefactory.pimento.context.AbstractPersistenceContextPhaseListener
      extended by org.spicefactory.pimento.context.SpringPersistenceContextPhaseListener
All Implemented Interfaces:
PhaseListener

public class SpringPersistenceContextPhaseListener
extends AbstractPersistenceContextPhaseListener

Implementation of Cinnamon's PhaseListener extension point that uses Springs transaction management and JPA support.

Author:
Jens Halm

Constructor Summary
SpringPersistenceContextPhaseListener(PlatformTransactionManager txManager, EntityManagerFactory emf)
          Creates a new instance.
 
Method Summary
protected  boolean bindEntityManager()
          Bind an EntityManager to the current thread.
protected  void commitTransaction(Object transactionContext)
          Commits the transaction represented by the specified parameter.
protected  Object createTransaction()
          Creates a transaction and returns a transaction status object.
protected  void rollbackTransaction(Object transactionContext)
          Performs a rollback for the transaction represented by the specified parameter.
protected  void unbindEntityManager()
          Unbind the EntityManager from the current thread.
 
Methods inherited from class org.spicefactory.pimento.context.AbstractPersistenceContextPhaseListener
afterDecodingException, afterEncoding, afterProcessing, beforeDecoding, beforeProcessing, containsError, createRequestContext, getEntityManagerFactory, releaseRequestContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringPersistenceContextPhaseListener

public SpringPersistenceContextPhaseListener(PlatformTransactionManager txManager,
                                             EntityManagerFactory emf)
Creates a new instance.

Parameters:
txManager - the transaction manager to use
emf - the EntityManagerFactory to use
Method Detail

createTransaction

protected Object createTransaction()
Description copied from class: AbstractPersistenceContextPhaseListener
Creates a transaction and returns a transaction status object. The type of the returned object depends on the transaction management system in use.

Specified by:
createTransaction in class AbstractPersistenceContextPhaseListener
Returns:
a transaction status object

commitTransaction

protected void commitTransaction(Object transactionContext)
Description copied from class: AbstractPersistenceContextPhaseListener
Commits the transaction represented by the specified parameter. The type of the parameter depends on the transaction management system in use. It is always the same instance that was returned from createTransaction.

Specified by:
commitTransaction in class AbstractPersistenceContextPhaseListener
Parameters:
transactionContext - the status object for the transaction to commit

rollbackTransaction

protected void rollbackTransaction(Object transactionContext)
Description copied from class: AbstractPersistenceContextPhaseListener
Performs a rollback for the transaction represented by the specified parameter. The type of the parameter depends on the transaction management system in use. It is always the same instance that was returned from createTransaction.

Specified by:
rollbackTransaction in class AbstractPersistenceContextPhaseListener
Parameters:
transactionContext - the status object for the transaction to rollback

bindEntityManager

protected boolean bindEntityManager()
Description copied from class: AbstractPersistenceContextPhaseListener
Bind an EntityManager to the current thread.

Specified by:
bindEntityManager in class AbstractPersistenceContextPhaseListener
Returns:
true if a new EntityManager was created

unbindEntityManager

protected void unbindEntityManager()
Description copied from class: AbstractPersistenceContextPhaseListener
Unbind the EntityManager from the current thread.

Specified by:
unbindEntityManager in class AbstractPersistenceContextPhaseListener