org.openejb.core.transaction
Class TxRequired

java.lang.Object
  |
  +--org.openejb.core.transaction.TransactionPolicy
        |
        +--org.openejb.core.transaction.TxRequired

public class TxRequired
extends TransactionPolicy

17.6.2.2 Required The Container must invoke an enterprise Bean method whose transaction attribute is set to Required with a valid transaction context. If a client invokes the enterprise Bean's method while the client is associated with a transaction context, the container invokes the enterprise Bean's method in the client's transaction context. If the client invokes the enterprise Bean's method while the client is not associated with a transaction context, the container automatically starts a new transaction before delegating a method call to the enterprise Bean business method. The Container automatically enlists all the resource managers accessed by the business method with the transaction. If the business method invokes other enterprise beans, the Container passes the transaction context with the invocation. The Container attempts to commit the transaction when the business method has completed. The container performs the commit protocol before the method result is sent to the client.

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

Fields inherited from class org.openejb.core.transaction.TransactionPolicy
BeanManaged, container, logger, Manditory, Never, NotSupported, policyType, Required, RequiresNew, Supports
 
Constructor Summary
TxRequired()
           
TxRequired(TransactionContainer container)
           
 
Method Summary
 void afterInvoke(javax.ejb.EnterpriseBean instance, TransactionContext context)
           
 void beforeInvoke(javax.ejb.EnterpriseBean instance, TransactionContext context)
           
 void handleApplicationException(java.lang.Throwable appException, TransactionContext context)
          Container's action
 void handleSystemException(java.lang.Throwable sysException, javax.ejb.EnterpriseBean instance, TransactionContext context)
          A system exception is any exception that is not an Application Exception.
 
Methods inherited from class org.openejb.core.transaction.TransactionPolicy
beginTransaction, commitTransaction, discardBeanInstance, getContainer, getTxMngr, handleCallbackException, logSystemException, markTxRollbackOnly, rollbackTransaction, throwAppExceptionToServer, throwExceptionToServer, throwTxExceptionToServer
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TxRequired

public TxRequired(TransactionContainer container)

TxRequired

public TxRequired()
Method Detail

beforeInvoke

public void beforeInvoke(javax.ejb.EnterpriseBean instance,
                         TransactionContext context)
                  throws SystemException,
                         ApplicationException
Overrides:
beforeInvoke in class TransactionPolicy

afterInvoke

public void afterInvoke(javax.ejb.EnterpriseBean instance,
                        TransactionContext context)
                 throws ApplicationException,
                        SystemException
Overrides:
afterInvoke in class TransactionPolicy

handleApplicationException

public void handleApplicationException(java.lang.Throwable appException,
                                       TransactionContext context)
                                throws ApplicationException
Container's action

Re-throw AppException

Client's view

Client receives AppException. Can attempt to continue computation in the transaction, and eventually commit the transaction (the commit would fail if the instance called setRollbackOnly()).

Overrides:
handleApplicationException in class TransactionPolicy

handleSystemException

public void handleSystemException(java.lang.Throwable sysException,
                                  javax.ejb.EnterpriseBean instance,
                                  TransactionContext context)
                           throws ApplicationException,
                                  SystemException
A system exception is any exception that is not an Application Exception.
Container's action

  1. Log the exception or error so that the System Administrator is alerted of the problem.
  2. Mark the transaction for rollback.
  3. Discard instance. The Container must not invoke any business methods or container callbacks on the instance.
  4. Throw javax.transaction.TransactionRolledbackException to remote client; throw javax.ejb.TransactionRolledbackLocalException to local client.

Client's view

Receives javax.transaction.TransactionRolledbackException or javax.ejb.TransactionRolledbackLocalException. Continuing transaction is fruitless.

Overrides:
handleSystemException in class TransactionPolicy