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/broker/core QueryReferenceBroker.java
Date Mon, 29 Nov 2004 22:11:59 GMT
tomdz       2004/11/29 14:11:59

  Modified:    src/java/org/apache/ojb/broker/core/proxy
                        SetProxyDefaultImpl.java ListProxyDefaultImpl.java
                        CollectionProxyDefaultImpl.java ProxyFactory.java
               src/java/org/apache/ojb/otm/core ConcreteEditingContext.java
               src/java/org/apache/ojb/otm/swizzle CopySwizzling.java
               src/java/org/apache/ojb/broker/core
                        QueryReferenceBroker.java
  Log:
  Removed static calls from the proxy classes to the PersistenceBrokerFactory
  
  Revision  Changes    Path
  1.4       +8 -8      db-ojb/src/java/org/apache/ojb/broker/core/proxy/SetProxyDefaultImpl.java
  
  Index: SetProxyDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/SetProxyDefaultImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SetProxyDefaultImpl.java	14 Nov 2004 09:34:27 -0000	1.3
  +++ SetProxyDefaultImpl.java	29 Nov 2004 22:11:59 -0000	1.4
  @@ -18,8 +18,8 @@
   import java.util.Collection;
   import java.util.Set;
   
  -import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.PersistenceConfiguration;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.util.collections.ManageableHashSet;
   
  @@ -36,23 +36,23 @@
   
       /**
   	 * Constructor for SetProxy.
  -	 * @param aKey
  +	 * @param persistenceConf
   	 * @param aQuery
   	 */
  -	public SetProxyDefaultImpl(PBKey aKey, Query aQuery)
  +	public SetProxyDefaultImpl(PersistenceConfiguration persistenceConf, Query aQuery)
   	{
  -		this(aKey, ManageableHashSet.class, aQuery);
  +		this(persistenceConf, ManageableHashSet.class, aQuery);
   	}
   
   	/**
   	 * Constructor for SetProxy.
  -	 * @param aKey
  +	 * @param persistenceConf
   	 * @param aCollClass
   	 * @param aQuery
   	 */
  -	public SetProxyDefaultImpl(PBKey aKey, Class aCollClass, Query aQuery)
  +	public SetProxyDefaultImpl(PersistenceConfiguration persistenceConf, Class aCollClass,
Query aQuery)
   	{
  -		super(aKey, aCollClass, aQuery);
  +		super(persistenceConf, aCollClass, aQuery);
   	}
   
       protected Set getSetData()
  
  
  
  1.4       +8 -8      db-ojb/src/java/org/apache/ojb/broker/core/proxy/ListProxyDefaultImpl.java
  
  Index: ListProxyDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/ListProxyDefaultImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ListProxyDefaultImpl.java	14 Nov 2004 09:34:27 -0000	1.3
  +++ ListProxyDefaultImpl.java	29 Nov 2004 22:11:59 -0000	1.4
  @@ -19,8 +19,8 @@
   import java.util.List;
   import java.util.ListIterator;
   
  -import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.PersistenceConfiguration;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
   
  @@ -37,23 +37,23 @@
   
       /**
        * Constructor for ListProxy.
  -     * @param aKey
  +     * @param persistenceConf
        * @param aQuery
        */
  -    public ListProxyDefaultImpl(PBKey aKey, Query aQuery)
  +    public ListProxyDefaultImpl(PersistenceConfiguration persistenceConf, Query aQuery)
       {
  -        this(aKey, RemovalAwareCollection.class, aQuery);
  +        this(persistenceConf, RemovalAwareCollection.class, aQuery);
       }
   
       /**
        * Constructor for ListProxy.
  -     * @param aKey
  +     * @param persistenceConf
        * @param aCollClass
        * @param aQuery
        */
  -    public ListProxyDefaultImpl(PBKey aKey, Class aCollClass, Query aQuery)
  +    public ListProxyDefaultImpl(PersistenceConfiguration persistenceConf, Class aCollClass,
Query aQuery)
       {
  -        super(aKey, aCollClass, aQuery);
  +        super(persistenceConf, aCollClass, aQuery);
       }
   
       /**
  
  
  
  1.16      +49 -25    db-ojb/src/java/org/apache/ojb/broker/core/proxy/CollectionProxyDefaultImpl.java
  
  Index: CollectionProxyDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/CollectionProxyDefaultImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- CollectionProxyDefaultImpl.java	28 Nov 2004 03:13:16 -0000	1.15
  +++ CollectionProxyDefaultImpl.java	29 Nov 2004 22:11:59 -0000	1.16
  @@ -15,6 +15,9 @@
    * limitations under the License.
    */
   
  +import java.io.IOException;
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
  @@ -25,7 +28,7 @@
   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.PersistenceConfiguration;
   import org.apache.ojb.broker.core.PersistenceBrokerThreadMapping;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.query.Query;
  @@ -44,8 +47,12 @@
   {
       private static final long serialVersionUID = -6505291808050247424L;
   
  -    /** The key for acquiring the above broker */
  -    private PBKey m_brokerKey;
  +    /**
  +     * The persistence configuration that this proxy is bound to. Note that
  +     * upon loading of the collection this reference will be cleared to avoid
  +     * holding onto a link into OJB for longer than necessary.
  +     */
  +    private transient PersistenceConfiguration persistenceConf;
       /** The query that defines the values in the collection */
       private Query m_query;
       /** The actual data (if already loaded) */
  @@ -70,24 +77,24 @@
        * {@link org.apache.ojb.broker.util.collections.RemovalAwareCollection}
        * as the collection class).
        * 
  -     * @param brokerKey The key of the persistence broker
  -     * @param query     The defining query
  +     * @param persistenceConf The persistence configuration that this proxy is bound to
  +     * @param query           The defining query
        */
  -    public CollectionProxyDefaultImpl(PBKey brokerKey, Query query)
  +    public CollectionProxyDefaultImpl(PersistenceConfiguration persistenceConf, Query query)
       {
  -        this(brokerKey, RemovalAwareCollection.class, query);
  +        this(persistenceConf, RemovalAwareCollection.class, query);
       }
   
       /**
        * Creates a new collection proxy that uses the given collection type.
        * 
  -     * @param brokerKey The key of the persistence broker
  -     * @param collClass The collection type
  -     * @param query     The defining query
  +     * @param persistenceConf The persistence configuration that this proxy is bound to
  +     * @param collClass       The collection type
  +     * @param query           The defining query
        */
  -    public CollectionProxyDefaultImpl(PBKey brokerKey, Class collClass, Query query)
  +    public CollectionProxyDefaultImpl(PersistenceConfiguration persistenceConf, Class collClass,
Query query)
       {
  -        setBrokerKey(brokerKey);
  +        this.persistenceConf = persistenceConf;
           setCollectionClass(collClass);
           setQuery(query);
       }
  @@ -101,6 +108,8 @@
           {
               beforeLoading();
               setData(loadData());
  +            // release reference into OJB
  +            persistenceConf = null;
               afterLoading();
           }
           
  @@ -423,7 +432,7 @@
           // current broker not found or was closed, create a intern new one
           if (broker == null || broker.isClosed())
           {
  -            broker = PersistenceBrokerFactory.createPersistenceBroker(getBrokerKey());
  +            broker = persistenceConf.createPersistenceBroker();
               // signal that we use a new internal obtained PB instance to read the
               // data and that this instance have to be closed after use
               m_needsClose = true;
  @@ -523,17 +532,7 @@
        */
       public PBKey getBrokerKey()
       {
  -        return m_brokerKey;
  -    }
  -
  -    /**
  -     * Sets the key of the persistence broker used by this collection.
  -     * 
  -     * @param brokerKey The key of the broker
  -     */
  -    protected void setBrokerKey(PBKey brokerKey)
  -    {
  -        m_brokerKey = brokerKey;
  +        return persistenceConf.getKey();
       }
   
       /**
  @@ -563,4 +562,29 @@
           }
       }
   
  +    /**
  +     * This method (together with the {@link #readObject(ObjectInputStream)} method) overrides
  +     * the default serialization mechanism so that the real collection is serialized.
  +     *  
  +     * @param out The output stream
  +     */
  +    private void writeObject(ObjectOutputStream out) throws IOException
  +    {
  +        // force loading of the data
  +        load();
  +        // and then default action
  +        out.defaultWriteObject();
  +    }
  +
  +    /**
  +     * This method (together with the {@link #writeObject(ObjectOutputStream)} method)
overrides
  +     * the default serialization mechanism so that the real collection is serialized.
  +     *  
  +     * @param in The input stream
  +     */
  +    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
  +    {
  +        // default action
  +        in.defaultReadObject();
  +    }
   }
  
  
  
  1.3       +7 -6      db-ojb/src/java/org/apache/ojb/broker/core/proxy/ProxyFactory.java
  
  Index: ProxyFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/ProxyFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProxyFactory.java	14 Nov 2004 09:34:27 -0000	1.2
  +++ ProxyFactory.java	29 Nov 2004 22:11:59 -0000	1.3
  @@ -26,6 +26,7 @@
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.PersistenceConfiguration;
   import org.apache.ojb.broker.metadata.MetadataException;
   import org.apache.ojb.broker.query.Query;
   
  @@ -150,7 +151,7 @@
               throw new MetadataException("Illegal class "+proxyClass.getName()+" specified
for "+typeDesc+". Must be a concrete subclass of "+baseType.getName());
           }
   
  -        Class[] paramType = {PBKey.class, Class.class, Query.class};
  +        Class[] paramType = {PersistenceConfiguration.class, Class.class, Query.class};
   
           try
           {
  @@ -160,7 +161,7 @@
           {
               throw new MetadataException("The class "+proxyClass.getName()+" specified for
"+
                                           typeDesc+" is required to have a public constructor
with signature ("+
  -                                        PBKey.class.getName()+", "+Class.class.getName()+",
"+Query.class.getName()+").");
  +                                        PersistenceConfiguration.class.getName()+", "+Class.class.getName()+",
"+Query.class.getName()+").");
           }
       }
       
  @@ -288,14 +289,14 @@
       /**
        * Create a Collection Proxy for a given query.
        * 
  -     * @param brokerKey       The key of the persistence broker
  +     * @param persistenceConf The persistence configuration that the proxy will be bound
to
        * @param query           The query
        * @param collectionClass The class to build the proxy for
        * @return The collection proxy
        */
  -    public ManageableCollection createCollectionProxy(PBKey brokerKey, Query query, Class
collectionClass)
  +    public ManageableCollection createCollectionProxy(PersistenceConfiguration persistenceConf,
Query query, Class collectionClass)
       {
  -        Object args[] = { brokerKey, collectionClass, query };
  +        Object args[] = { persistenceConf, collectionClass, query };
   
           try
           {
  
  
  
  1.53      +1 -1      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.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- ConcreteEditingContext.java	14 Nov 2004 09:39:57 -0000	1.52
  +++ ConcreteEditingContext.java	29 Nov 2004 22:11:59 -0000	1.53
  @@ -1162,7 +1162,7 @@
                   {
                       CollectionProxy cp = (CollectionProxy) col;
                       
  -                    col = (Collection)_pb.getProxyFactory().createCollectionProxy(_pb.getPBKey(),
null, cp.getCollectionClass());
  +                    col = (Collection)_pb.getProxyFactory().createCollectionProxy(_pb.getConfiguration(),
null, cp.getCollectionClass());
                       col.clear();
                   }
                   else
  
  
  
  1.15      +1 -1      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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- CopySwizzling.java	14 Nov 2004 09:39:57 -0000	1.14
  +++ CopySwizzling.java	29 Nov 2004 22:11:59 -0000	1.15
  @@ -124,7 +124,7 @@
                   if (newCol instanceof CollectionProxy)
                   {
                       CollectionProxy cp = (CollectionProxy) newCol;
  -                    oldCol = (Collection)((PersistenceBrokerInternal)pb).getProxyFactory().createCollectionProxy(pb.getPBKey(),
cp.getQuery(), cp.getCollectionClass());
  +                    oldCol = (Collection)((PersistenceBrokerInternal)pb).getProxyFactory().createCollectionProxy(pb.getConfiguration(),
cp.getQuery(), cp.getCollectionClass());
   
                       if (!((CollectionProxy) newCol).isLoaded())
                       {
  
  
  
  1.24      +2 -2      db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java
  
  Index: QueryReferenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- QueryReferenceBroker.java	14 Nov 2004 09:34:27 -0000	1.23
  +++ QueryReferenceBroker.java	29 Nov 2004 22:11:59 -0000	1.24
  @@ -221,7 +221,7 @@
               {
                   if (lazy)
                   {
  -                    result = pb.getProxyFactory().createCollectionProxy(pb.getPBKey(),
query, collectionClass);
  +                    result = pb.getProxyFactory().createCollectionProxy(pb.getConfiguration(),
query, collectionClass);
                   }
                   else
                   {
  
  
  

---------------------------------------------------------------------
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