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/broker/core QueryReferenceBroker.java
Date Fri, 26 Aug 2005 19:26:39 GMT
brj         2005/08/26 12:26:39

  Modified:    src/java/org/apache/ojb/otm/core Tag: OJB_1_0_RELEASE
                        BaseConnection.java
               src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_1_0_RELEASE OJBIterator.java
                        ChainingIterator.java RsIterator.java
                        PagingIterator.java
               src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
                        QueryReferenceBroker.java
  Log:
  fix for OJB-68
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.37.2.1  +9 -1      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.37
  retrieving revision 1.37.2.1
  diff -u -r1.37 -r1.37.2.1
  --- BaseConnection.java	12 Apr 2004 16:32:41 -0000	1.37
  +++ BaseConnection.java	26 Aug 2005 19:26:39 -0000	1.37.2.1
  @@ -599,6 +599,14 @@
           {
               return _it.size();
           }
  +
  +        /**
  +         * @see org.apache.ojb.broker.accesslayer.OJBIterator#disableLifeCycleEvents()
  +         */
  +        public void disableLifeCycleEvents()
  +        {
  +            _it.disableLifeCycleEvents();
  +        }
       }
   
       private class OTMOQLQueryImpl extends OQLQueryImpl
  
  
  
  No                   revision
  No                   revision
  1.9.2.1   +6 -1      db-ojb/src/java/org/apache/ojb/broker/accesslayer/OJBIterator.java
  
  Index: OJBIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/OJBIterator.java,v
  retrieving revision 1.9
  retrieving revision 1.9.2.1
  diff -u -r1.9 -r1.9.2.1
  --- OJBIterator.java	5 May 2004 13:06:03 -0000	1.9
  +++ OJBIterator.java	26 Aug 2005 19:26:39 -0000	1.9.2.1
  @@ -72,4 +72,9 @@
        * this method will be called implicitely.
        */
       public void releaseDbResources();
  +    
  +    /**
  +     * Do not fire any PBLifeCycleEvent when reading next item. 
  +     */
  +    public void disableLifeCycleEvents();
   }
  
  
  
  1.13.2.1  +16 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/ChainingIterator.java
  
  Index: ChainingIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ChainingIterator.java,v
  retrieving revision 1.13
  retrieving revision 1.13.2.1
  diff -u -r1.13 -r1.13.2.1
  --- ChainingIterator.java	22 May 2004 09:51:26 -0000	1.13
  +++ ChainingIterator.java	26 Aug 2005 19:26:39 -0000	1.13.2.1
  @@ -52,6 +52,8 @@
       private int m_activeIteratorIndex = 0;
       private int m_fullSize = -1;
       private int m_currentCursorPosition = 0;
  +    /** if true do not fire PBLifeCycleEvent. */
  +    private boolean disableLifeCycleEvents = false;
   
       /**
        * Constructor for ChainingIterator.
  @@ -394,4 +396,17 @@
           return result;
       }
   
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.OJBIterator#disableLifeCycleEvents()
  +     */
  +    public void disableLifeCycleEvents()
  +    {
  +        Iterator iterators = m_rsIterators.iterator();
  +        while (iterators.hasNext())
  +        {
  +            OJBIterator iter = (OJBIterator) iterators.next();
  +            iter.disableLifeCycleEvents();
  +        }        
  +    }
  +
   }
  
  
  
  1.63.2.15 +18 -4     db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.63.2.14
  retrieving revision 1.63.2.15
  diff -u -r1.63.2.14 -r1.63.2.15
  --- RsIterator.java	22 Aug 2005 15:30:59 -0000	1.63.2.14
  +++ RsIterator.java	26 Aug 2005 19:26:39 -0000	1.63.2.15
  @@ -151,6 +151,9 @@
       private boolean autoRelease = true;
   
       private ResourceWrapper resourceListener;
  +    
  +    /** if true do not fire PBLifeCycleEvent. */
  +    private boolean disableLifeCycleEvents = false;
   
       /**
        * RsIterator constructor.
  @@ -280,9 +283,12 @@
   
                   // Invoke events on PersistenceBrokerAware instances and listeners
                   // set target object
  -                getAfterLookupEvent().setTarget(obj);
  -                getBroker().fireBrokerEvent(getAfterLookupEvent());
  -                getAfterLookupEvent().setTarget(null);
  +                if (!disableLifeCycleEvents)
  +                {
  +                    getAfterLookupEvent().setTarget(obj);
  +                    getBroker().fireBrokerEvent(getAfterLookupEvent());
  +                    getAfterLookupEvent().setTarget(null);
  +                }    
                   return obj;
               }
               else
  @@ -1110,4 +1116,12 @@
               super(msg, cause);
           }
       }
  +
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.OJBIterator#disableLifeCycleEvents()
  +     */
  +    public void disableLifeCycleEvents()
  +    {
  +        disableLifeCycleEvents = true;
  +    }
   }
  
  
  
  1.10.2.1  +16 -21    db-ojb/src/java/org/apache/ojb/broker/accesslayer/PagingIterator.java
  
  Index: PagingIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/PagingIterator.java,v
  retrieving revision 1.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- PagingIterator.java	4 Apr 2004 23:53:31 -0000	1.10
  +++ PagingIterator.java	26 Aug 2005 19:26:39 -0000	1.10.2.1
  @@ -31,7 +31,6 @@
    */
   public class PagingIterator implements OJBIterator
   {
  -
       private final OJBIterator m_iterator;
       private int m_startAt;
       private int m_endAt;
  @@ -81,9 +80,7 @@
           m_iterator.absolute(m_currentCursorPosition);
       }
   
  -    /*
  -	 * (non-Javadoc)
  -	 * 
  +    /**
   	 * @see org.apache.ojb.broker.accesslayer.OJBIterator#size()
   	 */
       public int size() throws PersistenceBrokerException
  @@ -98,7 +95,7 @@
           }
       }
   
  -    /* (non-Javadoc)
  +    /**
        * @see org.apache.ojb.broker.accesslayer.OJBIterator#fullSize()
        */
       public int fullSize() throws PersistenceBrokerException
  @@ -106,9 +103,7 @@
           return m_fullSize;
       }
       
  -    /*
  -	 * (non-Javadoc)
  -	 * 
  +    /**
   	 * @see org.apache.ojb.broker.accesslayer.OJBIterator#absolute(int)
   	 */
       public boolean absolute(int row) throws PersistenceBrokerException
  @@ -129,9 +124,7 @@
           return m_iterator.absolute(newPosition);
       }
   
  -    /*
  -	 * (non-Javadoc)
  -	 * 
  +    /**
   	 * @see org.apache.ojb.broker.accesslayer.OJBIterator#relative(int)
   	 */
       public boolean relative(int row) throws PersistenceBrokerException
  @@ -139,9 +132,7 @@
           return absolute(m_currentCursorPosition - (m_startAt - 1) + row);
       }
   
  -    /*
  -	 * (non-Javadoc)
  -	 * 
  +    /**
   	 * @see org.apache.ojb.broker.accesslayer.OJBIterator#releaseDbResources()
   	 */
       public void releaseDbResources()
  @@ -157,9 +148,7 @@
           throw new UnsupportedOperationException("remove not supported by PagingIterator");
       }
   
  -    /*
  -	 * (non-Javadoc)
  -	 * 
  +    /**
   	 * @see java.util.Iterator#hasNext()
   	 */
       public boolean hasNext()
  @@ -176,9 +165,7 @@
   
       }
   
  -    /*
  -	 * (non-Javadoc)
  -	 * 
  +    /**
   	 * @see java.util.Iterator#next()
   	 */
       public Object next()
  @@ -186,4 +173,12 @@
           m_currentCursorPosition++;
           return m_iterator.next();
       }
  +
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.OJBIterator#disableLifeCycleEvents()
  +     */
  +    public void disableLifeCycleEvents()
  +    {
  +        m_iterator.disableLifeCycleEvents();       
  +    }
   }
  
  
  
  No                   revision
  No                   revision
  1.17.2.12 +21 -11    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.17.2.11
  retrieving revision 1.17.2.12
  diff -u -r1.17.2.11 -r1.17.2.12
  --- QueryReferenceBroker.java	22 Aug 2005 15:30:59 -0000	1.17.2.11
  +++ QueryReferenceBroker.java	26 Aug 2005 19:26:39 -0000	1.17.2.12
  @@ -25,6 +25,7 @@
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.ManageableCollection;
  +import org.apache.ojb.broker.PBLifeCycleEvent;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.accesslayer.OJBIterator;
   import org.apache.ojb.broker.accesslayer.PagingIterator;
  @@ -75,10 +76,12 @@
       private final boolean batchRetrieval = true;
       private final boolean prefetchProxies = true;
       private Class classToPrefetch;
  +    private PBLifeCycleEvent afterLookupEvent;
   
       public QueryReferenceBroker(final PersistenceBrokerImpl pb)
       {
           this.pb = pb;
  +        afterLookupEvent = new PBLifeCycleEvent(pb, PBLifeCycleEvent.Type.AFTER_LOOKUP);
       }
   
       /**
  @@ -110,8 +113,11 @@
           try
           {
               result = (ManageableCollection) collectionClass.newInstance();
  +            
               // now iterate over all elements and add them to the new collection
  +            // lifecycle events are disabled
               iter = pb.getIteratorFromQuery(query, cld);
  +            iter.disableLifeCycleEvents();
   
               // BRJ : get fullSizefor Query
               // to be removed when Query.fullSize is removed
  @@ -134,8 +140,7 @@
                   {
                       IndirectionHandler handler = ProxyHelper.getIndirectionHandler(candidate);
   
  -                    if ((handler != null)
  -                            || itemClass.isAssignableFrom(candidate.getClass()))
  +                    if ((handler != null) || itemClass.isAssignableFrom(candidate.getClass()))
                       {
                           result.ojbAdd(candidate);
   
  @@ -176,6 +181,17 @@
                   }
               }
   
  +            // BRJ: fire LifeCycleEvents after execution of RetrievalTasks
  +            // to ensure objects are fully materialized
  +            Iterator resultIter = result.ojbIterator();
  +            while (resultIter.hasNext())
  +            {
  +                Object obj = resultIter.next();
  +                afterLookupEvent.setTarget(obj);
  +                pb.fireBrokerEvent(afterLookupEvent);
  +                afterLookupEvent.setTarget(null);
  +            }
  +
               // ==> disable materialization cache
               pb.getInternalCache().disableMaterializationCache();
           }
  @@ -185,19 +201,13 @@
               pb.getInternalCache().doLocalClear();
               throw e;
           }
  -        catch (InstantiationException ex)
  +        catch (Exception ex)
           {
               // ==> clear materialization cache
               pb.getInternalCache().doLocalClear();
               log.error(ex);
               throw new PersistenceBrokerException(ex);
           }
  -        catch (IllegalAccessException ex)
  -        {
  -            pb.getInternalCache().doLocalClear();
  -            log.error(ex);
  -            throw new PersistenceBrokerException(ex);
  -        }
           finally
           {
               if (iter != null)
  @@ -217,7 +227,7 @@
               fullSize = size;	// use size of result
           }
           query.fullSize(fullSize);
  -
  +        
           return result;
       }
   
  
  
  

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