You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/03/05 00:43:29 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/odmg/transaction SunOneTransactionManagerFactory.java JOnASTransactionManagerFactory.java AbstractTransactionManagerFactory.java TransactionManagerFactoryException.java WebSphereTransactionManagerFactory.java WeblogicTransactionManagerFactory.java TransactionManagerFactoryFactory.java TransactionManagerFactory.java OrionTransactionManagerFactory.java JBossTransactionManagerFactory.java TransactionManagerAbstractFactory.java

arminw      2004/03/04 15:43:29

  Modified:    src/java/org/apache/ojb/odmg/transaction
                        TransactionManagerFactoryException.java
                        WebSphereTransactionManagerFactory.java
                        WeblogicTransactionManagerFactory.java
                        TransactionManagerFactoryFactory.java
                        TransactionManagerFactory.java
                        OrionTransactionManagerFactory.java
                        JBossTransactionManagerFactory.java
  Added:       src/java/org/apache/ojb/odmg/transaction
                        SunOneTransactionManagerFactory.java
                        JOnASTransactionManagerFactory.java
                        AbstractTransactionManagerFactory.java
  Removed:     src/java/org/apache/ojb/odmg/transaction
                        TransactionManagerAbstractFactory.java
  Log:
  - add support for JOnAS/SunOne TM
  - class refactoring
  
  Revision  Changes    Path
  1.3       +11 -4     db-ojb/src/java/org/apache/ojb/odmg/transaction/TransactionManagerFactoryException.java
  
  Index: TransactionManagerFactoryException.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/transaction/TransactionManagerFactoryException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TransactionManagerFactoryException.java	27 Feb 2004 20:17:38 -0000	1.2
  +++ TransactionManagerFactoryException.java	4 Mar 2004 23:43:29 -0000	1.3
  @@ -1,11 +1,14 @@
   package org.apache.ojb.odmg.transaction;
  +
  +import org.apache.ojb.broker.OJBException;
  +
   /**
    * Exception when TransactionManagerFactory is unable to fetch the transaction.
  - * 
  - * @author matthew.baird
    *
  + * @author matthew.baird
  + * @version $Id$
    */
  -public class TransactionManagerFactoryException extends Exception
  +public class TransactionManagerFactoryException extends OJBException
   {
   	/**
   	 * Constructor for TransactionManagerFactoryException.
  @@ -22,5 +25,9 @@
   	{
   		super(message);
   	}
  -	
  +
  +    public TransactionManagerFactoryException(String msg, Throwable cause)
  +    {
  +        super(msg, cause);
  +    }
   }
  
  
  
  1.4       +21 -84    db-ojb/src/java/org/apache/ojb/odmg/transaction/WebSphereTransactionManagerFactory.java
  
  Index: WebSphereTransactionManagerFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/transaction/WebSphereTransactionManagerFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WebSphereTransactionManagerFactory.java	27 Feb 2004 20:17:38 -0000	1.3
  +++ WebSphereTransactionManagerFactory.java	4 Mar 2004 23:43:29 -0000	1.4
  @@ -1,4 +1,5 @@
   package org.apache.ojb.odmg.transaction;
  +
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  @@ -52,92 +53,28 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  +
   /**
  + * Websphere (4 and above) {@link javax.transaction.TransactionManager} lookup.
  + *
    * @author matthew.baird
  + * @version $Id$
    */
  -import java.lang.reflect.InvocationTargetException;
  -import java.lang.reflect.Method;
  -
  -import javax.transaction.TransactionManager;
  -
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  -
  -
  -public class WebSphereTransactionManagerFactory
  -	implements TransactionManagerFactory
  +public class WebSphereTransactionManagerFactory extends AbstractTransactionManagerFactory
   {
  -	
  -	private static Logger log;
  -	
  -	/**
  -	 * Constructor for WebSphereTransactionManagerFactory.
  -	 */
  -	public WebSphereTransactionManagerFactory()
  -	{
  -		super();
  -		log = LoggerFactory.getLogger(WebSphereTransactionManagerFactory.class);
  -	}
  -	
  -	/**
  -	 * use reflection to bind to the appropriate websphere classes so we don't have
  -	 * to import or have those libraries available.
  -	 * 
  -	 * com.ibm.ejcs.jts.jta.JTSXA.getTransactionManager()
  -	 * @see org.apache.ojb.otm.jdo.transactionmanager.TransactionManagerFactory#getTransactionManager()
  -	 */
  -	public TransactionManager getTransactionManager()
  -		throws TransactionManagerFactoryException
  -	{
  -		if (log.isDebugEnabled())
  -			log.debug(
  -				"WeblogicTransactionManagerFactory.getTransactionManager called");
  -		TransactionManager txManager = null;
  -		try
  -		{
  -			Class TransactionManagerFactory 
  -				= Class.forName("com.ibm.ejs.jts.jta.TransactionManagerFactory");
  -			Method method = TransactionManagerFactory.getMethod("getTransactionManager", null);
  -			txManager = (TransactionManager) method.invoke(TransactionManagerFactory, null);
  -		}
  -		catch (Exception e)
  -		{
  -			/**
  -			 * error getting tm for websphere 5, fall back to 4
  -			 */
  -			try
  -			{
  -				/**
  -				 * call the method on the class because it is static.
  -				 * WebSphere 4
  -				 */
  -				Class JTSXA = Class.forName("com.ibm.ejs.jts.jta.JTSXA");
  -				Method method =
  -					JTSXA.getMethod("getTransactionManager", null);
  -				txManager = (TransactionManager) method.invoke(JTSXA, null);
  -			}
  -			catch (IllegalAccessException illegalAccessException)
  -			{
  -				throw new TransactionManagerFactoryException(
  -					"IllegalAccessException: " + illegalAccessException.getMessage());
  -			}
  -			catch (ClassNotFoundException classNotFoundException)
  -			{
  -				throw new TransactionManagerFactoryException(
  -					"ClassNotFoundException: " + classNotFoundException.getMessage());
  -			}
  -			catch (InvocationTargetException invocationTargetException)
  -			{
  -				throw new TransactionManagerFactoryException(
  -					"InvocationTargetException: " + invocationTargetException.getMessage());
  -			}
  -			catch (NoSuchMethodException noSuchMethodException)
  -			{
  -				throw new TransactionManagerFactoryException(
  -					"NoSuchMethodException: " + noSuchMethodException.getMessage());
  -			}
  -		}
  -		
  -		return txManager;
  -	}
  +    /**
  +     * Support versions (Websphere 4, 5 and >5)
  +     */
  +    private static final String[][] config = {
  +        {"Websphere 4", TM_DEFAULT_METHOD_NAME, "com.ibm.ejs.jts.jta.JTSXA"},
  +        {"Websphere 5", TM_DEFAULT_METHOD_NAME, "com.ibm.ejs.jts.jta.TransactionManagerFactory"},
  +        {"Websphere >5", TM_DEFAULT_METHOD_NAME, "com.ibm.ws.Transaction.TransactionManagerFactory"}};
  +
  +    /**
  +     * @see AbstractTransactionManagerFactory#getLookupInfo
  +     */
  +    public String[][] getLookupInfo()
  +    {
  +        return config;
  +    }
   }
  
  
  
  1.3       +14 -42    db-ojb/src/java/org/apache/ojb/odmg/transaction/WeblogicTransactionManagerFactory.java
  
  Index: WeblogicTransactionManagerFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/transaction/WeblogicTransactionManagerFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WeblogicTransactionManagerFactory.java	27 Feb 2004 20:17:38 -0000	1.2
  +++ WeblogicTransactionManagerFactory.java	4 Mar 2004 23:43:29 -0000	1.3
  @@ -52,51 +52,23 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -import javax.naming.InitialContext;
  -import javax.naming.NamingException;
  -import javax.transaction.TransactionManager;
   
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
   /**
  + * Weblogic {@link javax.transaction.TransactionManager} lookup.
  + *
    * @author matthew.baird
  + * @version $Id$
    */
  -public class WeblogicTransactionManagerFactory
  -	implements TransactionManagerFactory
  +public class WeblogicTransactionManagerFactory extends AbstractTransactionManagerFactory
   {
  -	private static final String TM_LOOKUP =
  -		"javax.transaction.TransactionCoordinator";
  -	private static Logger log;
  -	/**
  -	 * Constructor for WeblogicTransactionManagerFactory.
  -	 */
  -	public WeblogicTransactionManagerFactory()
  -	{
  -		super();
  -		log = LoggerFactory.getLogger(WeblogicTransactionManagerFactory.class);
  -	}
  -	/**
  -	 * Similar to JBOSS in that it looks up transactionmanager from JNDI, however
  -	 * we provide a separate implementation instead of a configuration for ease of use,
  -	 * and potentially their implementation may change.
  -	 * @see org.apache.ojb.otm.jdo.transactionmanager.TransactionManagerFactory#getTransactionManager()
  -	 */
  -	public TransactionManager getTransactionManager()
  -		throws TransactionManagerFactoryException
  -	{
  -		if (log.isDebugEnabled())
  -			log.debug(
  -				"WeblogicTransactionManagerFactory.getTransactionManager called");
  -		TransactionManager retval = null;
  -		try
  -		{
  -			javax.naming.Context myContext = new InitialContext();
  -			retval = (TransactionManager) myContext.lookup(TM_LOOKUP);
  -		}
  -		catch (NamingException ne)
  -		{
  -			throw new TransactionManagerFactoryException(ne.getMessage());
  -		}
  -		return retval;
  -	}
  +    private static final String[][] config = {
  +        {"Weblogic", "javax.transaction.TransactionManager", null}};
  +
  +    /**
  +     * @see AbstractTransactionManagerFactory#getLookupInfo
  +     */
  +    public String[][] getLookupInfo()
  +    {
  +        return config;
  +    }
   }
  
  
  
  1.3       +22 -42    db-ojb/src/java/org/apache/ojb/odmg/transaction/TransactionManagerFactoryFactory.java
  
  Index: TransactionManagerFactoryFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/transaction/TransactionManagerFactoryFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TransactionManagerFactoryFactory.java	27 Feb 2004 20:17:38 -0000	1.2
  +++ TransactionManagerFactoryFactory.java	4 Mar 2004 23:43:29 -0000	1.3
  @@ -1,65 +1,45 @@
   package org.apache.ojb.odmg.transaction;
   
  -import org.apache.ojb.broker.util.configuration.Configuration;
  -import org.apache.ojb.broker.util.configuration.Configurator;
  -import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
  +import org.apache.ojb.broker.util.factory.ConfigurableFactory;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
   /**
  - * @author Matthew Baird
    *
  - * To change this generated comment edit the template variable "typecomment":
  - * Window>Preferences>Java>Templates.
  - * To enable and disable the creation of type comments go to
  - * Window>Preferences>Java>Code Generation.
  + * @author Matthew Baird
  + * @version $Id$
    */
   public class TransactionManagerFactoryFactory 
   {
  -	private static Logger log;
  -    private static TransactionManagerFactory singleton;
  -    private static Configurator configurator;
  -
  +    private static Logger log = LoggerFactory.getLogger(TransactionManagerFactoryFactory.class);
  +    private static TransactionManagerFactory tmInstance;
       static
       {
  -        configurator = OjbConfigurator.getInstance();
  -        log = LoggerFactory.getLogger(TransactionManagerFactoryFactory.class);
  +        try
  +        {
  +            tmInstance = new TMFactoryFactory().createTransactionManagerFactory();
  +        }
  +        catch (Exception e)
  +        {
  +            log.error("Instantiation of TransactionManagerFactory failed", e);
  +        }
       }
   
       public synchronized static TransactionManagerFactory instance()
       {
  -        if (singleton == null)
  -        {
  -            singleton = instantiate();
  -        }
  -        return singleton;
  +        return tmInstance;
       }
  -    
  -	private static TransactionManagerFactory instantiate()
  -	{
  - 		if (log.isDebugEnabled()) log.debug("Instantiate TransactionManagerFactory");
  -        try
  +
  +    public static class TMFactoryFactory extends ConfigurableFactory
  +    {
  +        protected String getConfigurationKey()
           {
  -            Configuration config = getConfigurator().getConfigurationFor(null);
  -            Class otmClass = config.getClass("JTATransactionManagerClass", JBossTransactionManagerFactory.class);
  -            TransactionManagerFactory result = (TransactionManagerFactory) otmClass.newInstance();
  -            if (log.isDebugEnabled()) log.debug("TransactionManagerFactory class: " + otmClass.getName());
  -            return result;
  +            return "JTATransactionManagerClass";
           }
  -        catch (Throwable e)
  +
  +        protected TransactionManagerFactory createTransactionManagerFactory()
           {
  -            log.warn("Error in instantiation of OJBTxManager class, returning default LocalTxManager");
  -            if (log.isDebugEnabled())
  -            {
  -                e.printStackTrace();
  -            }
  -            return new JBossTransactionManagerFactory();
  +            return (TransactionManagerFactory) this.createNewInstance();
           }
  -	}
  -	
  -    public static Configurator getConfigurator()
  -    {
  -        return configurator;
       }
  -
   }
  
  
  
  1.3       +6 -0      db-ojb/src/java/org/apache/ojb/odmg/transaction/TransactionManagerFactory.java
  
  Index: TransactionManagerFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/transaction/TransactionManagerFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TransactionManagerFactory.java	27 Feb 2004 20:17:38 -0000	1.2
  +++ TransactionManagerFactory.java	4 Mar 2004 23:43:29 -0000	1.3
  @@ -2,6 +2,12 @@
   
   import javax.transaction.TransactionManager;
   
  +/**
  + * Responsible for {@link javax.transaction.TransactionManager} lookup in
  + * managed environments.
  + * 
  + * @version $Id$
  + */
   public interface TransactionManagerFactory
   {
   	TransactionManager getTransactionManager() throws TransactionManagerFactoryException;
  
  
  
  1.4       +8 -26     db-ojb/src/java/org/apache/ojb/odmg/transaction/OrionTransactionManagerFactory.java
  
  Index: OrionTransactionManagerFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/transaction/OrionTransactionManagerFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- OrionTransactionManagerFactory.java	27 Feb 2004 20:17:38 -0000	1.3
  +++ OrionTransactionManagerFactory.java	4 Mar 2004 23:43:29 -0000	1.4
  @@ -54,41 +54,23 @@
    * <http://www.apache.org/>.
    */
   
  -import org.apache.ojb.broker.core.NamingLocator;
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  -import javax.transaction.TransactionManager;
   
   /**
  - * TransactionManagerFactory implementation for Orion
  - * Application Server.
  + * Orion {@link javax.transaction.TransactionManager} lookup.
    *
    * @author andreas.bayer
    * @version $Id$
    */
  -public class OrionTransactionManagerFactory
  -        implements TransactionManagerFactory
  +public class OrionTransactionManagerFactory extends AbstractTransactionManagerFactory
   {
  -    private static final String TM_LOOKUP = "java:comp/UserTransaction";
  -    private static Logger log;
  -    private static TransactionManager TM = null;
  +    private static final String[][] config = {{"Orion", "java:comp/UserTransaction", null}};
   
  -    public OrionTransactionManagerFactory()
  +    /**
  +     * @see AbstractTransactionManagerFactory#getLookupInfo
  +     */
  +    public String[][] getLookupInfo()
       {
  -        super();
  -        log = LoggerFactory.getLogger(OrionTransactionManagerFactory.class);
  -    }
  -
  -    public TransactionManager getTransactionManager()
  -            throws TransactionManagerFactoryException
  -    {
  -        if (TM == null)
  -        {
  -            if (log.isDebugEnabled())
  -                log.debug("OrionTransactionManagerFactory.getTransactionManager called");
  -            TM = (TransactionManager) NamingLocator.lookup(TM_LOOKUP);
  -        }
  -        return TM;
  +        return config;
       }
   }
  
  
  
  1.4       +13 -38    db-ojb/src/java/org/apache/ojb/odmg/transaction/JBossTransactionManagerFactory.java
  
  Index: JBossTransactionManagerFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/transaction/JBossTransactionManagerFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JBossTransactionManagerFactory.java	27 Feb 2004 20:17:38 -0000	1.3
  +++ JBossTransactionManagerFactory.java	4 Mar 2004 23:43:29 -0000	1.4
  @@ -52,46 +52,21 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  +
   /**
  + * JBoss {@link javax.transaction.TransactionManager} lookup.
  + *
    * @author matthew.baird
    */
  -import javax.transaction.TransactionManager;
  -
  -import org.apache.ojb.broker.core.NamingLocator;
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  -public class JBossTransactionManagerFactory
  -	implements TransactionManagerFactory
  +public class JBossTransactionManagerFactory extends AbstractTransactionManagerFactory
   {
  -	private static final String TM_LOOKUP = "java:/TransactionManager";
  -	private static Logger log;
  -	private static TransactionManager TM = null;
  -	/**
  -	 * Constructor for JBossTransactionManagerFactory.
  -	 */
  -	public JBossTransactionManagerFactory()
  -	{
  -		super();
  -		log = LoggerFactory.getLogger(JBossTransactionManagerFactory.class);
  -	}
  -	/**
  -	 * Jboss stores the transactionmanager in JNDI.
  -	 * todo: cache resolved transactionmanager.
  -	 * @see org.apache.ojb.otm.jdo.transactionmanager.TransactionManagerFactory#getTransactionManager()
  -	 */
  -	public TransactionManager getTransactionManager()
  -		throws TransactionManagerFactoryException
  -	{
  -		/**
  -		 * MBAIRD: No need to synchronize this as it's a read operation. Worse case is
  -		 * we lookup the TM two times. No biggie.
  -		 */
  -		if (TM == null)
  -		{
  -			if (log.isDebugEnabled())
  -				log.debug("JBossTransactionManagerFactory.getTransactionManager called");
  -			TM = (TransactionManager) NamingLocator.lookup(TM_LOOKUP);
  -		}
  -		return TM;
  -	}
  +    private static final String[][] config = {{"JBoss", "java:/TransactionManager", null}};
  +
  +    /**
  +     * @see AbstractTransactionManagerFactory#getLookupInfo
  +     */
  +    public String[][] getLookupInfo()
  +    {
  +        return config;
  +    }
   }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/transaction/SunOneTransactionManagerFactory.java
  
  Index: SunOneTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.odmg.transaction;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  
  
  /**
   * SunOne {@link javax.transaction.TransactionManager} lookup.
   *
   * @author Rice Yeh
   * @version $Id: SunOneTransactionManagerFactory.java,v 1.1 2004/03/04 23:43:29 arminw Exp $
   */
  public class SunOneTransactionManagerFactory extends AbstractTransactionManagerFactory
  {
      private static final String[][] config = {
          {"SunOne", "getTransactionManagerImpl", "com.sun.jts.jta.TransactionManagerImpl"}};
  
      /**
       * @see AbstractTransactionManagerFactory#getLookupInfo
       */
      public String[][] getLookupInfo()
      {
          return config;
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/transaction/JOnASTransactionManagerFactory.java
  
  Index: JOnASTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.odmg.transaction;
  
  /**
   * JOnAS {@link javax.transaction.TransactionManager} lookup.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: JOnASTransactionManagerFactory.java,v 1.1 2004/03/04 23:43:29 arminw Exp $
   */
  public class JOnASTransactionManagerFactory extends AbstractTransactionManagerFactory
  {
      private static final String[][] config = {{"JOnAS", "javax.transaction.UserTransaction", null}};
  
      /**
       * @see AbstractTransactionManagerFactory#getLookupInfo
       */
      public String[][] getLookupInfo()
      {
          return config;
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/transaction/AbstractTransactionManagerFactory.java
  
  Index: AbstractTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.odmg.transaction;
  
  import javax.transaction.TransactionManager;
  
  import org.apache.commons.lang.SystemUtils;
  import org.apache.ojb.broker.core.NamingLocator;
  import org.apache.ojb.broker.util.ClassHelper;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  
  /**
   * Abstract base class {@link TransactionManagerFactory} implementation
   * for {@link javax.transaction.TransactionManager} lookup.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: AbstractTransactionManagerFactory.java,v 1.1 2004/03/04 23:43:29 arminw Exp $
   */
  public abstract class AbstractTransactionManagerFactory implements TransactionManagerFactory
  {
      private static Logger log = LoggerFactory.getLogger(AbstractTransactionManagerFactory.class);
  
      /**
       * Returns "getTransactionManager";
       */
      public static String TM_DEFAULT_METHOD_NAME = "getTransactionManager";
  
  
      private static TransactionManager tm = null;
  
      /**
       * Returns an array of possible JNDI lookup / class names for
       * the {@link TransactionManager} instance. An array was used
       * because for different application server versions the
       * JNDI/class name may change.
       * <p>
       * Expect an [n][3] string array. Following arguments are available:
       * <ul>
       *    <li>info[i][0] = short description of used TM, e.g. appServer name</li>
       *    <li>info[i][2] = JNDI name to lookup TM or the method name to retrieve TM instance</li>
       *    <li>info[i][3] = if 'null' an JNDI lookup was made with JNDI name set above, if not null
       * the class name of the TM factory was assumed and the method name set above will be invoked</li>
       * </ul>
       * Example:
       * <br/>
       * {{"JBoss", "java:/TransactionManager", null}};
       * <br/>
       * {{"Websphere 4", TM_DEFAULT_METHOD_NAME, "com.ibm.ejs.jts.jta.JTSXA"},
       *    {"Websphere 5", TM_DEFAULT_METHOD_NAME, "com.ibm.ejs.jts.jta.TransactionManagerFactory"},
       *    {"Websphere >5", TM_DEFAULT_METHOD_NAME, "com.ibm.ws.Transaction.TransactionManagerFactory"}};
       * </p>
       */
      public abstract String[][] getLookupInfo();
  
      /**
       * @see org.apache.ojb.odmg.transaction.TransactionManagerFactory
       */
      public synchronized TransactionManager getTransactionManager() throws TransactionManagerFactoryException
      {
          if (tm == null)
          {
              StringBuffer msg = new StringBuffer();
              String[][] lookupInfo = getLookupInfo();
              String EOL = SystemUtils.LINE_SEPARATOR;
  
              for (int i = 0; i < lookupInfo.length; i++)
              {
                  String description = lookupInfo[i][0];
                  String methodName = lookupInfo[i][1];
                  String className = lookupInfo[i][2];
                  try
                  {
                      if (className == null)
                      {
                          tm = jndiLookup(description, methodName);
                      }
                      else
                      {
                          tm = instantiateClass(description, className, methodName);
                      }
                      msg.append("Successfully requested TM for " + description + EOL);
                  }
                  catch (Exception e)
                  {
                      if (className == null)
                          msg.append("Error on TM request for " + description +
                                  ", using jndi-lookup '" + methodName + "'" + EOL + e.getMessage() + EOL);
                      else
                          msg.append("Error on TM request for " + description + ", using method '" +
                                  methodName + "' for class '" + className + "'" + EOL + e.getMessage() + EOL);
                  }
                  if (tm != null) break;
              }
              // if we don't get an TM instance throw exception
              if (tm == null)
              {
                  throw new TransactionManagerFactoryException("Can't lookup transaction manager:" + EOL + msg.toString());
              }
          }
          return tm;
      }
  
      protected TransactionManager jndiLookup(String description, String methodName)
      {
          log.info(description + ", lookup TransactionManager: '" + methodName + "'");
          return (TransactionManager) NamingLocator.lookup(methodName);
      }
  
      protected TransactionManager instantiateClass(String description, String className, String methodName) throws Exception
      {
          log.info(description + ", invoke method '"
                  + methodName + "()' on class " + className);
          Class tmClass = ClassHelper.getClass(className);
          return (TransactionManager) tmClass.getMethod(methodName, null).invoke(null, null);
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org