You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by br...@apache.org on 2003/06/19 20:03:51 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/core PersistenceBrokerImpl.java

brj         2003/06/19 11:03:51

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
  Log:
  (OJB181) added support for proxies in assertFkAssignment
  
  Revision  Changes    Path
  1.12      +21 -18    db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PersistenceBrokerImpl.java	13 Jun 2003 23:06:45 -0000	1.11
  +++ PersistenceBrokerImpl.java	19 Jun 2003 18:03:51 -0000	1.12
  @@ -685,17 +685,17 @@
           }
       }
   
  +    /**
  +     * update the the foreign key fields of obj with the key fields of ref
  +     * @param obj
  +     * @param ref referenced object
  +     * @param rds
  +     */
       private void assertFkAssignment(Object obj, Object ref, ObjectReferenceDescriptor rds)
       {
  -        /**
  -         * MBAIRD
  -         * we have 'disassociated' this object from the referenced object, the object representing the ord is now null,
  -         * so set the fk to null.
  -         *
  -         * Note: I can't believe this wasn't tested (as of June9/2002), attaching and removing objects seems to be a
  -         * pretty important piece of functionality.
  -         *
  -         */
  +         // MBAIRD
  +         // we have 'disassociated' this object from the referenced object, 
  +         // the object representing the ord is now null, so set the fk to null.
           if (ref == null)
           {
               ClassDescriptor cld = descriptorRepository.getDescriptorFor(obj.getClass());
  @@ -707,19 +707,22 @@
                       f[i].getPersistentField().set(obj, null);
                   }
               }
  -
           }
   
  -        if ((!(obj instanceof VirtualProxy))
  -                && (!(obj instanceof Proxy))
  -                && (ref != null)
  -                && (!(ref instanceof VirtualProxy))
  -                && (!(ref instanceof Proxy)))
  +        if (
  +            (!(obj instanceof VirtualProxy)) &&
  +            (!(obj instanceof Proxy)) &&
  +            (ref != null)             
  +           )
           {
  -            ClassDescriptor refCld = descriptorRepository.getDescriptorFor(ref.getClass());
  +            // BRJ: ref may be Proxy
  +            Class refClass = ProxyHelper.getRealClass(ref);
  +            ClassDescriptor refCld = descriptorRepository.getDescriptorFor(refClass);
               Object[] refPkValues = brokerHelper.getKeyValues(refCld, ref, false);
  +
               ClassDescriptor objCld = descriptorRepository.getDescriptorFor(obj.getClass());
               FieldDescriptor[] objFkFields = rds.getForeignKeyFieldDescriptors(objCld);
  +
               if (objFkFields != null)
               {
                   FieldDescriptor fld = null;