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/metadata ClassDescriptor.java RepositoryXmlHandler.java SuperReferenceDescriptor.java
Date Sat, 07 May 2005 16:43:06 GMT
arminw      2005/05/07 09:43:06

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql Tag:
                        OJB_1_0_RELEASE SqlSelectStatement.java
               src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_1_0_RELEASE RowReaderDefaultImpl.java
                        StatementsForClassImpl.java
               src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        ClassDescriptor.java RepositoryXmlHandler.java
                        SuperReferenceDescriptor.java
  Log:
  - add TODO comment for inchoate "extends" attribute in class-descriptor, this stuff is not
working for a long time (years). Think we should discard the source code in classes.
  - update "super"-reference inheritance
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.22.2.3  +10 -3     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
  
  Index: SqlSelectStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java,v
  retrieving revision 1.22.2.2
  retrieving revision 1.22.2.3
  diff -u -r1.22.2.2 -r1.22.2.3
  --- SqlSelectStatement.java	22 Jan 2005 20:51:14 -0000	1.22.2.2
  +++ SqlSelectStatement.java	7 May 2005 16:43:05 -0000	1.22.2.3
  @@ -218,9 +218,12 @@
               
               orderByFields = query.getOrderBy();
               columnList = ensureColumns(orderByFields, columnList, stmt);
  -          
  +/*
  +arminw:
  +TODO: this feature doesn't work, so remove this in future
  +*/
               /**
  -             * treeder: going to map superclass tables here, 
  +             * treeder: going to map superclass tables here,
                * not sure about the columns, just using all columns for now
                */
               ClassDescriptor cld = super.getBaseClassDescriptor();
  @@ -250,6 +253,10 @@
           return stmt.toString();
       }
   
  +/*
  +arminw:
  +TODO: this feature doesn't work, so remove this in future
  +*/
       private void appendSuperClassJoin(ClassDescriptor cld, ClassDescriptor cldSuper, StringBuffer
stmt, StringBuffer where)
       {
           stmt.append(",").append(cldSuper.getFullTableName());
  
  
  
  No                   revision
  No                   revision
  1.30.2.3  +5 -1      db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
  
  Index: RowReaderDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java,v
  retrieving revision 1.30.2.2
  retrieving revision 1.30.2.3
  diff -u -r1.30.2.2 -r1.30.2.3
  --- RowReaderDefaultImpl.java	12 Sep 2004 00:50:49 -0000	1.30.2.2
  +++ RowReaderDefaultImpl.java	7 May 2005 16:43:05 -0000	1.30.2.3
  @@ -163,6 +163,10 @@
       public void readObjectArrayFrom(ResultSet rs, Map row)
       {
           FieldDescriptor[] fields = null;
  +/*
  +arminw:
  +TODO: this feature doesn't work, so remove this in future
  +*/
           if (m_cld.getSuperClass() != null)
           {
               /**
  
  
  
  1.22.2.4  +6 -6      db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java
  
  Index: StatementsForClassImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java,v
  retrieving revision 1.22.2.3
  retrieving revision 1.22.2.4
  diff -u -r1.22.2.3 -r1.22.2.4
  --- StatementsForClassImpl.java	26 Apr 2005 03:41:35 -0000	1.22.2.3
  +++ StatementsForClassImpl.java	7 May 2005 16:43:05 -0000	1.22.2.4
  @@ -119,7 +119,7 @@
           }
           catch (SQLException ex)
           {
  -            log.error(ex);
  +            log.error("Can't prepare delete statement: " + deleteSql, ex);
               throw ex;
           }
       }
  @@ -168,7 +168,7 @@
           }
           catch (SQLException ex)
           {
  -            log.error(ex);
  +            log.error("Can't prepare insert statement: " + insertSql, ex);
               throw ex;
           }
       }
  @@ -186,9 +186,9 @@
               stmt = prepareStatement(con, sql, scrollable,
                       createPreparedStatement, explicitFetchSizeHint);
           }
  -        catch (java.sql.SQLException ex)
  +        catch (SQLException ex)
           {
  -            log.error(ex);
  +            log.error("Can't prepare statement: " + sql, ex);
               throw new PersistenceBrokerSQLException(ex);
           }
           return stmt;
  @@ -238,7 +238,7 @@
           }
           catch (SQLException ex)
           {
  -            log.error(ex);
  +            log.error("Can't prepare update statement: " + updateSql, ex);
               throw ex;
           }
       }
  
  
  
  No                   revision
  No                   revision
  1.83.2.21 +5 -4      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.83.2.20
  retrieving revision 1.83.2.21
  diff -u -r1.83.2.20 -r1.83.2.21
  --- PersistenceBrokerImpl.java	28 Apr 2005 20:31:56 -0000	1.83.2.20
  +++ PersistenceBrokerImpl.java	7 May 2005 16:43:06 -0000	1.83.2.21
  @@ -890,7 +890,7 @@
           // get all members of obj that are references and store them
           Collection listRds = cld.getObjectReferenceDescriptors();
           // return if nothing to do
  -        if(listRds.size() == 0)
  +        if(listRds == null || listRds.size() == 0)
           {
               return;
           }
  @@ -920,9 +920,9 @@
           {
               if(rds.isSuperReferenceDescriptor())
               {
  -                ClassDescriptor superCld = getDescriptorRepository().getDescriptorFor(rds.getClassDescriptor().getBaseClass());
  -                Identity oid = serviceIdentity().buildIdentity(superCld, obj);
  -                storeToDb(obj, superCld, oid, insert);
  +                ClassDescriptor superCld = rds.getClassDescriptor().getSuperClassDescriptor();
  +                Identity oid = serviceIdentity().buildIdentity(superCld, ref);
  +                storeToDb(ref, superCld, oid, insert);
               }
               else store(ref);
           }
  @@ -1794,6 +1794,7 @@
           2. go down through heirarchy until current class
           3. todo: store to full extent?
   
  +// arminw: TODO: The extend-attribute feature dosn't work, should we remove this stuff?
           This if-clause will go up the inheritance heirarchy to store all the super classes.
           The id for the top most super class will be the id for all the subclasses too
            */
  
  
  
  No                   revision
  No                   revision
  1.88.2.15 +22 -4     db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.88.2.14
  retrieving revision 1.88.2.15
  diff -u -r1.88.2.14 -r1.88.2.15
  --- ClassDescriptor.java	22 Apr 2005 17:08:13 -0000	1.88.2.14
  +++ ClassDescriptor.java	7 May 2005 16:43:06 -0000	1.88.2.15
  @@ -168,6 +168,10 @@
        * the RowReader for this class
        */
       private RowReader m_rowReader = null;
  +/*
  +arminw:
  +TODO: this feature doesn't work, so remove/reuse this in future
  +*/
       /**
        * the class that this class extends
        */
  @@ -603,7 +607,15 @@
       {
           if (!m_superCldSet)
           {
  -            if(getBaseClass() != null) m_superCld = getRepository().getDescriptorFor(getBaseClass());
  +            if(getBaseClass() != null)
  +            {
  +                m_superCld = getRepository().getDescriptorFor(getBaseClass());
  +                if(m_superCld.isAbstract() || m_superCld.isInterface())
  +                {
  +                    throw new MetadataException("Super class mapping only work for real
class, but declared super class" +
  +                            " is an interface or is abstract. Declared class: " + m_superCld.getClassNameOfObject());
  +                }
  +            }
               m_superCldSet = true;
           }
   
  @@ -846,7 +858,10 @@
       {
           return getFieldDescriptorForPath(aPath, new HashMap());
       }
  -
  +/*
  +arminw:
  +TODO: this feature doesn't work, so remove this in future
  +*/
       /**
        *
        * @return this classes FieldDescriptor's as well as it's parents and so on and so
on
  @@ -1625,7 +1640,10 @@
                   }
           }
       }
  -
  +/*
  +arminw:
  +TODO: this feature doesn't work, so remove this in future
  +*/
       /**
        * Set name of the super class.
        */
  
  
  
  1.58.2.8  +2 -1      db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
  
  Index: RepositoryXmlHandler.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java,v
  retrieving revision 1.58.2.7
  retrieving revision 1.58.2.8
  diff -u -r1.58.2.7 -r1.58.2.8
  --- RepositoryXmlHandler.java	22 Apr 2005 17:08:13 -0000	1.58.2.7
  +++ RepositoryXmlHandler.java	7 May 2005 16:43:06 -0000	1.58.2.8
  @@ -265,6 +265,7 @@
                           }
   
                           // set if extends
  +// arminw: TODO: this feature doesn't work, remove this stuff?
                           String extendsAtt = atts.getValue(tags.getTagById(EXTENDS));
                           if (isDebug) logger.debug("     " + tags.getTagById(EXTENDS) +
": " + extendsAtt);
                           if (checkString(extendsAtt))
  
  
  
  1.1.2.2   +227 -128  db-ojb/src/java/org/apache/ojb/broker/metadata/Attic/SuperReferenceDescriptor.java
  
  Index: SuperReferenceDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/Attic/SuperReferenceDescriptor.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- SuperReferenceDescriptor.java	22 Apr 2005 17:08:14 -0000	1.1.2.1
  +++ SuperReferenceDescriptor.java	7 May 2005 16:43:06 -0000	1.1.2.2
  @@ -1,10 +1,14 @@
   package org.apache.ojb.broker.metadata;
   
   import java.util.List;
  +import java.util.Map;
  +import java.util.HashMap;
   
   import org.apache.commons.lang.SystemUtils;
   import org.apache.ojb.broker.metadata.fieldaccess.AnonymousPersistentField;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  +import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldFactory;
  +import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -32,15 +36,24 @@
    */
   public class SuperReferenceDescriptor extends ObjectReferenceDescriptor
   {
  +    private transient Logger log;
  +
       public static final String ANONYMOUS_NAME = null;
  +    static final String SUPER_FIELD_NAME = "super";
   
  -    private Boolean inheritedPK;
  +    private Boolean javaInheritance;
  +    private Map declaredInheritanceFields = new HashMap();
   
       public SuperReferenceDescriptor(ClassDescriptor descriptor)
       {
           super(descriptor);
           // most important call, create new specific field for inheritance
           super.setPersistentField(new SuperReferenceField(this));
  +        // needed immutable settings
  +        super.setLazy(false);
  +        super.setCascadeRetrieve(true);
  +        super.setCascadingStore(CASCADE_OBJECT);
  +        super.setCascadingDelete(CASCADE_OBJECT);
       }
   
       public boolean isSuperReferenceDescriptor()
  @@ -51,67 +64,12 @@
       public void setItemClass(Class c)
       {
           super.setItemClass(c);
  -        setCldBaseClass();
  -    }
  -
  -    private void setCldBaseClass()
  -    {
  -        String refClass = getItemClassName();
  -        Class actualClass = getClassDescriptor().getClassOfObject();
  -        String superClass = actualClass.getSuperclass().getName();
  -        if(superClass.equals(refClass))
  -        {
  -            if(getClassDescriptor().getBaseClass() != null)
  -            {
  -                throw new MetadataException("Multiple 'super reference descriptor' not
authorized in "
  -                        + actualClass.getName() + ", the base class was already set (currentBaseClass="
  -                        + getClassDescriptor().getBaseClass() + ", tryToSet=" + superClass
+ ")");
  -            }
  -            getClassDescriptor().setBaseClass(superClass);
  -        }
  -        else
  -        {
  -            if(superClass.equalsIgnoreCase(refClass))
  -            {
  -                throw new MetadataException("Classes name are case sensitive: super class
of '"
  -                        + actualClass.getName() + "' is '" + superClass + "' not '" + refClass
+ "'");
  -            }
  -            else
  -            {
  -                throw new MetadataException("Class '" + refClass + "' is not a superclass
of class '"
  -                        + actualClass.getName() + "'");
  -            }
  -        }
  -    }
  -
  -    public boolean isInheritedViaPK()
  -    {
  -        if(inheritedPK == null)
  -        {
  -            // get the FK fields of main class to check which kind of
  -            // "table per subclass" inheritance is used
  -            FieldDescriptor[] flds = getForeignKeyFieldDescriptors(getClassDescriptor());
  -            
  -            for(int i = 0; i < flds.length; i++)
  -            {
  -                FieldDescriptor fld = flds[i];
  -                if(fld.isPrimaryKey())
  -                {
  -                    inheritedPK = Boolean.TRUE;
  -                    break;
  -                }
  -            }
  -            if(inheritedPK == null)
  -            {
  -                inheritedPK = Boolean.FALSE;
  -            }
  -        }
  -        return inheritedPK.booleanValue();
  +        getClassDescriptor().setBaseClass(c.getName());
       }
   
       /**
        * Noop, a specific {@link org.apache.ojb.broker.metadata.fieldaccess.PersistentField}
is
  -     * used internal - {@link org.apache.ojb.broker.metadata.SuperReferenceDescriptor.SuperReferenceField}.
  +     * used internal - {@link org.apache.ojb.broker.metadata.SuperReferenceDescriptor_2.SuperReferenceField}.
        */
       public void setPersistentField(Class c, String fieldname)
       {
  @@ -120,18 +78,101 @@
   
       /**
        * Noop, a specific {@link org.apache.ojb.broker.metadata.fieldaccess.PersistentField}
is
  -     * used internal - {@link org.apache.ojb.broker.metadata.SuperReferenceDescriptor.SuperReferenceField}.
  +     * used internal - {@link org.apache.ojb.broker.metadata.SuperReferenceDescriptor_2.SuperReferenceField}.
        */
       public void setPersistentField(PersistentField pf)
       {
           // noop
       }
   
  +    public void setLazy(boolean lazy)
  +    {
  +        getLog().info("Not allowed to change this property, will ignore setting");
  +    }
  +
  +    public void setCascadeRetrieve(boolean b)
  +    {
  +        getLog().info("Not allowed to change this property, will ignore setting");
  +    }
  +
  +    public void setCascadingStore(int cascade)
  +    {
  +        getLog().info("Not allowed to change this property, will ignore setting");
  +    }
  +
  +    public void setCascadingStore(String value)
  +    {
  +        getLog().info("Not allowed to change this property, will ignore setting");
  +    }
  +
  +    public void setCascadingDelete(int cascade)
  +    {
  +        getLog().info("Not allowed to change this property, will ignore setting");
  +    }
  +
  +    public void setCascadingDelete(String value)
  +    {
  +        getLog().info("Not allowed to change this property, will ignore setting");
  +    }
  +
  +    public void setCascadeStore(boolean cascade)
  +    {
  +        getLog().info("Not allowed to change this property, will ignore setting");
  +    }
  +
  +    public void setCascadeDelete(boolean cascade)
  +    {
  +        getLog().info("Not allowed to change this property, will ignore setting");
  +    }
  +
       public SuperReferenceField getInheritanceField()
       {
           return (SuperReferenceField) getPersistentField();
       }
   
  +    /**
  +     * If this method returns <em>true</em> the inheritance described by this
object
  +     * is a <em>normal</em> JAVA inheritance. If <em>false</em>
the inheritance is only declared
  +     * in the O/R mapping it's a <em>declarative inheritance</em>, the referenced
"super class" in <strong>not</strong>
  +     * a JAVA super class of the main class.
  +     */
  +    public boolean isJavaInheritance()
  +    {
  +        if(javaInheritance == null)
  +        {
  +            javaInheritance = getClassDescriptor().getSuperClassDescriptor().getClassOfObject()
  +                    .isAssignableFrom(getClassDescriptor().getClassOfObject()) ? Boolean.TRUE
: Boolean.FALSE;
  +        }
  +        return javaInheritance.booleanValue();
  +    }
  +
  +    synchronized PersistentField getDeclaredInheritanceField(Class target, String name)
  +    {
  +        Map fields = (HashMap) declaredInheritanceFields.get(target);
  +        if(fields == null)
  +        {
  +            fields = new HashMap();
  +            declaredInheritanceFields.put(target, fields);
  +        }
  +        PersistentField pf = (PersistentField) fields.get(name);
  +        if(pf == null)
  +        {
  +            pf = PersistentFieldFactory.createPersistentField(target, name);
  +            // System.out.println("## tmp field: " + target + ", name: " + name + ", field:
" + pf);
  +            fields.put(name, pf);
  +        }
  +        return pf;
  +    }
  +
  +    private Logger getLog()
  +    {
  +        if(log == null)
  +        {
  +            log = LoggerFactory.getLogger(SuperReferenceField.class);
  +        }
  +        return log;
  +    }
  +
   
       //====================================================
       // inner class
  @@ -158,94 +199,152 @@
               return log;
           }
   
  -        void copySuperFields(Object target, Object source)
  +        /**
  +         * Field values of 'value' (base object) are copied to 'obj' (derived object)
  +         * then obj is saved in a map
  +         *
  +         * @param target - the base object instance
  +         * @param value  - the derived object instance
  +         * @throws MetadataException
  +         */
  +        public synchronized void set(Object target, Object value) throws MetadataException
           {
  -            if(getLog().isDebugEnabled())
  +            // System.out.println("target: " + target + " value: " + value);
  +            ClassDescriptor superCld = superRef.getClassDescriptor().getSuperClassDescriptor();
  +            if(superRef.isJavaInheritance())
               {
  -                String msg = ("Using descriptor " + superRef + ":" + SystemUtils.LINE_SEPARATOR
  -                        + "Copy fields from source object '" + source.getClass()
  -                        + "' to target object '" + target.getClass() + "'");
  -                getLog().debug(msg);
  +                copyFields(superCld, target, superCld, value, true, true);
               }
  -            ClassDescriptor superCld = superRef.getClassDescriptor().getSuperClassDescriptor();
  -            if(!source.getClass().isAssignableFrom(target.getClass()))
  +            else
  +            {
  +                copyFields(superRef.getClassDescriptor(), target, superCld, value, false,
false);
  +            }
  +        }
  +
  +        /**
  +         * Field values of specified 'obj' (the derived object) are copied to
  +         * 'value' (base object) then value is returned as a referenced object.
  +         * If the base object is the super class of the specified 'obj', then
  +         * return the specified object.
  +         * Else a base class instance will be created at runtime and the field values
  +         * from the derived object are copied to the base class object.
  +         *
  +         * @param obj - the base object instance
  +         * @throws MetadataException
  +         */
  +        public synchronized Object get(Object obj) throws MetadataException
  +        {
  +            if(obj == null) return null;
  +            if(superRef.isJavaInheritance())
  +            {
  +                return obj;
  +            }
  +            else
  +            {
  +                return getObjectWithDeclaredSuperClass(obj);
  +            }
  +        }
  +
  +        private Object getObjectWithDeclaredSuperClass(Object obj)
  +        {
  +            Object value = getFromFieldCache(obj);
  +            if(value == null)
  +            {
  +                ClassDescriptor baseCld = null;
  +                try
  +                {
  +                    baseCld = superRef.getClassDescriptor().getSuperClassDescriptor();
  +                    value = ClassHelper.buildNewObjectInstance(baseCld);
  +                }
  +                catch(Exception e)
  +                {
  +                    throw new MetadataException("Can't create new base class object for
'"
  +                            + (baseCld != null ? baseCld.getClassNameOfObject() : null)
+ "'", e);
  +                }
  +                copyFields(baseCld, value, superRef.getClassDescriptor(), obj, true, false);
  +                putToFieldCache(obj, value);
  +            }
  +            return value;
  +        }
  +
  +        void copyFields(ClassDescriptor targetCld, Object target, ClassDescriptor sourceCld,
Object source, boolean targetIsSuper, boolean javaInheritance)
  +        {
  +            if(getLog().isDebugEnabled())
               {
  -                throw new MetadataException("Expect the 'super class' of target object
class '"
  -                        + target.getClass() + ", but specified was class " + source.getClass());
  +                String msg = ("Copy fields from " + SystemUtils.LINE_SEPARATOR
  +                        + "source object '" + (source != null ? source.getClass().getName()
: null) + "'" + SystemUtils.LINE_SEPARATOR
  +                        + "using source fields declared in '" + sourceCld.getClassNameOfObject()
+ "'" + SystemUtils.LINE_SEPARATOR
  +                        + "to target object '" + (target != null ? target.getClass().getName()
: null) + "'" + SystemUtils.LINE_SEPARATOR
  +                        + "using target fields declared in '" + targetCld.getClassNameOfObject()
+ "'" + SystemUtils.LINE_SEPARATOR
  +                        + "the fields to copy are declared in '" + (targetIsSuper ? targetCld.getClassNameOfObject()
: sourceCld.getClassNameOfObject()) + "' class" + SystemUtils.LINE_SEPARATOR
  +                        + "the used classes are associated by java inheritance: " + javaInheritance
+ SystemUtils.LINE_SEPARATOR);
  +                getLog().debug(msg);
               }
  -            FieldDescriptor[] fields = superCld.getNonPkRwFields();
  +            /*
  +            arminw:
  +            If the target object is a super object of the source object, iterate all target
object fields.
  +            If the source object is a super object of the target object, iterate all source
object fields
  +
  +            If java inheritance is used (target is super class of source or vice versa)
we can use the same
  +            FieldDescriptor to copy the fields.
  +            If only a "declarative inheritance" is used (no class inheritance, only identical
field names of the super class)
  +            we have to use the associated FieldDescriptor of target and source ClassDescriptor
  +            */
  +            FieldDescriptor[] fields = targetIsSuper ? targetCld.getFieldDescriptions()
: sourceCld.getFieldDescriptions();
               for(int i = 0; i < fields.length; i++)
               {
                   FieldDescriptor field = fields[i];
  -                PersistentField pf = field.getPersistentField();
  -                if(getLog().isDebugEnabled()) getLog().debug("Set field '" + pf.getName()
+ "'");
  -                pf.set(target, pf.get(source));
  +                if(!field.isAnonymous())
  +                {
  +                    performFieldCopy(target,  targetCld, source, sourceCld,
  +                                field.getPersistentField(), targetIsSuper, javaInheritance);
  +                }
               }
  -            List refs = superCld.getCollectionDescriptors();
  +            List refs = targetIsSuper ? targetCld.getCollectionDescriptors() : sourceCld.getCollectionDescriptors();
               for(int i = 0; i < refs.size(); i++)
               {
                   CollectionDescriptor col = (CollectionDescriptor) refs.get(i);
                   PersistentField pf = col.getPersistentField();
  -                if(getLog().isDebugEnabled()) getLog().debug("Set field '" + pf.getName()
+ "'");
  -                pf.set(target, pf.get(source));
  +                performFieldCopy(target,  targetCld, source, sourceCld, pf, targetIsSuper,
javaInheritance);
               }
  -            refs = superCld.getObjectReferenceDescriptors();
  +
  +            refs = targetIsSuper ? targetCld.getObjectReferenceDescriptors() : sourceCld.getObjectReferenceDescriptors();
               for(int i = 0; i < refs.size(); i++)
               {
  -                ObjectReferenceDescriptor col = (ObjectReferenceDescriptor) refs.get(i);
  -                PersistentField pf = col.getPersistentField();
  -                if(getLog().isDebugEnabled()) getLog().debug("Set field '" + pf.getName()
+ "'");
  -                pf.set(target, pf.get(source));
  +                ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) refs.get(i);
  +                PersistentField pf = ord.getPersistentField();
  +                performFieldCopy(target,  targetCld, source, sourceCld, pf, targetIsSuper,
javaInheritance);
               }
           }
   
  -//        void XXXcopySuperFields(Object target, Object source)
  -//        {
  -//            System.out.println("## Set in " + target.getClass() + " fields of value class
" + source.getClass());
  -//            AttributeDescriptorBase[] fields = superRef.getClassDescriptor().getPersistentSuperFields();
  -//            for(int i = 0; i < fields.length; i++)
  -//            {
  -//                AttributeDescriptorBase field = fields[i];
  -//                // if we found another declared super inheritance, perform value settings
too
  -//                if(field instanceof ObjectReferenceDescriptor)
  -//                {
  -//                    if(((ObjectReferenceDescriptor) field).isSuperReferenceDescriptor())
  -//                    {
  -//                        ((SuperReferenceDescriptor) field).getInheritanceField().copySuperFields(target,
source);
  -//                    }
  -//                }
  -//                else
  -//                {
  -//                    PersistentField pf = field.getPersistentField();
  -//                    System.out.println("Set in " + target.getClass() + " value " + pf.get(source));
  -//                    pf.set(target, pf.get(source));
  -//                }
  -//            }
  -//        }
  -
  -        /**
  -         * Field values of 'value' (base object) are copied to 'obj' (derived object)
  -         * then obj is saved in a map
  -         *
  -         * @param target - the base object instance
  -         * @param value  - the derived object instance
  -         * @throws MetadataException
  -         */
  -        public synchronized void set(Object target, Object value) throws MetadataException
  +        private void performFieldCopy(Object target, ClassDescriptor targetCld, Object
source,
  +                                 ClassDescriptor sourceCld, PersistentField pf, boolean
targetIsSuper, boolean javaInheritance)
           {
  -            copySuperFields(target, value);
  -        }
  -
  -        /**
  -         * Field values of 'obj' (derived object) are copied to 'value' (base object)
  -         * then value is returned as a referenced object.
  -         *
  -         * @param obj - the base object instance
  -         * @throws MetadataException
  -         */
  -        public synchronized Object get(Object obj) throws MetadataException
  -        {
  -            return obj;
  +            if(javaInheritance)
  +            {
  +                pf.set(target, pf.get(source));
  +            }
  +            else
  +            {
  +                if(targetIsSuper)
  +                {
  +                    if(pf instanceof SuperReferenceField)
  +                    {
  +                        log.error("Declared inheritance doesn't support nested super references,
target '"
  +                                + targetCld.getClassNameOfObject() + "' has super reference");
  +                    }
  +                    else
  +                    {
  +                        PersistentField tmp = superRef.getDeclaredInheritanceField(sourceCld.getClassOfObject(),
pf.getName());
  +                        pf.set(target, tmp.get(source));
  +                    }
  +                }
  +                else
  +                {
  +                    PersistentField tmp = superRef.getDeclaredInheritanceField(targetCld.getClassOfObject(),
pf.getName());
  +                    tmp.set(target, pf.get(source));
  +                }
  +            }
           }
       }
   }
  
  
  

---------------------------------------------------------------------
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