db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/singlevm PersistenceBrokerImpl.java
Date Sun, 01 Dec 2002 11:47:20 GMT
thma        2002/12/01 03:47:20

  Modified:    src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
  Log:
  repair retrieve references
  
  Revision  Changes    Path
  1.87      +49 -52    jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java,v
  retrieving revision 1.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- PersistenceBrokerImpl.java	30 Nov 2002 00:34:23 -0000	1.86
  +++ PersistenceBrokerImpl.java	1 Dec 2002 11:47:20 -0000	1.87
  @@ -863,14 +863,17 @@
       }
   
       /**
  -     * retrieve all References (also Collection-attributes) of a given instance
  +     * retrieve all References (also Collection-attributes) of a given instance.
  +     * Loading is forced, even if the collection- and reference-descriptors differ.
        * @param pInstance the persistent instance to work with
        */
       public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException
       {
           ClassDescriptor cld = descriptorRepository.getDescriptorFor(pInstance.getClass());
  -        retrieveReferences(pInstance, cld);
  -        retrieveCollections(pInstance, cld);
  +        // force loading of references
  +        final boolean forced = true;
  +        retrieveReferences(pInstance, cld, forced);
  +        retrieveCollections(pInstance, cld, forced);
       }
   
       /**
  @@ -885,14 +888,14 @@
           CollectionDescriptor cod = cld.getCollectionDescriptorByName(pAttributeName);
           if (cod != null)
           {
  -            retrieveCollection(pInstance, cld, cod);
  +            retrieveCollection(pInstance, cld, cod, true);
           }
           else
           {
               ObjectReferenceDescriptor ord = cld.getObjectReferenceDescriptorByName(pAttributeName);
               if (ord != null)
               {
  -                retrieveReference(pInstance, cld, ord);
  +                retrieveReference(pInstance, cld, ord, true);
               }
               else
               {
  @@ -904,60 +907,58 @@
   
       /**
        * Retrieve all References
  -     *
  -     *
  -     * @param newObj
  -     * @param cld
  -     *
  +     * 
  +     * @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 retrieveReferences(Object newObj, ClassDescriptor cld) throws PersistenceBrokerException
  +    public void retrieveReferences(Object newObj, ClassDescriptor cld, boolean forced)
throws PersistenceBrokerException
       {
           Iterator i = cld.getObjectReferenceDescriptors().iterator();
           ObjectReferenceDescriptor rds = null;
           while (i.hasNext())
           {
               rds = (ObjectReferenceDescriptor) i.next();
  -            retrieveReference(newObj, cld, rds);
  +            retrieveReference(newObj, cld, rds, forced);
           }
       }
   
       /**
        * Retrieve a single Reference.
  -     * This implementation retrieves a referenced object from the data backend if <b>cascade-retrieve</b>
is true.
  -     *
  +     * This implementation retrieves a referenced object from the data backend 
  +     * if <b>cascade-retrieve</b> is true or if <b>forced</b> is
true.
        *
        * @param obj - object that will have it's field set with a referenced object.
  -     * @param cld
  -     * @param rds
  +     * @param cld - the ClassDescriptor describring obj 
  +     * @param rds - the ObjectReferenceDescriptor of the reference attribute to be loaded
  +     * @param forced - if set to true, the reference is loaded even if the rds differs.

        */
  -    private void retrieveReference(Object obj, ClassDescriptor cld, ObjectReferenceDescriptor
rds)
  +    private void retrieveReference(Object obj, ClassDescriptor cld, ObjectReferenceDescriptor
rds, boolean forced)
       {
           PersistentField refField;
           Object refObj;
  -        if (rds.getCascadeRetrieve())
  +        if (forced || rds.getCascadeRetrieve())
           {
               refObj = getReferencedObject(obj, rds, cld);
               refField = rds.getPersistentField();
  -            //logger.info("RETRIEVING reference for "+obj);
  -            //logger.info("RETRIEVING reference field "+refField.getName()+"="+refObj);
  -
               refField.set(obj, refObj);
           }
       }
   
       /**
        * Retrieve a single Collection on behalf of <b>obj</b>.
  -     * The Collection is retrieved only if <b>cascade.retrieve is true</b>
  +     * The Collection is retrieved only if <b>cascade.retrieve is true</b>

  +     * or if <b>forced</b> is set to true.     *
        *
  -     *
  -     * @param obj
  -     * @param cld
  -     * @param cds
  +     * @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 loading is forced, even if cds differs.
        *
        */
  -    private void retrieveCollection(Object obj, ClassDescriptor cld, CollectionDescriptor
cds)
  +    private void retrieveCollection(Object obj, ClassDescriptor cld, CollectionDescriptor
cds, boolean forced)
       {
  -        if (cds.getCascadeRetrieve())
  +        if (forced || cds.getCascadeRetrieve())
           {
               // this collection type will be used:
               Class collectionClass = cds.getCollectionClass();
  @@ -1013,20 +1014,21 @@
       }
   
       /**
  -     * Retrieve all Collections
  +     * Retrieve all Collection attributes of a given instance
        *
  -     * @param newObj
  -     * @param cld
  +     * @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 retrieveCollections(Object newObj, ClassDescriptor cld) throws PersistenceBrokerException
  +    public void retrieveCollections(Object newObj, ClassDescriptor cld, boolean forced)
throws PersistenceBrokerException
       {
           Iterator i = cld.getCollectionDescriptors().iterator();
           CollectionDescriptor cds;
           while (i.hasNext())
           {
               cds = (CollectionDescriptor) i.next();
  -            retrieveCollection(newObj, cld, cds);
  +            retrieveCollection(newObj, cld, cds, forced);
           }
       }
   
  @@ -1048,7 +1050,7 @@
               cds = (CollectionDescriptor) iter.next();
               if (cds.isRefresh())
               {
  -                retrieveCollection(obj, cld, cds);
  +                retrieveCollection(obj, cld, cds, false);
               }
           }
           //
  @@ -1060,7 +1062,7 @@
               rds = (ObjectReferenceDescriptor) iter.next();
               if (rds.isRefresh())
               {
  -                retrieveReference(obj, cld, rds);
  +                retrieveReference(obj, cld, rds, false);
               }
           }
       }
  @@ -1402,11 +1404,13 @@
   				 * BEFORE resolving refs
   				 */
                   ClassDescriptor newObjCld = descriptorRepository.getDescriptorFor(newObj.getClass());
  +				// don't force loading of references:
  +				final boolean unforced = false;
   
                   // 2. retrieve non-skalar fields that contain objects retrievable from
other tables
  -                retrieveReferences(newObj, newObjCld);
  +                retrieveReferences(newObj, newObjCld, unforced);
                   // 3. retrieve collection fields from foreign-key related tables:
  -                retrieveCollections(newObj, newObjCld);
  +                retrieveCollections(newObj, newObjCld, unforced);
               }
           }
   
  @@ -1654,16 +1658,6 @@
   
   
       /**
  -     * retrieve an instance of Class c from the underlying persistence system
  -     * by using a sample object for providing primary key information.
  -     */
  -    private Object getObjectByExample(Object exampleObj) throws PersistenceBrokerException
  -    {
  -        Identity oid = new Identity(exampleObj);
  -        return getObjectByIdentity(oid);
  -    }
  -
  -    /**
        * Method declaration
        *
        * @param id
  @@ -1702,15 +1696,18 @@
       {
           if (query instanceof QueryByIdentity)
           {
  +        	// example obj may be an entity or an Identity
               Object obj = query.getExampleObject();
  +            Identity oid = null;
               if (obj instanceof Identity)
               {
  -                return getObjectByIdentity((Identity) obj);
  +            	oid = (Identity) obj;
               }
  -            else
  +            else 
               {
  -                return getObjectByExample(obj);
  +            	oid = new Identity(obj);
               }
  +            return getObjectByIdentity(oid);
           }
           else
           {
  @@ -2479,7 +2476,7 @@
               try
               {
                   Connection conn = connectionManager.getConnection();
  -                AutoCreatorDb.autoCreate(descriptorRepository, this, conn);
  +                AutoCreatorDb.autoCreate(descriptorRepository, conn);
               }
               catch (LookupException e)
               {
  
  
  

Mime
View raw message