org.openejb.core.transaction
Class TransactionPolicy

java.lang.Object
  |
  +--org.openejb.core.transaction.TransactionPolicy
Direct Known Subclasses:
CastorCmpEntityTxPolicy, SessionSynchronizationTxPolicy, StatefulBeanManagedTxPolicy, StatefulContainerManagedTxPolicy, StatelessBeanManagedTxPolicy, TxManditory, TxNever, TxNotSupported, TxRequired, TxRequiresNew, TxSupports

public abstract class TransactionPolicy
extends java.lang.Object

Use container callbacks so containers can implement any special behavior Callbacks are similar to sessionsynchronization with the addition of discardInstace createSystemException

Version:
$Revision: 1.1 $ $Date: 2002/01/21 08:09:03 $

Field Summary
static int BeanManaged
           
protected  TransactionContainer container
           
 org.apache.log4j.Category logger
           
static int Manditory
           
static int Never
           
static int NotSupported
           
 int policyType
           
static int Required
           
static int RequiresNew
           
static int Supports
           
 
Constructor Summary
TransactionPolicy()
           
 
Method Summary
abstract  void afterInvoke(javax.ejb.EnterpriseBean bean, TransactionContext context)
           
abstract  void beforeInvoke(javax.ejb.EnterpriseBean bean, TransactionContext context)
           
protected  void beginTransaction()
           
protected  void commitTransaction(javax.transaction.Transaction tx)
           
protected  void discardBeanInstance(javax.ejb.EnterpriseBean instance, ThreadContext callContext)
           
 TransactionContainer getContainer()
           
protected  javax.transaction.TransactionManager getTxMngr()
           
abstract  void handleApplicationException(java.lang.Throwable appException, TransactionContext context)
           
protected  void handleCallbackException()
          18.3.3 Exceptions from container-invoked callbacks
abstract  void handleSystemException(java.lang.Throwable sysException, javax.ejb.EnterpriseBean instance, TransactionContext context)
           
protected  void logSystemException(java.lang.Throwable sysException)
           
protected  void markTxRollbackOnly(javax.transaction.Transaction tx)
           
protected  void rollbackTransaction(javax.transaction.Transaction tx)
           
protected  void throwAppExceptionToServer(java.lang.Throwable appException)
           
protected  void throwExceptionToServer(java.lang.Throwable sysException)
          Throw RemoteException to remote client; throw EJBException to local client.
protected  void throwTxExceptionToServer(java.lang.Throwable sysException)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Manditory

public static final int Manditory

Never

public static final int Never

NotSupported

public static final int NotSupported

Required

public static final int Required

RequiresNew

public static final int RequiresNew

Supports

public static final int Supports

BeanManaged

public static final int BeanManaged

policyType

public int policyType

container

protected TransactionContainer container

logger

public org.apache.log4j.Category logger
Constructor Detail

TransactionPolicy

public TransactionPolicy()
Method Detail

getTxMngr

protected javax.transaction.TransactionManager getTxMngr()

getContainer

public TransactionContainer getContainer()

handleApplicationException

public abstract void handleApplicationException(java.lang.Throwable appException,
                                                TransactionContext context)
                                         throws ApplicationException

handleSystemException

public abstract void handleSystemException(java.lang.Throwable sysException,
                                           javax.ejb.EnterpriseBean instance,
                                           TransactionContext context)
                                    throws ApplicationException,
                                           SystemException

beforeInvoke

public abstract void beforeInvoke(javax.ejb.EnterpriseBean bean,
                                  TransactionContext context)
                           throws SystemException,
                                  ApplicationException

afterInvoke

public abstract void afterInvoke(javax.ejb.EnterpriseBean bean,
                                 TransactionContext context)
                          throws ApplicationException,
                                 SystemException

markTxRollbackOnly

protected void markTxRollbackOnly(javax.transaction.Transaction tx)
                           throws SystemException

commitTransaction

protected void commitTransaction(javax.transaction.Transaction tx)
                          throws SystemException

rollbackTransaction

protected void rollbackTransaction(javax.transaction.Transaction tx)
                            throws SystemException

throwAppExceptionToServer

protected void throwAppExceptionToServer(java.lang.Throwable appException)
                                  throws ApplicationException

throwTxExceptionToServer

protected void throwTxExceptionToServer(java.lang.Throwable sysException)
                                 throws ApplicationException

throwExceptionToServer

protected void throwExceptionToServer(java.lang.Throwable sysException)
                               throws ApplicationException
Throw RemoteException to remote client; throw EJBException to local client.
Parameters:
sysException -  
Throws:
ApplicationException -  

logSystemException

protected void logSystemException(java.lang.Throwable sysException)

discardBeanInstance

protected void discardBeanInstance(javax.ejb.EnterpriseBean instance,
                                   ThreadContext callContext)

beginTransaction

protected void beginTransaction()
                         throws javax.transaction.SystemException

handleCallbackException

protected void handleCallbackException()
18.3.3 Exceptions from container-invoked callbacks

Handles the exceptions thrown from the from the following container-invoked callback methods of the enterprise bean. EntityBean: • ejbActivate() • ejbLoad() • ejbPassivate() • ejbStore() • setEntityContext(EntityContext) • unsetEntityContext() SessionBean: • ejbActivate() • ejbPassivate() • setSessionContext(SessionContext) MessageDrivenBean: • setMessageDrivenContext(MessageDrivenContext) SessionSynchronization interface: • afterBegin() • beforeCompletion() • and afterCompletion(boolean)

The Container must handle all exceptions or errors from these methods as follows: • Log the exception or error to bring the problem to the attention of the System Administrator. • If the instance is in a transaction, mark the transaction for rollback. • Discard the instance. The Container must not invoke any business methods or container callbacks on the instance. • If the exception or error happened during the processing of a client invoked method, throw the java.rmi.RemoteException to the client if the client is a remote client or throw the javax.ejb.EJBException to the client if the client is a local client. If the instance executed in the client's transaction, the Container should throw the javax.transaction.TransactionRolledbackException to a remote client or the javax.ejb.TransactionRolledbackLocalException to a local client, because it provides more information to the client. (The client knows that it is fruitless to continue the transaction.)