aclute      2005/08/10 12:32:19

  Modified:    src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
                        QueryReferenceBroker.java
               src/java/org/apache/ojb/broker/cache Tag: OJB_1_0_RELEASE
                        ObjectCacheTwoLevelImpl.java
  Log:
  Refactor to allow for TLCache to able to force proxies for Collections and 
References when retrieveing an object from cache.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.17.2.10 +52 -12    
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.9
  retrieving revision 1.17.2.10
  diff -u -r1.17.2.9 -r1.17.2.10
  --- QueryReferenceBroker.java 9 Aug 2005 20:03:20 -0000       1.17.2.9
  +++ QueryReferenceBroker.java 10 Aug 2005 19:32:19 -0000      1.17.2.10
  @@ -273,11 +273,8 @@
           return (Collection) 
getCollectionByQuery(RemovalAwareCollection.class, query, lazy);
       }
   
  -    /**
  -     * retrieve a collection of itemClass Objects matching the Query query
  -     */
  -    private Collection getCollectionByQuery(Query query, 
CollectionDescriptor cds) throws PersistenceBrokerException
  -    {
  +    
  +    private Class getCollectionTypeClass(CollectionDescriptor cds) throws 
PersistenceBrokerException{
           // BRJ: do not use RemovalAwareCollection for m:n relationships
           // see 
http://db.apache.org/ojb/docu/guides/basic-technique.html#Mapping+m%3An+associations
   
  @@ -304,10 +301,10 @@
           {
               throw new MetadataException("Cannot determine a default 
collection type for collection "+cds.getAttributeName()+" in type 
"+cds.getClassDescriptor().getClassNameOfObject());
           }
  -
  -        return (Collection)getCollectionByQuery(collType, query, 
cds.isLazy());
  +        return collType;
       }
       
  +    
       /**
        * @return true if this is the first task for the given 
ObjectReferenceDescriptor
        */
  @@ -677,7 +674,7 @@
               return pb.doGetObjectByIdentity(id);
           }
       }
  -
  +    
       /**
        * Retrieve a single Collection on behalf of <b>obj</b>.
        * The Collection is retrieved only if <b>cascade.retrieve is true</b>
  @@ -691,6 +688,27 @@
        */
       public void retrieveCollection(Object obj, ClassDescriptor cld, 
CollectionDescriptor cds, boolean forced)
       {
  +        doRetrieveCollection(obj, cld, cds, forced, cds.isLazy());
  +    }
  +    
  +    /**
  +     * Retrieve a single Proxied Collection on behalf of <b>obj</b>.
  +     * The Collection is retrieved only if <b>cascade.retrieve is true</b>
  +     * or if <b>forced</b> is set to true.     *
  +     *
  +     * @param obj - the object to be updated
  +     * @param cld - the ClassDescriptor describing obj
  +     * @param cds - the CollectionDescriptor describing the collection 
attribute to be loaded
  +     * @param forced - if set to true a proxy will be placed, even if cds 
differs.
  +     *
  +     */
  +    public void retrieveProxyCollection(Object obj, ClassDescriptor cld, 
CollectionDescriptor cds, boolean forced)
  +    {
  +        doRetrieveCollection(obj, cld, cds, forced, true);
  +    }
  +    
  +    private void doRetrieveCollection(Object obj, ClassDescriptor cld, 
CollectionDescriptor cds, boolean forced, boolean lazyLoad)
  +    {
           if (forced || cds.getCascadeRetrieve())
           {
               if ((m_retrievalTasks != null) && !cds.isLazy()
  @@ -712,7 +730,7 @@
                   {
                       if (collectionClass == null)
                       {
  -                        Collection result = getCollectionByQuery(fkQuery, 
cds);
  +                        Collection result = 
(Collection)getCollectionByQuery(getCollectionTypeClass(cds), fkQuery, 
lazyLoad);
   
                           // assign collection to objects attribute
                           // if attribute has an array type build an array, 
else assign collection directly
  @@ -736,7 +754,7 @@
                       }
                       else
                       {
  -                        ManageableCollection result = 
getCollectionByQuery(collectionClass, fkQuery, cds.isLazy());
  +                        ManageableCollection result = 
getCollectionByQuery(collectionClass, fkQuery, lazyLoad);
                           collectionField.set(obj, result);
                           value = result;
                       }
  @@ -893,6 +911,24 @@
        */
       public void retrieveCollections(Object newObj, ClassDescriptor cld, 
boolean forced) throws PersistenceBrokerException
       {
  +        doRetrieveCollections(newObj, cld, forced, false);
  +    }
  +    
  +    /**
  +     * Retrieve all Collection attributes of a given instance, and make all 
of the Proxy Collections
  +     *
  +     * @param newObj the instance to be loaded or refreshed
  +     * @param cld the ClassDescriptor of the instance
  +     * @param forced if set to true, loading is forced even if cld differs
  +     *
  +     */
  +    public void retrieveProxyCollections(Object newObj, ClassDescriptor cld, 
boolean forced) throws PersistenceBrokerException
  +    {
  +        doRetrieveCollections(newObj, cld, forced, true);
  +    }
  +    
  +    private void doRetrieveCollections(Object newObj, ClassDescriptor cld, 
boolean forced, boolean forceProxyCollection) throws PersistenceBrokerException
  +    {
           Iterator i = cld.getCollectionDescriptors().iterator();
   
           // turn off auto prefetching for related proxies
  @@ -905,7 +941,11 @@
               while (i.hasNext())
               {
                   CollectionDescriptor cds = (CollectionDescriptor) i.next();
  -                retrieveCollection(newObj, cld, cds, forced);
  +                if (forceProxyCollection){
  +                    retrieveProxyCollection(newObj, cld, cds, forced);
  +                } else {
  +                    retrieveCollection(newObj, cld, cds, forced);
  +                }
               }
               pb.getInternalCache().disableMaterializationCache();
           }
  
  
  
  No                   revision
  No                   revision
  1.1.2.8   +4 -3      
db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheTwoLevelImpl.java
  
  Index: ObjectCacheTwoLevelImpl.java
  ===================================================================
  RCS file: 
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheTwoLevelImpl.java,v
  retrieving revision 1.1.2.7
  retrieving revision 1.1.2.8
  diff -u -r1.1.2.7 -r1.1.2.8
  --- ObjectCacheTwoLevelImpl.java      9 Aug 2005 20:03:22 -0000       1.1.2.7
  +++ ObjectCacheTwoLevelImpl.java      10 Aug 2005 19:32:19 -0000      1.1.2.8
  @@ -382,10 +382,11 @@
           final boolean forced = false;
           if (forceProxies){
               broker.getReferenceBroker().retrieveProxyReferences(target, cld, 
forced);
  +            broker.getReferenceBroker().retrieveProxyCollections(target, 
cld, forced);
           }else{
               broker.getReferenceBroker().retrieveReferences(target, cld, 
forced);
  -        }      
  -        broker.getReferenceBroker().retrieveCollections(target, cld, forced);
  +            broker.getReferenceBroker().retrieveCollections(target, cld, 
forced);
  +        }    
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to