db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/jdo PersistenceManagerImpl.java
Date Sun, 24 Oct 2004 15:36:16 GMT
brj         2004/10/24 08:36:16

  Modified:    src/test/org/apache/ojb/broker M2NTest.java
               src/java/org/apache/ojb/broker/core/proxy
                        CollectionProxy.java
                        CollectionProxyDefaultImpl.java
               src/java/org/apache/ojb/jdo PersistenceManagerImpl.java
  Log:
  interface CollectionProxy extends Collection
  
  Revision  Changes    Path
  1.13      +2 -2      db-ojb/src/test/org/apache/ojb/broker/M2NTest.java
  
  Index: M2NTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/M2NTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- M2NTest.java	23 Oct 2004 18:31:03 -0000	1.12
  +++ M2NTest.java	24 Oct 2004 15:36:15 -0000	1.13
  @@ -80,7 +80,7 @@
           for (int i = 0;i < moviesArray.length; i++)
           {
               CollectionProxy proxy = (CollectionProxy) moviesArray[i].getActors();
  -            proxy.getData();					// materialize the proxy
  +            proxy.load();					// materialize the proxy
               assertTrue(proxy.isLoaded());
           }
           
  
  
  
  1.3       +6 -28     db-ojb/src/java/org/apache/ojb/broker/core/proxy/CollectionProxy.java
  
  Index: CollectionProxy.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/CollectionProxy.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CollectionProxy.java	20 Oct 2004 18:50:46 -0000	1.2
  +++ CollectionProxy.java	24 Oct 2004 15:36:15 -0000	1.3
  @@ -1,7 +1,6 @@
   package org.apache.ojb.broker.core.proxy;
   
   import java.util.Collection;
  -import java.util.Iterator;
   
   import org.apache.ojb.broker.query.Query;
   
  @@ -17,7 +16,7 @@
    * @version $Id$
    *
    */
  -public interface CollectionProxy
  +public interface CollectionProxy extends Collection
   {
       /**
        * Adds a listener to this collection.
  @@ -41,14 +40,12 @@
       public boolean isLoaded();
   
       /**
  -     * Returns the collection data, load it if not already done so.
  -     * 
  -     * @return The data Collection
  +     * Force loading of the data, if not already done.
        */
  -    public Collection getData();
  +    public void load();
   
       /**
  -     * Set the collection data.
  +     * Set the collection data, bypassing clear()
        * 
        * @param aCollection
        */
  @@ -66,24 +63,5 @@
        * @return
        */
       public Query getQuery();
  -    
  -    /**
  -     * Return an Iterator.
  -     * @see Collection#iterator()
  -     * @return
  -     */
  -    public Iterator iterator();
  -
  -    /**
  -     * Add all elements of aCollection.
  -     * @see Collection#addAll(java.util.Collection)
  -     * @param aCollection
  -     */
  -    public boolean addAll(Collection aCollection);
  -    
  -    /**
  -     * Remove all Elements.
  -     */
  -    public void clear();
  -    
  +        
   }
  
  
  
  1.14      +62 -53    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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CollectionProxyDefaultImpl.java	23 Oct 2004 15:51:03 -0000	1.13
  +++ CollectionProxyDefaultImpl.java	24 Oct 2004 15:36:15 -0000	1.14
  @@ -40,22 +40,22 @@
    * @version $Id$
    */
   public class CollectionProxyDefaultImpl 
  -	implements Collection, ManageableCollection, IRemovalAwareCollection, CollectionProxy
  +	implements CollectionProxy, ManageableCollection, IRemovalAwareCollection
   {
       private static final long serialVersionUID = -6505291808050247424L;
   
       /** Reference to the used PersistenceBroker */
  -    private transient PersistenceBroker _broker;
  +    private transient PersistenceBroker m_broker;
       /** The key for acquiring the above broker */
  -    private PBKey _brokerKey;
  +    private PBKey m_brokerKey;
       /** The query that defines the values in the collection */
  -    private Query _query;
  +    private Query m_query;
       /** The actual data (if already loaded) */
  -    private Collection _data;
  +    private Collection m_data;
       /** The collection type */
  -    private Class _collectionClass;
  +    private Class m_collectionClass;
       /** The number of objects */
  -    private int _size = -1;
  +    private int m_size = -1;
       
       /*
       arminw
  @@ -63,9 +63,9 @@
       obtained from PersistenceBrokerThreadMapping.
       TODO: Could we find a better solution for this?
       */
  -    private boolean _needsClose;
  +    private boolean m_needsClose;
       /** Objects that listen on this proxy for loading events */
  -    private transient ArrayList _listeners;
  +    private transient ArrayList m_listeners;
   
       /**
        * Creates a new collection proxy (uses
  @@ -95,13 +95,27 @@
       }
   
       /**
  +     * @see org.apache.ojb.broker.core.proxy.CollectionProxy#load()
  +     */
  +    public synchronized void load()
  +    {
  +        if (!isLoaded())
  +        {
  +            beforeLoading();
  +            setData(loadData());
  +            afterLoading();
  +        }
  +        
  +    }
  +    
  +    /**
        * Determines whether the collection data already has been loaded from the database.
        * 
        * @return <code>true</code> if the data is already loaded
        */
       public boolean isLoaded()
       {
  -        return _data != null;
  +        return m_data != null;
       }
   
       /**
  @@ -133,7 +147,7 @@
        */
       protected synchronized void setSize(int size)
       {
  -        _size = size;
  +        m_size = size;
       }
       
       /**
  @@ -148,11 +162,11 @@
           {
               Collection result;
   
  -            if (_data != null) // could be set by listener
  +            if (m_data != null) // could be set by listener
               {
  -                result = _data;
  +                result = m_data;
               }
  -            else if (_size != 0)
  +            else if (m_size != 0)
               {
                   result = (Collection)getBroker().getCollectionByQuery(getCollectionClass(),
getQuery());
               }
  @@ -177,13 +191,13 @@
        */
       protected void beforeLoading()
       {
  -        if (_listeners != null)
  +        if (m_listeners != null)
           {
               CollectionProxyListener listener;
   
  -            for (int idx = _listeners.size() - 1; idx >= 0; idx--)
  +            for (int idx = m_listeners.size() - 1; idx >= 0; idx--)
               {
  -                listener = (CollectionProxyListener)_listeners.get(idx);
  +                listener = (CollectionProxyListener)m_listeners.get(idx);
                   listener.beforeLoading(this);
               }
           }
  @@ -194,13 +208,13 @@
        */
       protected void afterLoading()
       {
  -        if (_listeners != null)
  +        if (m_listeners != null)
           {
               CollectionProxyListener listener;
   
  -            for (int idx = _listeners.size() - 1; idx >= 0; idx--)
  +            for (int idx = m_listeners.size() - 1; idx >= 0; idx--)
               {
  -                listener = (CollectionProxyListener)_listeners.get(idx);
  +                listener = (CollectionProxyListener)m_listeners.get(idx);
                   listener.afterLoading(this);
               }
           }
  @@ -217,11 +231,11 @@
           }
           else
           {
  -            if (_size < 0)
  +            if (m_size < 0)
               {
  -                _size = loadSize();
  +                m_size = loadSize();
               }
  -            return _size;
  +            return m_size;
           }
       }
   
  @@ -344,7 +358,7 @@
   
               setData(coll);
           }
  -        _size = 0;
  +        m_size = 0;
       }
   
       /**
  @@ -354,7 +368,7 @@
        */
       public Query getQuery()
       {
  -        return _query;
  +        return m_query;
       }
   
       /**
  @@ -364,7 +378,7 @@
        */
       protected void setQuery(Query query)
       {
  -        _query = query;
  +        m_query = query;
       }
   
       /**
  @@ -378,11 +392,11 @@
           it from the PBF, do nothing if we obtain it from
           PBThreadMapping
           */
  -        if (_broker != null && _needsClose)
  +        if (m_broker != null && m_needsClose)
           {
  -            _needsClose = false;
  -            _broker.close();
  -            _broker = null;
  +            m_needsClose = false;
  +            m_broker.close();
  +            m_broker = null;
           }
       }
   
  @@ -410,12 +424,12 @@
           // current broker not found, create a intern new one
           if (broker == null)
           {
  -            if (_broker == null)
  +            if (m_broker == null)
               {
  -                _broker = PersistenceBrokerFactory.createPersistenceBroker(getBrokerKey());
  +                m_broker = PersistenceBrokerFactory.createPersistenceBroker(getBrokerKey());
                   // TODO: Better way?
  -                _needsClose = true;
  -                broker      = _broker;
  +                m_needsClose = true;
  +                broker      = m_broker;
               }
           }
           return broker;
  @@ -426,16 +440,11 @@
        * 
        * @return The data
        */
  -    public synchronized Collection getData()
  +    protected synchronized Collection getData()
       {
  -        if (!isLoaded())
  -        {
  -            beforeLoading();
  -            setData(loadData());
  -            afterLoading();
  -        }
  +        load();
   
  -        return _data;
  +        return m_data;
       }
   
       /**
  @@ -445,7 +454,7 @@
        */
       public void setData(Collection data)
       {
  -        _data = data;
  +        m_data = data;
       }
   
       /**
  @@ -455,7 +464,7 @@
        */
       public Class getCollectionClass()
       {
  -        return _collectionClass;
  +        return m_collectionClass;
       }
   
       /**
  @@ -465,7 +474,7 @@
        */
       protected void setCollectionClass(Class collClass)
       {
  -        _collectionClass = collClass;
  +        m_collectionClass = collClass;
       }
   
       /**
  @@ -518,7 +527,7 @@
        */
       public PBKey getBrokerKey()
       {
  -        return _brokerKey;
  +        return m_brokerKey;
       }
   
       /**
  @@ -528,7 +537,7 @@
        */
       protected void setBrokerKey(PBKey brokerKey)
       {
  -        _brokerKey = brokerKey;
  +        m_brokerKey = brokerKey;
       }
   
       /**
  @@ -538,11 +547,11 @@
        */
       public synchronized void addListener(CollectionProxyListener listener)
       {
  -        if (_listeners == null)
  +        if (m_listeners == null)
           {
  -            _listeners = new ArrayList();
  +            m_listeners = new ArrayList();
           }
  -        _listeners.add(listener);
  +        m_listeners.add(listener);
       }
   
       /**
  @@ -552,9 +561,9 @@
        */
       public synchronized void removeListener(CollectionProxyListener listener)
       {
  -        if (_listeners != null)
  +        if (m_listeners != null)
           {
  -            _listeners.remove(listener);
  +            m_listeners.remove(listener);
           }
       }
   
  
  
  
  1.15      +1 -1      db-ojb/src/java/org/apache/ojb/jdo/PersistenceManagerImpl.java
  
  Index: PersistenceManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/jdo/PersistenceManagerImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PersistenceManagerImpl.java	20 Oct 2004 18:50:46 -0000	1.14
  +++ PersistenceManagerImpl.java	24 Oct 2004 15:36:15 -0000	1.15
  @@ -733,7 +733,7 @@
           if (ProxyHelper.isCollectionProxy(collection))
           {
               CollectionProxy cp = (CollectionProxy) collection;
  -            cp.getData();
  +            cp.load();
           }
       }
   
  
  
  

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