org.krakenapps.jpa.handler
Class TransactionalHandler

java.lang.Object
  extended by org.apache.felix.ipojo.Handler
      extended by org.apache.felix.ipojo.PrimitiveHandler
          extended by org.krakenapps.jpa.handler.TransactionalHandler
All Implemented Interfaces:
org.apache.felix.ipojo.FieldInterceptor, org.apache.felix.ipojo.MethodInterceptor, EntityManagerFactoryListener

public class TransactionalHandler
extends org.apache.felix.ipojo.PrimitiveHandler
implements EntityManagerFactoryListener

Provide declarative transaction support using iPOJO component handler. TransactionHandler starts transaction at method entry, and commit/rollback transaction at method exit.

Author:
xeraph

Field Summary
 
Fields inherited from class org.apache.felix.ipojo.PrimitiveHandler
HANDLER_TYPE
 
Fields inherited from class org.apache.felix.ipojo.Handler
HANDLER_LEVEL_PROPERTY, HANDLER_NAME_PROPERTY, HANDLER_NAMESPACE_PROPERTY, HANDLER_TYPE_PROPERTY, m_instance, m_isValid
 
Constructor Summary
TransactionalHandler()
           
 
Method Summary
 void configure(org.apache.felix.ipojo.metadata.Element metadata, java.util.Dictionary configuration)
          Find and hook all transactional methods.
 void factoryAdded(java.lang.String factoryName, javax.persistence.EntityManagerFactory factory)
          Move to valid state if associated entity manager factory is added.
 void factoryRemoved(java.lang.String factoryName, javax.persistence.EntityManagerFactory factory)
          Move to invalid state if associated entity manager factory is removed.
 void onEntry(java.lang.Object pojo, java.lang.reflect.Method method, java.lang.Object[] args)
          Find the entity manager in the current thread context and begin transaction at entry of transactional method.
 void onError(java.lang.Object pojo, java.lang.reflect.Method method, java.lang.Throwable throwable)
          Rollback transaction in the current thread context if an exception raised.
 void onExit(java.lang.Object pojo, java.lang.reflect.Method method, java.lang.Object returnedObj)
          Commit transaction in the current thread context at exit of transactional method. onError method will be called if commit failed.
 void onFinally(java.lang.Object pojo, java.lang.reflect.Method method)
          Close the entity manager in the current thread context.
 void setJpaService(JpaService jpaService)
          Set new JPA service and register event listener to JPA service.
 void setThreadLocalEntityManager(ThreadLocalEntityManagerService threadLocalEntityManager)
          Set new thread local entity manager service
 void start()
          Check if entity manager factory is available and register factory life cycle event listener
 void stop()
          Unregister factory life cycle event listener.
 
Methods inherited from class org.apache.felix.ipojo.PrimitiveHandler
attach, getFactory, getHandler, getInstanceManager, getLogger, getPojoMetadata, onCreation, onGet, onSet, setFactory
 
Methods inherited from class org.apache.felix.ipojo.Handler
debug, error, error, getDescription, getHandlerManager, getValidity, info, initializeComponentFactory, isValid, reconfigure, setValidity, stateChanged, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionalHandler

public TransactionalHandler()
Method Detail

configure

public void configure(org.apache.felix.ipojo.metadata.Element metadata,
                      java.util.Dictionary configuration)
               throws org.apache.felix.ipojo.ConfigurationException
Find and hook all transactional methods.

Specified by:
configure in class org.apache.felix.ipojo.Handler
Throws:
org.apache.felix.ipojo.ConfigurationException

start

public void start()
Check if entity manager factory is available and register factory life cycle event listener

Specified by:
start in class org.apache.felix.ipojo.Handler

stop

public void stop()
Unregister factory life cycle event listener.

Specified by:
stop in class org.apache.felix.ipojo.Handler

onEntry

public void onEntry(java.lang.Object pojo,
                    java.lang.reflect.Method method,
                    java.lang.Object[] args)
Find the entity manager in the current thread context and begin transaction at entry of transactional method.

Specified by:
onEntry in interface org.apache.felix.ipojo.MethodInterceptor
Overrides:
onEntry in class org.apache.felix.ipojo.PrimitiveHandler

onExit

public void onExit(java.lang.Object pojo,
                   java.lang.reflect.Method method,
                   java.lang.Object returnedObj)
Commit transaction in the current thread context at exit of transactional method. onError method will be called if commit failed.

Specified by:
onExit in interface org.apache.felix.ipojo.MethodInterceptor
Overrides:
onExit in class org.apache.felix.ipojo.PrimitiveHandler

onError

public void onError(java.lang.Object pojo,
                    java.lang.reflect.Method method,
                    java.lang.Throwable throwable)
Rollback transaction in the current thread context if an exception raised.

Specified by:
onError in interface org.apache.felix.ipojo.MethodInterceptor
Overrides:
onError in class org.apache.felix.ipojo.PrimitiveHandler

onFinally

public void onFinally(java.lang.Object pojo,
                      java.lang.reflect.Method method)
Close the entity manager in the current thread context.

Specified by:
onFinally in interface org.apache.felix.ipojo.MethodInterceptor
Overrides:
onFinally in class org.apache.felix.ipojo.PrimitiveHandler

setJpaService

public void setJpaService(JpaService jpaService)
Set new JPA service and register event listener to JPA service.

Parameters:
jpaService - new JPA service

setThreadLocalEntityManager

public void setThreadLocalEntityManager(ThreadLocalEntityManagerService threadLocalEntityManager)
Set new thread local entity manager service

Parameters:
threadLocalEntityManager - the thread local entity manager service

factoryAdded

public void factoryAdded(java.lang.String factoryName,
                         javax.persistence.EntityManagerFactory factory)
Move to valid state if associated entity manager factory is added.

Specified by:
factoryAdded in interface EntityManagerFactoryListener
Parameters:
factoryName - the name of entity manager factory
factory - the newly added entity manager factory

factoryRemoved

public void factoryRemoved(java.lang.String factoryName,
                           javax.persistence.EntityManagerFactory factory)
Move to invalid state if associated entity manager factory is removed.

Specified by:
factoryRemoved in interface EntityManagerFactoryListener
Parameters:
factoryName - the name of entity manager factory
factory - the removed entity manager factory


Copyright © 2008-2009 Kraken Project. All Rights Reserved.