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 to...@apache.org on 2004/11/14 10:37:21 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/odmg ImplementationInternal.java NamedRootsMap.java TransactionExt.java OJBTxManager.java TransactionAware.java ObjectEnvelopeTable.java ImplementationJTAImpl.java LocalTxManager.java ImplementationImpl.java DatabaseImpl.java J2EETransactionImpl.java JTATxManager.java TransactionImpl.java NarrowTransaction.java OJB.java

tomdz       2004/11/14 01:37:21

  Modified:    src/java/org/apache/ojb/odmg NamedRootsMap.java
                        TransactionExt.java OJBTxManager.java
                        TransactionAware.java ObjectEnvelopeTable.java
                        ImplementationJTAImpl.java LocalTxManager.java
                        ImplementationImpl.java DatabaseImpl.java
                        J2EETransactionImpl.java JTATxManager.java
                        TransactionImpl.java NarrowTransaction.java
                        OJB.java
  Added:       src/java/org/apache/ojb/odmg ImplementationInternal.java
  Log:
  Reworked the OJB core:
  - replaced the factories/configuration concept with the ComponentContainer
  - removal of most static calls within OJB
  - removed the old "D" collection implementations and renamed the new ones
  - moved StatementForClassIF handling to the PersistenceConfiguration
  - moved RowReader caching from the ClassDescriptor to the PersistenceConfiguration
  and other changes (see mail on the dev list for more details)
  
  Revision  Changes    Path
  1.13      +3 -15     db-ojb/src/java/org/apache/ojb/odmg/NamedRootsMap.java
  
  Index: NamedRootsMap.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/NamedRootsMap.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- NamedRootsMap.java	4 Apr 2004 23:53:38 -0000	1.12
  +++ NamedRootsMap.java	14 Nov 2004 09:37:20 -0000	1.13
  @@ -52,9 +52,9 @@
        * constructor is private, use getInstance()
        *
        */
  -    private NamedRootsMap()
  +    public NamedRootsMap(OJBTxManager txManager)
       {
  -        txManager = TxManagerFactory.instance();
  +        this.txManager = txManager;
       }
   
       /**
  @@ -76,18 +76,6 @@
               if(log.isDebugEnabled()) log.debug("Could not get identity for key "+key, e);
               return null;
           }
  -    }
  -
  -    /**
  -     * factory method returns singleton instance
  -     */
  -    public synchronized static NamedRootsMap getInstance()
  -    {
  -        if (_instance == null)
  -        {
  -            _instance = new NamedRootsMap();
  -        }
  -        return _instance;
       }
   
       /**
  
  
  
  1.5       +20 -9     db-ojb/src/java/org/apache/ojb/odmg/TransactionExt.java
  
  Index: TransactionExt.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionExt.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TransactionExt.java	4 Apr 2004 23:53:39 -0000	1.4
  +++ TransactionExt.java	14 Nov 2004 09:37:20 -0000	1.5
  @@ -1,7 +1,5 @@
   package org.apache.ojb.odmg;
   
  -import org.odmg.Transaction;
  -
   /* Copyright 2003-2004 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
  @@ -16,13 +14,20 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  +
  +import org.odmg.Transaction;
  +
  +/**
  + * Extension of the <code>Transaction</code> interface that provides additional
  + * functionality.
  + */
   public interface TransactionExt extends Transaction, HasBroker
   {
       /**
        * marks an object for deletion without
        * locking the object.
        *
  -     * @param  anObject Object to be marked
  +     * @param anObject Object to be marked
        */
       public void markDelete(Object anObject);
   
  @@ -30,7 +35,7 @@
        * marks an object as dirty without
        * locking the object.
        *
  -     * @param  anObject Object to be marked
  +     * @param anObject Object to be marked
        */
       public void markDirty(Object anObject);
   
  @@ -42,19 +47,25 @@
        * The ODMG transaction retains all locks it held on those objects at the time the flush
        * was invoked.
        * <p/>
  -     * This method is very similair to {@link org.odmg.Transaction#checkpoint}.
  +     * This method is very similar to {@link org.odmg.Transaction#checkpoint}.
        */
       public void flush();
       
  -    
  +    /**
  +     * Returns whether the transaction performs implicit locking.
  +     * 
  +     * @return <code>true</code> if implicit locking is on
  +     */
  +    public boolean getImplicitLocking();
  +
       /**
        * 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.
  +     * 
  +     * @param useImplicitLocking Whether to enable implicit locking
        **/
  -    public void setImplicitLocking(boolean value);
  +    public void setImplicitLocking(boolean useImplicitLocking);
   }
  
  
  
  1.7       +2 -3      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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- OJBTxManager.java	3 May 2004 23:05:56 -0000	1.6
  +++ OJBTxManager.java	14 Nov 2004 09:37:20 -0000	1.7
  @@ -1,4 +1,5 @@
   package org.apache.ojb.odmg;
  +
   /* Copyright 2002-2004 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
  @@ -14,8 +15,6 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.util.configuration.Configurable;
  -
   /**
    *  The OJBTxManager defines the contract for associating the caller with the
    *  current or new transaction in ODMG.
  @@ -23,7 +22,7 @@
    * @author Matthew Baird
    * @version $Id$
    */
  -public interface OJBTxManager extends Configurable
  +public interface OJBTxManager
   {
   	/**
        * Returns the current transaction for the calling thread.
  
  
  
  1.7       +1 -1      db-ojb/src/java/org/apache/ojb/odmg/TransactionAware.java
  
  Index: TransactionAware.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionAware.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TransactionAware.java	5 Apr 2004 12:16:16 -0000	1.6
  +++ TransactionAware.java	14 Nov 2004 09:37:20 -0000	1.7
  @@ -1 +1 @@
  -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 java.io.Serializable;

/**
 *
 * TransactionAware is an interface that can be implemented
 * to provide hooks into the Transaction interface provided
 * by ObJectRelationalBridge.
 * Only objects which have a write lock acquired on them can
 * participate in a transaction.
 * To kill a transaction, implement beforeCommit() and throw
 * a TransactionAbortedException.  This will force the entire
 * transaction to rollback.
 *
 * To rebuild an object after a rollback use the afterAbort()
 * call.  This is a good place to populate transient or other
 * variables.
 *
 * beforeAbort and afterCommit are there for informational
 * purposes.
 *
 * Here are some common ways you can expect this interface
 * to be called:
 *
 * Sucessful commit:
 * beforeCommit()
 * afterCommit()
 *
 * Transaction Failure (1):
 * beforeCommit()
 * beforeAbort()
 * afterAbort()
 *
 * Transaction Failure (2):
 * beforeAbort()
 * afterAbort()
 *
 * Commits and Aborts aren't directly provided to TransactionAware classes.
 * The idea is that Transactions are difficult to handle, and most of it
 * will be handled by ObjectSnapshot.  However, you use TransactionAware
 * to do one of two things, kill a transaction from happening, and clean
 * up after a rollback.
 *
 * @version $Id$
 */
public interface TransactionAware extends Serializable
{
	static final long serialVersionUID = 3690863289834166023L;    /**
     *
     * beforeCommit will give an object a chance to kill a
     * transaction before it is committed.
     * To kill a transaction, throw a new TransactionAbortedException.
     *
     */
    public void beforeCommit() throws org.odmg.TransactionAbortedException;

    /**
     *
     * afterCommit is called only after a successful commit has taken
     * place.
     *
     */
    public void afterCommit();

    /**
     *
     * beforeAbort is called before a transaction is aborted.
     *
     */
    public void beforeAbort();

    /**
     *
     * afterAbort will be called after a transaction has been aborted.
     * The values of fields which get persisted will have changed to
     * what they were at the begining of the transaction.  This method
     * should be overridden to reset any transient or non-persistent
     * fields.
     *
     */
    public void afterAbort();
}
  +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 java.io.Serializable;

/**
 *
 * TransactionAware is an interface that can be implemented
 * to provide hooks into the Transaction interface provided
 * by ObJectRelationalBridge.
 * Only objects which have a write lock acquired on them can
 * participate in a transaction.
 * To kill a transaction, implement beforeCommit() and throw
 * a TransactionAbortedException.  This will force the entire
 * transaction to rollback.
 *
 * To rebuild an object after a rollback use the afterAbort()
 * call.  This is a good place to populate transient or other
 * variables.
 *
 * beforeAbort and afterCommit are there for informational
 * purposes.
 *
 * Here are some common ways you can expect this interface
 * to be called:
 *
 * Sucessful commit:
 * beforeCommit()
 * afterCommit()
 *
 * Transaction Failure (1):
 * beforeCommit()
 * beforeAbort()
 * afterAbort()
 *
 * Transaction Failure (2):
 * beforeAbort()
 * afterAbort()
 *
 * Commits and Aborts aren't directly provided to TransactionAware classes.
 * The idea is that Transactions are difficult to handle, and most of it
 * will be handled by ObjectSnapshot.  However, you use TransactionAware
 * to do one of two things, kill a transaction from happening, and clean
 * up after a rollback.
 *
 * @version $Id$
 */
public interface TransactionAware extends Serializable
{
	static final long serialVersionUID = 3690863289834166023L;    /**
     *
     * beforeCommit will give an object a chance to kill a
     * transaction before it is committed.
     * To kill a transaction, throw a new TransactionAbortedException.
     *
     */
    public void beforeCommit() throws org.odmg.TransactionAbortedException;

    /**
     *
     * afterCommit is called only after a successful commit has taken
     * place.
     *
     */
    public void afterCommit();

    /**
     *
     * beforeAbort is called before a transaction is aborted.
     *
     */
    public void beforeAbort();

    /**
     *
     * afterAbort will be called after a transaction has been aborted.
     * The values of fields which get persisted will have changed to
     * what they were at the begining of the transaction.  This method
     * should be overridden to reset any transient or non-persistent
     * fields.
     *
     */
    public void afterAbort();
}
  
  
  
  1.38      +2 -18     db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java
  
  Index: ObjectEnvelopeTable.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- ObjectEnvelopeTable.java	23 Oct 2004 15:46:22 -0000	1.37
  +++ ObjectEnvelopeTable.java	14 Nov 2004 09:37:20 -0000	1.38
  @@ -29,7 +29,6 @@
   import org.apache.ojb.broker.OptimisticLockException;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
  @@ -40,7 +39,6 @@
   import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  -import org.apache.ojb.odmg.locking.LockManagerFactory;
   import org.apache.ojb.odmg.states.StateOldClean;
   import org.odmg.LockNotGrantedException;
   import org.odmg.Transaction;
  @@ -283,7 +281,6 @@
        */
       private void upgradeImplicitLocksAndCheckIfCommitIsNeeded()
       {
  -        boolean useImplicitLocking = getConfiguration().useImplicitLocking();
           // using clone to avoid ConcurentModificationException
           Iterator iter = ((List) mvOrderOfIds.clone()).iterator();
           while (iter.hasNext())
  @@ -303,7 +300,7 @@
   					 * now, the quickest thing to check is the useImplicitLocking flag. If we are using
   					 * implicit locking, let's try to upgrade the lock, and mark the markDirty
   					 */
  -					if (useImplicitLocking)
  +					if (transaction.getImplicitLocking())
   					{
   						// implicitely acquire a write lock !
   						transaction.lock(mod.getObject(), Transaction.UPGRADE);
  @@ -314,7 +311,7 @@
   					 * If useImplicitLocking is false, we still need to check if the object in the envelope
   					 * is write locked. If it is, we don't have to upgrade the lock, just mark markDirty
   					 */
  -					else if (LockManagerFactory.getLockManager().checkWrite(transaction, mod.getObject()))
  +					else if (transaction.getLockManager().checkWrite(transaction, mod.getObject()))
   					{
   						// objects needs commit action, thus set markDirty to true:
   						markDirty = true;
  @@ -644,17 +641,4 @@
               }
           }
       }
  -
  -    /**
  -     * get Configuration
  -     * @return OdmgConfiguration
  -     */
  -    private OdmgConfiguration getConfiguration()
  -    {
  -        OdmgConfiguration config =
  -            (OdmgConfiguration) PersistenceBrokerFactory.getConfigurator().getConfigurationFor(
  -                null);
  -        return config;
  -    }
  -
   }
  
  
  
  1.4       +15 -18    db-ojb/src/java/org/apache/ojb/odmg/ImplementationJTAImpl.java
  
  Index: ImplementationJTAImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ImplementationJTAImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ImplementationJTAImpl.java	14 Aug 2004 23:48:12 -0000	1.3
  +++ ImplementationJTAImpl.java	14 Nov 2004 09:37:20 -0000	1.4
  @@ -15,10 +15,7 @@
    * 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.broker.OJB;
   import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
   import org.odmg.DArray;
   import org.odmg.DBag;
  @@ -37,11 +34,15 @@
    */
   public class ImplementationJTAImpl extends ImplementationImpl
   {
  -    private Logger log = LoggerFactory.getLogger(ImplementationJTAImpl.class);
  -
  -    protected ImplementationJTAImpl()
  +    /**
  +     * Creates a new implementation instance. Please do not use this directly
  +     * but rather the {@link OJB#getInstance()} method.
  +     * 
  +     * @param ojb The OJB runtime
  +     */
  +    protected ImplementationJTAImpl(OJB ojb)
       {
  -        super();
  +        super(ojb);
       }
   
       public Database getDatabase(Object obj)
  @@ -121,15 +122,11 @@
       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);
  -        }
  +
  +        J2EETransactionImpl tx = new J2EETransactionImpl(getCurrentDatabase(), getTxManager(), getLockManager());
  +
  +        getOJBRuntime().getComponentContainer().configure(tx);
  +        tx.setImplicitLocking(isUsingImplicitLocking());
           return tx;
       }
   
  
  
  
  1.6       +3 -8      db-ojb/src/java/org/apache/ojb/odmg/LocalTxManager.java
  
  Index: LocalTxManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/LocalTxManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LocalTxManager.java	4 Apr 2004 23:53:38 -0000	1.5
  +++ LocalTxManager.java	14 Nov 2004 09:37:20 -0000	1.6
  @@ -1,6 +1,5 @@
   package org.apache.ojb.odmg;
   
  -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.odmg.TransactionNotInProgressException;
  @@ -21,7 +20,7 @@
    */
   public class LocalTxManager implements OJBTxManager
   {
  -    private static Logger log = LoggerFactory.getLogger(LocalTxManager.class);
  +    private Logger log = LoggerFactory.getLogger(LocalTxManager.class);
   
       /**
        * Internal table which provides mapping between threads and transactions.
  @@ -30,6 +29,8 @@
        * If the thread joins a transaction, then "getTransaction()" should return
        * the apropriate one.  The only way we can ensure that is by keeping hold
        * of the txTable.
  +     * 
  +     * TODO: Is there a better way than using static ?
        */
       private static TransactionTable tx_table = new TransactionTable();
   
  @@ -87,10 +88,4 @@
       	 * no op
       	 */
       }
  -    
  -    public void configure(Configuration config)
  -    {
  -    	
  -    }
  -    
   }
  
  
  
  1.4       +120 -69   db-ojb/src/java/org/apache/ojb/odmg/ImplementationImpl.java
  
  Index: ImplementationImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ImplementationImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ImplementationImpl.java	25 Sep 2004 14:26:17 -0000	1.3
  +++ ImplementationImpl.java	14 Nov 2004 09:37:20 -0000	1.4
  @@ -16,14 +16,15 @@
    */
   
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.OJB;
  +import org.apache.ojb.broker.OJBRuntimeException;
   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.ClassHelper;
   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.collections.DListImpl;
  +import org.apache.ojb.odmg.locking.LockManager;
   import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
   import org.apache.ojb.odmg.oql.OQLQueryImpl;
   import org.odmg.DArray;
  @@ -34,7 +35,6 @@
   import org.odmg.Database;
   import org.odmg.DatabaseClosedException;
   import org.odmg.Implementation;
  -import org.odmg.ODMGRuntimeException;
   import org.odmg.Transaction;
   
   import java.util.ArrayList;
  @@ -50,23 +50,66 @@
    *
    * @version $Id$
    */
  -public class ImplementationImpl extends Object implements Implementation
  +public class ImplementationImpl extends Object implements ImplementationInternal
   {
  -    private Logger log = LoggerFactory.getLogger(ImplementationImpl.class);
  +    protected Logger log = LoggerFactory.getLogger(getClass());
   
  +    private OJB ojb;
       private List usedDatabases = new ArrayList();
       private DatabaseImpl currentDatabase;
  -    private Configurator configurator;
  -    private OJBTxManager ojbTxManager;
  +    /** The transaction manager */
  +    private OJBTxManager txManager;
  +    /** The lock manager */
  +    private LockManager lockManager;
  +    /** The collection class used for OQL queries */
  +    private Class oqlCollectionClass = DListImpl.class;
  +    /** Whether we're using implicit locking */
  +    private boolean usingImplicitLocking = true;
   
       /**
  -     * private Constructor: use static factory method
  -     * getInstance() to obtain an instance
  +     * Creates a new implementation instance. Please do not use this directly
  +     * but rather the {@link OJB#getInstance()} method which will configure
  +     * the instance correctly.
  +     * 
  +     * @param ojb The OJB runtime
        */
  -    protected ImplementationImpl()
  +    public ImplementationImpl(OJB ojb)
       {
  -        ojbTxManager = TxManagerFactory.instance();
  -        setConfigurator(PersistenceBrokerFactory.getConfigurator());
  +        this.ojb    = ojb;
  +        txManager   = (OJBTxManager)ojb.getComponentContainer().getSingletonInstance(OJBTxManager.class);
  +        lockManager = (LockManager)ojb.getComponentContainer().getSingletonInstance(LockManager.class);
  +    }
  +
  +    protected OJB getOJBRuntime()
  +    {
  +        return ojb;
  +    }
  +    
  +    /**
  +     * Returns the oql collection class.
  +     * 
  +     * @return The oql collection class
  +     */
  +    public String getOqlCollectionClass()
  +    {
  +        return oqlCollectionClass.getName();
  +    }
  +
  +    /**
  +     * Sets the oql collection class.
  +     *
  +     * @param oqlCollectionClass The new oql collection class
  +     */
  +    public void setOqlCollectionClass(String oqlCollectionClass)
  +    {
  +        try
  +        {
  +            this.oqlCollectionClass = ClassHelper.getClass(oqlCollectionClass, false);
  +        }
  +        catch (ClassNotFoundException ex)
  +        {
  +            throw new OJBRuntimeException("Could not find class "+oqlCollectionClass+" specified as thge OQL collection class", ex);
  +        }
       }
   
       /**
  @@ -89,74 +132,70 @@
       }
   
       /**
  -     * Gets the configurator.
  -     * @return Returns a Configurator
  +     * Returns the transaction manager.
  +     * 
  +     * @return The transaction manager
        */
  -    public Configurator getConfigurator()
  +    public OJBTxManager getTxManager()
       {
  -        return configurator;
  +        return txManager;
       }
   
       /**
  -     * Sets the configurator.
  -     * @param configurator The configurator to set
  +     * Returns the lock manager.
  +     * 
  +     * @return The lock manager
        */
  -    public void setConfigurator(Configurator configurator)
  +    public LockManager getLockManager()
       {
  -        this.configurator = configurator;
  +        return lockManager;
       }
   
       /**
        * 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))
  +        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());
  -        }
  +
  +        TransactionImpl tx = new TransactionImpl(getCurrentDatabase(), txManager, lockManager);
  +
  +        ojb.getComponentContainer().configure(tx);
  +        tx.setImplicitLocking(usingImplicitLocking);
           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))
  +        if (getCurrentDatabase() == null)
           {
               throw new DatabaseClosedException("Database is NULL, must have a DB in order to create a transaction");
           }
  -        return ojbTxManager.getTransaction();
  +        return txManager.getTransaction();
       }
   
       public boolean hasOpenTransaction()
       {
  -        TransactionImpl tx = ojbTxManager.getTransaction();
  +        TransactionImpl tx = txManager.getTransaction();
           return tx != null ? tx.isOpen() : false;
       }
   
       /**
        * Create a new <code>Database</code> object.
  -     * @return The new <code>Database</code> object.
  -     * @see Database
  +     * 
  +     * @return The new <code>Database</code> object
        */
       public Database newDatabase()
       {
  -        return new DatabaseImpl(this);
  +        return new DatabaseImpl(this, txManager);
       }
   
       /**
  @@ -170,17 +209,8 @@
           {
               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;
   
  +        return new OQLQueryImpl(this.getCurrentPBKey(), txManager, oqlCollectionClass);
       }
   
       /**
  @@ -190,11 +220,11 @@
        */
       public DList newDList()
       {
  -        if ((getCurrentDatabase() == null))
  +        if (getCurrentDatabase() == null)
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DList with a null database.");
           }
  -        return DCollectionFactory.getInstance().createDList(getCurrentPBKey());
  +        return (DList)ojb.getComponentContainer().getInstance(DList.class);
       }
   
       /**
  @@ -204,11 +234,11 @@
        */
       public DBag newDBag()
       {
  -        if ((getCurrentDatabase() == null))
  +        if (getCurrentDatabase() == null)
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DBag with a null database.");
           }
  -        return DCollectionFactory.getInstance().createDBag(getCurrentPBKey());
  +        return (DBag)ojb.getComponentContainer().getInstance(DBag.class);
       }
   
       /**
  @@ -218,11 +248,11 @@
        */
       public DSet newDSet()
       {
  -        if ((getCurrentDatabase() == null))
  +        if (getCurrentDatabase() == null)
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DSet with a null database.");
           }
  -        return DCollectionFactory.getInstance().createDSet(getCurrentPBKey());
  +        return (DSet)ojb.getComponentContainer().getInstance(DSet.class);
       }
   
       /**
  @@ -232,11 +262,11 @@
        */
       public DArray newDArray()
       {
  -        if ((getCurrentDatabase() == null))
  +        if (getCurrentDatabase() == null)
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DArray with a null database.");
           }
  -        return DCollectionFactory.getInstance().createDArray(getCurrentPBKey());
  +        return (DArray)ojb.getComponentContainer().getInstance(DArray.class);
       }
   
       /**
  @@ -246,11 +276,11 @@
        */
       public DMap newDMap()
       {
  -        if ((getCurrentDatabase() == null))
  +        if (getCurrentDatabase() == null)
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DMap with a null database.");
           }
  -        return DCollectionFactory.getInstance().createDMap(getCurrentPBKey());
  +        return (DMap)ojb.getComponentContainer().getInstance(DMap.class);
       }
   
       /**
  @@ -269,14 +299,14 @@
               /**
                * is there an open database we are calling getObjectId against? if yes, use it
                */
  -            broker = PersistenceBrokerFactory.createPersistenceBroker(getCurrentDatabase().getPBKey());
  +            broker = ojb.lookupBroker(getCurrentDatabase().getPBKey());
           }
           else
           {
               /**
                * otherwise, use default.
                */
  -            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +            broker = ojb.lookupBroker();
           }
   
           oid = new Identity(obj, broker);
  @@ -319,17 +349,38 @@
       }
   
       /**
  +     * Determines whether the transactions are using implicit locking.
  +     * 
  +     * @return <code>true</code> if implicit locking is used
  +     */
  +    public boolean isUsingImplicitLocking()
  +    {
  +        return usingImplicitLocking;
  +    }
  +
  +    /**
  +     * This method can be used to activate or deactivate the implicit
  +     * locking mechanism for transactions.
  +     * 
  +     * @param useImplicitLocking Whether to enable implicit locking
  +     */
  +    public void setUsingImplicitLocking(boolean useImplicitLocking)
  +    {
  +        usingImplicitLocking = useImplicitLocking;
  +    }
  +    
  +    /**
        * 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
  +     * 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)
  +     * 
  +     * @param useImplicitLocking Whether to enabler implicit locking
  +     */
  +	public void setImplicitLockingForCurrentTransaction(boolean useImplicitLocking)
   	{
  -		((TransactionExt)currentTransaction()).setImplicitLocking(value);
  +		((TransactionExt)currentTransaction()).setImplicitLocking(useImplicitLocking);
   	}
   
   
  
  
  
  1.28      +19 -11    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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- DatabaseImpl.java	14 Aug 2004 23:48:11 -0000	1.27
  +++ DatabaseImpl.java	14 Nov 2004 09:37:20 -0000	1.28
  @@ -20,7 +20,6 @@
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  @@ -35,7 +34,7 @@
   import org.odmg.TransactionNotInProgressException;
   
   /**
  - *
  + *  
    * @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>
  @@ -54,11 +53,11 @@
        */
       private NamedRootsMap nrm;
   
  -    public DatabaseImpl(ImplementationImpl ojb)
  +    public DatabaseImpl(ImplementationImpl impl, OJBTxManager txManager)
       {
  -        nrm = NamedRootsMap.getInstance();
  -        isOpen = false;
  -        this.odmg = ojb;
  +        this.nrm    = new NamedRootsMap(txManager);
  +        this.isOpen = false;
  +        this.odmg   = impl;
       }
   
       private TransactionImpl getTransaction()
  @@ -67,7 +66,7 @@
           // TODO: remove this workaround
           // In managed environments only wrapped tx are returned, so
           // we have to extract the real tx first
  -        if(result instanceof NarrowTransaction)
  +        if (result instanceof NarrowTransaction)
           {
               return ((NarrowTransaction) result).getRealTransaction();
           }
  @@ -87,6 +86,16 @@
           return pbKey;
       }
   
  +    /**
  +     * Returns a persistence broker.
  +     * 
  +     * @return The broker
  +     */
  +    public PersistenceBroker getBroker()
  +    {
  +        return odmg.getOJBRuntime().lookupBroker(getPBKey());
  +    }
  +
       public boolean isOpen()
       {
           return this.isOpen;
  @@ -117,12 +126,11 @@
               if (name == null)
               {
                   log.info("Given argument was 'null', open default database");
  -                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                broker = odmg.getOJBRuntime().lookupBroker();
               }
               else
               {
  -                broker = PersistenceBrokerFactory.createPersistenceBroker(
  -                        BrokerHelper.extractAllTokens(name));
  +                broker = odmg.getOJBRuntime().lookupBroker(BrokerHelper.extractAllTokens(name));
               }
               pbKey = broker.getPBKey();
               isOpen = true;
  
  
  
  1.27      +13 -5     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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- J2EETransactionImpl.java	13 Sep 2004 10:54:31 -0000	1.26
  +++ J2EETransactionImpl.java	14 Nov 2004 09:37:20 -0000	1.27
  @@ -23,6 +23,7 @@
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.ojb.odmg.locking.LockManager;
   import org.odmg.LockNotGrantedException;
   import org.odmg.TransactionAbortedException;
   
  @@ -43,9 +44,16 @@
       private boolean beforeCompletionCall = false;
       private boolean afterCompletionCall = false;
   
  -    public J2EETransactionImpl(DatabaseImpl theCurrentDB)
  +    /**
  +     * Creates a new JTA transaction object.
  +     * 
  +     * @param db          The associated database
  +     * @param txManager   The transaction manager
  +     * @param lockManager The lock manager
  +     */
  +    public J2EETransactionImpl(DatabaseImpl db, OJBTxManager txManager, LockManager lockManager)
       {
  -        super(theCurrentDB);
  +        super(db, txManager, lockManager);
           isInExternTransaction = false;
       }
   
  @@ -126,7 +134,7 @@
           int status = Status.STATUS_UNKNOWN;
           try
           {
  -            JTATxManager mgr = (JTATxManager) TxManagerFactory.instance();
  +            JTATxManager mgr = (JTATxManager) getTxManager();
               status = mgr.getJTATransaction().getStatus();
               // ensure proper work, check all possible status
               // normally only check for 'STATUS_MARKED_ROLLBACK' is necessary
  @@ -239,7 +247,7 @@
                   log.error("Failure while do abort call", ignore);
               }
   
  -            TxManagerFactory.instance().abortExternalTx(this);
  +            getTxManager().abortExternalTx(this);
   
               try
               {
  
  
  
  1.10      +13 -12    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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JTATxManager.java	13 Sep 2004 10:54:31 -0000	1.9
  +++ JTATxManager.java	14 Nov 2004 09:37:20 -0000	1.10
  @@ -16,11 +16,10 @@
    */
   
   import org.apache.ojb.broker.OJBRuntimeException;
  -import org.apache.ojb.broker.util.configuration.Configuration;
  +import org.apache.ojb.broker.transaction.tm.TransactionManagerFactory;
  +import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  -import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
  -import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryFactory;
   import org.odmg.TransactionNotInProgressException;
   
   import javax.transaction.Status;
  @@ -38,9 +37,17 @@
    */
   public class JTATxManager implements OJBTxManager
   {
  -    private static Logger log = LoggerFactory.getLogger(JTATxManager.class);
  +    private Logger log = LoggerFactory.getLogger(JTATxManager.class);
       private static ThreadLocal txRepository = new ThreadLocal();
   
  +    /** The transaction manager factory */
  +    private TransactionManagerFactory transactionManagerFactory;
  +    
  +    public JTATxManager(TransactionManagerFactory transactionManagerFactory)
  +    {
  +        this.transactionManagerFactory = transactionManagerFactory;
  +    }
  +
       /**
        * Remove the ODMG transaction from the transaction buffer
        * ODMG transactions are associated with JTA transactions via a map
  @@ -162,10 +169,11 @@
       private TransactionManager getTransactionManager()
       {
           TransactionManager retval = null;
  +
           try
           {
               if (log.isDebugEnabled()) log.debug("getTransactionManager called");
  -            retval = TransactionManagerFactoryFactory.instance().getTransactionManager();
  +            retval = transactionManagerFactory.getTransactionManager();
           }
           catch (TransactionManagerFactoryException e)
           {
  @@ -234,13 +242,6 @@
           catch (Exception ignore)
           {
           }
  -    }
  -
  -    public void configure(Configuration config)
  -    {
  -        /**
  -         * no-op
  -         */
       }
   
       //************************************************************************
  
  
  
  1.66      +96 -57    db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- TransactionImpl.java	23 Oct 2004 15:46:22 -0000	1.65
  +++ TransactionImpl.java	14 Nov 2004 09:37:20 -0000	1.66
  @@ -27,7 +27,6 @@
   import org.apache.ojb.broker.PBFactoryException;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.core.proxy.CollectionProxy;
  @@ -41,13 +40,9 @@
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.util.GUID;
  -import org.apache.ojb.broker.util.configuration.Configurable;
  -import org.apache.ojb.broker.util.configuration.Configuration;
  -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.locking.LockManager;
  -import org.apache.ojb.odmg.locking.LockManagerFactory;
   import org.odmg.DatabaseClosedException;
   import org.odmg.LockNotGrantedException;
   import org.odmg.ODMGRuntimeException;
  @@ -66,13 +61,14 @@
    * @version $Id$
    *
    */
  -public class TransactionImpl
  -        implements Transaction, MaterializationListener, Configurable, CollectionProxyListener, TransactionExt
  +public class TransactionImpl implements TransactionExt,
  +                                        MaterializationListener,
  +                                        CollectionProxyListener
   {
       private Logger log = LoggerFactory.getLogger(TransactionImpl.class);
       private Hashtable myNrm = null;
  -    private boolean useWriteLocks;
  -    private boolean useImplicitLocking;
  +    private boolean useWriteLocks = true;
  +    private boolean implicitLocking = true;
       private String txGUID;
       protected PersistenceBroker broker = null;
       private ArrayList registeredForLock = new ArrayList();
  @@ -83,7 +79,7 @@
        * javax.transaction package.
        * See {@link javax.transaction.Status} for list of valid values.
        */
  -    private int m_txStatus = Status.STATUS_NO_TRANSACTION;
  +    private int txStatus = Status.STATUS_NO_TRANSACTION;
   
       /**
        * the internal table containing all Objects "touched" by this tx and their
  @@ -114,16 +110,43 @@
        */
       private ArrayList unmaterializedLocks = new ArrayList();
   
  +    /** The locak manager */
  +    private LockManager lockManager;
  +
       /**
  -     * Creates new Transaction
  -     * @param theCurrentDB - create a transaction that is associated with the database.
  +     * Creates a new transaction object.
  +     * 
  +     * @param db          The associated database
  +     * @param txManager   The transaction manager
  +     * @param lockManager The lock manager
        */
  -    public TransactionImpl(DatabaseImpl theCurrentDB)
  +    public TransactionImpl(DatabaseImpl db, OJBTxManager txManager, LockManager lockManager)
       {
  -        txManager = TxManagerFactory.instance();
  +        this.txManager   = txManager;
  +        this.lockManager = lockManager; 
           // assign a globally uniqe id to this tx
           txGUID = new GUID().toString();
  -        curDB = theCurrentDB;
  +        curDB  = db;
  +    }
  +
  +    /**
  +     * Returns the way how associations are locked.
  +     * 
  +     * @return Either READ or WRITE
  +     */
  +    public String getLockAssociations()
  +    {
  +        return useWriteLocks ? "WRITE" : "READ";
  +    }
  +    
  +    /**
  +     * Sets the association locking strategy.
  +     * 
  +     * @param strategy Either READ or WRITE
  +     */
  +    public void setLockAssociations(String strategy)
  +    {
  +        useWriteLocks = "WRITE".equals(strategy);
       }
   
       /**
  @@ -134,14 +157,34 @@
           return this.curDB;
       }
   
  +    /**
  +     * Returns the {@link OJBTxManager} instance associated with this transaction.
  +     * 
  +     * @return The <code>OJBTxManager</code> instance
  +     */
  +    public OJBTxManager getTxManager()
  +    {
  +        return txManager;
  +    }
  +
  +    /**
  +     * Returns the lock manager used by this transaction.
  +     * 
  +     * @return The lock manager
  +     */
  +    public LockManager getLockManager()
  +    {
  +        return lockManager;
  +    }
  +
       protected int getStatus()
       {
  -        return m_txStatus;
  +        return txStatus;
       }
   
       protected void setStatus(int status)
       {
  -        this.m_txStatus = status;
  +        this.txStatus = status;
       }
   
       private void checkForDB()
  @@ -259,24 +302,23 @@
               oid = handler.getIdentity();
           }
   
  -        LockManager lm = LockManagerFactory.getLockManager();
           if (lockMode == Transaction.READ)
           {
  -            if (!lm.readLock(this,oid, obj))
  +            if (!lockManager.readLock(this,oid, obj))
               {
                   throw new LockNotGrantedException("Can not lock for READ: " + obj);
               }
           }
           else if (lockMode == Transaction.WRITE)
           {
  -            if (!lm.writeLock(this, oid, obj))
  +            if (!lockManager.writeLock(this, oid, obj))
               {
                   throw new LockNotGrantedException("Can not lock for WRITE: " + obj);
               }
           }
           else if (lockMode == Transaction.UPGRADE)
           {
  -            if (!lm.upgradeLock(this, oid, obj))
  +            if (!lockManager.upgradeLock(this, oid, obj))
               {
                   throw new LockNotGrantedException("Can not lock for UPGRADE: " + obj);
               }
  @@ -289,7 +331,7 @@
           catch (Throwable t)
           {
               log.error("Locking obj " + obj + " with lock mode " + lockMode + " failed", t);
  -            lm.releaseLock(this, obj);
  +            lockManager.releaseLock(this, obj);
               throw new LockNotGrantedException(t.getMessage());
           }
       }
  @@ -418,7 +460,7 @@
           broker = null;
           registeredForLock.clear();
           unmaterializedLocks.clear();
  -        m_txStatus = Status.STATUS_NO_TRANSACTION;
  +        txStatus = Status.STATUS_NO_TRANSACTION;
       }
   
       /**
  @@ -448,7 +490,7 @@
               finally
               {
                   doClose();
  -                m_txStatus = Status.STATUS_ROLLEDBACK;
  +                txStatus = Status.STATUS_ROLLEDBACK;
               }
               if (t instanceof TransactionAbortedException)
               {
  @@ -486,7 +528,7 @@
               finally
               {
                   doClose();
  -                m_txStatus = Status.STATUS_ROLLEDBACK;
  +                txStatus = Status.STATUS_ROLLEDBACK;
               }
               if (t instanceof TransactionAbortedException)
               {
  @@ -552,7 +594,7 @@
        */
       private boolean removeLock(Object obj, int lockType)
       {
  -        return LockManagerFactory.getLockManager().releaseLock(this, obj);
  +        return lockManager.releaseLock(this, obj);
       }
   
       /**
  @@ -581,20 +623,20 @@
           {
               prepare();
               // Never commit transaction that has been marked for rollback
  -            if (m_txStatus == Status.STATUS_MARKED_ROLLBACK)
  +            if (txStatus == Status.STATUS_MARKED_ROLLBACK)
                   throw new TransactionAbortedExceptionOJB("persist.markedRollback");
  -            if (m_txStatus != Status.STATUS_PREPARED)
  +            if (txStatus != Status.STATUS_PREPARED)
                   throw new IllegalStateException("persist.missingPrepare");
   
  -            m_txStatus = Status.STATUS_COMMITTING;
  +            txStatus = Status.STATUS_COMMITTING;
               if (log.isDebugEnabled()) log.debug("Commit transaction " + this + ", commit on broker " + broker);
               if(hasBroker()) getBroker().commitTransaction();
               doClose();
  -            m_txStatus = Status.STATUS_COMMITTED;
  +            txStatus = Status.STATUS_COMMITTED;
           }
           catch (ODMGRuntimeException ex)
           {
  -            m_txStatus = Status.STATUS_MARKED_ROLLBACK;
  +            txStatus = Status.STATUS_MARKED_ROLLBACK;
               if (log.isDebugEnabled()) log.debug("Commit fails, do abort this tx", ex);
               abort();
               throw ex;
  @@ -615,32 +657,32 @@
        */
       protected boolean prepare() throws TransactionAbortedException, LockNotGrantedException
       {
  -        if (m_txStatus == Status.STATUS_MARKED_ROLLBACK)
  +        if (txStatus == Status.STATUS_MARKED_ROLLBACK)
               throw new TransactionAbortedExceptionOJB("persist.markedRollback");
  -        if (m_txStatus != Status.STATUS_ACTIVE)
  +        if (txStatus != Status.STATUS_ACTIVE)
               throw new IllegalStateException("persist.noTransaction");
           try
           {
  -            m_txStatus = Status.STATUS_PREPARING;
  +            txStatus = Status.STATUS_PREPARING;
               doWriteObjects();
  -            m_txStatus = Status.STATUS_PREPARED;
  +            txStatus = Status.STATUS_PREPARED;
           }
           catch (LockNotGrantedException e)
           {
               log.error("Could not prepare for commit: " + e.getMessage());
  -            m_txStatus = Status.STATUS_MARKED_ROLLBACK;
  +            txStatus = Status.STATUS_MARKED_ROLLBACK;
               throw e;
           }
           catch (TransactionAbortedException e)
           {
               log.error("Could not prepare for commit: " + e.getMessage());
  -            m_txStatus = Status.STATUS_MARKED_ROLLBACK;
  +            txStatus = Status.STATUS_MARKED_ROLLBACK;
               throw e;
           }
           catch (PersistenceBrokerSQLException pbse)
           {
               log.error("Could not prepare for commit: " + pbse.getMessage());
  -            m_txStatus = Status.STATUS_MARKED_ROLLBACK;
  +            txStatus = Status.STATUS_MARKED_ROLLBACK;
               throw pbse;
           }
           return true;
  @@ -656,13 +698,13 @@
           /*
           do nothing if already rolledback
           */
  -        if (m_txStatus == Status.STATUS_ROLLEDBACK)
  +        if (txStatus == Status.STATUS_ROLLEDBACK)
           {
               return;
           }
  -        if (m_txStatus != Status.STATUS_ACTIVE && m_txStatus != Status.STATUS_PREPARED &&
  -                m_txStatus != Status.STATUS_MARKED_ROLLBACK)
  -            throw new IllegalStateException("Illegal state for abort call, state was '" + TxUtil.getStatusString(m_txStatus) + "'");
  +        if (txStatus != Status.STATUS_ACTIVE && txStatus != Status.STATUS_PREPARED &&
  +                txStatus != Status.STATUS_MARKED_ROLLBACK)
  +            throw new IllegalStateException("Illegal state for abort call, state was '" + TxUtil.getStatusString(txStatus) + "'");
           log.info("Abort transaction was called on tx " + this + ", associated PB was " + broker);
           try
           {
  @@ -675,7 +717,7 @@
           finally
           {
               doClose();
  -            m_txStatus = Status.STATUS_ROLLEDBACK;
  +            txStatus = Status.STATUS_ROLLEDBACK;
           }
       }
   
  @@ -710,7 +752,7 @@
           // register transaction
           txManager.registerTx(this);
           // mark tx as active (open)
  -        m_txStatus = Status.STATUS_ACTIVE;
  +        txStatus = Status.STATUS_ACTIVE;
           if (log.isDebugEnabled()) log.debug("Begin transaction was called on tx " + this + ", with associated PB " + broker);
       }
   
  @@ -831,7 +873,7 @@
           {
               assLockMode = Transaction.READ;
           }
  -        if (useImplicitLocking)
  +        if (implicitLocking)
           {
               lockReferences(cld, objectToRegister, assLockMode);
           }
  @@ -845,7 +887,7 @@
           {
               assLockMode = Transaction.READ;
           }
  -        if (useImplicitLocking)
  +        if (implicitLocking)
           {
               lockCollections(cld, objectToRegister, assLockMode);
           }
  @@ -1113,7 +1155,7 @@
               try
               {
                   checkForDB();
  -                broker = PersistenceBrokerFactory.createPersistenceBroker(curDB.getPBKey());
  +                broker = curDB.getBroker();
               }
               catch (PBFactoryException e)
               {
  @@ -1154,22 +1196,19 @@
       }
   
       /*
  -     * @see Configurable#configure(Configuration)
  +     * @see org.apache.ojb.odmg.TransactionExt#getImplicitLocking()
        */
  -    public void configure(Configuration config) throws ConfigurationException
  +    public boolean getImplicitLocking()
       {
  -        OdmgConfiguration odmgConfig = (OdmgConfiguration) config;
  -
  -        useWriteLocks = odmgConfig.lockAssociationAsWrites();
  -        useImplicitLocking = odmgConfig.useImplicitLocking();
  +        return implicitLocking;
       }
   
  -    /**
  +    /*
        * @see org.apache.ojb.odmg.TransactionExt#setImplicitLocking(boolean)
        */
       public synchronized void setImplicitLocking(boolean value)
       {
  -        useImplicitLocking = value;
  +        implicitLocking = value;
       }
   
       /**
  @@ -1195,7 +1234,7 @@
           for (Iterator iterator = colProxy.iterator(); iterator.hasNext();)
           {
               Object o = iterator.next();
  -            if (useImplicitLocking && this.isOpen())
  +            if (implicitLocking && this.isOpen())
               {
                   int lock = useWriteLocks ? Transaction.WRITE : Transaction.READ;
                   this.register(null, o, lock, false);
  
  
  
  1.12      +10 -2     db-ojb/src/java/org/apache/ojb/odmg/NarrowTransaction.java
  
  Index: NarrowTransaction.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/NarrowTransaction.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- NarrowTransaction.java	14 Aug 2004 23:48:12 -0000	1.11
  +++ NarrowTransaction.java	14 Nov 2004 09:37:20 -0000	1.12
  @@ -143,12 +143,20 @@
   	{
   		return ((TransactionImpl)tx).getObjectByIdentity(id);
   	}
  -    /**
  +
  +    /*
  +     * @see org.apache.ojb.odmg.TransactionExt#getImplicitLocking()
  +     */
  +    public boolean getImplicitLocking()
  +    {
  +        return tx.getImplicitLocking();
  +    }
  +
  +    /*
        * @see org.apache.ojb.odmg.TransactionExt#setImplicitLocking(boolean)
        */
       public void setImplicitLocking(boolean value)
       {
       	tx.setImplicitLocking(value);
       }
  -
   }
  
  
  
  1.18      +26 -23    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- OJB.java	3 May 2004 23:05:56 -0000	1.17
  +++ OJB.java	14 Nov 2004 09:37:20 -0000	1.18
  @@ -15,45 +15,48 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.util.factory.ConfigurableFactory;
  +import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.core.configuration.ComponentContainer;
   import org.odmg.Implementation;
   
   
   /**
  - * Facade to the persistence ObjectServer system.
  - * Implements the factory interface for a particular ODMG implementation.
  + * Facade to the persistence ObjectServer system. Please note that this
  + * class is not intended to be instantiated.
  + * 
  + * TODO: Rename this class, e.g. to something like ODMGFacade or similar ?
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class OJB extends ConfigurableFactory
  +public abstract class OJB
   {
  -    private static OJB instance;
  -
  -    static
  -    {
  -        instance = new OJB();
  -    }
  -
       /**
  -     * protected Constructor: use static factory method
  -     * getInstance() to obtain an instance of {@link Implementation}
  +     * Returns a new instance of the {@link org.odmg.Implementation} class which
  +     * uses the default core OJB runtime. The used implementation class can be
  +     * specified in OJB properties file, per default {@link ImplementationImpl}
  +     * is used.
  +     * 
  +     * @return The ODMG implementation instance 
        */
  -    protected OJB()
  +    public static Implementation getInstance()
       {
  +        return getInstance(PersistenceBrokerFactory.getOjb());
       }
   
       /**
  -     * Return new instance of the {@link org.odmg.Implementation} class.
  -     * The used implementation class can be specified in OJB properties file.
  +     * Returns a new instance of the {@link org.odmg.Implementation} class which
  +     * uses the given core OJB runtime. The used implementation class can be
  +     * specified in OJB properties file, per default {@link ImplementationImpl}
  +     * is used.
  +     * 
  +     * @param runtime The core runtime used by the implementation
  +     * @return The ODMG implementation instance 
        */
  -    public static Implementation getInstance()
  +    public static Implementation getInstance(org.apache.ojb.broker.OJB runtime)
       {
  -        return (Implementation) instance.createNewInstance();
  -    }
  +        ComponentContainer container = runtime.getComponentContainer();
   
  -    protected String getConfigurationKey()
  -    {
  -        return "ImplementationClass";
  +        return (Implementation)container.getInstance(Implementation.class);
       }
   }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/ImplementationInternal.java
  
  Index: ImplementationInternal.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.odmg.locking.LockManager;
  import org.odmg.DArray;
  import org.odmg.DBag;
  import org.odmg.DList;
  import org.odmg.DMap;
  import org.odmg.DSet;
  import org.odmg.Implementation;
  
  /**
   * OJB-specific extension of the {@link org.odmg.Implementation} interface that
   * provides additional services.
   *
   * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak<a>
   */
  public interface ImplementationInternal extends Implementation
  {
      /**
       * Returns the transaction manager.
       * 
       * @return The transaction manager
       */
      public OJBTxManager getTxManager();
  
      /**
       * Returns the lock manager.
       * 
       * @return The lock manager
       */
      public LockManager getLockManager();
  
      /**
       * Determines whether the transactions are using implicit locking.
       * 
       * @return <code>true</code> if implicit locking is used
       */
      public boolean isUsingImplicitLocking();
  
      /**
       * This method can be used to activate or deactivate the implicit
       * locking mechanism for transactions.
       * 
       * @param useImplicitLocking Whether to enable implicit locking
       */
      public void setUsingImplicitLocking(boolean useImplicitLocking);
  
      /**
       * Creates a new <code>DList</code> object.
       * 
       * @return The new <code>DList</code> object.
       */
      public DList newDList();
  
      /**
       * Creates a new <code>DBag</code> object.
       * 
       * @return The new <code>DBag</code> object.
       */
      public DBag newDBag();
  
      /**
       * Creates a new <code>DSet</code> object.
       * 
       * @return The new <code>DSet</code> object.
       */
      public DSet newDSet();
  
      /**
       * Creates a new <code>DArray</code> object.
       * 
       * @return The new <code>DArray</code> object.
       */
      public DArray newDArray();
  
      /**
       * Creates a new <code>DMap</code> object.
       * 
       * @return The new <code>DMap</code> object.
       */
      public DMap newDMap();
  }
  
  
  

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