db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/otm/swizzle CopySwizzling.java
Date Thu, 12 Jun 2003 23:41:52 GMT
olegnitz    2003/06/12 16:41:52

  Added:       src/java/org/apache/ojb/otm/swizzle CopySwizzling.java
  Log:
  CopySwizzling implementation
  
  Revision  Changes    Path
  1.1                  db-ojb/src/java/org/apache/ojb/otm/swizzle/CopySwizzling.java
  
  Index: CopySwizzling.java
  ===================================================================
  package org.apache.ojb.otm.swizzle;
  
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.metadata.FieldDescriptor;
  import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  
  /**
   *
   * the new object data is copied into the existing object
   *
   * @author <a href="mailto:olegnitz@apache.org">Oleg Nitz</a>
   *
   */
  public class CopySwizzling implements Swizzling
  {
  
      /**
       * @see org.apache.ojb.otm.swizzle.Swizzling#swizzle(Object, Object, PersistenceBroker)
       */
      public Object swizzle(Object newObj, Object oldObj, PersistenceBroker pb)
      {
          if (oldObj == null)
          {
              return newObj;
          }
  
          if (!newObj.getClass().equals(oldObj.getClass()))
          {
              throw new IllegalStateException("Trying to swizzle objects of different classes:
"
                      + newObj.getClass() + " and " + oldObj.getClass());
          }
  
          ClassDescriptor mif = pb.getClassDescriptor(newObj.getClass());
          FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
  
          for (int i = 0; i < fieldDescs.length; i++)
          {
              FieldDescriptor fd = fieldDescs[i];
              PersistentField f = fd.getPersistentField();
              f.set(oldObj, f.get(newObj));
          }
  
          return oldObj;
      }
  
      /**
       * @see org.apache.ojb.otm.swizzle.Swizzling#isSameInstance(Object, Object)
       */
      public boolean isSameInstance(Object swizzledObject, Object object)
      {
          return (swizzledObject == object);
      }
  
      /**
       * @see org.apache.ojb.otm.swizzle.Swizzling#getRealTarget(Object)
       */
      public Object getRealTarget(Object swizzledObject)
      {
          return swizzledObject;
      }
  
  }
  
  
  

Mime
View raw message