db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/otm/transaction ManagedTransactionFactory.java
Date Sun, 14 Nov 2004 09:39:57 GMT
tomdz       2004/11/14 01:39:57

  Modified:    src/java/org/apache/ojb/otm/core ConcreteEditingContext.java
                        BaseConnection.java
               src/prevayler/org/apache/ojb/broker/prevayler
                        PBPrevaylerImpl.java
               src/java/org/apache/ojb/otm/swizzle CopySwizzling.java
               src/java/org/apache/ojb/odmg/oql OQLQueryImpl.java
               src/java/org/apache/ojb/otm/transaction
                        ManagedTransactionFactory.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.52      +4 -5      db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java
  
  Index: ConcreteEditingContext.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- ConcreteEditingContext.java	3 Nov 2004 19:01:49 -0000	1.51
  +++ ConcreteEditingContext.java	14 Nov 2004 09:39:57 -0000	1.52
  @@ -32,14 +32,13 @@
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PBKey;
  -import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerInternal;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.broker.core.proxy.CollectionProxy;
   import org.apache.ojb.broker.core.proxy.CollectionProxyListener;
   import org.apache.ojb.broker.core.proxy.IndirectionHandler;
   import org.apache.ojb.broker.core.proxy.MaterializationListener;
  -import org.apache.ojb.broker.core.proxy.ProxyFactory;
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  @@ -79,7 +78,7 @@
       private HashMap _objects;
       private ArrayList _order;
       private Transaction _tx;
  -    private PersistenceBroker _pb;
  +    private PersistenceBrokerInternal _pb;
       private HashMap _original;
       private HashMap _checkpointed;
       private HashMap _colProxyListeners;
  @@ -88,7 +87,7 @@
       // Constructor
       //////////////////////////////////////////
   
  -    public ConcreteEditingContext(Transaction tx, PersistenceBroker pb)
  +    public ConcreteEditingContext(Transaction tx, PersistenceBrokerInternal pb)
       {
           PBKey pbkey;
   
  @@ -1163,7 +1162,7 @@
                   {
                       CollectionProxy cp = (CollectionProxy) col;
                       
  -                    col = (Collection) ProxyFactory.createCollectionProxy(_pb.getPBKey(),
null, cp.getCollectionClass());
  +                    col = (Collection)_pb.getProxyFactory().createCollectionProxy(_pb.getPBKey(),
null, cp.getCollectionClass());
                       col.clear();
                   }
                   else
  
  
  
  1.40      +9 -20     db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java
  
  Index: BaseConnection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- BaseConnection.java	21 Oct 2004 20:16:33 -0000	1.39
  +++ BaseConnection.java	14 Nov 2004 09:39:57 -0000	1.40
  @@ -22,8 +22,7 @@
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.ReportQuery;
  -import org.apache.ojb.broker.util.configuration.ConfigurationException;
  -import org.apache.ojb.broker.util.configuration.Configurator;
  +import org.apache.ojb.odmg.collections.DListImpl;
   import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
   import org.apache.ojb.odmg.oql.OQLQueryImpl;
   import org.apache.ojb.otm.EditingContext;
  @@ -31,7 +30,6 @@
   import org.apache.ojb.otm.copy.ObjectCopyStrategy;
   import org.apache.ojb.otm.lock.LockType;
   import org.apache.ojb.otm.lock.LockingException;
  -import org.odmg.ODMGRuntimeException;
   import org.odmg.OQLQuery;
   
   import java.util.Collection;
  @@ -51,10 +49,9 @@
   public abstract class BaseConnection implements OTMConnection
   {
   
  -    private PersistenceBroker _pb;
  +    private PersistenceBrokerInternal _pb;
       private Transaction _tx;
       private ConcreteEditingContext _editingContext;
  -    private Configurator m_configurator;
   
       /**
        * Constructor for BaseConnection.
  @@ -62,8 +59,7 @@
        */
       public BaseConnection(PBKey pbKey)
       {
  -        _pb = PersistenceBrokerFactory.createPersistenceBroker(pbKey);
  -        m_configurator = PersistenceBrokerFactory.getConfigurator();
  +        _pb = (PersistenceBrokerInternal)PersistenceBrokerFactory.createPersistenceBroker(pbKey);
       }
   
       public void close()
  @@ -390,17 +386,9 @@
       public EnhancedOQLQuery newOQLQuery(int lock)
       {
           checkTransaction("newOQLQuery");
  -        OQLQueryImpl query = new OTMOQLQueryImpl(_pb.getPBKey(), lock);
  -        try
  -        {
  -            m_configurator.configure(query);
  -        }
  -        catch (ConfigurationException e)
  -        {
  -            throw new ODMGRuntimeException("Error in configuration of OQLQueryImpl instance:
"
  -                    + e.getMessage());
  -        }
  -        return query;
  +
  +        // TODO: How do we get the oqlCollectionClass value
  +        return new OTMOQLQueryImpl(_pb.getPBKey(), DListImpl.class, lock);
       }
   
       public int getCount(Query query)
  @@ -615,9 +603,10 @@
       {
           int _lock;
   
  -        public OTMOQLQueryImpl(PBKey key, int lock)
  +        public OTMOQLQueryImpl(PBKey key, Class collectionClass, int lock)
           {
  -            super(key);
  +            // no transaction manager because we override the execute method anyway
  +            super(key, null, collectionClass);
               _lock = lock;
           }
   
  
  
  
  1.5       +347 -348  db-ojb/src/prevayler/org/apache/ojb/broker/prevayler/PBPrevaylerImpl.java
  
  Index: PBPrevaylerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/prevayler/org/apache/ojb/broker/prevayler/PBPrevaylerImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PBPrevaylerImpl.java	5 Apr 2004 00:21:13 -0000	1.4
  +++ PBPrevaylerImpl.java	14 Nov 2004 09:39:57 -0000	1.5
  @@ -1,5 +1,5 @@
  -package org.apache.ojb.broker.prevayler;
  -
  +package org.apache.ojb.broker.prevayler;
  +
   /* Copyright 2003-2004 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
  @@ -14,349 +14,348 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  -
  -import java.io.File;
  -import java.io.IOException;
  -import java.io.Serializable;
  -import java.util.ArrayList;
  -import java.util.Collection;
  -import java.util.Enumeration;
  -import java.util.Iterator;
  -
  -import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.ManageableCollection;
  -import org.apache.ojb.broker.MtoNImplementor;
  -import org.apache.ojb.broker.PBKey;
  -import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
  -import org.apache.ojb.broker.TransactionAbortedException;
  -import org.apache.ojb.broker.TransactionInProgressException;
  -import org.apache.ojb.broker.TransactionNotInProgressException;
  -import org.apache.ojb.broker.core.PersistenceBrokerFactoryIF;
  -import org.apache.ojb.broker.core.PersistenceBrokerImpl;
  -import org.apache.ojb.broker.query.Query;
  -import org.apache.ojb.broker.query.QueryByIdentity;
  -import org.apache.ojb.broker.util.BrokerHelper;
  -import org.apache.ojb.broker.util.ObjectModification;
  -import org.prevayler.Command;
  -import org.prevayler.Prevayler;
  -import org.prevayler.implementation.SnapshotPrevayler;
  -
  -
  -/**
  - * An OJB PersistenBroker implementation working against a datastore
  - * that is persisted by Prevayler.
  - * So in other word, this is an OODBMS with a PB API.
  - * Of course you can use OJB/ODMG or OJB/JDO on top of it.
  - * 
  - * important note: this implementation is not finished. 
  - * Do not try to use it in production environments.
  - * 
  - * @author Thomas Mahler
  - */
  -public class PBPrevaylerImpl extends PersistenceBrokerImpl
  -{
  -
  -	private transient Database db;
  -	
  -	private Prevayler prevayler;
  -
  -	private ArrayList commandLog = new ArrayList(100);
  -	
  -	private boolean inTransaction = false;
  -
  -
  -    /**
  -     * Constructor for PBPrevaylerImpl.
  -     * @param key
  -     * @param pbf
  -     */
  -    public PBPrevaylerImpl(PBKey key, PersistenceBrokerFactoryIF pbf)
  -    {
  -    	super(key, pbf);
  -        refresh();
  -        if(key == null) throw new PersistenceBrokerException("Could not instantiate broker
with PBKey 'null'");
  -        this.pbf = pbf;
  -        this.setPBKey(key);
  -
  -        brokerHelper = new BrokerHelper(this);
  -        //connectionManager = ConnectionManagerFactory.getInstance().createConnectionManager(this);
  -        //objectCache = ObjectCacheFactory.getInstance().createObjectCache(this);
  -        //sequenceManager = SequenceManagerFactory.getSequenceManager(this);
  -        //dbAccess = JdbcAccessFactory.getInstance().createJdbcAccess(this);
  -        //statementManager = StatementManagerFactory.getInstance().createStatementManager(this);
  -        //sqlGenerator = SqlGeneratorFactory.getInstance().createSqlGenerator(connectionManager.getSupportedPlatform());
  -
  -        //markedForDelete = new ArrayList();        
  -        try
  -        {
  -             prevayler = new SnapshotPrevayler(new Database(), "PrevalenceBase" + File.separator
+ "Database");
  -             db = (Database) prevayler.system();	
  -             db.setBroker(this);
  -        }
  -        catch (Exception e)
  -        {
  -        }
  -    }
  -
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#abortTransaction()
  -	 */
  -	public void abortTransaction() throws TransactionNotInProgressException
  -	{
  -		if (! isInTransaction())
  -		{
  -			throw new TransactionNotInProgressException();
  -		}
  -		inTransaction = false;
  -		commandLog.clear();		
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#beginTransaction()
  -	 */
  -	public void beginTransaction()
  -		throws TransactionInProgressException, TransactionAbortedException
  -	{
  -		if (this.isInTransaction())
  -		{
  -			throw new TransactionInProgressException();
  -		}
  -		inTransaction = true;
  -		commandLog.clear();
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#commitTransaction()
  -	 */
  -    public void commitTransaction()
  -        throws TransactionNotInProgressException, TransactionAbortedException
  -    {
  -        if (!isInTransaction())
  -        {
  -            throw new TransactionNotInProgressException();
  -        }
  -
  -        Iterator iter = commandLog.iterator();
  -        try
  -        {
  -            while (iter.hasNext())
  -            {
  -                Command cmd = (Command) iter.next();
  -                prevayler.executeCommand(cmd);
  -            }
  -        }
  -        catch (Exception e)
  -        {
  -            this.abortTransaction();
  -        }
  -        inTransaction = false;
  -        commandLog.clear();
  -    }
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#isInTransaction()
  -	 */
  -	public boolean isInTransaction() throws PersistenceBrokerException
  -	{
  -		return inTransaction;
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#close()
  -	 */
  -	public boolean close()
  -	{
  -        if (isInTransaction())
  -        {
  -            abortTransaction();
  -        }
  -		try
  -        {
  -            ((SnapshotPrevayler)prevayler).takeSnapshot();
  -        }
  -        catch (IOException e)
  -        {
  -        }
  -        setClosed(true);
  -		return true;
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#clearCache()
  -	 */
  -	public void clearCache() throws PersistenceBrokerException
  -	{
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#removeFromCache(Object)
  -	 */
  -	public void removeFromCache(Object obj) throws PersistenceBrokerException
  -	{
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#store(Object, ObjectModification)
  -	 */
  -	public void store(Object obj, ObjectModification modification)
  -		throws PersistenceBrokerException
  -	{
  -		this.store(obj);
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#store(Object)
  -	 */
  -	public void store(Object obj) throws PersistenceBrokerException
  -	{
  -		if (! (obj instanceof Serializable))
  -		{
  -			throw new PersistenceBrokerException(obj.getClass().getName() + "does not implement
java.io.Serializable.");
  -		}
  -		
  -		CommandStore cmd = new CommandStore(obj);
  -		commandLog.add(cmd);		
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#delete(Object)
  -	 */
  -	public void delete(Object obj) throws PersistenceBrokerException
  -	{
  -		Command cmd = new CommandDelete(obj);
  -		commandLog.add(cmd);
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#deleteMtoNImplementor(MtoNImplementor)
  -	 */
  -	public void deleteMtoNImplementor(MtoNImplementor m2nImpl)
  -		throws PersistenceBrokerException
  -	{
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#addMtoNImplementor(MtoNImplementor)
  -	 */
  -	public void addMtoNImplementor(MtoNImplementor m2nImpl)
  -		throws PersistenceBrokerException
  -	{
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#deleteByQuery(Query)
  -	 */
  -	public void deleteByQuery(Query query) throws PersistenceBrokerException
  -	{
  -		throw new PersistenceBrokerException("not yet implemented");
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#retrieveAllReferences(Object)
  -	 */
  -	public void retrieveAllReferences(Object pInstance)
  -		throws PersistenceBrokerException
  -	{
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#retrieveReference(Object, String)
  -	 */
  -	public void retrieveReference(Object pInstance, String pAttributeName)
  -		throws PersistenceBrokerException
  -	{
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#getCount(Query)
  -	 */
  -	public int getCount(Query query) throws PersistenceBrokerException
  -	{
  -		throw new PersistenceBrokerException("not yet implemented");
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Query)
  -	 */
  -	public Collection getCollectionByQuery(Query query)
  -		throws PersistenceBrokerException
  -	{
  -		// needs some more work ;-)
  -		return db.getTable().values();
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Class, Query)
  -	 */
  -	public ManageableCollection getCollectionByQuery(
  -		Class collectionClass,
  -		Query query)
  -		throws PersistenceBrokerException
  -	{
  -		throw new PersistenceBrokerException("not yet implemented");
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#getIteratorByQuery(Query)
  -	 */
  -	public Iterator getIteratorByQuery(Query query)
  -		throws PersistenceBrokerException
  -	{
  -		throw new PersistenceBrokerException("not yet implemented");
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#getReportQueryIteratorByQuery(Query)
  -	 */
  -	public Iterator getReportQueryIteratorByQuery(Query query)
  -		throws PersistenceBrokerException
  -	{
  -		throw new PersistenceBrokerException("not yet implemented");
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#getObjectByIdentity(Identity)
  -	 */
  -	public Object getObjectByIdentity(Identity id)
  -		throws PersistenceBrokerException
  -	{
  -		return db.lookupObjectByIdentity(id);
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#getObjectByQuery(Query)
  -	 */
  -	public Object getObjectByQuery(Query query)
  -		throws PersistenceBrokerException
  -	{
  -		if (query instanceof QueryByIdentity)
  -		{
  -			Object id = ((QueryByIdentity) query).getExampleObject();
  -			if (! (id instanceof Identity))
  -			{
  -				id = new Identity(id,PersistenceBrokerFactory.defaultPersistenceBroker());	
  -			}			
  -			Identity oid = (Identity) id;
  -			return db.lookupObjectByIdentity(oid);
  -		}
  -		else
  -		{
  -			throw new PersistenceBrokerException("not yet implemented");	
  -		}
  -	}
  -
  -	/**
  -	 * @see org.apache.ojb.broker.PersistenceBroker#getPKEnumerationByQuery(Class, Query)
  -	 */
  -	public Enumeration getPKEnumerationByQuery(
  -		Class PrimaryKeyClass,
  -		Query query)
  -		throws PersistenceBrokerException
  -	{
  -		throw new PersistenceBrokerException("not yet implemented");
  -	}
  -
  -
  -}
  +
  +import java.io.File;
  +import java.io.IOException;
  +import java.io.Serializable;
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Enumeration;
  +import java.util.Iterator;
  +
  +import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.ManageableCollection;
  +import org.apache.ojb.broker.MtoNImplementor;
  +import org.apache.ojb.broker.PBKey;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.TransactionAbortedException;
  +import org.apache.ojb.broker.TransactionInProgressException;
  +import org.apache.ojb.broker.TransactionNotInProgressException;
  +import org.apache.ojb.broker.core.PersistenceBrokerFactoryIF;
  +import org.apache.ojb.broker.core.PersistenceBrokerImpl;
  +import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.query.QueryByIdentity;
  +import org.apache.ojb.broker.util.BrokerHelper;
  +import org.apache.ojb.broker.util.ObjectModification;
  +import org.prevayler.Command;
  +import org.prevayler.Prevayler;
  +import org.prevayler.implementation.SnapshotPrevayler;
  +
  +
  +/**
  + * An OJB PersistenBroker implementation working against a datastore
  + * that is persisted by Prevayler.
  + * So in other word, this is an OODBMS with a PB API.
  + * Of course you can use OJB/ODMG or OJB/JDO on top of it.
  + * 
  + * important note: this implementation is not finished. 
  + * Do not try to use it in production environments.
  + * 
  + * @author Thomas Mahler
  + */
  +public class PBPrevaylerImpl extends PersistenceBrokerImpl
  +{
  +
  +	private transient Database db;
  +	
  +	private Prevayler prevayler;
  +
  +	private ArrayList commandLog = new ArrayList(100);
  +	
  +	private boolean inTransaction = false;
  +
  +
  +    /**
  +     * Constructor for PBPrevaylerImpl.
  +     * @param key
  +     * @param pbf
  +     */
  +    public PBPrevaylerImpl(PBKey key, PersistenceBrokerFactoryIF pbf)
  +    {
  +    	super(key, pbf);
  +        refresh();
  +        if(key == null) throw new PersistenceBrokerException("Could not instantiate broker
with PBKey 'null'");
  +        this.setPBKey(key);
  +
  +        brokerHelper = new BrokerHelper(this);
  +        //connectionManager = ConnectionManagerFactory.getInstance().createConnectionManager(this);
  +        //objectCache = ObjectCacheFactory.getInstance().createObjectCache(this);
  +        //sequenceManager = SequenceManagerFactory.getSequenceManager(this);
  +        //dbAccess = JdbcAccessFactory.getInstance().createJdbcAccess(this);
  +        //statementManager = StatementManagerFactory.getInstance().createStatementManager(this);
  +        //sqlGenerator = SqlGeneratorFactory.getInstance().createSqlGenerator(connectionManager.getSupportedPlatform());
  +
  +        //markedForDelete = new ArrayList();        
  +        try
  +        {
  +             prevayler = new SnapshotPrevayler(new Database(), "PrevalenceBase" + File.separator
+ "Database");
  +             db = (Database) prevayler.system();	
  +             db.setBroker(this);
  +        }
  +        catch (Exception e)
  +        {
  +        }
  +    }
  +
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#abortTransaction()
  +	 */
  +	public void abortTransaction() throws TransactionNotInProgressException
  +	{
  +		if (! isInTransaction())
  +		{
  +			throw new TransactionNotInProgressException();
  +		}
  +		inTransaction = false;
  +		commandLog.clear();		
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#beginTransaction()
  +	 */
  +	public void beginTransaction()
  +		throws TransactionInProgressException, TransactionAbortedException
  +	{
  +		if (this.isInTransaction())
  +		{
  +			throw new TransactionInProgressException();
  +		}
  +		inTransaction = true;
  +		commandLog.clear();
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#commitTransaction()
  +	 */
  +    public void commitTransaction()
  +        throws TransactionNotInProgressException, TransactionAbortedException
  +    {
  +        if (!isInTransaction())
  +        {
  +            throw new TransactionNotInProgressException();
  +        }
  +
  +        Iterator iter = commandLog.iterator();
  +        try
  +        {
  +            while (iter.hasNext())
  +            {
  +                Command cmd = (Command) iter.next();
  +                prevayler.executeCommand(cmd);
  +            }
  +        }
  +        catch (Exception e)
  +        {
  +            this.abortTransaction();
  +        }
  +        inTransaction = false;
  +        commandLog.clear();
  +    }
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#isInTransaction()
  +	 */
  +	public boolean isInTransaction() throws PersistenceBrokerException
  +	{
  +		return inTransaction;
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#close()
  +	 */
  +	public boolean close()
  +	{
  +        if (isInTransaction())
  +        {
  +            abortTransaction();
  +        }
  +		try
  +        {
  +            ((SnapshotPrevayler)prevayler).takeSnapshot();
  +        }
  +        catch (IOException e)
  +        {
  +        }
  +        setClosed(true);
  +		return true;
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#clearCache()
  +	 */
  +	public void clearCache() throws PersistenceBrokerException
  +	{
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#removeFromCache(Object)
  +	 */
  +	public void removeFromCache(Object obj) throws PersistenceBrokerException
  +	{
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#store(Object, ObjectModification)
  +	 */
  +	public void store(Object obj, ObjectModification modification)
  +		throws PersistenceBrokerException
  +	{
  +		this.store(obj);
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#store(Object)
  +	 */
  +	public void store(Object obj) throws PersistenceBrokerException
  +	{
  +		if (! (obj instanceof Serializable))
  +		{
  +			throw new PersistenceBrokerException(obj.getClass().getName() + "does not implement
java.io.Serializable.");
  +		}
  +		
  +		CommandStore cmd = new CommandStore(obj);
  +		commandLog.add(cmd);		
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#delete(Object)
  +	 */
  +	public void delete(Object obj) throws PersistenceBrokerException
  +	{
  +		Command cmd = new CommandDelete(obj);
  +		commandLog.add(cmd);
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#deleteMtoNImplementor(MtoNImplementor)
  +	 */
  +	public void deleteMtoNImplementor(MtoNImplementor m2nImpl)
  +		throws PersistenceBrokerException
  +	{
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#addMtoNImplementor(MtoNImplementor)
  +	 */
  +	public void addMtoNImplementor(MtoNImplementor m2nImpl)
  +		throws PersistenceBrokerException
  +	{
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#deleteByQuery(Query)
  +	 */
  +	public void deleteByQuery(Query query) throws PersistenceBrokerException
  +	{
  +		throw new PersistenceBrokerException("not yet implemented");
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#retrieveAllReferences(Object)
  +	 */
  +	public void retrieveAllReferences(Object pInstance)
  +		throws PersistenceBrokerException
  +	{
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#retrieveReference(Object, String)
  +	 */
  +	public void retrieveReference(Object pInstance, String pAttributeName)
  +		throws PersistenceBrokerException
  +	{
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getCount(Query)
  +	 */
  +	public int getCount(Query query) throws PersistenceBrokerException
  +	{
  +		throw new PersistenceBrokerException("not yet implemented");
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Query)
  +	 */
  +	public Collection getCollectionByQuery(Query query)
  +		throws PersistenceBrokerException
  +	{
  +		// needs some more work ;-)
  +		return db.getTable().values();
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Class, Query)
  +	 */
  +	public ManageableCollection getCollectionByQuery(
  +		Class collectionClass,
  +		Query query)
  +		throws PersistenceBrokerException
  +	{
  +		throw new PersistenceBrokerException("not yet implemented");
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getIteratorByQuery(Query)
  +	 */
  +	public Iterator getIteratorByQuery(Query query)
  +		throws PersistenceBrokerException
  +	{
  +		throw new PersistenceBrokerException("not yet implemented");
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getReportQueryIteratorByQuery(Query)
  +	 */
  +	public Iterator getReportQueryIteratorByQuery(Query query)
  +		throws PersistenceBrokerException
  +	{
  +		throw new PersistenceBrokerException("not yet implemented");
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getObjectByIdentity(Identity)
  +	 */
  +	public Object getObjectByIdentity(Identity id)
  +		throws PersistenceBrokerException
  +	{
  +		return db.lookupObjectByIdentity(id);
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getObjectByQuery(Query)
  +	 */
  +	public Object getObjectByQuery(Query query)
  +		throws PersistenceBrokerException
  +	{
  +		if (query instanceof QueryByIdentity)
  +		{
  +			Object id = ((QueryByIdentity) query).getExampleObject();
  +			if (! (id instanceof Identity))
  +			{
  +				id = new Identity(id,PersistenceBrokerFactory.defaultPersistenceBroker());	
  +			}			
  +			Identity oid = (Identity) id;
  +			return db.lookupObjectByIdentity(oid);
  +		}
  +		else
  +		{
  +			throw new PersistenceBrokerException("not yet implemented");	
  +		}
  +	}
  +
  +	/**
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getPKEnumerationByQuery(Class, Query)
  +	 */
  +	public Enumeration getPKEnumerationByQuery(
  +		Class PrimaryKeyClass,
  +		Query query)
  +		throws PersistenceBrokerException
  +	{
  +		throw new PersistenceBrokerException("not yet implemented");
  +	}
  +
  +
  +}
  
  
  
  1.14      +2 -2      db-ojb/src/java/org/apache/ojb/otm/swizzle/CopySwizzling.java
  
  Index: CopySwizzling.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/swizzle/CopySwizzling.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CopySwizzling.java	21 Oct 2004 20:16:33 -0000	1.13
  +++ CopySwizzling.java	14 Nov 2004 09:39:57 -0000	1.14
  @@ -6,9 +6,9 @@
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerInternal;
   import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.broker.core.proxy.CollectionProxy;
  -import org.apache.ojb.broker.core.proxy.ProxyFactory;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  @@ -124,7 +124,7 @@
                   if (newCol instanceof CollectionProxy)
                   {
                       CollectionProxy cp = (CollectionProxy) newCol;
  -                    oldCol = (Collection) ProxyFactory.createCollectionProxy(pb.getPBKey(),
cp.getQuery(), cp.getCollectionClass());
  +                    oldCol = (Collection)((PersistenceBrokerInternal)pb).getProxyFactory().createCollectionProxy(pb.getPBKey(),
cp.getQuery(), cp.getCollectionClass());
   
                       if (!((CollectionProxy) newCol).isLoaded())
                       {
  
  
  
  1.19      +16 -31    db-ojb/src/java/org/apache/ojb/odmg/oql/OQLQueryImpl.java
  
  Index: OQLQueryImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/oql/OQLQueryImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- OQLQueryImpl.java	4 Apr 2004 23:53:40 -0000	1.18
  +++ OQLQueryImpl.java	14 Nov 2004 09:39:57 -0000	1.19
  @@ -20,7 +20,6 @@
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.accesslayer.OJBIterator;
   import org.apache.ojb.broker.query.BetweenCriteria;
   import org.apache.ojb.broker.query.Criteria;
  @@ -28,14 +27,11 @@
   import org.apache.ojb.broker.query.ReportQuery;
   import org.apache.ojb.broker.query.SelectionCriteria;
   import org.apache.ojb.broker.util.collections.ManageableArrayList;
  -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.OdmgConfiguration;
  +import org.apache.ojb.odmg.OJBTxManager;
   import org.apache.ojb.odmg.PBCapsule;
  -import org.apache.ojb.odmg.TxManagerFactory;
  +import org.apache.ojb.odmg.TransactionExt;
   import org.odmg.QueryInvalidException;
   import org.odmg.Transaction;
   
  @@ -49,7 +45,7 @@
    * Insert the type's description here.
    * Creation date: (08.05.01 13:12:58)
    */
  -public class OQLQueryImpl implements EnhancedOQLQuery, Configurable
  +public class OQLQueryImpl implements EnhancedOQLQuery
   {
       private Logger log = LoggerFactory.getLogger(OQLQueryImpl.class);
   
  @@ -63,10 +59,14 @@
       private Query query = null;
       private ListIterator bindIterator = null;
       private PBKey pbKey;
  +    /** The transaction manager */
  +    private OJBTxManager txManager;
   
  -    public OQLQueryImpl(PBKey key)
  +    public OQLQueryImpl(PBKey key, OJBTxManager txManager, Class collectionClass)
       {
  -        this.pbKey = key;
  +        this.pbKey           = key;
  +        this.txManager       = txManager;
  +        this.collectionClass = collectionClass;
       }
   
   
  @@ -79,9 +79,11 @@
       }
   
       /**
  -     * returns the collection type to be used to contain oql query result sets
  +     * Returns the collection class used to contain oql query result sets.
  +     * 
  +     * @return The collection class
        */
  -    protected Class getCollectionClass()
  +    public Class getCollectionClass()
       {
           return collectionClass;
       }
  @@ -228,7 +230,7 @@
           if (log.isDebugEnabled()) log.debug("Start execute query");
   
           //obtain current ODMG transaction
  -        Transaction tx = TxManagerFactory.instance().getTransaction();
  +        TransactionExt tx = txManager.getTransaction();
           // create PBCapsule
           PBCapsule capsule = null;
           ManageableCollection result = null;
  @@ -306,10 +308,9 @@
               PersistenceBroker broker,
               ManageableCollection result)
       {
  -        OdmgConfiguration config = getConfiguration();
           // if tx is available and implicit locking is required,
           // we do READ-lock all found objects
  -        if ((tx != null) && config.useImplicitLocking())
  +        if ((tx != null) && ((TransactionExt)tx).getImplicitLocking())
           {
               // read-lock all resulting objects to the current transaction
               Iterator iter = result.ojbIterator();
  @@ -343,14 +344,6 @@
           }
       }
   
  -
  -    protected OdmgConfiguration getConfiguration()
  -    {
  -        OdmgConfiguration config = (OdmgConfiguration) PersistenceBrokerFactory.getConfigurator().getConfigurationFor(null);
  -        return config;
  -    }
  -
  -
       /**
        * Sets the query.
        * @param query The query to set
  @@ -378,16 +371,8 @@
           this.bindIterator = bindIterator;
       }
   
  -    /*
  -     * @see Configurable#configure(Configuration)
  -     */
  -    public void configure(Configuration pConfig) throws ConfigurationException
  -    {
  -        collectionClass = ((OdmgConfiguration) pConfig).getOqlCollectionClass();
  -    }
  -
       public int fullSize()
       {
  -        return this.query.fullSize();
  +        return query.fullSize();
       }
   }
  
  
  
  1.9       +10 -2     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ManagedTransactionFactory.java	3 May 2004 23:05:56 -0000	1.8
  +++ ManagedTransactionFactory.java	14 Nov 2004 09:39:57 -0000	1.9
  @@ -21,7 +21,8 @@
   import javax.transaction.TransactionManager;
   
   import org.apache.ojb.broker.PBKey;
  -import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryFactory;
  +import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.transaction.tm.TransactionManagerFactory;
   import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
   import org.apache.ojb.otm.OTMConnection;
   import org.apache.ojb.otm.core.BaseConnection;
  @@ -39,6 +40,8 @@
   
       private HashMap _transactionMap;
       private TransactionManager tm;
  +    /** Factory for transaction managers */
  +    private TransactionManagerFactory transactionManagerFactory;
   
   	/**
   	 * Constructor for ManagedTransactionFactory.
  @@ -46,6 +49,11 @@
   	public ManagedTransactionFactory()
   	{
   		_transactionMap = new HashMap();
  +        // TODO: Hack to acquire a transaction manager factory instance
  +        //       OTM needs a connection to the core OJB i.e. via an OJB
  +        //       instance in the Kit
  +        transactionManagerFactory = (TransactionManagerFactory)PersistenceBrokerFactory.getOjb().
  +                                         getComponentContainer().getInstance(TransactionManagerFactory.class);
   	}
   
   
  @@ -101,7 +109,7 @@
           {
               try
               {
  -                tm = TransactionManagerFactoryFactory.instance().getTransactionManager();
  +                tm = transactionManagerFactory.getTransactionManager();
               }
               catch (TransactionManagerFactoryException e)
               {
  
  
  

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


Mime
View raw message