org.clazzes.util.jpa.interceptors
Class EntityManagerInterceptor

java.lang.Object
  extended by org.clazzes.util.jpa.interceptors.EntityManagerInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor

public class EntityManagerInterceptor
extends java.lang.Object
implements org.aopalliance.intercept.MethodInterceptor

This interceptor open an entity manager throughout an operation and closes it at the end in a finally operation.

It might be either used with a subsequent EntityTransactionInterceptor or it may be configured to join a JTA transaction by setting jtaMode to true.


Constructor Summary
EntityManagerInterceptor()
           
 
Method Summary
 java.lang.Class<?> getContextClass()
           
 javax.persistence.EntityManagerFactory getEntityManagerFactory()
           
 java.lang.String getThreadLocalKey()
           
 java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
           
 boolean isJoinMode()
           
 void setContextClass(java.lang.Class<?> contextClass)
           
 void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
           
 void setJoinMode(boolean joinMode)
           
 void setThreadLocalKey(java.lang.String threadLocalKey)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EntityManagerInterceptor

public EntityManagerInterceptor()
Method Detail

invoke

public java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
                        throws java.lang.Throwable
Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
java.lang.Throwable

getEntityManagerFactory

public javax.persistence.EntityManagerFactory getEntityManagerFactory()
Returns:
the entityManagerFactory usually injected through blueprint.

setEntityManagerFactory

public void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
Parameters:
entityManagerFactory - the entityManagerFactory usually injected through blueprint to set.

getThreadLocalKey

public java.lang.String getThreadLocalKey()
Returns:
the threadLocalKey under which the EntityManager is bound to the current thread using ThreadLocalManager.bindResource(String, Object).

setThreadLocalKey

public void setThreadLocalKey(java.lang.String threadLocalKey)
Parameters:
threadLocalKey - the threadLocalKey under which the EntityManager is bound to the current thread using ThreadLocalManager.bindResource(String, Object) to set.

getContextClass

public java.lang.Class<?> getContextClass()
Returns:
the context class, which acts as a source of the context class loader set before proceeding. If null, the context class loader is not changed by this interceptor. If you are using a PersistenceUnitInfo implementation, which contains the correct application class loader, you should not need to set the context class here.

setContextClass

public void setContextClass(java.lang.Class<?> contextClass)
Parameters:
contextClass - the context class, which acts as a source of the context class loader to set before proceeding. If null, the context class loader is not changed by this interceptor. If you are using a PersistenceUnitInfo implementation, which contains the correct application class loader, you should not need to set the context class here.

isJoinMode

public boolean isJoinMode()
Returns:
Whether to join JTA transactions by EntityManager.joinTransaction().

setJoinMode

public void setJoinMode(boolean joinMode)
Parameters:
joinMode - Whether to join JTA transactions by EntityManager.joinTransaction(). Is set to false, you might consider to use a complementing EntityTransactionInterceptor.


Copyright © 2011. All Rights Reserved.