db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/core/proxy CollectionProxyDefaultImpl.java
Date Sun, 28 Nov 2004 03:13:16 GMT
arminw      2004/11/27 19:13:16

  Modified:    src/java/org/apache/ojb/broker/core/proxy
                        CollectionProxyDefaultImpl.java
  Log:
  more strict handling of PB instances
  
  Revision  Changes    Path
  1.15      +17 -21    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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- CollectionProxyDefaultImpl.java	24 Oct 2004 15:36:15 -0000	1.14
  +++ CollectionProxyDefaultImpl.java	28 Nov 2004 03:13:16 -0000	1.15
  @@ -44,8 +44,6 @@
   {
       private static final long serialVersionUID = -6505291808050247424L;
   
  -    /** Reference to the used PersistenceBroker */
  -    private transient PersistenceBroker m_broker;
       /** The key for acquiring the above broker */
       private PBKey m_brokerKey;
       /** The query that defines the values in the collection */
  @@ -126,9 +124,10 @@
        */
       protected synchronized int loadSize() throws PersistenceBrokerException
       {
  +        PersistenceBroker broker = getBroker();
           try
           {
  -            return getBroker().getCount(getQuery());
  +            return broker.getCount(getQuery());
           }
           catch (Exception ex)
           {
  @@ -136,7 +135,7 @@
           }
           finally
           {
  -            releaseBroker();
  +            releaseBroker(broker);
           }
       }
   
  @@ -158,6 +157,7 @@
        */
       protected Collection loadData() throws PersistenceBrokerException
       {
  +        PersistenceBroker broker = getBroker();
           try
           {
               Collection result;
  @@ -168,7 +168,7 @@
               }
               else if (m_size != 0)
               {
  -                result = (Collection)getBroker().getCollectionByQuery(getCollectionClass(),
getQuery());
  +                result = (Collection) broker.getCollectionByQuery(getCollectionClass(),
getQuery());
               }
               else
               {
  @@ -182,7 +182,7 @@
           }
           finally
           {
  -            releaseBroker();
  +            releaseBroker(broker);
           }
       }
   
  @@ -384,7 +384,7 @@
       /**
        * Release the broker instance.
        */
  -    protected synchronized void releaseBroker()
  +    protected synchronized void releaseBroker(PersistenceBroker broker)
       {
           /*
           arminw:
  @@ -392,11 +392,10 @@
           it from the PBF, do nothing if we obtain it from
           PBThreadMapping
           */
  -        if (m_broker != null && m_needsClose)
  +        if (broker != null && m_needsClose)
           {
               m_needsClose = false;
  -            m_broker.close();
  -            m_broker = null;
  +            broker.close();
           }
       }
   
  @@ -421,16 +420,13 @@
           }
           // 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)
  +        // current broker not found or was closed, create a intern new one
  +        if (broker == null || broker.isClosed())
           {
  -            if (m_broker == null)
  -            {
  -                m_broker = PersistenceBrokerFactory.createPersistenceBroker(getBrokerKey());
  -                // TODO: Better way?
  -                m_needsClose = true;
  -                broker      = m_broker;
  -            }
  +            broker = PersistenceBrokerFactory.createPersistenceBroker(getBrokerKey());
  +            // 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;
           }
           return broker;
       }
  @@ -506,7 +502,7 @@
       }
   
       /**
  -     * @see org.apache.ojb.broker.IRemovalAwareCollection#afterStore(PersistenceBroker,
CollectionDescriptor)
  +     * @see IRemovalAwareCollection#afterStore(PersistenceBroker, CollectionDescriptor)
        */
       public void afterStore(PersistenceBroker broker, CollectionDescriptor cod) throws PersistenceBrokerException
       {
  
  
  

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