db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mka...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/core QueryReferenceBroker.java
Date Tue, 15 Mar 2005 06:42:04 GMT
mkalen      2005/03/14 22:42:04

  Modified:    src/java/org/apache/ojb/broker/core
                        QueryReferenceBroker.java
  Log:
  Remove som warnings. Merge with OJB_1_0_RELEASE branch: Patch by Vadim Gritsenko: assert
that classToPrefetch is always restored in a finally clause after temporary modification.
  
  Revision  Changes    Path
  1.29      +35 -28    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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- QueryReferenceBroker.java	6 Jan 2005 21:00:00 -0000	1.28
  +++ QueryReferenceBroker.java	15 Mar 2005 06:42:04 -0000	1.29
  @@ -93,10 +93,10 @@
           ClassDescriptor cld = pb.getClassDescriptor(itemClass);
           ManageableCollection result = null;
           OJBIterator iter = null;
  -        boolean isRetrievalTasksCreated = (batchRetrieval && (m_retrievalTasks
== null));
           int fullSize = -1;
           int size = 0;
   
  +        final boolean isRetrievalTasksCreated = batchRetrieval && m_retrievalTasks
== null;
           if (isRetrievalTasksCreated)
           {
               // Maps ReferenceDescriptors to HashSets of owners
  @@ -161,10 +161,16 @@
               if (isRetrievalTasksCreated)
               {
                   // turn off auto prefetching for related proxies
  -                Class saveClassToPrefetch = classToPrefetch;
  +                final Class saveClassToPrefetch = classToPrefetch;
                   classToPrefetch = null;
  -                performRetrievalTasks();
  -                classToPrefetch = saveClassToPrefetch;
  +                try
  +                {
  +                    performRetrievalTasks();
  +                }
  +                finally
  +                {
  +                    classToPrefetch = saveClassToPrefetch;
  +                }
               }
           }
           catch(RuntimeException e)
  @@ -368,7 +374,7 @@
                   }
                   else
                   {
  -                    refObj = getReferencedObject(id, rds, cld);
  +                    refObj = getReferencedObject(id, rds);
                   }
   
                   if (isRefObjDefined)
  @@ -412,16 +418,16 @@
       public void retrieveReferences(Object newObj, ClassDescriptor cld, boolean forced)
throws PersistenceBrokerException
       {
           Iterator i = cld.getObjectReferenceDescriptors().iterator();
  -        ObjectReferenceDescriptor rds = null;
  +
           // turn off auto prefetching for related proxies
  -        Class saveClassToPrefetch = classToPrefetch;
  +        final Class saveClassToPrefetch = classToPrefetch;
           classToPrefetch = null;
           pb.ojbLocalCache().enableMaterializationCache();
           try
           {
               while (i.hasNext())
               {
  -                rds = (ObjectReferenceDescriptor) i.next();
  +                ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
                   retrieveReference(newObj, cld, rds, forced);
               }
           }
  @@ -431,9 +437,11 @@
               pb.ojbLocalCache().reset(false);
               throw e;
           }
  +        finally
  +        {
  +            classToPrefetch = saveClassToPrefetch;
  +        }
           pb.ojbLocalCache().disableMaterializationCache();
  -
  -        classToPrefetch = saveClassToPrefetch;
       }
   
      /**
  @@ -517,7 +525,7 @@
        * <br>
        * If no Proxy-class is defined, a getObjectByIdentity(...) lookup is performed.
        */
  -    private Object getReferencedObject(Identity id, ObjectReferenceDescriptor rds, ClassDescriptor
cld)
  +    private Object getReferencedObject(Identity id, ObjectReferenceDescriptor rds)
       {
           Class referencedProxy;
   
  @@ -581,7 +589,7 @@
                   // this collection type will be used:
                   Class collectionClass = cds.getCollectionClass();
                   PersistentField collectionField = cds.getPersistentField();
  -                Query fkQuery = getFKQuery(obj, cld, cds);
  +                Query fkQuery = getFKQuery(obj, cds);
                   Object value;
   
                   pb.ojbLocalCache().enableMaterializationCache();
  @@ -648,22 +656,21 @@
        * defined by CollectionDescriptor.
        *
        * @param obj the owner of the relationship
  -     * @param cld the ClassDescriptor for the owner
  -     * @param cod the CollectionDescriptor
  +     * @param cds the CollectionDescriptor
        * @return org.apache.ojb.broker.query.Query
        */
  -    private Query getFKQuery(Object obj, ClassDescriptor cld, CollectionDescriptor cds)
  +    private Query getFKQuery(Object obj, CollectionDescriptor cds)
       {
           Query fkQuery = null;
           QueryByCriteria fkQueryCrit = null;
   
           if (cds.isMtoNRelation())
           {
  -            fkQueryCrit = getFKQueryMtoN(obj, cld, cds);
  +            fkQueryCrit = getFKQueryMtoN(obj, cds);
           }
           else
           {
  -            fkQueryCrit = getFKQuery1toN(obj, cld, cds);
  +            fkQueryCrit = getFKQuery1toN(obj, cds);
           }
   
           // check if collection must be ordered
  @@ -694,11 +701,10 @@
        * supports UNIDIRECTIONAL m:n using QueryByMtoNCriteria.
        * 
        * @param obj the owner of the relationship
  -     * @param cld the ClassDescriptor for the owner
        * @param cod the CollectionDescriptor
        * @return org.apache.ojb.broker.query.QueryByCriteria
        */
  -    private QueryByCriteria getFKQueryMtoN(Object obj, ClassDescriptor cld, CollectionDescriptor
cod)
  +    private QueryByCriteria getFKQueryMtoN(Object obj, CollectionDescriptor cod)
       {
           ValueContainer[] values = pb.serviceBrokerHelper().getFkTargetValuesForObject(cod,
obj ,false);
           Object[] thisClassFks = cod.getFksToThisClass();
  @@ -724,11 +730,10 @@
        * Get Foreign key query for 1:n relationship.
        * 
        * @param obj the owner of the relationship
  -     * @param cld the ClassDescriptor for the owner
        * @param cod the CollectionDescriptor
        * @return org.apache.ojb.broker.query.QueryByCriteria
        */
  -    private QueryByCriteria getFKQuery1toN(Object obj, ClassDescriptor cld, CollectionDescriptor
cod)
  +    private QueryByCriteria getFKQuery1toN(Object obj, CollectionDescriptor cod)
       {
           ValueContainer[] values = pb.serviceBrokerHelper().getFkTargetValuesForObject(cod,
obj ,false);
           ClassDescriptor refCld = cod.getItemClassDescriptor();
  @@ -776,16 +781,16 @@
       public void retrieveCollections(Object newObj, ClassDescriptor cld, boolean forced)
throws PersistenceBrokerException
       {
           Iterator i = cld.getCollectionDescriptors().iterator();
  -        CollectionDescriptor cds;
  +
           // turn off auto prefetching for related proxies
  -        Class saveClassToPrefetch = classToPrefetch;
  +        final Class saveClassToPrefetch = classToPrefetch;
           classToPrefetch = null;
           pb.ojbLocalCache().enableMaterializationCache();
           try
           {
               while (i.hasNext())
               {
  -                cds = (CollectionDescriptor) i.next();
  +                CollectionDescriptor cds = (CollectionDescriptor) i.next();
                   retrieveCollection(newObj, cld, cds, forced);
               }
           }
  @@ -795,9 +800,11 @@
               pb.ojbLocalCache().reset(false);
               throw e;
           }
  +        finally
  +        {
  +            classToPrefetch = saveClassToPrefetch;
  +        }
           pb.ojbLocalCache().disableMaterializationCache();
  -
  -        classToPrefetch = saveClassToPrefetch;
       }
   
   
  @@ -934,7 +941,7 @@
                   prefetchingAll = false;
               }
   
  -            Class saveClassToPrefetch = classToPrefetch;
  +            final Class saveClassToPrefetch = classToPrefetch;
               classToPrefetch = prefetcher.getItemClassDescriptor().getClassOfObject();
               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