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/05/04 01:05:57 UTC

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

arminw      2004/05/03 16:05:57

  Modified:    .        release-notes.txt
               src/test/org/apache/ojb OJB.properties
               src/java/org/apache/ojb/otm/transaction
                        ManagedTransactionFactory.java
               src/java/org/apache/ojb/odmg TxManagerFactory.java
                        OJBTxManager.java OJBJ2EE_2.java OJB.java
                        JTATxManager.java J2EETransactionImpl.java
                        DatabaseImpl.java
               src/java/org/apache/ojb/broker/util ConstructorHelper.java
                        ClassHelper.java
               src/java/org/apache/ojb/broker/util/factory
                        ConfigurableFactory.java
  Added:       src/java/org/apache/ojb/odmg ImplementationJTAImpl.java
                        ImplementationDefaultImpl.java
               src/java/org/apache/ojb/broker/transaction
                        TransactionNotInProgressException.java
                        OJBTxObject.java OJBTxManager.java
               src/java/org/apache/ojb/broker/transaction/tm
                        WebSphereTransactionManagerFactory.java
                        WeblogicTransactionManagerFactory.java
                        TransactionManagerFactoryFactory.java
                        TransactionManagerFactoryException.java
                        TransactionManagerFactory.java
                        SunOneTransactionManagerFactory.java
                        OrionTransactionManagerFactory.java
                        JOnASTransactionManagerFactory.java
                        JBossTransactionManagerFactory.java
                        AbstractTransactionManagerFactory.java
  Log:
  - move internal package org.apache.ojb.odmg.transaction to org.apache.ojb.broker.transaction.tm
  - adapt all API's to use new kernel based OJBTxManager, instead duplicate code in each API
  - Make org.odmg.Implementation implementation configurable via OJB.properties
  - Enable ConfigurableFactory class to instantiate private/protected classes too
  - Adapt ejb-examples
  - PBFSyncImpl class now release used connections before the JTA transaction was commited/rolled back
  
  Revision  Changes    Path
  1.41      +14 -2     db-ojb/release-notes.txt
  
  Index: release-notes.txt
  ===================================================================
  RCS file: /home/cvs/db-ojb/release-notes.txt,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- release-notes.txt	29 Apr 2004 08:56:10 -0000	1.40
  +++ release-notes.txt	3 May 2004 23:05:56 -0000	1.41
  @@ -14,11 +14,23 @@
   NEW FEATURES:
   
   NOTES:
  +- OJB.properties file has changed, don't forget to replace on update! One new property
  +to set in managed environments.
   
   CHANGES:
  +- rename/move internal package org.apache.ojb.odmg.transaction to org.apache.ojb.broker.transaction.tm
  +In managed environments each (top-level) API use transaction manager access, thus the TM related
  +classes are moved to the PB kernel and OJB.properties entries change.
  +
  +- Base class for ODMG api access within non- or managed environments is now
  +org.apache.ojb.odmg.OJB. The used org.odmg.Implementation interface implementation
  +is specified in OJB.properties.
  +
   - ConnectionManager is more strict on CM.releaseConnection() method calls. Now an
   exception is thrown when CM is in a "local transaction" status when try to release
  -the connection.
  +the connection. The local tx status of ConnectionManager and PersistenceBroker implementation
  +is now decoupled, useful in managed environments allows to "close the connection" without
  +change the PB tx-state.
   
   BUG FIXES:
   
  
  
  
  1.66      +98 -79    db-ojb/src/test/org/apache/ojb/OJB.properties
  
  Index: OJB.properties
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/OJB.properties,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- OJB.properties	9 Apr 2004 13:22:30 -0000	1.65
  +++ OJB.properties	3 May 2004 23:05:56 -0000	1.66
  @@ -254,7 +254,7 @@
   # implementation is to be used.
   # If OJB is running on multiple concurrent clients it is recommended
   # to use the RemoteLockMapImpl. It guarantees to provide
  -# Lockmanagement across multiple JVMs. 
  +# Lockmanagement across multiple JVMs.
   # This Implemenation relies on a Servlet based Lockserver. To use it you have to
   # deploy the ojb-lockserver.war into a Servlet engine.
   # and you have to set the Property LockServletUrl to point to this servlet.
  @@ -297,73 +297,6 @@
   #
   #
   #----------------------------------------------------------------------------------------
  -# Logging
  -#----------------------------------------------------------------------------------------
  -# The LoggerClass entry tells OJB which concrete Logger
  -# implementation is to be used.
  -#
  -# Commons-logging
  -#LoggerClass=org.apache.ojb.broker.util.logging.CommonsLoggerImpl
  -# log4j based logging
  -#LoggerClass=org.apache.ojb.broker.util.logging.Log4jLoggerImpl
  -# OJB's own simple looging support
  -LoggerClass=org.apache.ojb.broker.util.logging.PoorMansLoggerImpl
  -LoggerConfigFile=log4j.properties
  -#
  -# The LogLevel entries tells OJB which LogLevels are active
  -# for the different loggers used within OJB
  -# Loglevels: DEBUG < INFO < WARN < ERROR < FATAL
  -# That is loglevel WARN won't log DEBUG and INFO messages,
  -# but will log WARN, ERROR, and FATAL messages
  -#
  -# Global default log level used for all logging
  -# entities if not specified
  -ROOT.LogLevel=ERROR
  -#
  -# The Default Logger instance used within OJB
  -DEFAULT.LogLevel=WARN
  -# Logger for PersistenceBrokerImpl class
  -org.apache.ojb.broker.core.PersistenceBrokerImpl.LogLevel=WARN
  -# Logger for PersistenceBrokerFactory class PersistenceBrokerFactoryDefaultImpl
  -org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.LogLevel=WARN
  -# Logger for RepositoryXmlHandler, useful for debugging parsing of repository.xml!
  -# persistence capable object metadata
  -org.apache.ojb.broker.metadata.RepositoryXmlHandler.LogLevel=WARN
  -# Logger for ConnectionDescriptorXmlHandler, useful for debugging parsing of repository.xml!
  -# connection specific metadata
  -org.apache.ojb.broker.metadata.ConnectionDescriptorXmlHandler.LogLevel=WARN
  -# Logger for JdbcAccess, useful for debugging JDBC related problems
  -org.apache.ojb.broker.accesslayer.JdbcAccessImpl.LogLevel=WARN
  -# Logger for RsIterator, useful for debugging problems with Object materialization
  -org.apache.ojb.broker.accesslayer.RsIterator.LogLevel=WARN
  -# Logger for StatementsForClass, useful for debugging JDBC Connection related problems
  -org.apache.ojb.broker.accesslayer.StatementsForClassImpl.LogLevel=WARN
  -# Logger for SqlGenerator, useful for debugging generation of SQL
  -org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.LogLevel=WARN
  -# Logger for RepositoryPersistor
  -org.apache.ojb.broker.metadata.RepositoryPersistor.LogLevel=WARN
  -# Logger for ConnectionFactory base class
  -org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.LogLevel=WARN
  -# Logger for ConnectionManager
  -org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.LogLevel=WARN
  -# Logger for IndirectionHandler class
  -org.apache.ojb.broker.core.proxy.IndirectionHandler.LogLevel=WARN
  -#
  -# Special Logger categories used in test suite and tutorials
  -#
  -# Logger for the ODMG Implementation
  -ODMG.LogLevel=DEBUG
  -# Logger for the JDO RI Implementation
  -JDO.LogLevel=DEBUG
  -# Logger for the performance tests
  -performance.LogLevel=INFO
  -# Logger for the soda api
  -soda.LogLevel=WARN
  -# Logger for the factory service
  -ConfigurableFactory.LogLevel=WARN
  -#
  -#
  -#----------------------------------------------------------------------------------------
   # OQL / SQL settings
   #----------------------------------------------------------------------------------------
   # The OqlCollectionClass entry defines the collection type returned
  @@ -387,6 +320,24 @@
   #----------------------------------------------------------------------------------------
   # ODMG settings
   #----------------------------------------------------------------------------------------
  +# Specify the used base class for ODMG API
  +# - ImplementationDefaultImpl is the default class
  +# - ImplementationJTAImpl is for use in managed environments like J2EE conform
  +# Application Server
  +#
  +ImplementationClass=org.apache.ojb.odmg.ImplementationDefaultImpl
  +#ImplementationClass=org.apache.ojb.odmg.ImplementationJTAImpl
  +#
  +#
  +# Specify the used tx handling.
  +# - LocalTxManager use if you want the transaction to be associated by a thread
  +# - JTATxManager use if you want the transaction to be associated via the Transaction
  +# manager that is in your application server.
  +#
  +OJBTxManagerClass=org.apache.ojb.odmg.LocalTxManager
  +#OJBTxManagerClass=org.apache.ojb.odmg.JTATxManager
  +#
  +#
   # Used ODMG collection implementation classes
   # (e.g. when do a Implementation#newDlist() call)
   #
  @@ -456,12 +407,8 @@
   #----------------------------------------------------------------------------------------
   # Transaction Management and assocation
   #----------------------------------------------------------------------------------------
  -# Use the LocalTxManager if you want the transaction to be associated by a thread
  -OJBTxManagerClass=org.apache.ojb.odmg.LocalTxManager
  -# Use the JTATxManager if you want the transaction to be associated via the Transaction
  -# manager that is in your application server.
  -#OJBTxManagerClass=org.apache.ojb.odmg.JTATxManager
  -#
  +# (optional, only used when OJB runs within managed environments)
  +# To praticipate in JTA transaction OJB needs access to the underlying transaction manager.
   # The TransactionManager is acquired in different ways dependent on the application server.
   # The JTATransactionManagerClass property allows you to specify the class that implements
   # the proper behaviour for finding the transaction manager. Only use when OJBTxManagerClass
  @@ -469,13 +416,85 @@
   # (org.apache.ojb.odmg.JTATxManager)
   #
   # JBoss Transaction Manager Factory
  -JTATransactionManagerClass=org.apache.ojb.odmg.transaction.JBossTransactionManagerFactory
  +JTATransactionManagerClass=org.apache.ojb.broker.transaction.tm.JBossTransactionManagerFactory
   # Weblogic Transaction Manager Factory
  -#JTATransactionManagerClass=org.apache.ojb.odmg.transaction.WeblogicTransactionManagerFactory
  +#JTATransactionManagerClass=org.apache.ojb.broker.transaction.tm.WeblogicTransactionManagerFactory
   # WebSphere transaction manager factory
  -#JTATransactionManagerClass=org.apache.ojb.odmg.transaction.WebSphereTransactionManagerFactory
  +#JTATransactionManagerClass=org.apache.ojb.broker.transaction.tm.WebSphereTransactionManagerFactory
   # Orion transaction manager factory
  -#JTATransactionManagerClass=org.apache.ojb.odmg.transaction.OrionTransactionManagerFactory
  +#JTATransactionManagerClass=org.apache.ojb.broker.transaction.tm.OrionTransactionManagerFactory
  +# SunOne transaction manager factory
  +#JTATransactionManagerClass=org.apache.ojb.broker.transaction.tm.SunOneTransactionManagerFactory
  +# JOnAs transaction manager factory
  +#JTATransactionManagerClass=org.apache.ojb.broker.transaction.tm.JOnASTransactionManagerFactory
  +#
  +#
  +#----------------------------------------------------------------------------------------
  +# Logging
  +#----------------------------------------------------------------------------------------
  +# The LoggerClass entry tells OJB which concrete Logger
  +# implementation is to be used.
  +#
  +# Commons-logging
  +#LoggerClass=org.apache.ojb.broker.util.logging.CommonsLoggerImpl
  +# log4j based logging
  +#LoggerClass=org.apache.ojb.broker.util.logging.Log4jLoggerImpl
  +# OJB's own simple looging support
  +LoggerClass=org.apache.ojb.broker.util.logging.PoorMansLoggerImpl
  +LoggerConfigFile=log4j.properties
  +#
  +# The LogLevel entries tells OJB which LogLevels are active
  +# for the different loggers used within OJB
  +# Loglevels: DEBUG < INFO < WARN < ERROR < FATAL
  +# That is loglevel WARN won't log DEBUG and INFO messages,
  +# but will log WARN, ERROR, and FATAL messages
  +#
  +# Global default log level used for all logging
  +# entities if not specified
  +ROOT.LogLevel=ERROR
  +#
  +# The Default Logger instance used within OJB
  +DEFAULT.LogLevel=WARN
  +# Logger for PersistenceBrokerImpl class
  +org.apache.ojb.broker.core.PersistenceBrokerImpl.LogLevel=WARN
  +# Logger for PersistenceBrokerFactory class PersistenceBrokerFactoryDefaultImpl
  +org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.LogLevel=WARN
  +# Logger for RepositoryXmlHandler, useful for debugging parsing of repository.xml!
  +# persistence capable object metadata
  +org.apache.ojb.broker.metadata.RepositoryXmlHandler.LogLevel=WARN
  +# Logger for ConnectionDescriptorXmlHandler, useful for debugging parsing of repository.xml!
  +# connection specific metadata
  +org.apache.ojb.broker.metadata.ConnectionDescriptorXmlHandler.LogLevel=WARN
  +# Logger for JdbcAccess, useful for debugging JDBC related problems
  +org.apache.ojb.broker.accesslayer.JdbcAccessImpl.LogLevel=WARN
  +# Logger for RsIterator, useful for debugging problems with Object materialization
  +org.apache.ojb.broker.accesslayer.RsIterator.LogLevel=WARN
  +# Logger for StatementsForClass, useful for debugging JDBC Connection related problems
  +org.apache.ojb.broker.accesslayer.StatementsForClassImpl.LogLevel=WARN
  +# Logger for SqlGenerator, useful for debugging generation of SQL
  +org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.LogLevel=WARN
  +# Logger for RepositoryPersistor
  +org.apache.ojb.broker.metadata.RepositoryPersistor.LogLevel=WARN
  +# Logger for ConnectionFactory base class
  +org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.LogLevel=WARN
  +# Logger for ConnectionManager
  +org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.LogLevel=WARN
  +# Logger for IndirectionHandler class
  +org.apache.ojb.broker.core.proxy.IndirectionHandler.LogLevel=WARN
  +#
  +# Special Logger categories used in test suite and tutorials
  +#
  +# Logger for the ODMG Implementation
  +ODMG.LogLevel=DEBUG
  +# Logger for the JDO RI Implementation
  +JDO.LogLevel=DEBUG
  +# Logger for the performance tests
  +performance.LogLevel=INFO
  +# Logger for the soda api
  +soda.LogLevel=WARN
  +# Logger for the factory service
  +ConfigurableFactory.LogLevel=WARN
  +#
   #
   #----------------------------------------------------------------------------------------
   # End of OJB.properties file
  
  
  
  1.8       +27 -18    db-ojb/src/java/org/apache/ojb/otm/transaction/ManagedTransactionFactory.java
  
  Index: ManagedTransactionFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/transaction/ManagedTransactionFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ManagedTransactionFactory.java	4 Apr 2004 23:53:42 -0000	1.7
  +++ ManagedTransactionFactory.java	3 May 2004 23:05:56 -0000	1.8
  @@ -21,22 +21,24 @@
   import javax.transaction.TransactionManager;
   
   import org.apache.ojb.broker.PBKey;
  +import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryFactory;
  +import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
   import org.apache.ojb.otm.OTMConnection;
   import org.apache.ojb.otm.core.BaseConnection;
   import org.apache.ojb.otm.core.Transaction;
   import org.apache.ojb.otm.core.TransactionException;
   
   /**
  - *
    * Factory for OTM Transactions within a managed environment (JTA).
  - * 
  + *
    * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
  - * 
  + *
    */
   public abstract class ManagedTransactionFactory implements TransactionFactory
   {
  -    
  +
       private HashMap _transactionMap;
  +    private TransactionManager tm;
   
   	/**
   	 * Constructor for ManagedTransactionFactory.
  @@ -45,7 +47,7 @@
   	{
   		_transactionMap = new HashMap();
   	}
  -    
  +
   
       //////////////////////////////////////////////////////
       // TransactionFactory protocol
  @@ -81,42 +83,49 @@
   	}
   
       /**
  -     * @see org.apache.ojb.otm.transaction.TransactionFactory#acquireConnection(OTMKit, PBKey)
  +     * @see org.apache.ojb.otm.transaction.TransactionFactory#acquireConnection
        */
       public OTMConnection acquireConnection(PBKey pbKey)
       {
           return new ManagedConnection(pbKey);
       }
  -    
  -    
  +
  +
       //////////////////////////////////////////
       // Other operations
       //////////////////////////////////////////
   
  -    public javax.transaction.Transaction getJTATransaction ()
  +    public javax.transaction.Transaction getJTATransaction()
       {
  +        if(tm == null)
  +        {
  +            try
  +            {
  +                tm = TransactionManagerFactoryFactory.instance().getTransactionManager();
  +            }
  +            catch (TransactionManagerFactoryException e)
  +            {
  +                throw new TransactionFactoryException("Can't instantiate TransactionManagerFactory", e);
  +            }
  +        }
           try
           {
  -            TransactionManager jtaTxManager = getJTATransactionManager();
  -            return jtaTxManager.getTransaction();
  +            return tm.getTransaction();
           }
  -        catch (SystemException systemException)
  +        catch(SystemException e)
           {
  -            throw new TransactionFactoryException(
  -                "Error acquiring JTA Transaction", systemException);
  +            throw new TransactionFactoryException("Error acquiring JTA Transaction", e);
           }
       }
   
  -    public abstract TransactionManager getJTATransactionManager ();
  -    
       private static class ManagedConnection extends BaseConnection
       {
  -        
  +
           public ManagedConnection (PBKey pbKey)
           {
               super(pbKey);
           }
  -        
  +
           /**
            * @see org.apache.ojb.otm.core.BaseConnection#transactionBegin()
            */
  
  
  
  1.5       +16 -29    db-ojb/src/java/org/apache/ojb/odmg/TxManagerFactory.java
  
  Index: TxManagerFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TxManagerFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TxManagerFactory.java	4 Apr 2004 23:53:39 -0000	1.4
  +++ TxManagerFactory.java	3 May 2004 23:05:56 -0000	1.5
  @@ -20,6 +20,7 @@
   import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.ojb.broker.util.factory.ConfigurableFactory;
   
   /**
    * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
  @@ -27,47 +28,33 @@
    * TransactionManagers. Set the "OJBTxManagerClass" property in
    * OJB.properties in order to install a new TxManagerFactory
    */
  -public class TxManagerFactory
  +public class TxManagerFactory extends ConfigurableFactory
   {
  -    private static Logger log;
  -    private static OJBTxManager singleton;
  -    private static Configurator configurator;
  +    private static TxManagerFactory singleton;
  +    private OJBTxManager manager;
   
       static
       {
  -        configurator = OjbConfigurator.getInstance();
  -        log = LoggerFactory.getLogger(TxManagerFactory.class);
  +        singleton = new TxManagerFactory();
       }
   
  -    public synchronized static OJBTxManager instance()
  +    private TxManagerFactory()
       {
  -        if (singleton == null)
  -        {
  -            singleton = instantiate();
  -        }
  -        return singleton;
  +        manager = (OJBTxManager) this.createNewInstance();
       }
   
  -    private static OJBTxManager instantiate()
  +    private OJBTxManager getManager()
  +    {
  +        return manager;
  +    }
  +
  +    public synchronized static OJBTxManager instance()
       {
  -        if (log.isDebugEnabled()) log.debug("Instantiate OJBTxManager");
  -        try
  -        {
  -            Configuration config = getConfigurator().getConfigurationFor(null);
  -            Class otmClass = config.getClass("OJBTxManagerClass", LocalTxManager.class);
  -            OJBTxManager result = (OJBTxManager) otmClass.newInstance();
  -            if (log.isDebugEnabled()) log.debug("OJBTxManager class: " + otmClass.getName());
  -            return result;
  -        }
  -        catch (Throwable e)
  -        {
  -            log.warn("Error in instantiation of OJBTxManager class, returning default LocalTxManager");
  -            return new LocalTxManager();
  -        }
  +        return singleton.getManager();
       }
   
  -    public static Configurator getConfigurator()
  +    protected String getConfigurationKey()
       {
  -        return configurator;
  +        return "OJBTxManagerClass";
       }
   }
  
  
  
  1.6       +2 -2      db-ojb/src/java/org/apache/ojb/odmg/OJBTxManager.java
  
  Index: OJBTxManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/OJBTxManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- OJBTxManager.java	4 Apr 2004 23:53:38 -0000	1.5
  +++ OJBTxManager.java	3 May 2004 23:05:56 -0000	1.6
  @@ -27,7 +27,7 @@
   {
   	/**
        * Returns the current transaction for the calling thread.
  -     * @throws {@link org.odmg.TransactionNotProgressException} if no transaction was found.
  +     * @throws org.odmg.TransactionNotInProgressException if no transaction was found.
        */
       TransactionImpl getCurrentTransaction();
   
  
  
  
  1.11      +20 -131   db-ojb/src/java/org/apache/ojb/odmg/OJBJ2EE_2.java
  
  Index: OJBJ2EE_2.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/OJBJ2EE_2.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- OJBJ2EE_2.java	4 Apr 2004 23:53:38 -0000	1.10
  +++ OJBJ2EE_2.java	3 May 2004 23:05:56 -0000	1.11
  @@ -1,5 +1,20 @@
   package org.apache.ojb.odmg;
   
  +/* Copyright 2002-2004 The Apache Software Foundation
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
  +
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
  @@ -15,140 +30,14 @@
   import org.odmg.DArray;
   import org.odmg.DMap;
   
  -/* Copyright 2002-2004 The Apache Software Foundation
  - *
  - * Licensed under the Apache License, Version 2.0 (the "License");
  - * you may not use this file except in compliance with the License.
  - * You may obtain a copy of the License at
  +/**
  + * Facade to the persistence ObjectServer system, returns an {@link Implementation}
  + *  interface instance for use in managed environments.
    *
  - *     http://www.apache.org/licenses/LICENSE-2.0
  - *
  - * Unless required by applicable law or agreed to in writing, software
  - * distributed under the License is distributed on an "AS IS" BASIS,
  - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - * See the License for the specific language governing permissions and
  - * limitations under the License.
  + * @deprecated use {@link OJB#getInstance} with setting for 'ImplementationClass'
  + *  declared in OJB properties file.
    */
   public class OJBJ2EE_2 extends OJB
   {
  -    private Logger log = LoggerFactory.getLogger(OJBJ2EE_2.class);
  -	private OJBTxManager m_ojbTxManager = TxManagerFactory.instance();
  -
  -    protected OJBJ2EE_2()
  -    {
  -        super();
  -    }
  -
  -    /**
  -     * Return new instance of the {@link org.odmg.Implementation} class.
  -     */
  -    public static Implementation getInstance()
  -    {
  -        OJBJ2EE_2 implementation = new OJBJ2EE_2();
  -        implementation.setConfigurator(PersistenceBrokerFactory.getConfigurator());
  -        return implementation;
  -    }
  -
  -    protected synchronized void registerOpenDatabase(DatabaseImpl newDB)
  -    {
  -        super.registerOpenDatabase(newDB);
  -        beginInternTransaction();
  -    }
  -
  -    public Database getDatabase(Object obj)
  -    {
  -        beginInternTransaction();
  -        return this.getCurrentDatabase();
  -    }
  -
  -    public Transaction currentTransaction()
  -    {
  -        beginInternTransaction();
  -        /*
  -        we wrap the intern odmg transaction to avoid unauthorised calls
  -        since we use proprietary extensions for Transaction interface
  -        do cast to enhanced interface
  -        */
  -        return new NarrowTransaction((TransactionExt) super.currentTransaction());
  -    }
  -
  -    public EnhancedOQLQuery newOQLQuery()
  -    {
  -        beginInternTransaction();
  -        return super.newOQLQuery();
  -    }
  -
  -    public DList newDList()
  -    {
  -        beginInternTransaction();
  -        return super.newDList();
  -    }
  -
  -    public DBag newDBag()
  -    {
  -        beginInternTransaction();
  -        return super.newDBag();
  -    }
  -
  -    public DSet newDSet()
  -    {
  -        beginInternTransaction();
  -        return super.newDSet();
  -    }
  -
  -    public DArray newDArray()
  -    {
  -        beginInternTransaction();
  -        return super.newDArray();
  -    }
  -
  -    public DMap newDMap()
  -    {
  -        beginInternTransaction();
  -        return super.newDMap();
  -    }
  -
  -    /**
  -     * Here we start a intern odmg-Transaction to hide transaction demarcation
  -     * This method could be invoked several times within a transaction, but only
  -     * the first call begin a intern odmg transaction
  -     */
  -    private void beginInternTransaction()
  -    {
  -        if (log.isDebugEnabled()) log.debug("beginInternTransaction was called");
  -        J2EETransactionImpl tx = (J2EETransactionImpl) super.currentTransaction();
  -        if (tx == null) tx = newInternTransaction();
  -        if (!tx.isOpen())
  -        {
  -            // start the transaction
  -            tx.begin();
  -            tx.setInExternTransaction(true);
  -        }
  -    }
  -
  -    /**
  -     * Returns a new intern odmg-transaction for the current database.
  -     */
  -    private J2EETransactionImpl newInternTransaction()
  -    {
  -        if (log.isDebugEnabled()) log.debug("obtain new intern odmg-transaction");
  -        J2EETransactionImpl tx = new J2EETransactionImpl(getCurrentDatabase());
  -        try
  -        {
  -            getConfigurator().configure(tx);
  -        }
  -        catch (ConfigurationException e)
  -        {
  -            throw new OJBRuntimeException("Cannot create new intern odmg transaction", e);
  -        }
  -        return tx;
  -    }
   
  -    /**
  -     * Not supported in managed-environment.
  -     */
  -    public Transaction newTransaction()
  -    {
  -        throw new UnsupportedOperationException("Not supported in managed environment");
  -    }
   }
  
  
  
  1.17      +14 -294   db-ojb/src/java/org/apache/ojb/odmg/OJB.java
  
  Index: OJB.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/OJB.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- OJB.java	4 Apr 2004 23:53:38 -0000	1.16
  +++ OJB.java	3 May 2004 23:05:56 -0000	1.17
  @@ -15,325 +15,45 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.PBKey;
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
  -import org.apache.ojb.broker.util.configuration.ConfigurationException;
  -import org.apache.ojb.broker.util.configuration.Configurator;
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  -import org.apache.ojb.odmg.collections.DCollectionFactory;
  -import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
  -import org.apache.ojb.odmg.oql.OQLQueryImpl;
  -import org.odmg.DArray;
  -import org.odmg.DBag;
  -import org.odmg.DList;
  -import org.odmg.DMap;
  -import org.odmg.DSet;
  -import org.odmg.Database;
  -import org.odmg.DatabaseClosedException;
  +import org.apache.ojb.broker.util.factory.ConfigurableFactory;
   import org.odmg.Implementation;
  -import org.odmg.ODMGRuntimeException;
  -import org.odmg.Transaction;
  -
  -import java.util.ArrayList;
  -import java.util.List;
   
   
   /**
    * Facade to the persistence ObjectServer system.
    * Implements the factory interface for a particular ODMG implementation.
    *
  - * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
  - * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class OJB extends Object implements Implementation
  +public class OJB extends ConfigurableFactory
   {
  -    private Logger log = LoggerFactory.getLogger(OJB.class);
  +    private static OJB instance;
   
  -    private List usedDatabases = new ArrayList();
  -    private DatabaseImpl currentDatabase;
  -    private Configurator configurator;
  -    private OJBTxManager ojbTxManager;
  +    static
  +    {
  +        instance = new OJB();
  +    }
   
       /**
  -     * private Constructor: use static factory method
  -     * getInstance() to obtain an instance
  +     * protected Constructor: use static factory method
  +     * getInstance() to obtain an instance of {@link Implementation}
        */
       protected OJB()
       {
  -        ojbTxManager = TxManagerFactory.instance();
       }
   
       /**
        * Return new instance of the {@link org.odmg.Implementation} class.
  +     * The used implementation class can be specified in OJB properties file.
        */
       public static Implementation getInstance()
       {
  -        OJB implementation = new OJB();
  -        implementation.setConfigurator(PersistenceBrokerFactory.getConfigurator());
  -        return implementation;
  -    }
  -
  -    /**
  -     * Method declaration
  -     * @param curDB
  -     */
  -    protected synchronized void setCurrentDatabase(DatabaseImpl curDB)
  -    {
  -        currentDatabase = curDB;
  -    }
  -
  -    public DatabaseImpl getCurrentDatabase()
  -    {
  -        return currentDatabase;
  -    }
  -
  -    public PBKey getCurrentPBKey()
  -    {
  -        return currentDatabase.getPBKey();
  -    }
  -
  -    /**
  -     * Gets the configurator.
  -     * @return Returns a Configurator
  -     */
  -    public Configurator getConfigurator()
  -    {
  -        return configurator;
  -    }
  -
  -    /**
  -     * Sets the configurator.
  -     * @param configurator The configurator to set
  -     */
  -    public void setConfigurator(Configurator configurator)
  -    {
  -        this.configurator = configurator;
  -    }
  -
  -    /**
  -     * Create a <code>Transaction</code> object and associate it with the current thread.
  -     * @return The newly created <code>Transaction</code> instance.
  -     * @see org.odmg.Transaction
  -     */
  -    public Transaction newTransaction()
  -    {
  -        if ((getCurrentDatabase() == null))
  -        {
  -            throw new DatabaseClosedException("Database is NULL, must have a DB in order to create a transaction");
  -        }
  -        TransactionImpl tx = new TransactionImpl(getCurrentDatabase());
  -        try
  -        {
  -            getConfigurator().configure(tx);
  -        }
  -        catch (ConfigurationException e)
  -        {
  -            throw new ODMGRuntimeException("Error in configuration of TransactionImpl instance: " + e.getMessage());
  -        }
  -        return tx;
  -    }
  -
  -    /**
  -     * Get the current <code>Transaction</code> for the thread.
  -     * @return The current <code>Transaction</code> object or null if there is none.
  -     * @see org.odmg.Transaction
  -     */
  -    public Transaction currentTransaction()
  -    {
  -        if ((getCurrentDatabase() == null))
  -        {
  -            throw new DatabaseClosedException("Database is NULL, must have a DB in order to create a transaction");
  -        }
  -        return ojbTxManager.getTransaction();
  +        return (Implementation) instance.createNewInstance();
       }
   
  -    /**
  -     * Create a new <code>Database</code> object.
  -     * @return The new <code>Database</code> object.
  -     * @see org.odmg.Database
  -     */
  -    public Database newDatabase()
  +    protected String getConfigurationKey()
       {
  -        return new DatabaseImpl(this);
  +        return "ImplementationClass";
       }
  -
  -    /**
  -     * Create a new <code>OQLQuery</code> object.
  -     * @return The new <code>OQLQuery</code> object.
  -     * @see org.odmg.OQLQuery
  -     */
  -    public EnhancedOQLQuery newOQLQuery()
  -    {
  -        if ((getCurrentDatabase() == null) || !getCurrentDatabase().isOpen())
  -        {
  -            throw new DatabaseClosedException("Database is not open");
  -        }
  -        OQLQueryImpl query = new OQLQueryImpl(this.getCurrentPBKey());
  -        try
  -        {
  -            getConfigurator().configure(query);
  -        }
  -        catch (ConfigurationException e)
  -        {
  -            throw new ODMGRuntimeException("Error in configuration of OQLQueryImpl instance: " + e.getMessage());
  -        }
  -        return query;
  -
  -    }
  -
  -    /**
  -     * Create a new <code>DList</code> object.
  -     * @return The new <code>DList</code> object.
  -     * @see org.odmg.DList
  -     */
  -    public DList newDList()
  -    {
  -        if ((getCurrentDatabase() == null))
  -        {
  -            throw new DatabaseClosedException("Database is NULL, cannot create a DList with a null database.");
  -        }
  -        return DCollectionFactory.getInstance().createDList(getCurrentPBKey());
  -    }
  -
  -    /**
  -     * Create a new <code>DBag</code> object.
  -     * @return The new <code>DBag</code> object.
  -     * @see org.odmg.DBag
  -     */
  -    public DBag newDBag()
  -    {
  -        if ((getCurrentDatabase() == null))
  -        {
  -            throw new DatabaseClosedException("Database is NULL, cannot create a DBag with a null database.");
  -        }
  -        return DCollectionFactory.getInstance().createDBag(getCurrentPBKey());
  -    }
  -
  -    /**
  -     * Create a new <code>DSet</code> object.
  -     * @return The new <code>DSet</code> object.
  -     * @see org.odmg.DSet
  -     */
  -    public DSet newDSet()
  -    {
  -        if ((getCurrentDatabase() == null))
  -        {
  -            throw new DatabaseClosedException("Database is NULL, cannot create a DSet with a null database.");
  -        }
  -        return DCollectionFactory.getInstance().createDSet(getCurrentPBKey());
  -    }
  -
  -    /**
  -     * Create a new <code>DArray</code> object.
  -     * @return The new <code>DArray</code> object.
  -     * @see org.odmg.DArray
  -     */
  -    public DArray newDArray()
  -    {
  -        if ((getCurrentDatabase() == null))
  -        {
  -            throw new DatabaseClosedException("Database is NULL, cannot create a DArray with a null database.");
  -        }
  -        return DCollectionFactory.getInstance().createDArray(getCurrentPBKey());
  -    }
  -
  -    /**
  -     * Create a new <code>DMap</code> object.
  -     * @return The new <code>DMap</code> object.
  -     * @see org.odmg.DMap
  -     */
  -    public DMap newDMap()
  -    {
  -        if ((getCurrentDatabase() == null))
  -        {
  -            throw new DatabaseClosedException("Database is NULL, cannot create a DMap with a null database.");
  -        }
  -        return DCollectionFactory.getInstance().createDMap(getCurrentPBKey());
  -    }
  -
  -    /**
  -     * Get a <code>String</code> representation of the object's identifier.
  -     * OJB returns the serialized Identity of the object.
  -     * @param obj The object whose identifier is being accessed.
  -     * @return The object's identifier in the form of a String
  -     */
  -    public String getObjectId(Object obj)
  -    {
  -        Identity oid = null;
  -        PersistenceBroker broker;
  -
  -        if (getCurrentDatabase() != null)
  -        {
  -            /**
  -             * is there an open database we are calling getObjectId against? if yes, use it
  -             */
  -            broker = PersistenceBrokerFactory.createPersistenceBroker(getCurrentDatabase().getPBKey());
  -        }
  -        else
  -        {
  -            /**
  -             * otherwise, use default.
  -             */
  -            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -        }
  -
  -        oid = new Identity(obj, broker);
  -        return new String(oid.serialize());
  -    }
  -
  -    /**
  -     * Returns the current used database or null.
  -     */
  -    public Database getDatabase(Object obj)
  -    {
  -        /* @todo enhance functionality */
  -        return getCurrentDatabase();
  -    }
  -
  -    /**
  -     * Register opened database via the PBKey.
  -     */
  -    protected synchronized void registerOpenDatabase(DatabaseImpl newDB)
  -    {
  -        DatabaseImpl old_db = getCurrentDatabase();
  -        if (old_db != null)
  -        {
  -            try
  -            {
  -                if (old_db.isOpen())
  -                {
  -                    log.warn("## There is still an opened database, close old one ##");
  -                    old_db.close();
  -                }
  -            }
  -            catch (Throwable t)
  -            {
  -                //ignore
  -            }
  -        }
  -        if (log.isDebugEnabled()) log.debug("Set current database " + newDB + " PBKey was " + newDB.getPBKey());
  -        setCurrentDatabase(newDB);
  -        usedDatabases.add(newDB.getPBKey());
  -    }
  -
  -    /**
  -     * This method can be used to activate or deactivate the implicit
  -     * locking mechanism for the current transaction.
  -     * turning of implicit locking may improve performance but requires
  -     * additional care to make sure all changed objects are properly
  -     * registered to the transaction.
  -     * @param value if set to true implicit locking is enabled, 
  -     *        if false, implicit locking is disabled.
  -     **/    
  -	public void setImplicitLocking(boolean value)
  -	{
  -		((TransactionExt)currentTransaction()).setImplicitLocking(value);
  -	}
  -
  -    
   }
  
  
  
  1.8       +2 -2      db-ojb/src/java/org/apache/ojb/odmg/JTATxManager.java
  
  Index: JTATxManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/JTATxManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JTATxManager.java	4 Apr 2004 23:53:38 -0000	1.7
  +++ JTATxManager.java	3 May 2004 23:05:56 -0000	1.8
  @@ -19,8 +19,8 @@
   import org.apache.ojb.broker.util.configuration.Configuration;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  -import org.apache.ojb.odmg.transaction.TransactionManagerFactoryException;
  -import org.apache.ojb.odmg.transaction.TransactionManagerFactoryFactory;
  +import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
  +import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryFactory;
   import org.odmg.TransactionNotInProgressException;
   
   import javax.transaction.Status;
  
  
  
  1.25      +5 -14     db-ojb/src/java/org/apache/ojb/odmg/J2EETransactionImpl.java
  
  Index: J2EETransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/J2EETransactionImpl.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- J2EETransactionImpl.java	4 Apr 2004 23:53:38 -0000	1.24
  +++ J2EETransactionImpl.java	3 May 2004 23:05:56 -0000	1.25
  @@ -14,25 +14,23 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  -/**
  - * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
  - *
  - * @version $Id$
  - */
   
   import javax.transaction.Status;
   import javax.transaction.Synchronization;
   
   import org.apache.ojb.broker.OJBRuntimeException;
  -import org.apache.ojb.broker.util.GUID;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  +/**
  + * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
  + *
  + * @version $Id$
  + */
   public class J2EETransactionImpl extends TransactionImpl implements Synchronization
   {
       private Logger log = LoggerFactory.getLogger(J2EETransactionImpl.class);
       private boolean isInExternTransaction;
  -    private String txGUID;
   
       /**
        * beforeCompletion is being called twice in JBoss, so this
  @@ -44,14 +42,7 @@
       public J2EETransactionImpl(DatabaseImpl theCurrentDB)
       {
           super(theCurrentDB);
  -        // strings are immutable.
  -        txGUID = new GUID().toString();
           isInExternTransaction = false;
  -    }
  -
  -    public String getGUID()
  -    {
  -        return txGUID;
       }
   
       public void setInExternTransaction(boolean mode)
  
  
  
  1.25      +4 -4      db-ojb/src/java/org/apache/ojb/odmg/DatabaseImpl.java
  
  Index: DatabaseImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/DatabaseImpl.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DatabaseImpl.java	4 Apr 2004 23:53:38 -0000	1.24
  +++ DatabaseImpl.java	3 May 2004 23:05:56 -0000	1.25
  @@ -47,14 +47,14 @@
   
       private PBKey pbKey;
       private boolean isOpen;
  -    private OJB ojb;
  +    private ImplementationDefaultImpl ojb;
       /**
        * the broker instance for persistence operations
        * the named roots map;
        */
       private NamedRootsMap nrm;
   
  -    public DatabaseImpl(OJB ojb)
  +    public DatabaseImpl(ImplementationDefaultImpl ojb)
       {
           nrm = NamedRootsMap.getInstance();
           isOpen = false;
  @@ -79,7 +79,7 @@
           return pbKey;
       }
   
  -    public OJB getAssociatedImplementation()
  +    public ImplementationDefaultImpl getAssociatedImplementation()
       {
           return ojb;
       }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/ImplementationJTAImpl.java
  
  Index: ImplementationJTAImpl.java
  ===================================================================
  package org.apache.ojb.odmg;
  
  /* Copyright 2002-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.ojb.broker.OJBRuntimeException;
  import org.apache.ojb.broker.util.configuration.ConfigurationException;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
  import org.odmg.DArray;
  import org.odmg.DBag;
  import org.odmg.DList;
  import org.odmg.DMap;
  import org.odmg.DSet;
  import org.odmg.Database;
  import org.odmg.Implementation;
  import org.odmg.Transaction;
  
  /**
   * Implementation of the ODMG {@link Implementation} interface for use in
   * managed enviroments.
   *
   * @version $Id: ImplementationJTAImpl.java,v 1.1 2004/05/03 23:05:56 arminw Exp $
   */
  public class ImplementationJTAImpl extends ImplementationDefaultImpl
  {
      private Logger log = LoggerFactory.getLogger(ImplementationJTAImpl.class);
  
      protected ImplementationJTAImpl()
      {
          super();
      }
  
      protected synchronized void registerOpenDatabase(DatabaseImpl newDB)
      {
          super.registerOpenDatabase(newDB);
          beginInternTransaction();
      }
  
      public Database getDatabase(Object obj)
      {
          beginInternTransaction();
          return this.getCurrentDatabase();
      }
  
      public Transaction currentTransaction()
      {
          beginInternTransaction();
          /*
          we wrap the intern odmg transaction to avoid unauthorised calls
          since we use proprietary extensions for Transaction interface
          do cast to enhanced interface
          */
          return new NarrowTransaction((TransactionExt) super.currentTransaction());
      }
  
      public EnhancedOQLQuery newOQLQuery()
      {
          beginInternTransaction();
          return super.newOQLQuery();
      }
  
      public DList newDList()
      {
          beginInternTransaction();
          return super.newDList();
      }
  
      public DBag newDBag()
      {
          beginInternTransaction();
          return super.newDBag();
      }
  
      public DSet newDSet()
      {
          beginInternTransaction();
          return super.newDSet();
      }
  
      public DArray newDArray()
      {
          beginInternTransaction();
          return super.newDArray();
      }
  
      public DMap newDMap()
      {
          beginInternTransaction();
          return super.newDMap();
      }
  
      /**
       * Here we start a intern odmg-Transaction to hide transaction demarcation
       * This method could be invoked several times within a transaction, but only
       * the first call begin a intern odmg transaction
       */
      private void beginInternTransaction()
      {
          if (log.isDebugEnabled()) log.debug("beginInternTransaction was called");
          J2EETransactionImpl tx = (J2EETransactionImpl) super.currentTransaction();
          if (tx == null) tx = newInternTransaction();
          if (!tx.isOpen())
          {
              // start the transaction
              tx.begin();
              tx.setInExternTransaction(true);
          }
      }
  
      /**
       * Returns a new intern odmg-transaction for the current database.
       */
      private J2EETransactionImpl newInternTransaction()
      {
          if (log.isDebugEnabled()) log.debug("obtain new intern odmg-transaction");
          J2EETransactionImpl tx = new J2EETransactionImpl(getCurrentDatabase());
          try
          {
              getConfigurator().configure(tx);
          }
          catch (ConfigurationException e)
          {
              throw new OJBRuntimeException("Cannot create new intern odmg transaction", e);
          }
          return tx;
      }
  
      /**
       * Not supported in managed-environment.
       */
      public Transaction newTransaction()
      {
          throw new UnsupportedOperationException("Not supported in managed environment");
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/ImplementationDefaultImpl.java
  
  Index: ImplementationDefaultImpl.java
  ===================================================================
  package org.apache.ojb.odmg;
  
  /* Copyright 2002-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  import org.apache.ojb.broker.util.configuration.ConfigurationException;
  import org.apache.ojb.broker.util.configuration.Configurator;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  import org.apache.ojb.odmg.collections.DCollectionFactory;
  import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
  import org.apache.ojb.odmg.oql.OQLQueryImpl;
  import org.odmg.DArray;
  import org.odmg.DBag;
  import org.odmg.DList;
  import org.odmg.DMap;
  import org.odmg.DSet;
  import org.odmg.Database;
  import org.odmg.DatabaseClosedException;
  import org.odmg.Implementation;
  import org.odmg.ODMGRuntimeException;
  import org.odmg.Transaction;
  
  import java.util.ArrayList;
  import java.util.List;
  
  
  /**
   * Default implementation of the {@link Implementation} interface.
   *
   * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   *
   * @version $Id: ImplementationDefaultImpl.java,v 1.1 2004/05/03 23:05:56 arminw Exp $
   */
  public class ImplementationDefaultImpl extends Object implements Implementation
  {
      private Logger log = LoggerFactory.getLogger(ImplementationDefaultImpl.class);
  
      private List usedDatabases = new ArrayList();
      private DatabaseImpl currentDatabase;
      private Configurator configurator;
      private OJBTxManager ojbTxManager;
  
      /**
       * private Constructor: use static factory method
       * getInstance() to obtain an instance
       */
      protected ImplementationDefaultImpl()
      {
          ojbTxManager = TxManagerFactory.instance();
          setConfigurator(PersistenceBrokerFactory.getConfigurator());
      }
  
      /**
       * Method declaration
       * @param curDB
       */
      protected synchronized void setCurrentDatabase(DatabaseImpl curDB)
      {
          currentDatabase = curDB;
      }
  
      public DatabaseImpl getCurrentDatabase()
      {
          return currentDatabase;
      }
  
      public PBKey getCurrentPBKey()
      {
          return currentDatabase.getPBKey();
      }
  
      /**
       * Gets the configurator.
       * @return Returns a Configurator
       */
      public Configurator getConfigurator()
      {
          return configurator;
      }
  
      /**
       * Sets the configurator.
       * @param configurator The configurator to set
       */
      public void setConfigurator(Configurator configurator)
      {
          this.configurator = configurator;
      }
  
      /**
       * Create a <code>Transaction</code> object and associate it with the current thread.
       * @return The newly created <code>Transaction</code> instance.
       * @see Transaction
       */
      public Transaction newTransaction()
      {
          if ((getCurrentDatabase() == null))
          {
              throw new DatabaseClosedException("Database is NULL, must have a DB in order to create a transaction");
          }
          TransactionImpl tx = new TransactionImpl(getCurrentDatabase());
          try
          {
              getConfigurator().configure(tx);
          }
          catch (ConfigurationException e)
          {
              throw new ODMGRuntimeException("Error in configuration of TransactionImpl instance: " + e.getMessage());
          }
          return tx;
      }
  
      /**
       * Get the current <code>Transaction</code> for the thread.
       * @return The current <code>Transaction</code> object or null if there is none.
       * @see Transaction
       */
      public Transaction currentTransaction()
      {
          if ((getCurrentDatabase() == null))
          {
              throw new DatabaseClosedException("Database is NULL, must have a DB in order to create a transaction");
          }
          return ojbTxManager.getTransaction();
      }
  
      /**
       * Create a new <code>Database</code> object.
       * @return The new <code>Database</code> object.
       * @see Database
       */
      public Database newDatabase()
      {
          return new DatabaseImpl(this);
      }
  
      /**
       * Create a new <code>OQLQuery</code> object.
       * @return The new <code>OQLQuery</code> object.
       * @see org.odmg.OQLQuery
       */
      public EnhancedOQLQuery newOQLQuery()
      {
          if ((getCurrentDatabase() == null) || !getCurrentDatabase().isOpen())
          {
              throw new DatabaseClosedException("Database is not open");
          }
          OQLQueryImpl query = new OQLQueryImpl(this.getCurrentPBKey());
          try
          {
              getConfigurator().configure(query);
          }
          catch (ConfigurationException e)
          {
              throw new ODMGRuntimeException("Error in configuration of OQLQueryImpl instance: " + e.getMessage());
          }
          return query;
  
      }
  
      /**
       * Create a new <code>DList</code> object.
       * @return The new <code>DList</code> object.
       * @see DList
       */
      public DList newDList()
      {
          if ((getCurrentDatabase() == null))
          {
              throw new DatabaseClosedException("Database is NULL, cannot create a DList with a null database.");
          }
          return DCollectionFactory.getInstance().createDList(getCurrentPBKey());
      }
  
      /**
       * Create a new <code>DBag</code> object.
       * @return The new <code>DBag</code> object.
       * @see DBag
       */
      public DBag newDBag()
      {
          if ((getCurrentDatabase() == null))
          {
              throw new DatabaseClosedException("Database is NULL, cannot create a DBag with a null database.");
          }
          return DCollectionFactory.getInstance().createDBag(getCurrentPBKey());
      }
  
      /**
       * Create a new <code>DSet</code> object.
       * @return The new <code>DSet</code> object.
       * @see DSet
       */
      public DSet newDSet()
      {
          if ((getCurrentDatabase() == null))
          {
              throw new DatabaseClosedException("Database is NULL, cannot create a DSet with a null database.");
          }
          return DCollectionFactory.getInstance().createDSet(getCurrentPBKey());
      }
  
      /**
       * Create a new <code>DArray</code> object.
       * @return The new <code>DArray</code> object.
       * @see DArray
       */
      public DArray newDArray()
      {
          if ((getCurrentDatabase() == null))
          {
              throw new DatabaseClosedException("Database is NULL, cannot create a DArray with a null database.");
          }
          return DCollectionFactory.getInstance().createDArray(getCurrentPBKey());
      }
  
      /**
       * Create a new <code>DMap</code> object.
       * @return The new <code>DMap</code> object.
       * @see DMap
       */
      public DMap newDMap()
      {
          if ((getCurrentDatabase() == null))
          {
              throw new DatabaseClosedException("Database is NULL, cannot create a DMap with a null database.");
          }
          return DCollectionFactory.getInstance().createDMap(getCurrentPBKey());
      }
  
      /**
       * Get a <code>String</code> representation of the object's identifier.
       * OJB returns the serialized Identity of the object.
       * @param obj The object whose identifier is being accessed.
       * @return The object's identifier in the form of a String
       */
      public String getObjectId(Object obj)
      {
          Identity oid = null;
          PersistenceBroker broker;
  
          if (getCurrentDatabase() != null)
          {
              /**
               * is there an open database we are calling getObjectId against? if yes, use it
               */
              broker = PersistenceBrokerFactory.createPersistenceBroker(getCurrentDatabase().getPBKey());
          }
          else
          {
              /**
               * otherwise, use default.
               */
              broker = PersistenceBrokerFactory.defaultPersistenceBroker();
          }
  
          oid = new Identity(obj, broker);
          return new String(oid.serialize());
      }
  
      /**
       * Returns the current used database or null.
       */
      public Database getDatabase(Object obj)
      {
          /* @todo enhance functionality */
          return getCurrentDatabase();
      }
  
      /**
       * Register opened database via the PBKey.
       */
      protected synchronized void registerOpenDatabase(DatabaseImpl newDB)
      {
          DatabaseImpl old_db = getCurrentDatabase();
          if (old_db != null)
          {
              try
              {
                  if (old_db.isOpen())
                  {
                      log.warn("## There is still an opened database, close old one ##");
                      old_db.close();
                  }
              }
              catch (Throwable t)
              {
                  //ignore
              }
          }
          if (log.isDebugEnabled()) log.debug("Set current database " + newDB + " PBKey was " + newDB.getPBKey());
          setCurrentDatabase(newDB);
          usedDatabases.add(newDB.getPBKey());
      }
  
      /**
       * This method can be used to activate or deactivate the implicit
       * locking mechanism for the current transaction.
       * turning of implicit locking may improve performance but requires
       * additional care to make sure all changed objects are properly
       * registered to the transaction.
       * @param value if set to true implicit locking is enabled,
       *        if false, implicit locking is disabled.
       **/
  	public void setImplicitLocking(boolean value)
  	{
  		((TransactionExt)currentTransaction()).setImplicitLocking(value);
  	}
  
  
  }
  
  
  
  1.7       +33 -56    db-ojb/src/java/org/apache/ojb/broker/util/ConstructorHelper.java
  
  Index: ConstructorHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/ConstructorHelper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConstructorHelper.java	4 Apr 2004 23:53:37 -0000	1.6
  +++ ConstructorHelper.java	3 May 2004 23:05:56 -0000	1.7
  @@ -1,4 +1,5 @@
   package org.apache.ojb.broker.util;
  +
   /* Copyright 2003-2004 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
  @@ -30,10 +31,10 @@
    */
   public class ConstructorHelper
   {
  -	/**
  -	 * represents a zero sized parameter array
  -	 */
  -	private static final Object[] NO_ARGS = {};
  +    /**
  +     * represents a zero sized parameter array
  +     */
  +    private static final Object[] NO_ARGS = {};
   
       /**
        * no public constructor, please use the static method only.
  @@ -42,56 +43,33 @@
       {
       }
   
  -	/**
  -	 * create a new instance of class clazz.
  -	 * first use the public default constructor.
  -	 * If this fails also try to use protected an private constructors.
  -	 * @param clazz the class to instantiate
  -	 * @return the fresh instance of class clazz
  -	 * @throws InstantiationException
  -	 */
  +    /**
  +     * create a new instance of class clazz.
  +     * first use the public default constructor.
  +     * If this fails also try to use protected an private constructors.
  +     * @param clazz the class to instantiate
  +     * @return the fresh instance of class clazz
  +     * @throws InstantiationException
  +     */
       public static Object instantiate(Class clazz) throws InstantiationException
       {
           Object result = null;
  -
           try
           {
  -            result = clazz.newInstance();
  +            result = ClassHelper.newInstance(clazz);
           }
  -        catch (IllegalAccessException e)
  +        catch(IllegalAccessException e)
           {
  -            // can't access constructor, so let's use reflection
  -            //1. get private no args constructor
  -            Class[] params = {};
  -            Constructor constructor;
               try
               {
  -                constructor = clazz.getDeclaredConstructor(params);
  -            }
  -            catch (NoSuchMethodException ex)
  -            {
  -                throw new ClassNotPersistenceCapableException(
  -                    clazz.getName() + " does not provide a zero argument constructor!",ex);
  +                result = ClassHelper.newInstance(clazz, true);
               }
  -
  -            //2. make is accessible
  -            constructor.setAccessible(true);
  -
  -            //3. use it to build a new instance
  -            Object[] args = {};
  -            try
  +            catch(Exception e1)
               {
  -                result = constructor.newInstance(args);
  +                throw new ClassNotPersistenceCapableException("Can't instantiate class '"
  +                        + (clazz != null ? clazz.getName() : "null")
  +                        + "', message was: " + e1.getMessage() + ")", e1);
               }
  -            catch (Throwable t)
  -            {
  -                throw new ClassNotPersistenceCapableException(
  -                    "Could not instantiate "
  -                        + clazz.getName()
  -                        + ": "
  -                        + t.getMessage() + ")",t);
  -            }
  -
           }
           return result;
       }
  @@ -106,28 +84,27 @@
        */
       public static Object instantiate(Constructor constructor) throws InstantiationException
       {
  -        if (constructor == null)
  +        if(constructor == null)
           {
               throw new ClassNotPersistenceCapableException(
  -                "A zero argument constructor was not provided!");
  +                    "A zero argument constructor was not provided!");
           }
   
           Object result = null;
  -
           try
           {
               result = constructor.newInstance(NO_ARGS);
           }
  -        catch (Throwable t)
  +        catch(InstantiationException e)
           {
  -            throw new ClassNotPersistenceCapableException(
  -                "(Could not instantiate "
  -                + constructor.getDeclaringClass().getName()
  -                + ": "
  -                + t.getMessage() + ")", t);
  +            throw e;
           }
  -
  -       return result;
  -   }
  -
  +        catch(Exception e)
  +        {
  +            throw new ClassNotPersistenceCapableException("Can't instantiate class '"
  +                    + (constructor != null ? constructor.getDeclaringClass().getName() : "null")
  +                    + "' with given constructor: " + e.getMessage(), e);
  +        }
  +        return result;
  +    }
   }
  
  
  
  1.7       +101 -19   db-ojb/src/java/org/apache/ojb/broker/util/ClassHelper.java
  
  Index: ClassHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/ClassHelper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ClassHelper.java	4 Apr 2004 23:53:36 -0000	1.6
  +++ ClassHelper.java	3 May 2004 23:05:56 -0000	1.7
  @@ -1,9 +1,5 @@
   package org.apache.ojb.broker.util;
   
  -import java.lang.reflect.InvocationTargetException;
  -import java.lang.reflect.Method;
  -import java.lang.reflect.Field;
  -
   /* Copyright 2002-2004 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
  @@ -18,9 +14,27 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  +
  +import java.lang.reflect.InvocationTargetException;
  +import java.lang.reflect.Method;
  +import java.lang.reflect.Field;
  +import java.lang.reflect.Constructor;
  +
  +import org.apache.ojb.broker.OJBRuntimeException;
  +
  +/**
  + * Helper class with static methods for class, method, field handling.
  + *
  + * @version $Id$
  + */
   public class ClassHelper
   {
  -    //private static Logger log = LoggerFactory.getLogger(ClassHelper.class);
  +    private static final Object[] NO_ARGS = {};
  +    private static final Class[] NO_ARGS_CLASS = {};
  +
  +    private ClassHelper()
  +    {
  +    }
   
       /**
        * Returns a class object for the given name or <i>null</i>
  @@ -40,13 +54,69 @@
       }
   
       /**
  -     * Returns new instance of the given class name, using the default constructor.
  +     * Returns new instance of the given class, using the default constructor - if argument
  +     * <code>makeAccessible</code> is set 'true' Java language access
  +     * checking will be suppressed..
  +     */
  +    public static Object newInstance(Class target, boolean makeAccessible) throws InstantiationException,
  +            IllegalAccessException
  +    {
  +        if(makeAccessible)
  +        {
  +            try
  +            {
  +                return newInstance(target, NO_ARGS_CLASS, NO_ARGS, makeAccessible);
  +            }
  +            catch(InvocationTargetException e)
  +            {
  +                throw new OJBRuntimeException("Unexpected exception while instantiate class '"
  +                        + target + "' with default constructor", e);
  +            }
  +            catch(NoSuchMethodException e)
  +            {
  +                throw new OJBRuntimeException("Unexpected exception while instantiate class '"
  +                        + target + "' with default constructor", e);
  +            }
  +        }
  +        else
  +        {
  +            return target.newInstance();
  +        }
  +    }
  +
  +    /**
  +     * Returns new instance of the given class, using specified constructor.
        */
       public static Object newInstance(Class target, Class[] types, Object[] args) throws
               InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
               NoSuchMethodException, SecurityException
       {
  -        return target.getConstructor(types).newInstance(args);
  +        return newInstance(target, types, args, false);
  +    }
  +
  +    /**
  +     * Returns new instance of the given class, using specified constructor - if argument
  +     * <code>makeAccessible</code> is set 'true' Java language access
  +     * checking will be suppressed.
  +     */
  +    public static Object newInstance(Class target, Class[] types, Object[] args, boolean makeAccessible) throws
  +            InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
  +            NoSuchMethodException, SecurityException
  +    {
  +        Constructor con;
  +        if(makeAccessible)
  +        {
  +            con = target.getDeclaredConstructor(types);
  +            if(makeAccessible)
  +            {
  +                if(!con.isAccessible()) con.setAccessible(true);
  +            }
  +        }
  +        else
  +        {
  +            con = target.getConstructor(types);
  +        }
  +        return con.newInstance(args);
       }
   
       /**
  @@ -57,11 +127,15 @@
        * @return method invokable via <code>java.lang.reflect.Method#invoke</code>,
        * or <code>null</code> if no matching method can be found
        */
  -    public static Method getMethod(Class clazz, String methodName, Class[] params) {
  +    public static Method getMethod(Class clazz, String methodName, Class[] params)
  +    {
           Method method;
  -        try {
  +        try
  +        {
               method = clazz.getMethod(methodName, params);
  -        } catch (Exception ignore) {
  +        }
  +        catch(Exception ignore)
  +        {
               method = null;
           }
           return method;
  @@ -74,11 +148,15 @@
        * @return field retrievable via <code>java.lang.reflect.Field#getXXX</code>,
        * or <code>null</code> if no matching field can be found
        */
  -    public static Field getField(Class clazz, String fieldName) {
  +    public static Field getField(Class clazz, String fieldName)
  +    {
           Field field;
  -        try {
  +        try
  +        {
               field = clazz.getField(fieldName);
  -        } catch (Exception ignore) {
  +        }
  +        catch(Exception ignore)
  +        {
               field = null;
           }
           return field;
  @@ -115,7 +193,7 @@
               InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
               NoSuchMethodException, SecurityException, ClassNotFoundException
       {
  -        return newInstance(getClass(className),types, args);
  +        return newInstance(getClass(className), types, args);
       }
   
       public static Object newInstance(Class target, Class type, Object arg) throws
  @@ -140,7 +218,8 @@
        * @return method invokable via <code>java.lang.reflect.Method#invoke</code>,
        * or <code>null</code> if no matching method can be found
        */
  -    public static Method getMethod(Object object, String methodName, Class[] params) {
  +    public static Method getMethod(Object object, String methodName, Class[] params)
  +    {
           return getMethod(object.getClass(), methodName, params);
       }
   
  @@ -152,14 +231,17 @@
        * @return method invokable via <code>java.lang.reflect.Method#invoke</code>,
        * or <code>null</code> if no matching method can be found
        */
  -    public static Method getMethod(String className, String methodName, Class[] params) {
  +    public static Method getMethod(String className, String methodName, Class[] params)
  +    {
           Method method = null;
  -        try {
  +        try
  +        {
               Class clazz = getClass(className, false);
               method = getMethod(clazz, methodName, params);
  -        } catch (Exception ignore) {
  +        }
  +        catch(Exception ignore)
  +        {
           }
           return method;
       }
  -
   }
  
  
  
  1.15      +2 -2      db-ojb/src/java/org/apache/ojb/broker/util/factory/ConfigurableFactory.java
  
  Index: ConfigurableFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/factory/ConfigurableFactory.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ConfigurableFactory.java	4 Apr 2004 23:53:37 -0000	1.14
  +++ ConfigurableFactory.java	3 May 2004 23:05:56 -0000	1.15
  @@ -98,11 +98,11 @@
               // create an instance of the target class
               if (types != null)
               {
  -                result = ClassHelper.newInstance(getClassToServe(), types, args);
  +                result = ClassHelper.newInstance(getClassToServe(), types, args, true);
               }
               else
               {
  -                result = ClassHelper.newInstance(getClassToServe());
  +                result = ClassHelper.newInstance(getClassToServe(), true);
               }
               // if defined in OJB.properties all instances are wrapped by an interceptor
               result = InterceptorFactory.getInstance().createInterceptorFor(result);
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/TransactionNotInProgressException.java
  
  Index: TransactionNotInProgressException.java
  ===================================================================
  package org.apache.ojb.broker.transaction;
  
  import org.apache.ojb.broker.OJBRuntimeException;
  
  /**
   *
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: TransactionNotInProgressException.java,v 1.1 2004/05/03 23:05:56 arminw Exp $
   */
  public class TransactionNotInProgressException extends OJBRuntimeException
  {
      public TransactionNotInProgressException()
      {
      }
  
      public TransactionNotInProgressException(String msg)
      {
          super(msg);
      }
  
      public TransactionNotInProgressException(Throwable cause)
      {
          super(cause);
      }
  
      public TransactionNotInProgressException(String msg, Throwable cause)
      {
          super(msg, cause);
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/OJBTxObject.java
  
  Index: OJBTxObject.java
  ===================================================================
  package org.apache.ojb.broker.transaction;
  
  /**
   * Internal used tagging interface for transactional objects. 
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: OJBTxObject.java,v 1.1 2004/05/03 23:05:56 arminw Exp $
   */
  public interface OJBTxObject
  {
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/OJBTxManager.java
  
  Index: OJBTxManager.java
  ===================================================================
  package org.apache.ojb.broker.transaction;
  
  import javax.transaction.Transaction;
  
  /**
   * Class give support in transaction handling.
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: OJBTxManager.java,v 1.1 2004/05/03 23:05:56 arminw Exp $
   */
  public interface OJBTxManager
  {
      void registerTx(OJBTxObject obj);
  
      void deregisterTx(OJBTxObject obj);
  
      /**
       * Returns the current transaction for the calling thread or <code>null</code>
       * if no transaction was found.
       *
       * @see #getCurrentJTATransaction
       */
      Transaction getJTATransaction();
  
      /**
       * Returns the current transaction for the calling thread.
       *
       * @see #getJTATransaction
       * @throws TransactionNotInProgressException if no transaction was found.
       */
      Transaction getCurrentJTATransaction();
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/WebSphereTransactionManagerFactory.java
  
  Index: WebSphereTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  import org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory;
  
  /* Copyright 2003-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * Websphere (4 and above) {@link javax.transaction.TransactionManager} lookup.
   *
   * @author matthew.baird
   * @version $Id: WebSphereTransactionManagerFactory.java,v 1.1 2004/05/03 23:05:56 arminw Exp $
   */
  public class WebSphereTransactionManagerFactory extends AbstractTransactionManagerFactory
  {
      /**
       * 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 org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory#getLookupInfo
       */
      public String[][] getLookupInfo()
      {
          return config;
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/WeblogicTransactionManagerFactory.java
  
  Index: WeblogicTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  import org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory;
  
  /* Copyright 2003-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * Weblogic {@link javax.transaction.TransactionManager} lookup.
   *
   * @author matthew.baird
   * @version $Id: WeblogicTransactionManagerFactory.java,v 1.1 2004/05/03 23:05:56 arminw Exp $
   */
  public class WeblogicTransactionManagerFactory extends AbstractTransactionManagerFactory
  {
      private static final String[][] config = {
          {"Weblogic", "javax.transaction.TransactionManager", null}};
  
      /**
       * @see org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory#getLookupInfo
       */
      public String[][] getLookupInfo()
      {
          return config;
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/TransactionManagerFactoryFactory.java
  
  Index: TransactionManagerFactoryFactory.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  import org.apache.ojb.broker.util.factory.ConfigurableFactory;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  import org.apache.ojb.broker.transaction.tm.TransactionManagerFactory;
  
  /* Copyright 2003-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  public class TransactionManagerFactoryFactory
  {
      private static Logger log = LoggerFactory.getLogger(TransactionManagerFactoryFactory.class);
      private static TransactionManagerFactory tmInstance;
      static
      {
          try
          {
              tmInstance = new TMFactoryFactory().createTransactionManagerFactory();
          }
          catch (Exception e)
          {
              log.error("Instantiation of TransactionManagerFactory failed", e);
          }
      }
  
      public synchronized static TransactionManagerFactory instance()
      {
          return tmInstance;
      }
  
      public static class TMFactoryFactory extends ConfigurableFactory
      {
          protected String getConfigurationKey()
          {
              return "JTATransactionManagerClass";
          }
  
          protected TransactionManagerFactory createTransactionManagerFactory()
          {
              return (TransactionManagerFactory) this.createNewInstance();
          }
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/TransactionManagerFactoryException.java
  
  Index: TransactionManagerFactoryException.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  import org.apache.ojb.broker.OJBException;
  
  /* Copyright 2003-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  public class TransactionManagerFactoryException extends OJBException
  {
  	/**
  	 * Constructor for TransactionManagerFactoryException.
  	 */
  	public TransactionManagerFactoryException()
  	{
  		super();
  	}
  	/**
  	 * Constructor for TransactionManagerFactoryException.
  	 * @param message
  	 */
  	public TransactionManagerFactoryException(String message)
  	{
  		super(message);
  	}
  
      public TransactionManagerFactoryException(String msg, Throwable cause)
      {
          super(msg, cause);
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/TransactionManagerFactory.java
  
  Index: TransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  import javax.transaction.TransactionManager;
  
  /* Copyright 2003-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  public interface TransactionManagerFactory
  {
  	TransactionManager getTransactionManager() throws TransactionManagerFactoryException;
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/SunOneTransactionManagerFactory.java
  
  Index: SunOneTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  import org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory;
  
  /* Copyright 2004-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  
  /**
   * SunOne {@link javax.transaction.TransactionManager} lookup.
   *
   * @author Rice Yeh
   * @version $Id: SunOneTransactionManagerFactory.java,v 1.1 2004/05/03 23:05:56 arminw Exp $
   */
  public class SunOneTransactionManagerFactory extends AbstractTransactionManagerFactory
  {
      private static final String[][] config = {
          {"SunOne", "getTransactionManagerImpl", "com.sun.jts.jta.TransactionManagerImpl"}};
  
      /**
       * @see org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory#getLookupInfo
       */
      public String[][] getLookupInfo()
      {
          return config;
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/OrionTransactionManagerFactory.java
  
  Index: OrionTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  import org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory;
  
  /* Copyright 2003-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  
  /**
   * Orion {@link javax.transaction.TransactionManager} lookup.
   *
   * @author andreas.bayer
   * @version $Id: OrionTransactionManagerFactory.java,v 1.1 2004/05/03 23:05:56 arminw Exp $
   */
  public class OrionTransactionManagerFactory extends AbstractTransactionManagerFactory
  {
      private static final String[][] config = {{"Orion", "java:comp/UserTransaction", null}};
  
      /**
       * @see org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory#getLookupInfo
       */
      public String[][] getLookupInfo()
      {
          return config;
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/JOnASTransactionManagerFactory.java
  
  Index: JOnASTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  import org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory;
  
  /* Copyright 2004-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  public class JOnASTransactionManagerFactory extends AbstractTransactionManagerFactory
  {
      private static final String[][] config = {{"JOnAS", "javax.transaction.UserTransaction", null}};
  
      /**
       * @see org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory#getLookupInfo
       */
      public String[][] getLookupInfo()
      {
          return config;
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/JBossTransactionManagerFactory.java
  
  Index: JBossTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  import org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory;
  
  /* Copyright 2003-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * JBoss {@link javax.transaction.TransactionManager} lookup.
   *
   * @author matthew.baird
   */
  public class JBossTransactionManagerFactory extends AbstractTransactionManagerFactory
  {
      private static final String[][] config = {{"JBoss", "java:/TransactionManager", null}};
  
      /**
       * @see org.apache.ojb.broker.transaction.tm.AbstractTransactionManagerFactory#getLookupInfo
       */
      public String[][] getLookupInfo()
      {
          return config;
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/transaction/tm/AbstractTransactionManagerFactory.java
  
  Index: AbstractTransactionManagerFactory.java
  ===================================================================
  package org.apache.ojb.broker.transaction.tm;
  
  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;
  
  /* Copyright 2004-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  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 javax.transaction.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.broker.transaction.tm.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