arminw      2005/08/14 09:00:34

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql Tag:
                        OJB_1_0_RELEASE SqlQueryStatement.java
               src/java/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        ClassDescriptor.java DescriptorRepository.java
                        RepositoryXmlHandler.java
                        SuperReferenceDescriptor.java
  Removed:     src/java/org/apache/ojb/broker/metadata/fieldaccess Tag:
                        OJB_1_0_RELEASE
                        AnonymousPersistentFieldForInheritance.java
                        AnonymousPersistentFieldHelper.java
               src/java/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        AnonymousObjectReferenceDescriptor.java
  Log:
  Map class on multiple joined table: enhance use of new "super"-reference 
handling, add methods needed to solve OJB-63, remove unused 'old' 
"super"-reference classes
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.75.2.9  +24 -64    
db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
  
  Index: SqlQueryStatement.java
  ===================================================================
  RCS file: 
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
  retrieving revision 1.75.2.8
  retrieving revision 1.75.2.9
  diff -u -r1.75.2.8 -r1.75.2.9
  --- SqlQueryStatement.java    10 Jun 2005 16:47:06 -0000      1.75.2.8
  +++ SqlQueryStatement.java    14 Aug 2005 16:00:33 -0000      1.75.2.9
  @@ -31,6 +31,7 @@
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.FieldHelper;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  +import org.apache.ojb.broker.metadata.SuperReferenceDescriptor;
   import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.query.BetweenCriteria;
   import org.apache.ojb.broker.query.Criteria;
  @@ -170,7 +171,7 @@
        protected AttributeInfo getAttributeInfo(String attr, boolean 
useOuterJoins, UserAlias aUserAlias, Map pathClasses)
        {
                AttributeInfo result = new AttributeInfo();
  -             TableAlias tableAlias = null;
  +             TableAlias tableAlias;
                SqlHelper.PathInfo pathInfo = SqlHelper.splitPath(attr);
                String colName = pathInfo.column;
                int sp;
  @@ -228,19 +229,14 @@
        * if translate try to convert attribute name into column name otherwise 
use attribute name<br>
        * if a FieldDescriptor is found for the attribute name the column name 
is taken from
        * there prefixed with the alias (firstname -> A0.F_NAME).
  -     *
  -     * @param aTableAlias
  -     * @param aPathInfo
  -     * @param translate
  -     * @return
        */
       protected String getColName(TableAlias aTableAlias, PathInfo aPathInfo, 
boolean translate)
       {
  -        FieldDescriptor fld = null;
           String result = null;
   
           if (translate)
           {
  +            FieldDescriptor fld;
               // translate attribute name into column name
               fld = getFieldDescriptor(aTableAlias, aPathInfo);
   
  @@ -354,10 +350,7 @@
       }
   
       /**
  -     * get FieldDescriptor from joined superclass
  -     * @param aTableAlias
  -     * @param aColName
  -     * @return
  +     * Get FieldDescriptor from joined superclass.
        */
       private FieldDescriptor getFldFromJoin(TableAlias aTableAlias, String 
aColName)
       {
  @@ -388,9 +381,6 @@
   
       /**
        * Get FieldDescriptor from Reference
  -     * @param aTableAlias
  -     * @param anOrd
  -     * @return
        */
       private FieldDescriptor getFldFromReference(TableAlias aTableAlias, 
ObjectReferenceDescriptor anOrd)
       {
  @@ -431,12 +421,6 @@
        * field names in functions (ie: sum(name) ) are tried to resolve
        * ie: name from FIELDDESCRIPTOR , UPPER(name_test) from Criteria<br>
        * also resolve pathExpression adress.city or owner.konti.saldo
  -     *
  -     * @param attr
  -     * @param useOuterJoins
  -     * @param aUserAlias
  -     * @param buf
  -     * @return
        */
        protected boolean appendColName(String attr, boolean useOuterJoins, 
UserAlias aUserAlias, StringBuffer buf)
       {
  @@ -453,13 +437,6 @@
        * field names in functions (ie: sum(name) ) are tried to resolve
        * ie: name from FIELDDESCRIPTOR , UPPER(name_test) from Criteria<br>
        * also resolve pathExpression adress.city or owner.konti.saldo
  -     *
  -     * @param attr
  -     * @param attrAlias column alias
  -     * @param useOuterJoins
  -     * @param aUserAlias
  -     * @param buf
  -     * @return
        */
        protected boolean appendColName(String attr, String attrAlias, boolean 
useOuterJoins, UserAlias aUserAlias,
               StringBuffer buf)
  @@ -617,9 +594,7 @@
       }
   
       /**
  -     * create SQL-String based on Criteria
  -     * @param crit
  -     * @return
  +     * Create SQL-String based on Criteria
        */
       private String asSQLStatement(Criteria crit)
       {
  @@ -1011,14 +986,14 @@
                String attr, attrPath = null;
                ObjectReferenceDescriptor ord;
                CollectionDescriptor cod;
  -             ClassDescriptor cld = null;
  -             Object[] prevKeys = null;
  -             Object[] keys = null;
  +             ClassDescriptor cld;
  +             Object[] prevKeys;
  +             Object[] keys;
                ArrayList descriptors;
                boolean outer = useOuterJoins;
                int pathLength;
   
  -             String pathAlias = aUserAlias == null ? null : 
aUserAlias.getAlias(aPath); 
  +             String pathAlias = aUserAlias == null ? null : 
aUserAlias.getAlias(aPath);
                curr = getTableAliasForPath(aPath, pathAlias);
   
                if (curr != null)
  @@ -1139,7 +1114,7 @@
                                }
                        }
   
  -                     pathAlias = aUserAlias == null ? null : 
aUserAlias.getAlias(attrPath); 
  +                     pathAlias = aUserAlias == null ? null : 
aUserAlias.getAlias(attrPath);
                        curr = getTableAliasForPath(attrPath, pathAlias);
   
                        if (curr == null)
  @@ -1228,10 +1203,7 @@
       }
   
       /**
  -     * Get the FieldDescriptors of the extent based on the FieldDescriptors 
of the parent
  -     * @param extAlias
  -     * @param fds
  -     * @return
  +     * Get the FieldDescriptors of the extent based on the FieldDescriptors 
of the parent.
        */
       private FieldDescriptor[] getExtentFieldDescriptors(TableAlias extAlias, 
FieldDescriptor[] fds)
       {
  @@ -1355,9 +1327,7 @@
       }
   
       /**
  -     * Answer the TableAlias for ClassDescriptor
  -     * @param aCld
  -     * @return
  +     * Answer the TableAlias for ClassDescriptor.
        */
       private TableAlias getTableAliasForClassDescriptor(ClassDescriptor aCld)
       {
  @@ -1665,25 +1635,19 @@
        */
       protected void buildSuperJoinTree(TableAlias left, ClassDescriptor cld, 
String name, boolean useOuterJoin)
       {
  -        Iterator objRefs = cld.getObjectReferenceDescriptors().iterator();
  -        while (objRefs.hasNext())
  +        ClassDescriptor superCld = cld.getSuperClassDescriptor();
  +        if (superCld != null)
           {
  -            ObjectReferenceDescriptor objRef = (ObjectReferenceDescriptor) 
objRefs.next();
  -            FieldDescriptor[] leftFields = 
objRef.getForeignKeyFieldDescriptors(cld);
  +            SuperReferenceDescriptor superRef = cld.getSuperReference();
  +            FieldDescriptor[] leftFields = 
superRef.getForeignKeyFieldDescriptors(cld);
  +            TableAlias base_alias = getTableAliasForPath(name, null);
  +            String aliasName = String.valueOf(getAliasChar()) + 
m_aliasCount++;
  +            TableAlias right = new TableAlias(superCld, aliasName, 
useOuterJoin, null);
   
  -            ClassDescriptor refCld = 
cld.getRepository().getDescriptorFor(objRef.getItemClassName());
  -            if (objRef.isSuperReferenceDescriptor())
  -            {
  -                TableAlias base_alias = getTableAliasForPath(name, null);
  -
  -                String aliasName = String.valueOf(getAliasChar()) + 
m_aliasCount++;
  -                TableAlias right = new TableAlias(refCld, aliasName, 
useOuterJoin, null);
  +            Join join1to1 = new Join(left, leftFields, right, 
superCld.getPkFields(), false, "superClass");
  +            base_alias.addJoin(join1to1);
   
  -                Join join1to1 = new Join(left, leftFields, right, 
refCld.getPkFields(), false, "superClass");
  -                base_alias.addJoin(join1to1);
  -
  -                buildSuperJoinTree(right, refCld, name, useOuterJoin);
  -            }
  +            buildSuperJoinTree(right, superCld, name, useOuterJoin);
           }
       }
   
  @@ -1909,9 +1873,7 @@
   
           /**
            * Copy the Alias and all it's extents adding a Postfix
  -         * Joins are not copied
  -         * @param aPostfix
  -         * @return
  +         * Joins are not copied.
            */
           TableAlias copy(String aPostfix)
           {
  @@ -1957,8 +1919,6 @@
   
           /**
            * Get the Join ponting to anAlias.
  -         * @param anAlias
  -         * @return
            */
           Join getJoin(TableAlias anAlias)
           {
  
  
  
  No                   revision
  No                   revision
  1.88.2.18 +68 -47    
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.17
  retrieving revision 1.88.2.18
  diff -u -r1.88.2.17 -r1.88.2.18
  --- ClassDescriptor.java      9 Aug 2005 20:03:22 -0000       1.88.2.17
  +++ ClassDescriptor.java      14 Aug 2005 16:00:33 -0000      1.88.2.18
  @@ -67,6 +67,7 @@
   
       private static final long serialVersionUID = -5212253607374173965L;
   
  +    public static final String DYNAMIC_STR = "dynamic";
       public static final String OJB_CONCRETE_CLASS = "ojbConcreteClass";
       private static final Class[] NO_PARAMS = {};
   
  @@ -156,7 +157,7 @@
        * the table name used to store the scalar attributes of this class
        */
       private String m_TableName = null;
  -    private Vector superPersistentFieldDescriptors = null;
  +//    private Vector superPersistentFieldDescriptors = null;
       /**
        * the RowReader for this class
        */
  @@ -251,7 +252,7 @@
       private Map m_fieldDescriptorNameMap = null;
       private Map m_collectionDescriptorNameMap = null;
       private Map m_objectReferenceDescriptorsNameMap = null;
  -    
  +
       // BRJ: ClassDescriptor referenced by 'super' ObjectReferenceDescriptor
       private ClassDescriptor m_superCld = null;
       private boolean m_superCldSet = false;
  @@ -284,17 +285,27 @@
       public void setBaseClass(String baseClass)
       {
           this.baseClass = baseClass;
  -    }
  -
  -    public void setSuperPersistentFieldDescriptors(Vector 
superPersistentFieldDescriptors)
  -    {
  -        this.superPersistentFieldDescriptors = 
superPersistentFieldDescriptors;
  -    }
  -
  -    public Vector getSuperPersistentFieldDescriptors()
  -    {
  -        return superPersistentFieldDescriptors;
  -    }
  +        // first deregister
  +        getRepository().deregisterSuperClassMultipleJoinedTables(this);
  +        // register classes using mapping of classes to multiple joined 
tables
  +        getRepository().registerSuperClassMultipleJoinedTables(this);
  +    }
  +
  +//    /**
  +//     * @deprecated no longer needed map class on multi joined table
  +//     */
  +//    public void setSuperPersistentFieldDescriptors(Vector 
superPersistentFieldDescriptors)
  +//    {
  +//        this.superPersistentFieldDescriptors = 
superPersistentFieldDescriptors;
  +//    }
  +//
  +//    /**
  +//     * @deprecated no longer needed map class on multi joined table
  +//     */
  +//    public Vector getSuperPersistentFieldDescriptors()
  +//    {
  +//        return superPersistentFieldDescriptors;
  +//    }
   
       /**
        * Returns the appropriate [EMAIL PROTECTED] ObjectCacheDescriptor}
  @@ -499,15 +510,10 @@
        */
       public ObjectReferenceDescriptor 
getObjectReferenceDescriptorByName(String name)
       {
  -        if (name == null)
  -        {
  -            return null;
  -        }
  -
  -        ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) 
  +        ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor)
               getObjectReferenceDescriptorsNameMap().get(name);
  -        
  -        // 
  +
  +        //
           // BRJ: if the ReferenceDescriptor is not found
           // look in the ClassDescriptor referenced by 'super' for it
           //
  @@ -539,7 +545,7 @@
   
           return m_objectReferenceDescriptorsNameMap;
       }
  -    
  +
       /**
        * Get an CollectionDescriptor by name  BRJ
        * @param name
  @@ -554,7 +560,7 @@
   
           CollectionDescriptor cod  = (CollectionDescriptor) 
getCollectionDescriptorNameMap().get(name);
   
  -        // 
  +        //
           // BRJ: if the CollectionDescriptor is not found
           // look in the ClassDescriptor referenced by 'super' for it
           //
  @@ -584,7 +590,7 @@
               }
               m_collectionDescriptorNameMap = nameMap;
           }
  -        
  +
           return m_collectionDescriptorNameMap;
       }
   
  @@ -610,7 +616,7 @@
   
           return m_superCld;
       }
  -    
  +
       /**
        * add an Extent class to the current descriptor
        * @param newExtendClass
  @@ -732,11 +738,10 @@
           }
           return proxyClass;
       }
  -    
  +
       public boolean isDynamicProxy()
       {
  -        String dynamic = "dynamic";
  -        return dynamic.equalsIgnoreCase(proxyClassName);
  +        return DYNAMIC_STR.equalsIgnoreCase(proxyClassName);
       }
   
       /**
  @@ -945,8 +950,7 @@
           ValueContainer[] result = new ValueContainer[fields.length];
           for (int i = 0; i < result.length; i++)
           {
  -            ValueContainer vc = new 
ValueContainer(fields[i].getPersistentField().get(o), fields[i].getJdbcType());
  -            result[i] = vc;
  +            result[i] = new 
ValueContainer(fields[i].getPersistentField().get(o), fields[i].getJdbcType());
           }
           return result;
       }
  @@ -966,9 +970,7 @@
               if (fmd.isUpdateLock())
               {
                   PersistentField f = fmd.getPersistentField();
  -                Object cv = null;
  -                cv = f.get(obj);
  -
  +                Object cv = f.get(obj);
                   // int
                   if ((f.getType() == int.class) || (f.getType() == 
Integer.class))
                   {
  @@ -1037,7 +1039,6 @@
           {
               // 1. collect all Primary Key fields from Field list
               Vector vec = new Vector();
  -            FieldDescriptor[] fields = null;
               // 1.a if descriptor describes an interface: take PK fields from 
an implementors ClassDescriptor
               if (m_isInterface)
               {
  @@ -1053,6 +1054,7 @@
               }
               else
               {
  +                FieldDescriptor[] fields;
                   // 1.b if not an interface The classdescriptor must have 
FieldDescriptors
                   fields = getFieldDescriptions();
                   // now collect all PK fields
  @@ -1170,7 +1172,7 @@
           return getLockingFields().length > 0;
       }
   
  -    
  +
       /**
        * return all AttributeDescriptors for the path<br>
        * ie: partner.addresses.street returns a Collection of 3 
AttributeDescriptors
  @@ -1214,13 +1216,13 @@
       {
           ArrayList result = new ArrayList();
           ClassDescriptor cld = this;
  -        ObjectReferenceDescriptor ord = null;
  -        FieldDescriptor fld = null;
  +        ObjectReferenceDescriptor ord;
  +        FieldDescriptor fld;
           String currPath = aPath;
           String segment;
           StringBuffer processedSegment = new StringBuffer();
           int sepPos;
  -        Class itemClass = null;
  +        Class itemClass;
   
           while (currPath.length() > 0)
           {
  @@ -1235,12 +1237,12 @@
                   segment = currPath;
                   currPath = "";
               }
  -            
  +
               if (processedSegment.length() > 0)
               {
                   processedSegment.append(".");
  -            }           
  -            processedSegment.append(segment); 
  +            }
  +            processedSegment.append(segment);
   
               // look for 1:1 or n:1 Relationship
               ord = cld.getObjectReferenceDescriptorByName(segment);
  @@ -1253,7 +1255,7 @@
               if (ord != null)
               {
                   // BRJ : look for hints for the processed segment
  -                // ie: ref pointng to ClassA and ref.ref pointing to ClassC 
  +                // ie: ref pointng to ClassA and ref.ref pointing to ClassC
                   List hintClasses = (List) 
pathHints.get(processedSegment.toString());
                   if (hintClasses != null && hintClasses.get(0) != null)
                   {
  @@ -1376,7 +1378,7 @@
            if (isDynamicProxy())   // tomdz: What about VirtualProxy ?
               {
                result.append( "    ");
  -                result.append( tags.getAttribute(CLASS_PROXY, "dynamic"));
  +                result.append( tags.getAttribute(CLASS_PROXY, DYNAMIC_STR));
                   result.append( eol );
            }
               else
  @@ -1701,7 +1703,6 @@
   
       /**
        * Method declaration
  -     * @return
        */
       private String getTableName()
       {
  @@ -2082,7 +2083,10 @@
   
   
       /**
  -     * @param pfClassName
  +     * Optional! Set the [EMAIL PROTECTED] 
org.apache.ojb.broker.metadata.fieldaccess.PersistentField}
  +     * implementation class used by this class.
  +     * @param pfClassName The full qualified class name of the
  +     * [EMAIL PROTECTED] 
org.apache.ojb.broker.metadata.fieldaccess.PersistentField}.
        */
       public void setPersistentFieldClassName(String pfClassName)
       {
  @@ -2091,7 +2095,8 @@
   
   
       /**
  -     * @return
  +     * Get the used [EMAIL PROTECTED] 
org.apache.ojb.broker.metadata.fieldaccess.PersistentField}
  +     * implementation name.
        */
       public String getPersistentFieldClassName()
       {
  @@ -2173,6 +2178,10 @@
       {
           if(withInherited && getSuperClassDescriptor() != null)
           {
  +            /*
  +            arminw: only return no-PK fields, because all PK fields are 
declared
  +            in sub-class too.
  +            */
               FieldDescriptor[] superFlds = 
getSuperClassDescriptor().getFieldDescriptorNonPk(true);
               if(m_FieldDescriptions == null)
               {
  @@ -2212,4 +2221,16 @@
               return getNonPkFields();
           }
       }
  +
  +    /**
  +     * Returns the [EMAIL PROTECTED] SuperReferenceDescriptor} of this class 
or <em>null</em>
  +     * if none was used.
  +     *
  +     * @return The reference descriptor for the <em>super</em>-reference or 
<em>null</em>
  +     * if not exists.
  +     */
  +    public SuperReferenceDescriptor getSuperReference()
  +    {
  +        return (SuperReferenceDescriptor) 
getObjectReferenceDescriptorByName(SuperReferenceDescriptor.SUPER_FIELD_INTERNAL_NAME);
  +    }
   }
  
  
  
  1.50.2.7  +148 -5    
db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
  
  Index: DescriptorRepository.java
  ===================================================================
  RCS file: 
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java,v
  retrieving revision 1.50.2.6
  retrieving revision 1.50.2.7
  diff -u -r1.50.2.6 -r1.50.2.7
  --- DescriptorRepository.java 4 Mar 2005 00:15:09 -0000       1.50.2.6
  +++ DescriptorRepository.java 14 Aug 2005 16:00:33 -0000      1.50.2.7
  @@ -26,6 +26,7 @@
   import org.apache.ojb.broker.locking.IsolationLevels;
   import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.ojb.broker.util.logging.Logger;
   
   /**
    * The repository containing all object mapping and manipulation information 
of
  @@ -41,7 +42,9 @@
   public final class DescriptorRepository extends DescriptorBase
           implements Serializable, XmlCapable, IsolationLevels
   {
  -     static final long serialVersionUID = -1556339982311359524L;
  +    static final long serialVersionUID = -1556339982311359524L;
  +    private Logger log = LoggerFactory.getLogger(DescriptorRepository.class);
  +
       /**
        * The version identifier of the Repository.
        * Used to validate repository.xml against the dtd.
  @@ -55,7 +58,7 @@
        * This table holds all known Mapping descriptions.
        * Key values are the respective Class objects
        */
  -    private HashMap descriptorTable;
  +    private final HashMap descriptorTable;
       /**
        * We need a lot the extent, to which a class belongs
        * (@see DescriptorRepository#getExtentClass). To speed up the costy
  @@ -63,6 +66,8 @@
        */
       private Map extentTable;
   
  +    private Map superClassMultipleJoinedTablesMap;
  +
       private transient Map m_multiMappedTableMap;
       private transient Map m_topLevelClassTable;
       private transient Map m_firstConcreteClassMap;
  @@ -75,6 +80,7 @@
       {
           descriptorTable = new HashMap();
           extentTable = new HashMap();
  +        superClassMultipleJoinedTablesMap = new HashMap();
       }
   
       public static String getVersion()
  @@ -187,7 +193,7 @@
           {
               m_multiMappedTableMap = new HashMap();
           }
  -        
  +
           FieldDescriptor[] retval = (FieldDescriptor[]) 
m_multiMappedTableMap.get(targetCld.getClassNameOfObject());
           if (retval == null)
           {
  @@ -465,6 +471,9 @@
                       removeExtent(((Class) extentClasses.get(i)).getName());
                   }
                   changeDescriptorEvent();
  +                // deregister classes using mapping of classes to multiple 
joined tables
  +                // the registration is done by the class-descriptor itself
  +                deregisterSuperClassMultipleJoinedTables(cld);
               }
           }
       }
  @@ -657,8 +666,142 @@
           return result;
       }
   
  +    /**
  +     * Internal used! Register sub-classes of specified class when mapping 
class to
  +     * multiple joined tables is used. Normally this method is called by the 
[EMAIL PROTECTED] ClassDescriptor}
  +     * itself.
  +     *
  +     * @param cld The [EMAIL PROTECTED] ClassDescriptor} of the class to 
register.
  +     */
  +    protected void registerSuperClassMultipleJoinedTables(ClassDescriptor 
cld)
  +    {
  +        /*
  +        arminw: Sadly, we can't map to sub class-descriptor, because it's 
not guaranteed
  +        that they exist when this method is called. Thus we map the class 
instance instead
  +        of the class-descriptor.
  +        */
  +        if(cld.getBaseClass() != null)
  +        {
  +            try
  +            {
  +                Class superClass = ClassHelper.getClass(cld.getBaseClass());
  +                Class currentClass = cld.getClassOfObject();
  +                synchronized(descriptorTable)
  +                {
  +                    List subClasses = (List) 
superClassMultipleJoinedTablesMap.get(superClass);
  +                    if(subClasses == null)
  +                    {
  +                        subClasses = new ArrayList();
  +                        superClassMultipleJoinedTablesMap.put(superClass,  
subClasses);
  +                    }
  +                    if(!subClasses.contains(currentClass))
  +                    {
  +                        if(log.isDebugEnabled())
  +                        {
  +                            log.debug("(MultipleJoinedTables): Register 
sub-class '" + currentClass
  +                                    + "' for class '" + superClass);
  +                        }
  +                        subClasses.add(currentClass);
  +                    }
  +                }
  +            }
  +            catch(Exception e)
  +            {
  +                throw new MetadataException("Can't register super class '" + 
cld.getBaseClass()
  +                        + "' for class-descriptor: " + cld, e);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Internal used! Deregister sub-classes of specified class when mapping 
to multiple joined tables
  +     * is used. Normally this method is called when [EMAIL PROTECTED] 
#remove(Class)} a class.
  +     *
  +     * @param cld The [EMAIL PROTECTED] ClassDescriptor} of the class to 
register.
  +     */
  +    protected void deregisterSuperClassMultipleJoinedTables(ClassDescriptor 
cld)
  +    {
  +        try
  +        {
  +            Class currentClass = cld.getClassOfObject();
  +            synchronized(descriptorTable)
  +            {
  +                // first remove registered sub-classes for current class
  +                List subClasses = (List) 
superClassMultipleJoinedTablesMap.remove(currentClass);
  +                if(subClasses != null && log.isDebugEnabled())
  +                {
  +                    log.debug("(MultipleJoinedTables): Deregister class " + 
currentClass
  +                            + " with sub classes " + subClasses);
  +                }
  +                if(cld.getBaseClass() != null)
  +                {
  +                    // then remove sub-class entry of current class for 
super-class
  +                    Class superClass = 
ClassHelper.getClass(cld.getBaseClass());
  +                    subClasses = (List) 
superClassMultipleJoinedTablesMap.get(superClass);
  +                    if(subClasses != null)
  +                    {
  +                        boolean removed = subClasses.remove(currentClass);
  +                        if(removed && log.isDebugEnabled())
  +                        {
  +                            log.debug("(MultipleJoinedTables): Remove 
sub-class entry '" + currentClass
  +                            + "' in mapping for class '" + superClass + "'");
  +                        }
  +                    }
  +                }
  +            }
  +        }
  +        catch(Exception e)
  +        {
  +            throw new MetadataException("Can't deregister super class '" + 
cld.getBaseClass()
  +                    + "' for class-descriptor: " + cld, e);
  +        }
  +    }
  +
  +    /**
  +     * Return <em>sub-classes</em> of the specified class using the
  +     * <em>"super"-Reference</em> concept.
  +     * @param cld The [EMAIL PROTECTED] ClassDescriptor} of the class to 
search for sub-classes.
  +     * @param wholeTree If set <em>true</em>, the whole sub-class tree of 
the specified
  +     * class will be returned. If <em>false</em> only the direct sub-classes 
of the specified class
  +     * will be returned.
  +     * @return An array of <em>sub-classes</em> for the specified class.
  +     */
  +    public Class[] getSubClassesMultipleJoinedTables(ClassDescriptor cld, 
boolean wholeTree)
  +    {
  +        ArrayList result = new ArrayList();
  +        createResultSubClassesMultipleJoinedTables(result, cld, wholeTree);
  +        return (Class[]) result.toArray(new Class[result.size()]);
  +    }
  +
  +    /**
  +     * Add all sub-classes using multiple joined tables feature for 
specified class.
  +     * @param result The list to add results.
  +     * @param cld The [EMAIL PROTECTED] ClassDescriptor} of the class to 
search for sub-classes.
  +     * @param wholeTree If set <em>true</em>, the whole sub-class tree of 
the specified
  +     * class will be returned. If <em>false</em> only the direct sub-classes 
of the specified class
  +     * will be returned.
  +     */
  +    private void createResultSubClassesMultipleJoinedTables(List result, 
ClassDescriptor cld, boolean wholeTree)
  +    {
  +        List tmp = (List) 
superClassMultipleJoinedTablesMap.get(cld.getClassOfObject());
  +        if(tmp != null)
  +        {
  +            result.addAll(tmp);
  +            if(wholeTree)
  +            {
  +                for(int i = 0; i < tmp.size(); i++)
  +                {
  +                    Class subClass = (Class) tmp.get(i);
  +                    ClassDescriptor subCld = getDescriptorFor(subClass);
  +                    createResultSubClassesMultipleJoinedTables(result, 
subCld, wholeTree);
  +                }
  +            }
  +        }
  +    }
  +
       protected void finalize() throws Throwable
       {
  -        LoggerFactory.getDefaultLogger().info("# finalize 
DescriptorRepository instance #");
  +        log.info("# finalize DescriptorRepository instance #");
  +        super.finalize();
       }
   }
  
  
  
  1.58.2.9  +10 -12    
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.8
  retrieving revision 1.58.2.9
  diff -u -r1.58.2.8 -r1.58.2.9
  --- RepositoryXmlHandler.java 7 May 2005 16:43:06 -0000       1.58.2.8
  +++ RepositoryXmlHandler.java 14 Aug 2005 16:00:33 -0000      1.58.2.9
  @@ -200,8 +200,6 @@
                           try
                           {
                               
m_CurrentCLD.setClassOfObject(ClassHelper.getClass(classname));
  -                            // put cld to the metadata repository
  -                            m_repository.put(classname, m_CurrentCLD);
                           }
                           catch (ClassNotFoundException e)
                           {
  @@ -225,9 +223,9 @@
                           if (isDebug) logger.debug("     " + 
tags.getTagById(CLASS_PROXY) + ": " + proxy);
                           if (checkString(proxy))
                           {
  -                            if (proxy.equalsIgnoreCase("dynamic"))
  +                            if 
(proxy.equalsIgnoreCase(ClassDescriptor.DYNAMIC_STR))
                               {
  -                                m_CurrentCLD.setProxyClassName("dynamic");
  +                                
m_CurrentCLD.setProxyClassName(ClassDescriptor.DYNAMIC_STR);
                               }
                               else
                               {
  @@ -314,11 +312,14 @@
                           b = (Boolean.valueOf(refresh)).booleanValue();
                           m_CurrentCLD.setAlwaysRefresh(b);
   
  -                                             // persistent field
  +                        // TODO: remove this or make offical feature
  +                        // persistent field
                                                String pfClassName = 
atts.getValue("persistent-field-class");
                                                if (isDebug) logger.debug("     
persistent-field-class: " + pfClassName);
                                                
m_CurrentCLD.setPersistentFieldClassName(pfClassName);
   
  +                        // put cld to the metadata repository
  +                        m_repository.put(classname, m_CurrentCLD);
                           break;
                       }
                   case OBJECT_CACHE:
  @@ -488,7 +489,7 @@
                           String classRef = 
atts.getValue(tags.getTagById(REFERENCED_CLASS));
                           if (isDebug) logger.debug("     " + 
tags.getTagById(REFERENCED_CLASS) + ": " + classRef);
   
  -                        ObjectReferenceDescriptor ord = null;
  +                        ObjectReferenceDescriptor ord;
                           if (name.equals(TAG_SUPER))
                           {
                               // no longer needed sine 
SuperReferenceDescriptor was used
  @@ -904,15 +905,12 @@
                       }
                   case CONSTANT_ARGUMENT:
                       {
  -                        String value = null;
  -
                           if (isDebug) logger.debug("    > " + 
tags.getTagById(CONSTANT_ARGUMENT));
                           ArgumentDescriptor arg = new 
ArgumentDescriptor(m_CurrentProcedure);
   
                           // Get the value
  -                        value = atts.getValue(tags.getTagById(VALUE));
  -                        if (isDebug) logger.debug("     " + 
tags.getTagById(VALUE) +
  -                                                  ": " + value);
  +                        String value = atts.getValue(tags.getTagById(VALUE));
  +                        if (isDebug) logger.debug("     " + 
tags.getTagById(VALUE) + ": " + value);
   
                           // Set the value for the argument
                           arg.setValue(value);
  
  
  
  1.1.2.5   +3 -3      
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.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- SuperReferenceDescriptor.java     24 Jul 2005 23:32:43 -0000      1.1.2.4
  +++ SuperReferenceDescriptor.java     14 Aug 2005 16:00:33 -0000      1.1.2.5
  @@ -38,7 +38,7 @@
   {
       private transient Logger log;
   
  -    public static final String ANONYMOUS_NAME = null;
  +    public static final String SUPER_FIELD_INTERNAL_NAME = 
"ojbSuperFieldInternal";
       public static final String SUPER_FIELD_NAME = 
RepositoryElements.TAG_SUPER;
   
       private Boolean javaInheritance;
  @@ -186,7 +186,7 @@
   
           public SuperReferenceField(SuperReferenceDescriptor superRef)
           {
  -            super(ANONYMOUS_NAME);
  +            super(SUPER_FIELD_INTERNAL_NAME);
               this.superRef = superRef;
           }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to