org.objectweb.easybeans.transaction.interceptors
Class AbsTransactionInterceptor

java.lang.Object
  extended by org.objectweb.easybeans.transaction.interceptors.AbsTransactionInterceptor
All Implemented Interfaces:
EasyBeansInterceptor
Direct Known Subclasses:
BMTStatefulTransactionInterceptor, BMTStatelessTransactionInterceptor, BMTTransactionInterceptor, CMTMandatoryTransactionInterceptor, CMTNeverTransactionInterceptor, CMTNotSupportedTransactionInterceptor, CMTRequiredTransactionInterceptor, CMTRequiresNewTransactionInterceptor, CMTSupportsTransactionInterceptor, ListenerSessionSynchronizationInterceptor

public abstract class AbsTransactionInterceptor
extends java.lang.Object
implements EasyBeansInterceptor

Defines an abstract interceptor for transaction with common code used by all transaction interceptors.

Author:
Florent Benoit

Field Summary
private  JLog logger
          Logger.
private  javax.transaction.TransactionManager transactionManager
          Transaction manager.
 
Constructor Summary
AbsTransactionInterceptor()
          Constructor.
Acquire the transaction manager.
 
Method Summary
protected  void commit()
          Commit the current transaction.
protected  void discard(EasyBeansInvocationContext invocationContext)
          Remove from the factory's pool the bean found in the current invocation context.
protected  ApplicationException getApplicationException(EasyBeansInvocationContext invocationContext, java.lang.Exception e)
          Gets the application exception (if any) for the given invocation context and the given exception.
Note that a checked Exception is by default an application exception.
 javax.transaction.TransactionManager getTransactionManager()
          Gets the transaction manager.
protected  void handleBeanManagedException(EasyBeansInvocationContext invocationContext, java.lang.Exception e)
          Handle an exception for bean managed transaction.
See Chapter 14.3.1.
protected  void handleContextClientTransaction(EasyBeansInvocationContext invocationContext, java.lang.Exception e)
          Handle an exception and the transaction is the client transaction.
See Chapter 14.3.1.
protected  void handleContextContainerTransaction(EasyBeansInvocationContext invocationContext, java.lang.Exception e)
          Handle an exception and the transaction is the container transaction.
protected  void handleUnspecifiedTransactionContext(EasyBeansInvocationContext invocationContext, java.lang.Exception e)
          Handle an exception that are in an unspecified transaction context.
See Chapter 14.3.1.
abstract  java.lang.Object intercept(EasyBeansInvocationContext invocationContext)
          Defines the code used by the transaction interceptor on a given method.
protected  boolean isMarkedRollbackOnly()
          Test if current transaction is with status STATUS_MARKED_ROLLBACK.
protected  void markTransactionRollback()
          Marks the transaction for rollback.
protected  void rollback()
          Rollback the current transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private JLog logger
Logger.


transactionManager

private javax.transaction.TransactionManager transactionManager
Transaction manager.

Constructor Detail

AbsTransactionInterceptor

public AbsTransactionInterceptor()
Constructor.
Acquire the transaction manager.

Method Detail

intercept

public abstract java.lang.Object intercept(EasyBeansInvocationContext invocationContext)
                                    throws java.lang.Exception
Defines the code used by the transaction interceptor on a given method.

Specified by:
intercept in interface EasyBeansInterceptor
Parameters:
invocationContext - context with useful attributes on the current invocation
Returns:
result of the next invocation (to chain interceptors)
Throws:
java.lang.Exception - if interceptor fails

getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()
Gets the transaction manager.

Returns:
TM.

getApplicationException

protected ApplicationException getApplicationException(EasyBeansInvocationContext invocationContext,
                                                       java.lang.Exception e)
Gets the application exception (if any) for the given invocation context and the given exception.
Note that a checked Exception is by default an application exception.

Parameters:
invocationContext - context that provides access to the Method object.
e - the exception to check
Returns:
the application exception object, else null.

discard

protected void discard(EasyBeansInvocationContext invocationContext)
                throws PoolException
Remove from the factory's pool the bean found in the current invocation context.

Parameters:
invocationContext - the context of the current invocation
Throws:
PoolException - if removal is failing

markTransactionRollback

protected void markTransactionRollback()
Marks the transaction for rollback.


isMarkedRollbackOnly

protected boolean isMarkedRollbackOnly()
Test if current transaction is with status STATUS_MARKED_ROLLBACK.

Returns:
true if status == STATUS_MARKED_ROLLBACK

rollback

protected void rollback()
Rollback the current transaction.


commit

protected void commit()
Commit the current transaction.


handleBeanManagedException

protected void handleBeanManagedException(EasyBeansInvocationContext invocationContext,
                                          java.lang.Exception e)
                                   throws java.lang.Exception
Handle an exception for bean managed transaction.
See Chapter 14.3.1.

Parameters:
invocationContext - the context of the current invocation
e - the exception to handle
Throws:
java.lang.Exception - when handling the exception.

handleUnspecifiedTransactionContext

protected void handleUnspecifiedTransactionContext(EasyBeansInvocationContext invocationContext,
                                                   java.lang.Exception e)
                                            throws java.lang.Exception
Handle an exception that are in an unspecified transaction context.
See Chapter 14.3.1.

Parameters:
invocationContext - the context of the current invocation
e - the exception to handle
Throws:
java.lang.Exception - when handling the exception.

handleContextClientTransaction

protected void handleContextClientTransaction(EasyBeansInvocationContext invocationContext,
                                              java.lang.Exception e)
                                       throws java.lang.Exception
Handle an exception and the transaction is the client transaction.
See Chapter 14.3.1.

Parameters:
invocationContext - the context of the current invocation
e - the exception to handle
Throws:
java.lang.Exception - when handling the exception.

handleContextContainerTransaction

protected void handleContextContainerTransaction(EasyBeansInvocationContext invocationContext,
                                                 java.lang.Exception e)
                                          throws java.lang.Exception
Handle an exception and the transaction is the container transaction. Bean method runs in the context of a transaction that the container started immediately before dispatching the business method.
See Chapter 14.3.1.

Parameters:
invocationContext - the context of the current invocation
e - the exception to handle
Throws:
java.lang.Exception - when handling the exception.