FileDocCategorySizeDatePackage
UserTransactionImpl.javaAPI DocGlassfish v2 API9637Fri May 04 22:34:54 BST 2007com.sun.enterprise.distributedtx

UserTransactionImpl

public class UserTransactionImpl extends Object implements UserTransaction, Serializable
This class implements javax.transaction.UserTransaction . Its methods are called from TX_BEAN_MANAGED EJB code. Most of its methods just delegate to the TransactionManager after doing some EJB Container-related steps. Note: EJB1.1 Section 6.4.1 requires that the Container must be able to preserve an object reference of the UserTransaction interface across passivation, so we make this Serializable.
author
Tony Ng

Fields Summary
static Logger
_logger
private static com.sun.enterprise.util.i18n.StringManager
sm
private static final boolean
debug
private transient J2EETransactionManager
transactionManager
private transient InvocationManager
invocationManager
private transient boolean
initialized
private transient UserTransaction
userTx
private boolean
checkEjbAccess
Constructors Summary
public UserTransactionImpl()
Default constructor.


           
     
    
        this(true);
    
public UserTransactionImpl(boolean doEjbAccessChecks)
Alternate version of constructor that allows control over whether ejb access checks are performed.

        init();
        checkEjbAccess = doEjbAccessChecks;
    
Methods Summary
public voidbegin()

        if (!initialized) init();

        if (userTx != null) {
            userTx.begin();
            return;
        }

        ComponentInvocation inv = invocationManager.getCurrentInvocation();
	    if (inv != null) {
            checkUserTransactionMethodAccess(inv);
	    }

	    transactionManager.begin();
            /**
	    if ( transactionTimeout > 0 ) 
	        transactionManager.begin(transactionTimeout);
	    else
	        transactionManager.begin();
            **/

	    try {
                if (inv != null) {
	            if ( inv.getInvocationType() == ComponentInvocation.EJB_INVOCATION )
		        ((Container)inv.container).doAfterBegin(inv);

                    inv.setTransaction(transactionManager.getTransaction());
                    transactionManager.enlistComponentResources();
                }
        } catch ( RemoteException ex ) {
            _logger.log(Level.SEVERE,"enterprise_distributedtx.excep_in_utx_begin", ex);
            SystemException sysEx = new SystemException(ex.getMessage());
            sysEx.initCause(ex);
            throw sysEx;
        }
    
private voidcheckUserTransactionMethodAccess(ComponentInvocation inv)

        if ( (inv.getInvocationType() == ComponentInvocation.EJB_INVOCATION)
             && checkEjbAccess ) {
            Container ejbContainer = (Container) inv.container;
            if( !ejbContainer.userTransactionMethodsAllowed(inv) ) {
                throw new IllegalStateException(sm.getString("enterprise_distributedtx.operation_not_allowed"));
            }
        }
    
public voidcommit()

        if (!initialized) init();

        if (userTx != null) {
            userTx.commit();
            return;
        }

	    ComponentInvocation inv = invocationManager.getCurrentInvocation();
        if (inv != null) {
            checkUserTransactionMethodAccess(inv);
        }


        try {
            transactionManager.delistComponentResources(false);  // TMSUCCESS
            transactionManager.commit();
        } catch ( RemoteException ex ) {
            _logger.log(Level.SEVERE,"enterprise_distributedtx.excep_in_utx_commit", ex);
            throw new SystemException();
        } finally {
            if (inv != null)
                inv.setTransaction(null);
        }
    
public intgetStatus()

        if (!initialized) init();

        if (userTx != null) {
            return userTx.getStatus();
        }

        ComponentInvocation inv = invocationManager.getCurrentInvocation();
        if (inv != null) {
                checkUserTransactionMethodAccess(inv);
        }

        return transactionManager.getStatus();
    
private voidinit()
Could be called after passivation and reactivation

        initialized = true;
        Switch theSwitch = Switch.getSwitch();
        transactionManager = theSwitch.getTransactionManager();
        invocationManager = theSwitch.getInvocationManager();
	if (invocationManager == null) 
	    invocationManager = new InvocationManagerImpl();
        if (transactionManager == null) {
	    PEORBConfigurator.initTransactionService(null, new Properties());
	    transactionManager = 
		    J2EETransactionManagerImpl.createTransactionManager();
	    theSwitch.setTransactionManager(transactionManager);

            // non J2EE client, set up UserTransaction from JTS
           //  userTx = new com.sun.jts.jta.UserTransactionImpl();
        }
    
public voidrollback()

        if (!initialized) init();

        if (userTx != null) {
            userTx.rollback();
            return;
        }

        ComponentInvocation inv = invocationManager.getCurrentInvocation();
        if (inv != null) {
                checkUserTransactionMethodAccess(inv);
        }


        try {
            transactionManager.delistComponentResources(false); // TMSUCCESS
            transactionManager.rollback();
        } catch ( RemoteException ex ) {
            _logger.log(Level.SEVERE,"enterprise_distributedtx.excep_in_utx_rollback", ex);
            throw new SystemException();
        } finally {
            if (inv !=  null)
                inv.setTransaction(null);
        }
    
public voidsetRollbackOnly()

        if (!initialized) init();

        if (userTx != null) {
            userTx.setRollbackOnly();
            return;
        }

        ComponentInvocation inv = invocationManager.getCurrentInvocation();
        if (inv != null) {
                checkUserTransactionMethodAccess(inv);
        }

        transactionManager.setRollbackOnly();
    
public voidsetTransactionTimeout(int seconds)

        if (!initialized) init();

        if (userTx != null) {
            userTx.setTransactionTimeout(seconds);
            return;
        }

	ComponentInvocation inv = invocationManager.getCurrentInvocation();
        if (inv != null) {
                checkUserTransactionMethodAccess(inv);
        }
        
        if (seconds < 0) seconds = 0;
        // transactionTimeout = seconds;
        transactionManager.setTransactionTimeout(seconds);