Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2009, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags.
   * See the copyright.txt in the distribution for a full listing
   * of individual contributors.
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  *
  * (C) 2009,
  * @author JBoss Inc.
  */
 package com.arjuna.ats.internal.jta.transaction.arjunacore.jca;
 
 import  javax.resource.spi.XATerminator;
 import  javax.transaction.TransactionManager;
 
Utility factory class to return appropriate implementations of the TransactionImporter and XATerminator interfaces. This will automatically instantiate the correct implementations based on the use of the JTA or JTAX transaction manager configuration and is therefore preferred to instantiating a specific implementation class directly.
 
 public class SubordinationManager
 {
     public enum TxType { JTA, JTS }    
     
     private static TransactionImporter transactionImporter = null;
     private static XATerminator xaTerminator = null;
     private static TxType txType;
 
     public static TransactionImporter getTransactionImporter()
     {
         if( == null)
         {
             initTransactionImporter();
         }
         
         return ;
     }
 
     public static XATerminator getXATerminator()
     {
         if( == null)
         {
             initXATerminator();
         }
         
         return ;
     }
 
     public static TxType getTxType()
     {
         return ;
     }
 
     public static void setTxType(TxType txType)
     {
 		if (..isTraceEnabled()) {
             ..trace("SubordinationManager.setTxType(" + txType + ")");
         }
         
         if(. != null && . != txType)
         {
             throw new IllegalStateException("SubordinationManager can't change txType once it has been set.");
         }
         
         . = txType;
     }
 
     private static void initTransactionImporter()
     {
         if( == null) {
             setTxTypeguessTxType() );
         }
         
         if( == .)
         {
             // we are running in JTA mode
              = new TransactionImporterImple();
         }
         else
         {
             // it's not JTA, so it must be JTAX. However, we are in the JTA module and
             // can't link against the JTS code so we need to do it the hard way...
             try
             {
                 Class clazz = Class.forName("com.arjuna.ats.internal.jta.transaction.jts.jca.TransactionImporterImple");
                  = (TransactionImporter)clazz.newInstance();
            }
            catch(Exception e)
            {
            }
        }
    }
    
    private static void initXATerminator()
    {
        if( == null) {
            setTxTypeguessTxType() );
        }
        TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
        
        if( == .)
        {
            // we are running in JTA mode
             = new XATerminatorImple();
        }
        else
        {
            // it's not JTA, so it must be JTAX. However, we are in the JTA module and
            // can't link against the JTS code so we need to do it the hard way...
            try
            {
                Class clazz = Class.forName("com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple");
                 = (XATerminator)clazz.newInstance();
            }
            catch(Exception e)
            {
            }
        }
    }

    
Its rather tricky to figure out if we are running in JTA or JTAX(JTS) mode. We can make a reasonable guess based on the transaction manager implementation that is running, but it's going to break if some unknown or derived impl comes along. It's therefore safer to use setTxType explicitly in such cases.

Returns:
best guess at the currently configured TxType.
    private static TxType guessTxType() {
        TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
        
        {
            return .;
        } else if (tm.getClass().getName().contains(".jts.") || tm.getClass().getName().contains(".jtax.")) {
            return .;
        } else {
            return .;
        }
    }
New to GrepCode? Check out our FAQ X