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/proxy CollectionProxyDefaultImpl.java IndirectionHandlerDefaultImpl.java ProxyFactory.java
Date Wed, 01 Dec 2004 22:15:13 GMT
tomdz       2004/12/01 14:15:12

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/test/org/apache/ojb/broker BrokerExamples.java
                        PolymorphicExtents.java
               src/java/org/apache/ojb/broker/core/proxy
                        CollectionProxyDefaultImpl.java
                        IndirectionHandlerDefaultImpl.java
                        ProxyFactory.java
  Log:
  Replaced usage of PersistenceBrokerFactory in IndirectionHandlerDefaultImpl by binding it
to a PersistenceConfiguration (similar to the collection proxies)
  
  Revision  Changes    Path
  1.101     +2 -2      db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.100
  retrieving revision 1.101
  diff -u -r1.100 -r1.101
  --- PersistenceBrokerImpl.java	28 Nov 2004 03:12:51 -0000	1.100
  +++ PersistenceBrokerImpl.java	1 Dec 2004 22:15:01 -0000	1.101
  @@ -405,7 +405,7 @@
           try
           {
               // the invocation handler manages all delegation stuff
  -            IndirectionHandler handler     = getProxyFactory().createIndirectionHandler(getPBKey(),
realSubjectsIdentity);
  +            IndirectionHandler handler     = getProxyFactory().createIndirectionHandler(getConfiguration(),
realSubjectsIdentity);
               Constructor        constructor = null;
   
               // the proxy simply provides the interface of the real subject
  
  
  
  1.21      +1 -1      db-ojb/src/test/org/apache/ojb/broker/BrokerExamples.java
  
  Index: BrokerExamples.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/BrokerExamples.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- BrokerExamples.java	14 Nov 2004 09:41:31 -0000	1.20
  +++ BrokerExamples.java	1 Dec 2004 22:15:10 -0000	1.21
  @@ -41,7 +41,7 @@
           ProductGroup tmpPG = new ProductGroup();
           tmpPG.setId(1);
           Identity pgID = new Identity(tmpPG, broker);
  -        ProductGroupProxy pgProxy = new ProductGroupProxy(ojb.getProxyFactory().createIndirectionHandler(broker.getPBKey(),
pgID));
  +        ProductGroupProxy pgProxy = new ProductGroupProxy(ojb.getProxyFactory().createIndirectionHandler(persistenceConf,
pgID));
   
           a.setProductGroup(pgProxy);
           return a;
  
  
  
  1.18      +1 -1      db-ojb/src/test/org/apache/ojb/broker/PolymorphicExtents.java
  
  Index: PolymorphicExtents.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PolymorphicExtents.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- PolymorphicExtents.java	14 Nov 2004 09:41:31 -0000	1.17
  +++ PolymorphicExtents.java	1 Dec 2004 22:15:10 -0000	1.18
  @@ -39,7 +39,7 @@
   		ProductGroup tmpPG = new ProductGroup();
   		tmpPG.setId(1);
   		Identity pgID = new Identity(tmpPG, broker);
  -		ProductGroupProxy pgProxy = new ProductGroupProxy(ojb.getProxyFactory().createIndirectionHandler(broker.getPBKey(),pgID));
  +		ProductGroupProxy pgProxy = new ProductGroupProxy(ojb.getProxyFactory().createIndirectionHandler(persistenceConf,
pgID));
   		a.setProductGroup(pgProxy);
   		return a;
   	}
  
  
  
  1.17      +37 -43    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CollectionProxyDefaultImpl.java	29 Nov 2004 22:11:59 -0000	1.16
  +++ CollectionProxyDefaultImpl.java	1 Dec 2004 22:15:10 -0000	1.17
  @@ -54,23 +54,17 @@
        */
       private transient PersistenceConfiguration persistenceConf;
       /** The query that defines the values in the collection */
  -    private Query m_query;
  +    private Query query;
       /** The actual data (if already loaded) */
  -    private Collection m_data;
  +    private Collection data;
       /** The collection type */
  -    private Class m_collectionClass;
  +    private Class collectionClass;
       /** The number of objects */
  -    private int m_size = -1;
  -    
  -    /*
  -    arminw
  -    fix a bug, caused by closing PB instances
  -    obtained from PersistenceBrokerThreadMapping.
  -    TODO: Could we find a better solution for this?
  -    */
  -    private boolean m_needsClose;
  +    private int size = -1;
  +    /** Specifies whether we obtained a fresh broker which we have to close after we used
it */
  +    private boolean needsClose;
       /** Objects that listen on this proxy for loading events */
  -    private transient ArrayList m_listeners;
  +    private transient ArrayList listeners;
   
       /**
        * Creates a new collection proxy (uses
  @@ -122,7 +116,7 @@
        */
       public boolean isLoaded()
       {
  -        return m_data != null;
  +        return data != null;
       }
   
       /**
  @@ -155,7 +149,7 @@
        */
       protected synchronized void setSize(int size)
       {
  -        m_size = size;
  +        this.size = size;
       }
       
       /**
  @@ -171,11 +165,11 @@
           {
               Collection result;
   
  -            if (m_data != null) // could be set by listener
  +            if (data != null) // could be set by listener
               {
  -                result = m_data;
  +                result = data;
               }
  -            else if (m_size != 0)
  +            else if (size != 0)
               {
                   result = (Collection) broker.getCollectionByQuery(getCollectionClass(),
getQuery());
               }
  @@ -200,13 +194,13 @@
        */
       protected void beforeLoading()
       {
  -        if (m_listeners != null)
  +        if (listeners != null)
           {
               CollectionProxyListener listener;
   
  -            for (int idx = m_listeners.size() - 1; idx >= 0; idx--)
  +            for (int idx = listeners.size() - 1; idx >= 0; idx--)
               {
  -                listener = (CollectionProxyListener)m_listeners.get(idx);
  +                listener = (CollectionProxyListener)listeners.get(idx);
                   listener.beforeLoading(this);
               }
           }
  @@ -217,13 +211,13 @@
        */
       protected void afterLoading()
       {
  -        if (m_listeners != null)
  +        if (listeners != null)
           {
               CollectionProxyListener listener;
   
  -            for (int idx = m_listeners.size() - 1; idx >= 0; idx--)
  +            for (int idx = listeners.size() - 1; idx >= 0; idx--)
               {
  -                listener = (CollectionProxyListener)m_listeners.get(idx);
  +                listener = (CollectionProxyListener)listeners.get(idx);
                   listener.afterLoading(this);
               }
           }
  @@ -240,11 +234,11 @@
           }
           else
           {
  -            if (m_size < 0)
  +            if (size < 0)
               {
  -                m_size = loadSize();
  +                size = loadSize();
               }
  -            return m_size;
  +            return size;
           }
       }
   
  @@ -367,7 +361,7 @@
   
               setData(coll);
           }
  -        m_size = 0;
  +        size = 0;
       }
   
       /**
  @@ -377,7 +371,7 @@
        */
       public Query getQuery()
       {
  -        return m_query;
  +        return query;
       }
   
       /**
  @@ -387,7 +381,7 @@
        */
       protected void setQuery(Query query)
       {
  -        m_query = query;
  +        this.query = query;
       }
   
       /**
  @@ -401,9 +395,9 @@
           it from the PBF, do nothing if we obtain it from
           PBThreadMapping
           */
  -        if (broker != null && m_needsClose)
  +        if (broker != null && needsClose)
           {
  -            m_needsClose = false;
  +            needsClose = false;
               broker.close();
           }
       }
  @@ -435,7 +429,7 @@
               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;
  +            needsClose = true;
           }
           return broker;
       }
  @@ -449,7 +443,7 @@
       {
           load();
   
  -        return m_data;
  +        return data;
       }
   
       /**
  @@ -459,7 +453,7 @@
        */
       public void setData(Collection data)
       {
  -        m_data = data;
  +        this.data = data;
       }
   
       /**
  @@ -469,7 +463,7 @@
        */
       public Class getCollectionClass()
       {
  -        return m_collectionClass;
  +        return collectionClass;
       }
   
       /**
  @@ -479,7 +473,7 @@
        */
       protected void setCollectionClass(Class collClass)
       {
  -        m_collectionClass = collClass;
  +        collectionClass = collClass;
       }
   
       /**
  @@ -542,11 +536,11 @@
        */
       public synchronized void addListener(CollectionProxyListener listener)
       {
  -        if (m_listeners == null)
  +        if (listeners == null)
           {
  -            m_listeners = new ArrayList();
  +            listeners = new ArrayList();
           }
  -        m_listeners.add(listener);
  +        listeners.add(listener);
       }
   
       /**
  @@ -556,9 +550,9 @@
        */
       public synchronized void removeListener(CollectionProxyListener listener)
       {
  -        if (m_listeners != null)
  +        if (listeners != null)
           {
  -            m_listeners.remove(listener);
  +            listeners.remove(listener);
           }
       }
   
  
  
  
  1.8       +54 -70    db-ojb/src/java/org/apache/ojb/broker/core/proxy/IndirectionHandlerDefaultImpl.java
  
  Index: IndirectionHandlerDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/IndirectionHandlerDefaultImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- IndirectionHandlerDefaultImpl.java	7 Nov 2004 09:06:53 -0000	1.7
  +++ IndirectionHandlerDefaultImpl.java	1 Dec 2004 22:15:10 -0000	1.8
  @@ -15,6 +15,9 @@
    * limitations under the License.
    */
   
  +import java.io.IOException;
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.lang.reflect.Method;
   import java.util.ArrayList;
   
  @@ -22,7 +25,7 @@
   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.PersistenceConfiguration;
   import org.apache.ojb.broker.core.PersistenceBrokerThreadMapping;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.broker.PBKey;
  @@ -36,35 +39,28 @@
   public class IndirectionHandlerDefaultImpl implements IndirectionHandler
   {
   	static final long serialVersionUID = -1993879565033755826L;
  -    
  -    /** Reference to the used PersistenceBroker */
  -    private transient PersistenceBroker _broker = null;
  -    /** The key for acquiring the above broker */
  -	private PBKey _brokerKey;
  +
  +    /** The persistence configuration that this indirection handler is bound to */
  +	private transient PersistenceConfiguration persistenceConf;
       /** The real subject which this is hidden by the proxy */
  -    private Object _realSubject = null;
  +    private Object realSubject = null;
       /** Represents the identity of the real subject. When the real subject is not
        *  yet materialized, it can be loaded from the underlying db by this identity object
*/
  -    private Identity _id = null;
  +    private Identity id = null;
       /** The materialization listeners */
  -    private transient ArrayList _listeners;
  -    /*
  -    arminw:
  -    only close broker instance if we get it from PBF, do
  -    not close if we obtain from PBThreadMapping
  -    TODO: Find a better solution
  -    */
  -    private boolean _needsClose;
  +    private transient ArrayList listeners;
  +    /** Specifies whether we obtained a fresh broker which we have to close after we used
it */
  +    private boolean needsClose;
   
       /**
        * Creates a new indirection handler for the indicated object.
        * 
  -     * @param brokerKey The key of the persistence broker
  -     * @param id        The identity of the subject
  +     * @param persistenceConf The persistence configuration
  +     * @param id              The identity of the subject
        */
  -    public IndirectionHandlerDefaultImpl(PBKey brokerKey, Identity id)
  +    public IndirectionHandlerDefaultImpl(PersistenceConfiguration persistenceConf, Identity
id)
       {
  -        setBrokerKey(brokerKey);
  +        this.persistenceConf = persistenceConf;
           setIdentity(id);
       }
   
  @@ -75,7 +71,7 @@
        */
       public Identity getIdentity()
       {
  -        return _id;
  +        return id;
       }
   
       /**
  @@ -85,7 +81,7 @@
        */
       protected void setIdentity(Identity identity)
       {
  -        _id = identity;
  +        id = identity;
       }
   
       /**
  @@ -95,17 +91,7 @@
        */
       public PBKey getBrokerKey()
       {
  -        return _brokerKey;
  -    }
  -
  -    /**
  -     * Sets the key of the persistence broker used by this indirection handler.
  -     *
  -     * @param brokerKey The broker key
  -     */
  -    protected void setBrokerKey(PBKey brokerKey)
  -    {
  -        _brokerKey = brokerKey;
  +        return persistenceConf == null ? null : persistenceConf.getKey();
       }
   
       /**
  @@ -115,11 +101,11 @@
        */
       public synchronized void addListener(MaterializationListener listener)
       {
  -        if (_listeners == null)
  +        if (listeners == null)
           {
  -            _listeners = new ArrayList();
  +            listeners = new ArrayList();
           }
  -        _listeners.add(listener);
  +        listeners.add(listener);
       }
   
       /**
  @@ -129,9 +115,9 @@
        */
       public synchronized void removeListener(MaterializationListener listener)
       {
  -        if (_listeners != null)
  +        if (listeners != null)
           {
  -            _listeners.remove(listener);
  +            listeners.remove(listener);
           }
       }
   
  @@ -141,14 +127,14 @@
        */
       protected void beforeMaterialization()
       {
  -        if (_listeners != null)
  +        if (listeners != null)
           {
               MaterializationListener listener;
   
  -            for (int idx = _listeners.size() - 1; idx >= 0; idx--)
  +            for (int idx = listeners.size() - 1; idx >= 0; idx--)
               {
  -                listener = (MaterializationListener)_listeners.get(idx);
  -                listener.beforeMaterialization(this, _id);
  +                listener = (MaterializationListener)listeners.get(idx);
  +                listener.beforeMaterialization(this, id);
               }
           }
       }
  @@ -159,17 +145,17 @@
        */
       protected void afterMaterialization()
       {
  -        if (_listeners != null)
  +        if (listeners != null)
           {
               MaterializationListener listener;
   
               // listeners may remove themselves during the afterMaterialization callback.
               // thus we must iterate through the listeners vector from back to front
               // to avoid index problems.
  -            for (int idx = _listeners.size() - 1; idx >= 0; idx--)
  +            for (int idx = listeners.size() - 1; idx >= 0; idx--)
               {
  -                listener = (MaterializationListener)_listeners.get(idx);
  -                listener.afterMaterialization(this, _realSubject);
  +                listener = (MaterializationListener)listeners.get(idx);
  +                listener.afterMaterialization(this, realSubject);
               }
           }
       }
  @@ -197,29 +183,26 @@
           // first try to use the current threaded broker to avoid blocking
           broker = PersistenceBrokerThreadMapping.currentPersistenceBroker(getBrokerKey());
           // current broker not found, create a intern new one
  -        if (broker == null)
  +        if ((broker == null) || broker.isClosed())
           {
  -            if (_broker == null)
  -            {
  -                _broker = PersistenceBrokerFactory.createPersistenceBroker(getBrokerKey());
  -                // TODO: Better way?
  -                _needsClose = true;
  -                broker      = _broker;
  -            }
  +            broker = persistenceConf.createPersistenceBroker();
  +            // TODO: Better way?
  +            needsClose = true;
           }
           return broker;
       }
   
       /**
  -     * Release the PersistenceBroker instance currently used.
  +     * Release the PersistenceBroker instance.
  +     * 
  +     * @param broker The broker 
        */
  -    protected void releaseBroker()
  +    protected synchronized void releaseBroker(PersistenceBroker broker)
       {
  -        if (_broker != null && _needsClose)
  +        if (broker != null && needsClose)
           {
  -        	_needsClose = false;
  -            _broker.close();
  -        	_broker = null;
  +        	needsClose = false;
  +            broker.close();
           }
       }
   
  @@ -338,13 +321,13 @@
        */
       public Object getRealSubject() throws PersistenceBrokerException
       {
  -        if (_realSubject == null)
  +        if (realSubject == null)
           {
               beforeMaterialization();
  -            _realSubject = materializeSubject();
  +            realSubject = materializeSubject();
               afterMaterialization();
           }
  -        return _realSubject;
  +        return realSubject;
       }
   
       /**
  @@ -355,7 +338,7 @@
        */
       public void setRealSubject(Object object)
       {
  -        _realSubject = object;
  +        realSubject = object;
       }
   
       /**
  @@ -366,13 +349,15 @@
        */
       protected synchronized Object materializeSubject() throws PersistenceBrokerException
       {
  +        PersistenceBroker broker = getBroker();
  +
           try
           {
  -            Object realSubject = getBroker().getObjectByIdentity(_id);
  +            Object realSubject = broker.getObjectByIdentity(id);
   
               if (realSubject == null)
               {
  -                LoggerFactory.getLogger(IndirectionHandler.class).warn("Can not materialize
object for Identity " + _id + " - using PBKey " + _brokerKey);
  +                LoggerFactory.getLogger(IndirectionHandler.class).warn("Can not materialize
object for Identity " + id + " - using PBKey " + getBrokerKey());
               }
               return realSubject;
           }
  @@ -382,7 +367,7 @@
           }
           finally
           {
  -			releaseBroker();
  +			releaseBroker(broker);
           }
       }
   
  @@ -393,7 +378,6 @@
        */
       public boolean alreadyMaterialized()
       {
  -        return _realSubject != null;
  +        return realSubject != null;
       }
  -
   }
  
  
  
  1.4       +7 -8      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProxyFactory.java	29 Nov 2004 22:11:59 -0000	1.3
  +++ ProxyFactory.java	1 Dec 2004 22:15:12 -0000	1.4
  @@ -24,7 +24,6 @@
   
   import org.apache.ojb.broker.Identity;
   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;
  @@ -86,7 +85,7 @@
               throw new MetadataException("Illegal class "+indirectionHandlerClass.getName()+"
specified for IndirectionHandlerClass. Must be a concrete subclass of "+IndirectionHandler.class.getName());
           }
   
  -        Class[] paramType = {PBKey.class, Identity.class};
  +        Class[] paramType = {PersistenceConfiguration.class, Identity.class};
   
           try
           {
  @@ -96,20 +95,20 @@
           {
               throw new MetadataException("The class "+indirectionHandlerClass.getName()+"
specified for IndirectionHandlerClass"+
                                           " is required to have a public constructor with
signature ("+
  -                                        PBKey.class.getName()+", "+Identity.class.getName()+").");
  +                                        PersistenceConfiguration.class.getName()+", "+Identity.class.getName()+").");
           }
       }
   
       /**
        * Creates a new indirection handler instance.
        * 
  -     * @param brokerKey The key of the persistence broker
  -     * @param id        The subject's ids
  +     * @param persistenceConf The persistence configuration
  +     * @param id              The subject's ids
        * @return The new instance
        */
  -    public IndirectionHandler createIndirectionHandler(PBKey brokerKey, Identity id)
  +    public IndirectionHandler createIndirectionHandler(PersistenceConfiguration persistenceConf,
Identity id)
       {
  -        Object args[] = { brokerKey, id };
  +        Object args[] = { persistenceConf, id };
   
           try
           {
  
  
  

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