FileDocCategorySizeDatePackage
TransactionManagerHelper.javaAPI DocGlassfish v2 API8690Fri May 04 22:35:58 BST 2007com.sun.enterprise.transaction

TransactionManagerHelper

public class TransactionManagerHelper extends Object implements TransactionManager, TransactionImport
This class is wrapper for the actual transaction manager implementation. JNDI lookup name "java:appserver/TransactionManager" see the com/sun/enterprise/naming/java/javaURLContext.java

Fields Summary
private static TransactionManagerHelper
tmHelper
Constructors Summary
Methods Summary
public voidbegin()

	getTransactionManagerImpl().begin();
    
public voidcommit()

	getTransactionManagerImpl().commit();
    
public intgetStatus()

	return getTransactionManagerImpl().getStatus();
    
public javax.transaction.TransactiongetTransaction()

	return getTransactionManagerImpl().getTransaction();
    
public static javax.transaction.TransactionManagergetTransactionManager()

	return tmHelper;
    
private J2EETransactionManagergetTransactionManagerImpl()

        J2EETransactionManager tm = Switch.getSwitch().getTransactionManager();
	if (tm != null)
            return tm;
	new UserTransactionImpl(); // Hack to make clients work using this class
	tm = Switch.getSwitch().getTransactionManager();
	return tm;
    
public intgetTransactionRemainingTimeout()
Return duration before current transaction would timeout.

return
Returns the duration in seconds before current transaction would timeout. Returns zero if transaction has no timeout set and returns negative value if transaction already timed out.
exception
IllegalStateException Thrown if the current thread is not associated with a transaction.
exception
SystemException Thrown if the transaction manager encounters an unexpected error condition.

        int timeout = 0;
        Transaction txn = getTransaction(); 
        if (txn == null) {
            throw new IllegalStateException("no current transaction");
        } else if (txn instanceof J2EETransaction) {
            timeout = ((J2EETransaction)txn).getRemainingTimeout();
        }
        return timeout;
    
public javax.resource.spi.XATerminatorgetXATerminator()

        return getTransactionManagerImpl().getXATerminator();
    
public voidrecreate(javax.transaction.xa.Xid xid, long timeout)

        final J2EETransactionManager tm = getTransactionManagerImpl();
        
        try {
            tm.recreate(xid, timeout);
        } catch (javax.resource.spi.work.WorkException ex) {
            throw new IllegalStateException(ex);
        }
        servletPreInvokeTx();
    
public voidrelease(javax.transaction.xa.Xid xid)

        IllegalStateException rethrow = null;
        final J2EETransactionManager tm = getTransactionManagerImpl();
     
        servletPostInvokeTx(false);
        try {
            tm.release(xid);    
        } catch (javax.resource.spi.work.WorkException ex) {
            throw new IllegalStateException(ex);
        }  finally { 
            if (tm instanceof J2EETransactionManagerOpt) {
                ((J2EETransactionManagerOpt) tm).clearThreadTx();
            }
            if (rethrow != null) {
                throw rethrow;
            }
        } 
    
public voidresume(javax.transaction.Transaction tobj)

	getTransactionManagerImpl().resume(tobj);
    
public voidrollback()

	getTransactionManagerImpl().rollback();
    
public voidservletPostInvokeTx(boolean suspend)
PostInvoke Transaction configuration for Servlet Container. BaseContainer.preInvokeTx() handles all this for CMT EJB. Precondition: assumed called prior to current transcation being suspended or released.

param
suspend indicate whether the delisting is due to suspension or transaction completion(commmit/rollback)

        final ComponentInvocation inv = 
	    Switch.getSwitch().getInvocationManager().getCurrentInvocation();
        if (inv != null && inv.getInvocationType() == 
			ComponentInvocation.SERVLET_INVOCATION) {
            try {
                getTransactionManagerImpl().delistComponentResources(suspend);
            } catch (java.rmi.RemoteException re) {
                throw new IllegalStateException(re);
            } finally {   
		inv.setTransaction(null);
	    }
        }
    
public voidservletPreInvokeTx()
PreInvoke Transaction configuration for Servlet Container. BaseContainer.preInvokeTx() handles all this for CMT EJB. Compensate that J2EEInstanceListener.handleBeforeEvent( BEFORE_SERVICE_EVENT) gets called before WSIT WSTX Service pipe associates a JTA txn with incoming thread. Precondition: assumes JTA transaction already associated with current thread.

        final ComponentInvocation inv = 
		Switch.getSwitch().getInvocationManager().getCurrentInvocation();
        if (inv != null && 
            inv.getInvocationType() == ComponentInvocation.SERVLET_INVOCATION){
            try { 
                // Required side effect: note that 
                // enlistComponentResources calls
                // ComponentInvocation.setTransaction(currentJTATxn).
                // If this is not correctly set, managed XAResource connections
                // are not auto enlisted when they are created.
                getTransactionManagerImpl().enlistComponentResources();
            } catch (java.rmi.RemoteException re) {
                throw new IllegalStateException(re);
            }
        }
    
public voidsetRollbackOnly()

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

	getTransactionManagerImpl().setTransactionTimeout(seconds);
    
public javax.transaction.Transactionsuspend()

	return getTransactionManagerImpl().suspend();