FileDocCategorySizeDatePackage
TransactionManagerImpl.javaAPI DocExample12983Tue May 29 16:57:16 BST 2007com.sun.xml.ws.tx.common

TransactionManagerImpl

public class TransactionManagerImpl extends Object implements TransactionManager, TransactionSynchronizationRegistry
Access hosting JTA 1.1 TransactionManager and TransactionSynchronizationRegistry.

Dependencies: Sun Java System Application Server publishes TM at JNDI name:

author
jf39279

Fields Summary
private static final TxLogger
logger
private static final TransactionManagerImpl
singleton
private final TransactionManager
javaeeTM
private final TransactionSynchronizationRegistry
javaeeSynchReg
private static final String
AS_TXN_MGR_JNDI_NAME
private static final String
TXN_SYNC_REG_JNDI_NAME
private static final String
USER_TRANSACTION_JNDI_NAME
private static boolean
initialized
private static Method
servletPreInvokeTxMethod
private static Method
servletPostInvokeTxMethod
Constructors Summary
private TransactionManagerImpl()
Creates a new instance of TransactionManagerImpl

        javaeeTM = (TransactionManager) jndiLookup(AS_TXN_MGR_JNDI_NAME);
        javaeeSynchReg = (TransactionSynchronizationRegistry) jndiLookup(TXN_SYNC_REG_JNDI_NAME);
    
Methods Summary
public voidbegin()

        javaeeTM.begin();
    
public voidcommit()

        javaeeTM.commit();
    
public com.sun.xml.ws.tx.coordinator.CoordinationContextInterfacegetCoordinationContext()
Get the coordination context associated with the current transaction.

Returns null if none set.

        return (CoordinationContextInterface) getResource("WSCOOR-SUN");
    
public static com.sun.xml.ws.tx.common.TransactionManagerImplgetInstance()


        
        return singleton;
    
private static java.lang.reflect.MethodgetMethod(java.lang.Class theClass, java.lang.String methodName, java.lang.Class param)

        Method method = null;
        try {
            if (param == null) {
                method = theClass.getMethod(methodName);
            } else {
                method = theClass.getMethod(methodName, param);
            }
            logger.finest("getMethod", "found Sun App Server 9.1 container specific method via reflection " + theClass.getName() + "."  + methodName);
        } catch (Exception e) {
            logger.finest("getMethod", "reflection lookup of  " + theClass.getName() + "." + methodName + "("
                   + (param == null ? "" : param.getName()) 
                   + ") failed with handled exception ", e);
        }
        return method;
    
public intgetRemainingTimeout()
Returns in seconds duration till current transaction times out. Returns negative value if transaction has already timedout. Returns 0 if there is no timeout. Returns 0 if any exceptions occur looking up remaining transaction timeout.

        final String METHOD="getRemainingTimeout";
        try {
            return TransactionImportManager.getInstance().getTransactionRemainingTimeout();
        } catch (SystemException se) {
            if (logger.isLogging(Level.FINEST)) {
                logger.finest(METHOD, "getRemainingTimeout stack trace", se);
            } else {
                logger.info(METHOD, 
                        LocalizationMessages.TXN_MGR_OPERATION_FAILED_2008("getTransactionRemainingTimeout",
                                                                           se.getLocalizedMessage()));
            }
        } catch (Throwable t) {
             if (logger.isLogging(Level.FINEST)) {
                logger.finest(METHOD, "getTransactionRemainingTimeout() failed, default to no timeout" );
            } else {
                logger.info(METHOD, LocalizationMessages.TXN_MGR_OPERATION_FAILED_2008("getTransactionRemainingTimeout", 
                        t.getLocalizedMessage()));
         
            }
        }
         return 0;
    
public java.lang.ObjectgetResource(java.lang.Object object)

        return javaeeSynchReg.getResource(object);
    
public booleangetRollbackOnly()

        return javaeeSynchReg.getRollbackOnly();
    
public intgetStatus()

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

        return javaeeTM.getTransaction();
    
public java.lang.ObjectgetTransactionKey()

        return javaeeSynchReg.getTransactionKey();
    
javax.transaction.TransactionManagergetTransactionManager()

        return javaeeTM;
    
public intgetTransactionStatus()

        return javaeeSynchReg.getTransactionStatus();
    
public javax.transaction.UserTransactiongetUserTransaction()

        return (UserTransaction)jndiLookup(USER_TRANSACTION_JNDI_NAME);
    
private voidinitServletMethods()

    
       
         if (initialized == false) {
            initialized = true;
            servletPreInvokeTxMethod = getMethod(javaeeTM.getClass(), "servletPreInvokeTx", null);
            servletPostInvokeTxMethod = getMethod(javaeeTM.getClass(), "servletPostInvokeTx", boolean.class);
         }
    
public booleanisTransactionManagerAvailable()

        return javaeeTM != null;
    
private static java.lang.ObjectjndiLookup(java.lang.String jndiName)

        Object result = null;
        try {
            final Context ctx = new InitialContext();
            result = ctx.lookup(jndiName);
        } catch (NamingException e) {
            logger.fine("jndiLookup", LocalizationMessages.FAILED_JNDI_LOOKUP_2001(jndiName));
        }
        return result;
    
public voidputResource(java.lang.Object object, java.lang.Object object0)

        javaeeSynchReg.putResource(object, object0);
    
public voidregisterInterposedSynchronization(javax.transaction.Synchronization synchronization)

        javaeeSynchReg.registerInterposedSynchronization(synchronization);
    
public voidregisterSynchronization(javax.transaction.Synchronization sync)

        final String METHOD="registerSynchronization";
        
        if (sync == null) {
            return;
        }
        
        Transaction txn = null;
        try {
            txn = javaeeTM.getTransaction();
        } catch (SystemException ex) {
             logger.info(METHOD, LocalizationMessages.OPERATION_FAILED_2010("getTransaction"), ex);
        }
        if (txn == null) {
            logger.warning(METHOD, LocalizationMessages.REGISTER_SYNCH_NO_CURRENT_TXN_2011(sync.getClass().getName()));
        } else {
            try {
                txn.registerSynchronization(sync);
            } catch (IllegalStateException ex) {
                   logger.info(METHOD, LocalizationMessages.OPERATION_FAILED_2010(METHOD), ex);
            } catch (RollbackException ex) {
                   logger.info(METHOD, LocalizationMessages.OPERATION_FAILED_2010(METHOD), ex);
            } catch (SystemException ex) {
                  logger.info(METHOD, LocalizationMessages.OPERATION_FAILED_2010(METHOD), ex);
            }
        }
    
public voidresume(javax.transaction.Transaction transaction)

        javaeeTM.resume(transaction);
        servletPreInvokeTx();
    
public voidrollback()

        javaeeTM.rollback();
    
public voidservletPostInvokeTx(java.lang.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. Note: this method is a no-op when invoked on an EJB. The J2EE method only has an effect on servlets.

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

          final String METHOD = "servletPostInvokeTx";
       initServletMethods();
       if (servletPostInvokeTxMethod != null) {
            try {
                servletPostInvokeTxMethod.invoke(javaeeTM, suspend);
            } catch (Throwable ex) {
                 logger.info(METHOD, LocalizationMessages.OPERATION_FAILED_2010(METHOD), ex);
            }
       }
    
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. Note: this method is a no-op when invoked on an EJB.

       final String METHOD = "servletPreInvokeTx";
       initServletMethods();
       if (servletPreInvokeTxMethod != null) {
            try {
                servletPreInvokeTxMethod.invoke(javaeeTM);
            } catch (Throwable ex) {
                logger.info(METHOD, LocalizationMessages.OPERATION_FAILED_2010(METHOD), ex);
            }
       }
    
public voidsetCoordinationContext(com.sun.xml.ws.tx.coordinator.CoordinationContextInterface coordCtx)
Set the coordination context associated with the current transaction.

        putResource("WSCOOR-SUN", coordCtx);
    
public voidsetRollbackOnly()

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

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

        servletPostInvokeTx(true);
        return javaeeTM.suspend();