db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/sequence AbstractSequenceManager.java SequenceManagerHelper.java
Date Mon, 05 Jul 2004 08:37:41 GMT
arminw      2004/07/05 01:37:41

  Modified:    src/java/org/apache/ojb/broker/metadata/fieldaccess
                        AnonymousPersistentFieldHelper.java
               src/java/org/apache/ojb/broker/util/sequence
                        AbstractSequenceManager.java
                        SequenceManagerHelper.java
  Log:
  fix for OJB275,
  include PK fields for "super" class-descriptor when using "super" reference
  Now on object insert, the PK values are copied from the main object to the temporary
  created "super" objects.
  
  Revision  Changes    Path
  1.8       +17 -60    db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldHelper.java
  
  Index: AnonymousPersistentFieldHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldHelper.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AnonymousPersistentFieldHelper.java	4 Apr 2004 23:53:35 -0000	1.7
  +++ AnonymousPersistentFieldHelper.java	5 Jul 2004 08:37:41 -0000	1.8
  @@ -15,6 +15,10 @@
    * limitations under the License.
    */
   
  +import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Vector;
  +
   import org.apache.ojb.broker.metadata.AnonymousFieldDescriptor;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  @@ -22,56 +26,14 @@
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   
  -import java.lang.reflect.Field;
  -import java.util.Iterator;
  -import java.util.Map;
  -import java.util.Vector;
  -
   /**
    * Helper class for anonymous fields.
    *
    * @author Houar TINE
  - * @version $Id$ 
  + * @version $Id$
    */
   public class AnonymousPersistentFieldHelper
   {
  -    /**
  -     * An iterative version of org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldxxx
  -     * This implementastion is more efficient than recursive version
  -     * If fieldname not exist null is returned
  -     */
  -    public static Field getFieldIterative(final Class c, final String fieldname)
  -    {
  -        Field f = null;
  -        Class clazz = c;
  -        do
  -        {
  -            try
  -            {
  -                f = clazz.getDeclaredField(fieldname);
  -                break;
  -            }
  -            catch (NoSuchFieldException e)
  -            {
  -                // ignore
  -            }
  -            clazz = clazz.getSuperclass();
  -        }
  -        while (clazz != Object.class);
  -        return f;
  -    }
  -
  -    public static Vector getPkFieldNames(final ClassDescriptor cld)
  -    {
  -        FieldDescriptor[] pks = cld.getPkFields();
  -        Vector v = new Vector(pks.length);
  -        for (int i = pks.length - 1; i >= 0; i--)
  -        {
  -            v.add(pks[i].getPersistentField().getName());
  -        }
  -        return v;
  -    }
  -
       public static void computeInheritedPersistentFields(final DescriptorRepository repository)
       {
           Map descriptorTable = repository.getDescriptorTable();
  @@ -83,44 +45,39 @@
               String baseClass = cld.getBaseClass();
               if (null != baseClass)
               {
  -                Vector v = new Vector();
  +                Vector inheritedFields = new Vector();
                   do
                   {
  -                    ClassDescriptor tempCld = repository.getDescriptorFor(baseClass);
  -                    FieldDescriptor[] fields = tempCld.getFieldDescriptions();
  -                    Vector pkFields = getPkFieldNames(tempCld);
  -                    for (int i = fields.length - 1; i >= 0; i--)
  +                    ClassDescriptor baseCld = repository.getDescriptorFor(baseClass);
  +                    FieldDescriptor[] baseFields = baseCld.getFieldDescriptions();
  +                    for (int i = baseFields.length - 1; i >= 0; i--)
                       {
  -                        FieldDescriptor f = fields[i];
  +                        FieldDescriptor f = baseFields[i];
                           if (!(f instanceof AnonymousFieldDescriptor))
                           {
  -                            PersistentField pf = f.getPersistentField();
  -                            if (!pkFields.contains(pf.getName()))
  -                            {
  -                                v.add(f.getPersistentField());
  -                            }
  +                            inheritedFields.add(f.getPersistentField());
                           }
                       }
  -                    Vector ords = tempCld.getObjectReferenceDescriptors();
  +                    Vector ords = baseCld.getObjectReferenceDescriptors();
                       for (int i = ords.size() - 1; i >= 0; i--)
                       {
                           ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) ords.get(i);
                           PersistentField pf = ord.getPersistentField();
                           if (!(pf instanceof AnonymousPersistentFieldForInheritance))
                           {
  -                            v.add(pf);
  +                            inheritedFields.add(pf);
                           }
                       }
  -                    Vector cds = tempCld.getCollectionDescriptors();
  +                    Vector cds = baseCld.getCollectionDescriptors();
                       for (int i = cds.size() - 1; i >= 0; i--)
                       {
                           CollectionDescriptor cd = (CollectionDescriptor) cds.get(i);
  -                        v.add(cd.getPersistentField());
  +                        inheritedFields.add(cd.getPersistentField());
                       }
  -                    baseClass = tempCld.getBaseClass();
  +                    baseClass = baseCld.getBaseClass();
                   }
                   while ((null != baseClass) && !(baseClass.equals(OBJECT)));
  -                cld.setSuperPersistentFieldDescriptors(v);
  +                cld.setSuperPersistentFieldDescriptors(inheritedFields);
               }
           }
       }
  
  
  
  1.18      +3 -2      db-ojb/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java
  
  Index: AbstractSequenceManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- AbstractSequenceManager.java	22 May 2004 10:03:02 -0000	1.17
  +++ AbstractSequenceManager.java	5 Jul 2004 08:37:41 -0000	1.18
  @@ -117,7 +117,8 @@
           if(seqName == null)
           {
               seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(), field,
useAutoNaming());
  -            if(useAutoNaming()) field.setSequenceName(seqName);
  +            // already done in method above
  +            // if(useAutoNaming()) field.setSequenceName(seqName);
           }
           return seqName;
       }
  
  
  
  1.18      +23 -1     db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java
  
  Index: SequenceManagerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SequenceManagerHelper.java	22 May 2004 10:03:02 -0000	1.17
  +++ SequenceManagerHelper.java	5 Jul 2004 08:37:41 -0000	1.18
  @@ -99,6 +99,10 @@
           }
   
           ClassDescriptor cldTargetClass = field.getClassDescriptor();
  +        /*
  +        check for inheritance on multiple table
  +        */
  +        cldTargetClass = findInheritanceRoot(brokerForClass, cldTargetClass);
           Class topLevel = brokerForClass.getTopLevelClass(cldTargetClass.getClassOfObject());
           ClassDescriptor cldTopLevel = brokerForClass.getClassDescriptor(topLevel);
           /**
  @@ -155,6 +159,24 @@
               field.setSequenceName(seqName);
           }
           return seqName;
  +    }
  +
  +    /**
  +     * Returns the root {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the inheriatance
  +     * hierachy of the given descriptor or the descriptor itself if no inheriatance on
multiple table is
  +     * used.
  +     * @see ClassDescriptor#getBaseClass()
  +     * @see ClassDescriptor#getSuperPersistentFieldDescriptors()
  +     */
  +    private static ClassDescriptor findInheritanceRoot(PersistenceBroker broker, ClassDescriptor
cld)
  +    {
  +        ClassDescriptor result = cld;
  +        if(cld.getBaseClass() != null)
  +        {
  +            ClassDescriptor baseCld = broker.getDescriptorRepository().getDescriptorFor(cld.getBaseClass());
  +            result = findInheritanceRoot(broker, baseCld);
  +        }
  +        return result;
       }
   
       /**
  
  
  

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


Mime
View raw message