db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject cvs commit: db-ojb/src/xdoclet/java/src/xdoclet/modules/ojb/model TableDef.java TorqueModelDef.java
Date Thu, 17 Mar 2005 23:49:10 GMT
tomdz       2005/03/17 15:49:10

  Modified:    src/xdoclet/test/xdoclet/modules/ojb/tests Tag:
                        OJB_1_0_RELEASE
                        ReferenceTagClassRefAttributeTests.java
                        RunAllTests.java
                        ReferenceTagDatabaseForeignkeyAttributeTests.java
                        ReferenceTagForeignkeyAttributeTests.java
                        ModifyInheritedTagClassRefAttributeTests.java
               lib      Tag: OJB_1_0_RELEASE xdoclet-ojb-module-1.2.2.jar
               src/xdoclet/java/src/xdoclet/modules/ojb/model Tag:
                        OJB_1_0_RELEASE TableDef.java TorqueModelDef.java
  Log:
  Fixed last test issues for the XDoclet module
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.6.2.1   +14 -0     db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/ReferenceTagClassRefAttributeTests.java
  
  Index: ReferenceTagClassRefAttributeTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/ReferenceTagClassRefAttributeTests.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- ReferenceTagClassRefAttributeTests.java	29 Jun 2004 17:00:45 -0000	1.6
  +++ ReferenceTagClassRefAttributeTests.java	17 Mar 2005 23:49:10 -0000	1.6.2.1
  @@ -146,6 +146,13 @@
               "<class-descriptor\n"+
               "    class=\"test.B\"\n"+
               ">\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"id\"\n"+
  +            "        column=\"id\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "        primarykey=\"true\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
               "</class-descriptor>",
               runOjbXDoclet(OJB_DEST_FILE));
           assertEqualsTorqueSchemaFile(
  @@ -431,6 +438,13 @@
               "<class-descriptor\n"+
               "    class=\"test.B\"\n"+
               ">\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"id\"\n"+
  +            "        column=\"id\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "        primarykey=\"true\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
               "</class-descriptor>",
               runOjbXDoclet(OJB_DEST_FILE));
           assertEqualsTorqueSchemaFile(
  
  
  
  1.13.2.5  +6 -6      db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/RunAllTests.java
  
  Index: RunAllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/RunAllTests.java,v
  retrieving revision 1.13.2.4
  retrieving revision 1.13.2.5
  diff -u -r1.13.2.4 -r1.13.2.5
  --- RunAllTests.java	15 Mar 2005 23:58:30 -0000	1.13.2.4
  +++ RunAllTests.java	17 Mar 2005 23:49:10 -0000	1.13.2.5
  @@ -50,8 +50,8 @@
           suite.addTest(new TestSuite(ClassTagAttributesAttributeTests.class));
           suite.addTest(new TestSuite(ClassTagDetermineExtendsAttributeTests.class));
           suite.addTest(new TestSuite(ClassTagDocumentationAttributeTests.class));
  -        suite.addTest(new TestSuite(ClassTagFactoryClassAndMethodAttributeTests.class));*/
  -        suite.addTest(new TestSuite(ClassTagGenerateRepositoryInfoAttributeTests.class));/*
  +        suite.addTest(new TestSuite(ClassTagFactoryClassAndMethodAttributeTests.class));
  +        suite.addTest(new TestSuite(ClassTagGenerateRepositoryInfoAttributeTests.class));
           suite.addTest(new TestSuite(ClassTagGenerateTableInfoAttributeTests.class));
           suite.addTest(new TestSuite(ClassTagIncludeInheritedAttributeTests.class));
           suite.addTest(new TestSuite(ClassTagInitializationMethodAttributeTests.class));
  @@ -91,8 +91,8 @@
           suite.addTest(new TestSuite(ReferenceTagAutoUpdateAttributeTests.class));
           suite.addTest(new TestSuite(ReferenceTagClassRefAttributeTests.class));
           suite.addTest(new TestSuite(ReferenceTagDatabaseForeignkeyAttributeTests.class));
  -        suite.addTest(new TestSuite(ReferenceTagDocumentationAttributeTests.class));*/
  -        suite.addTest(new TestSuite(ReferenceTagForeignkeyAttributeTests.class));/*
  +        suite.addTest(new TestSuite(ReferenceTagDocumentationAttributeTests.class));
  +        suite.addTest(new TestSuite(ReferenceTagForeignkeyAttributeTests.class));
           suite.addTest(new TestSuite(ReferenceTagOtmDependentAttributeTests.class));
           suite.addTest(new TestSuite(ReferenceTagProxyAttributeTests.class));
           suite.addTest(new TestSuite(ReferenceTagRefreshAttributeTests.class));
  @@ -104,8 +104,8 @@
           suite.addTest(new TestSuite(CollectionTagAutoUpdateAttributeTests.class));
           suite.addTest(new TestSuite(CollectionTagCollectionClassAttributeTests.class));
           suite.addTest(new TestSuite(CollectionTagDocumentationAttributeTests.class));
  -        suite.addTest(new TestSuite(CollectionTagElementClassRefAttributeTests.class));*/
  -        suite.addTest(new TestSuite(CollectionTagForeignkeyAttributeTests.class));/*
  +        suite.addTest(new TestSuite(CollectionTagElementClassRefAttributeTests.class));
  +        suite.addTest(new TestSuite(CollectionTagForeignkeyAttributeTests.class));
           suite.addTest(new TestSuite(CollectionTagIndirectionTableAttributeTests.class));
           suite.addTest(new TestSuite(CollectionTagIndirectionTableDocumentationAttributesTests.class));
           suite.addTest(new TestSuite(CollectionTagIndirectionTablePrimarykeysAttributeTests.class));
  
  
  
  1.1.2.2   +19 -0     db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/Attic/ReferenceTagDatabaseForeignkeyAttributeTests.java
  
  Index: ReferenceTagDatabaseForeignkeyAttributeTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/Attic/ReferenceTagDatabaseForeignkeyAttributeTests.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- ReferenceTagDatabaseForeignkeyAttributeTests.java	1 Mar 2005 21:54:06 -0000	1.1.2.1
  +++ ReferenceTagDatabaseForeignkeyAttributeTests.java	17 Mar 2005 23:49:10 -0000	1.1.2.2
  @@ -277,6 +277,21 @@
               "    class=\"test.B\"\n"+
               ">\n"+
               "    <extent-class class-ref=\"test.C\"/>\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"idA\"\n"+
  +            "        column=\"idA\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "        primarykey=\"true\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"idB\"\n"+
  +            "        column=\"idB\"\n"+
  +            "        jdbc-type=\"VARCHAR\"\n"+
  +            "        primarykey=\"true\"\n"+
  +            "        length=\"254\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
               "</class-descriptor>\n"+
               "<class-descriptor\n"+
               "    class=\"test.C\"\n"+
  @@ -311,6 +326,10 @@
               "                type=\"VARCHAR\"\n"+
               "                size=\"254\"\n"+
               "        />\n"+
  +            "        <foreign-key foreignTable=\"C\">\n"+
  +            "            <reference local=\"attrKeyA\" foreign=\"idA\"/>\n"+
  +            "            <reference local=\"attrKeyB\" foreign=\"idB\"/>\n"+
  +            "        </foreign-key>\n"+
               "    </table>\n"+
               "    <table name=\"C\">\n"+
               "        <column name=\"idA\"\n"+
  
  
  
  1.6.2.3   +125 -0    db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/ReferenceTagForeignkeyAttributeTests.java
  
  Index: ReferenceTagForeignkeyAttributeTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/ReferenceTagForeignkeyAttributeTests.java,v
  retrieving revision 1.6.2.2
  retrieving revision 1.6.2.3
  diff -u -r1.6.2.2 -r1.6.2.3
  --- ReferenceTagForeignkeyAttributeTests.java	16 Mar 2005 23:54:33 -0000	1.6.2.2
  +++ ReferenceTagForeignkeyAttributeTests.java	17 Mar 2005 23:49:10 -0000	1.6.2.3
  @@ -751,12 +751,137 @@
               "                javaName=\"attrKey\"\n"+
               "                type=\"INTEGER\"\n"+
               "        />\n"+
  +            "        <foreign-key foreignTable=\"D\">\n"+
  +            "            <reference local=\"attrKey\" foreign=\"id\"/>\n"+
  +            "        </foreign-key>\n"+
               "    </table>\n"+
               "    <table name=\"B\">\n"+
               "        <column name=\"attrKey\"\n"+
               "                javaName=\"attrKey\"\n"+
               "                type=\"INTEGER\"\n"+
               "        />\n"+
  +            "        <foreign-key foreignTable=\"D\">\n"+
  +            "            <reference local=\"attrKey\" foreign=\"id\"/>\n"+
  +            "        </foreign-key>\n"+
  +            "    </table>\n"+
  +            "    <table name=\"D\">\n"+
  +            "        <column name=\"id\"\n"+
  +            "                javaName=\"id\"\n"+
  +            "                type=\"INTEGER\"\n"+
  +            "                primaryKey=\"true\"\n"+
  +            "                required=\"true\"\n"+
  +            "        />\n"+
  +            "    </table>\n"+
  +            "</database>",
  +            runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
  +    }
  +
  +    // Test: referenced type has a multiple subtypes that map to different tables
  +    public void testForeignkey14()
  +    {
  +        addClass(
  +            "test.A",
  +            "package test;\n"+
  +            "/** @ojb.class */\n"+
  +            "public class A {\n"+
  +            "  /** @ojb.field */\n"+
  +            "  private int attrKey;\n"+
  +            "  /** @ojb.reference foreignkey=\"attrKey\" */\n"+
  +            "  private test.B attr;\n"+
  +            "}\n");
  +        addClass(
  +            "test.B",
  +            "package test;\n"+
  +            "/** @ojb.class generate-repository-info=\"false\" */\n"+
  +            "public interface B {}\n");
  +        addClass(
  +            "test.C",
  +            "package test;\n"+
  +            "/** @ojb.class */\n"+
  +            "public class C implements B {\n"+
  +            "  /** @ojb.field primarykey=\"true\" */\n"+
  +            "  private int id;\n"+
  +            "}\n");
  +        addClass(
  +            "test.D",
  +            "package test;\n"+
  +            "/** @ojb.class */\n"+
  +            "public class D implements B {\n"+
  +            "  /** @ojb.field primarykey=\"true\" */\n"+
  +            "  private int id;\n"+
  +            "}\n");
  +        
  +        assertEqualsOjbDescriptorFile(
  +            "<class-descriptor\n"+
  +            "    class=\"test.A\"\n"+
  +            "    table=\"A\"\n"+
  +            ">\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"attrKey\"\n"+
  +            "        column=\"attrKey\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
  +            "    <reference-descriptor\n"+
  +            "        name=\"attr\"\n"+
  +            "        class-ref=\"test.B\"\n"+
  +            "    >\n"+
  +            "        <foreignkey field-ref=\"attrKey\"/>\n"+
  +            "    </reference-descriptor>\n"+
  +            "</class-descriptor>\n"+
  +            "<class-descriptor\n"+
  +            "    class=\"test.B\"\n"+
  +            ">\n"+
  +            "    <extent-class class-ref=\"test.C\"/>\n"+
  +            "    <extent-class class-ref=\"test.D\"/>\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"id\"\n"+
  +            "        column=\"id\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "        primarykey=\"true\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
  +            "</class-descriptor>\n"+
  +            "<class-descriptor\n"+
  +            "    class=\"test.C\"\n"+
  +            "    table=\"C\"\n"+
  +            ">\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"id\"\n"+
  +            "        column=\"id\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "        primarykey=\"true\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
  +            "</class-descriptor>\n"+
  +            "<class-descriptor\n"+
  +            "    class=\"test.D\"\n"+
  +            "    table=\"D\"\n"+
  +            ">\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"id\"\n"+
  +            "        column=\"id\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "        primarykey=\"true\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
  +            "</class-descriptor>",
  +            runOjbXDoclet(OJB_DEST_FILE));
  +        assertEqualsTorqueSchemaFile(
  +            "<database name=\"ojbtest\">\n"+
  +            "    <table name=\"A\">\n"+
  +            "        <column name=\"attrKey\"\n"+
  +            "                javaName=\"attrKey\"\n"+
  +            "                type=\"INTEGER\"\n"+
  +            "        />\n"+
  +            "    </table>\n"+
  +            "    <table name=\"C\">\n"+
  +            "        <column name=\"id\"\n"+
  +            "                javaName=\"id\"\n"+
  +            "                type=\"INTEGER\"\n"+
  +            "                primaryKey=\"true\"\n"+
  +            "                required=\"true\"\n"+
  +            "        />\n"+
               "    </table>\n"+
               "    <table name=\"D\">\n"+
               "        <column name=\"id\"\n"+
  
  
  
  1.3.2.1   +10 -6     db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/ModifyInheritedTagClassRefAttributeTests.java
  
  Index: ModifyInheritedTagClassRefAttributeTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/ModifyInheritedTagClassRefAttributeTests.java,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- ModifyInheritedTagClassRefAttributeTests.java	5 Apr 2004 12:16:16 -0000	1.3
  +++ ModifyInheritedTagClassRefAttributeTests.java	17 Mar 2005 23:49:10 -0000	1.3.2.1
  @@ -142,9 +142,6 @@
               "                javaName=\"attrKey\"\n"+
               "                type=\"INTEGER\"\n"+
               "        />\n"+
  -            "        <foreign-key foreignTable=\"C\">\n"+
  -            "            <reference local=\"attrKey\" foreign=\"id\"/>\n"+
  -            "        </foreign-key>\n"+
               "    </table>\n"+
               "    <table name=\"C\">\n"+
               "        <column name=\"id\"\n"+
  @@ -241,6 +238,13 @@
               "    class=\"test.C\"\n"+
               ">\n"+
               "    <extent-class class-ref=\"test.D\"/>\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"id\"\n"+
  +            "        column=\"id\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "        primarykey=\"true\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
               "</class-descriptor>\n"+
               "<class-descriptor\n"+
               "    class=\"test.D\"\n"+
  @@ -262,6 +266,9 @@
               "                javaName=\"attrKey\"\n"+
               "                type=\"INTEGER\"\n"+
               "        />\n"+
  +            "        <foreign-key foreignTable=\"D\">\n"+
  +            "            <reference local=\"attrKey\" foreign=\"id\"/>\n"+
  +            "        </foreign-key>\n"+
               "    </table>\n"+
               "    <table name=\"B\">\n"+
               "        <column name=\"attrKey\"\n"+
  @@ -538,9 +545,6 @@
               "                javaName=\"attrKey\"\n"+
               "                type=\"INTEGER\"\n"+
               "        />\n"+
  -            "        <foreign-key foreignTable=\"C\">\n"+
  -            "            <reference local=\"attrKey\" foreign=\"id\"/>\n"+
  -            "        </foreign-key>\n"+
               "    </table>\n"+
               "    <table name=\"B\">\n"+
               "        <column name=\"attrKey\"\n"+
  
  
  
  No                   revision
  No                   revision
  1.1.2.7   +49 -45    db-ojb/lib/Attic/xdoclet-ojb-module-1.2.2.jar
  
  	<<Binary file>>
  
  
  No                   revision
  No                   revision
  1.5.2.3   +9 -35     db-ojb/src/xdoclet/java/src/xdoclet/modules/ojb/model/TableDef.java
  
  Index: TableDef.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/xdoclet/java/src/xdoclet/modules/ojb/model/TableDef.java,v
  retrieving revision 1.5.2.2
  retrieving revision 1.5.2.3
  diff -u -r1.5.2.2 -r1.5.2.3
  --- TableDef.java	15 Mar 2005 23:58:30 -0000	1.5.2.2
  +++ TableDef.java	17 Mar 2005 23:49:10 -0000	1.5.2.3
  @@ -121,46 +121,20 @@
       /**
        * Adds a foreignkey to this table.
        * 
  -     * @param relationName The name of the relation represented by the foreignkey
  -     * @param remoteTable  The referenced table
  -     * @param localFields  The local fields
  -     * @param remoteFields The remote fields
  +     * @param relationName  The name of the relation represented by the foreignkey
  +     * @param remoteTable   The referenced table
  +     * @param localColumns  The local columns
  +     * @param remoteColumns The remote columns
        */
  -    public void addForeignkey(String relationName, String remoteTable, List localFields,
List remoteFields)
  +    public void addForeignkey(String relationName, String remoteTable, List localColumns,
List remoteColumns)
       {
  -        ForeignkeyDef      foreignkeyDef = new ForeignkeyDef(relationName, remoteTable);
  -        FieldDescriptorDef fieldDef;
  -        String             localColumn;
  -        String             remoteColumn;
  +        ForeignkeyDef foreignkeyDef = new ForeignkeyDef(relationName, remoteTable);
   
           // the field arrays have the same length if we already checked the constraints
  -        for (int idx = 0; idx < localFields.size(); idx++)
  +        for (int idx = 0; idx < localColumns.size(); idx++)
           {
  -            if (localFields.get(idx) instanceof FieldDescriptorDef)
  -            {
  -                fieldDef    = (FieldDescriptorDef)localFields.get(idx);
  -                localColumn = fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_COLUMN);
  -            }
  -            else
  -            {
  -                localColumn = localFields.get(idx).toString();
  -            }
  -            if (remoteFields.get(idx) instanceof FieldDescriptorDef)
  -            {
  -                fieldDef = (FieldDescriptorDef)remoteFields.get(idx);
  -                // we can only generate a database foreignkey if the target fields are
really present
  -                // in the remote table, i.e. if the field is not virtual
  -                if (fieldDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_VIRTUAL_FIELD,
false))
  -                {
  -                    return;
  -                }
  -                remoteColumn = fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_COLUMN);
  -            }
  -            else
  -            {
  -                remoteColumn = remoteFields.get(idx).toString();
  -            }
  -            foreignkeyDef.addColumnPair(localColumn, remoteColumn);
  +            foreignkeyDef.addColumnPair((String)localColumns.get(idx),
  +                                        (String)remoteColumns.get(idx));
           }
   
           // we got to determine whether this foreignkey is already present 
  
  
  
  1.6.2.7   +57 -14    db-ojb/src/xdoclet/java/src/xdoclet/modules/ojb/model/TorqueModelDef.java
  
  Index: TorqueModelDef.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/xdoclet/java/src/xdoclet/modules/ojb/model/TorqueModelDef.java,v
  retrieving revision 1.6.2.6
  retrieving revision 1.6.2.7
  diff -u -r1.6.2.6 -r1.6.2.7
  --- TorqueModelDef.java	16 Mar 2005 23:54:33 -0000	1.6.2.6
  +++ TorqueModelDef.java	17 Mar 2005 23:49:10 -0000	1.6.2.7
  @@ -227,7 +227,7 @@
               ArrayList localFields  = ownerClassDef.getFields(refDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY));
               ArrayList remoteFields = referencedClassDef.getPrimaryKeys();
   
  -            tableDef.addForeignkey(name, tableName, localFields, remoteFields);
  +            tableDef.addForeignkey(name, tableName, getColumns(localFields), getColumns(remoteFields));
           }
           catch (NoSuchFieldException ex)
           {
  @@ -316,7 +316,7 @@
                           elementTableDef = new TableDef(elementTableName);
                           addTable(elementTableDef);
                       }
  -                    elementTableDef.addForeignkey(name, tableDef.getName(), localFields,
remoteFields);
  +                    elementTableDef.addForeignkey(name, tableDef.getName(), getColumns(localFields),
getColumns(remoteFields));
                       processedTables.put(elementTableName, null);
                   }
               }
  @@ -328,6 +328,25 @@
       }
   
       /**
  +     * Extracts the list of columns from the given field list.
  +     * 
  +     * @param fields The fields
  +     * @return The corresponding columns
  +     */
  +    private List getColumns(List fields)
  +    {
  +        ArrayList columns = new ArrayList();
  +
  +        for (Iterator it = fields.iterator(); it.hasNext();)
  +        {
  +            FieldDescriptorDef fieldDef = (FieldDescriptorDef)it.next();
  +
  +            columns.add(fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_COLUMN));
  +        }
  +        return columns;
  +    }
  +    
  +    /**
        * Checks whether the given class maps to a different table but also has the given
collection.
        * 
        * @param origCollDef  The original collection to search for
  @@ -355,14 +374,16 @@
        * Tries to return the single target table to which the given foreign key columns map
in
        * all m:n collections that target this indirection table. 
        * 
  +     * @param targetClassDef   The original target class
        * @param indirectionTable The indirection table
        * @param foreignKeys      The foreign keys columns in the indirection table pointing
back to the
        *                         class' table
        * @return The table name or <code>null</code> if there is not exactly
one table
        */
  -    private String getTargetTable(ModelDef modelDef, String indirectionTable, String foreignKeys)
  +    private String getTargetTable(ClassDescriptorDef targetClassDef, String indirectionTable,
String foreignKeys)
       {
  -        String tableName = null;
  +        ModelDef modelDef  = (ModelDef)targetClassDef.getOwner();
  +        String   tableName = null;
   
           for (Iterator classIt = modelDef.getClasses(); classIt.hasNext();)
           {
  @@ -396,7 +417,16 @@
                   }
               }
           }
  -        return tableName;
  +        if (tableName == null)
  +        {
  +            // no fitting collection found -> indirection table with only one collection
  +            // we have to check whether the hierarchy of the target class maps to one table
only
  +            return getHierarchyTable(targetClassDef);
  +        }
  +        else
  +        {
  +            return tableName;
  +        }
       }
   
       /**
  @@ -409,25 +439,38 @@
        */
       private String getHierarchyTable(ClassDescriptorDef classDef)
       {
  -        boolean mapsToTable = classDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_TABLE_INFO,
true);
  -        String  tableName   = mapsToTable ? classDef.getProperty(PropertyHelper.OJB_PROPERTY_TABLE)
: null;
  +        ArrayList queue     = new ArrayList();
  +        String    tableName = null;
   
  -        for (Iterator it = classDef.getAllExtentClasses(); it.hasNext();)
  +        queue.add(classDef);
  +
  +        while (!queue.isEmpty())
           {
  -            ClassDescriptorDef curSubTypeDef = (ClassDescriptorDef)it.next();
  +            ClassDescriptorDef curClassDef = (ClassDescriptorDef)queue.get(0);
   
  -            if (curSubTypeDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_TABLE_INFO,
true))
  +            queue.remove(0);
  +
  +            if (curClassDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_TABLE_INFO,
true))
               {
                   if (tableName != null)
                   {
  -                    if (!tableName.equals(curSubTypeDef.getProperty(PropertyHelper.OJB_PROPERTY_TABLE)))
  +                    if (!tableName.equals(curClassDef.getProperty(PropertyHelper.OJB_PROPERTY_TABLE)))
                       {
                           return null;
                       }
                   }
                   else
                   {
  -                    tableName = curSubTypeDef.getProperty(PropertyHelper.OJB_PROPERTY_TABLE);
  +                    tableName = curClassDef.getProperty(PropertyHelper.OJB_PROPERTY_TABLE);
  +                }
  +            }
  +            for (Iterator it = curClassDef.getExtentClasses(); it.hasNext();)
  +            {
  +                curClassDef = (ClassDescriptorDef)it.next();
  +
  +                if (curClassDef.getReference("super") == null)
  +                {
  +                    queue.add(curClassDef);
                   }
               }
           }
  @@ -505,8 +548,8 @@
           ArrayList          remotePrimFields = elementClassDef.getPrimaryKeys();
           String             localKeyList     = collDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);
           String             remoteKeyList    = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);
  -        String             ownerTable       = getTargetTable(modelDef, tableName, localKeyList);
  -        String             elementTable     = getTargetTable(modelDef, tableName, remoteKeyList);
  +        String             ownerTable       = getTargetTable(ownerClassDef, tableName,
localKeyList);
  +        String             elementTable     = getTargetTable(elementClassDef, tableName,
remoteKeyList);
           CommaListIterator  localKeys        = new CommaListIterator(localKeyList);
           CommaListIterator  localKeyDocs     = new CommaListIterator(collDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY_DOCUMENTATION));
           CommaListIterator  remoteKeys       = new CommaListIterator(remoteKeyList);
  
  
  

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