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 ol...@apache.org on 2004/01/18 14:19:42 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/otm/swizzle CopySwizzling.java

olegnitz    2004/01/18 05:19:42

  Modified:    src/java/org/apache/ojb/otm/swizzle Tag: OJB_BRANCH_1_0
                        CopySwizzling.java
  Log:
  Special processing for proxy collections has been added
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.5.2.1   +23 -9     db-ojb/src/java/org/apache/ojb/otm/swizzle/CopySwizzling.java
  
  Index: CopySwizzling.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/swizzle/CopySwizzling.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- CopySwizzling.java	25 Jul 2003 00:22:00 -0000	1.5
  +++ CopySwizzling.java	18 Jan 2004 13:19:42 -0000	1.5.2.1
  @@ -5,6 +5,7 @@
   import java.util.Iterator;
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.accesslayer.CollectionProxy;
   import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  @@ -104,25 +105,37 @@
                   Collection oldCol;
   
                   newCol = (Collection) field.get(newObj);
  -                if (newCol == null)
  +                if ((newCol == null)
  +                        || ((newCol instanceof CollectionProxy)
  +                            && !((CollectionProxy) newCol).isLoaded()))
                   {
  -                    field.set(oldObj, null);
  +                    field.set(oldObj, newCol);
                       continue;
                   }
   
                   oldCol = (Collection) field.get(oldObj);
                   if (oldCol == null)
                   {
  -                    try
  +                    if (newCol instanceof CollectionProxy)
                       {
  -                        oldCol = (Collection) newCol.getClass().newInstance();
  +                        CollectionProxy cp = (CollectionProxy) newCol;
  +                        oldCol = new CollectionProxy(pb.getPBKey(), cp.getData().getClass(), null);
  +                        oldCol.clear();
                       }
  -                    catch (Exception ex)
  +                    else
                       {
  -                        System.err.println("Cannot instantiate collection field which is neither Collection nor array: " + field);
  -                        ex.printStackTrace();
  -                        return newObj;
  +                        try
  +                        {
  +                            oldCol = (Collection) newCol.getClass().newInstance();
  +                        }
  +                        catch (Exception ex)
  +                        {
  +                            System.err.println("Cannot instantiate collection field which is neither Collection nor array: " + field);
  +                            ex.printStackTrace();
  +                            return newObj;
  +                        }
                       }
  +                    field.set(oldObj, oldCol);
                   }
                   else
                   {
  @@ -144,7 +157,7 @@
               {
                   Object newArray = field.get(newObj);
                   int length = Array.getLength(newArray);
  -                Object oldArray = 
  +                Object oldArray =
                           Array.newInstance(field.getType().getComponentType(), length);
   
                   for (int i = 0; i < length; i++)
  @@ -158,6 +171,7 @@
                       }
                       Array.set(oldArray, i, oldRelObj);
                   }
  +                field.set(oldObj, oldArray);
               }
               else
               {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org