You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by to...@apache.org on 2006/03/05 16:47:14 UTC

svn commit: r383345 [1/3] - in /db/ojb/branches/OJB_1_0_RELEASE: lib/ src/doc/forrest/src/documentation/content/xdocs/docu/guides/ src/xdoclet/java/src/xdoclet/modules/ojb/model/ src/xdoclet/java/src/xdoclet/modules/ojb/resources/ src/xdoclet/test/xdoc...

Author: tomdz
Date: Sun Mar  5 07:47:13 2006
New Revision: 383345

URL: http://svn.apache.org/viewcvs?rev=383345&view=rev
Log:
Added new XDoclet attributes foreignkey-name, foreignkey-on-delete and foreignkey-on-update (and corresponding remote- variants) which fixes OJB-73 and OJB-100

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/lib/xdoclet-ojb-module-1.2.3.jar
    db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/xdoclet-module.xml
    db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/PropertyHelper.java
    db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TableDef.java
    db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TorqueModelDef.java
    db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/resources/intermediate-representation.xdt
    db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/resources/torque_xml.xdt
    db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/CollectionTagForeignkeyAttributeTests.java
    db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/CollectionTagIndirectionTableAttributeTests.java
    db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/ReferenceTagForeignkeyAttributeTests.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/lib/xdoclet-ojb-module-1.2.3.jar
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/lib/xdoclet-ojb-module-1.2.3.jar?rev=383345&r1=383344&r2=383345&view=diff
==============================================================================
Binary files - no diff available.

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/xdoclet-module.xml
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/xdoclet-module.xml?rev=383345&r1=383344&r2=383345&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/xdoclet-module.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/xdoclet-module.xml Sun Mar  5 07:47:13 2006
@@ -628,8 +628,10 @@
                     <a href="#ojb.collection">ojb.collection</a> (with
                     the exception of the attributes related to indirection tables (
                     <strong>indirection-table</strong>, <strong>remote-foreignkey</strong>,
-                    <strong>indirection-table-primarykeys</strong>, <strong>indirection-table-documentation</strong>,
-                    <strong>foreignkey-documentation</strong>, <strong>remote-foreignkey-documentation</strong>),
+                    <strong>remote-foreignkey-name</strong>, <strong>remote-foreignkey-on-delete</strong>,
+                    <strong>remote-foreignkey-on-update</strong>, <strong>indirection-table-primarykeys</strong>,
+                    <strong>indirection-table-documentation</strong>, <strong>foreignkey-documentation</strong>,
+                    <strong>remote-foreignkey-documentation</strong>),
                     and also:
                 </p>
                 <dl>
@@ -2050,6 +2052,56 @@
                         implement the association, i.e. contains the values of the primarykeys of the referenced object.
                         <br/>
                     </dd>
+
+                    <dt>
+                        <strong>foreignkey-name</strong>
+                    </dt>
+                    <dd>
+                        Specifies the name of the foreignkey in the database. If this attribute is not specified,
+                        then the tool generating the database, will generate one automatically. Note that the value of
+                        this attribute is ignored by OJB.
+                        <br/>
+                    </dd>
+
+                    <dt>
+                        <strong>foreignkey-on-delete : cascade | setnull | restrict | none (default)</strong>
+                    </dt>
+                    <dd>
+                        Specifies what the database shall do, when the referencing object is deleted. Note that
+                        it is database dependent whether the created database actually honors these specification.
+                        Also, OJB completely ignores the value of this attribute, so be careful when mixing it
+                        with the <code>auto-</code> attributes.<br/>
+                        The typical interpretation of these values by a database are:<br/>
+                        <ul>
+                            <li><strong>cascade</strong>:&nbsp;All child rows are deleted as well.</li>
+                            <li><strong>setnull</strong>:&nbsp;The child rows are updated so that the columns in the foreignkey
+                                 are set to the SQL <code>NULL</code> value.</li>
+                            <li><strong>restrict</strong>:&nbsp;The parent row can only be deleted if it is the single
+                                parent row of all its child rows, i.e. that now child row has multiple parent rows.</li>
+                            <li><strong>none</strong>:&nbsp;Nothing will happen to the child rows.</li>
+                        </ul>
+                        <br/>
+                    </dd>
+
+                    <dt>
+                        <strong>foreignkey-on-update : cascade | setnull | restrict | none (default)</strong>
+                    </dt>
+                    <dd>
+                        Specifies what the database shall do, when the referencing object, or more precisely the 
+                        foreignky columns in the parent row, are updated. Note that it is database dependent whether
+                        the created database actually honors these specification. Also, OJB completely ignores the
+                        value of this attribute, so be careful when mixing it with the <code>auto-</code> attributes.<br/>
+                        The typical interpretation of these values by a database are:<br/>
+                        <ul>
+                            <li><strong>cascade</strong>:&nbsp;All child rows are updated as well.</li>
+                            <li><strong>setnull</strong>:&nbsp;The child rows are updated so that the columns in the foreignkey
+                                 are set to the SQL <code>NULL</code> value.</li>
+                            <li><strong>restrict</strong>:&nbsp;The parent row can only be updated if it is the single
+                                parent row of all its child rows, i.e. that now child row has multiple parent rows.</li>
+                            <li><strong>none</strong>:&nbsp;Nothing will happen to the child rows.</li>
+                        </ul>
+                        <br/>
+                    </dd>
                 </dl>
                 <p>
                     Other supported attributes (see
@@ -2157,11 +2209,8 @@
                     Persistent collections which implement 1:n or m:n associations are denoted by the
                     <strong>ojb.collection</strong> tag. If the collection is an array, then the XDoclet OJB module can determine
                     the element type automatically (analogous to references). Otherwise the type must be specified using
-                    the
-                    <strong>element-class-ref</strong> attribute. m:n associations are also supported (collections on both
-                    sides) via the
-                    <strong>indirection-table</strong>,
-                    <strong>foreignkey</strong> and
+                    the <strong>element-class-ref</strong> attribute. m:n associations are also supported (collections on both
+                    sides) via the <strong>indirection-table</strong>, <strong>foreignkey</strong> and
                     <strong>remote-foreignkey</strong> attributes.
                 </p>
                 <p>
@@ -2255,6 +2304,56 @@
                     </dd>
 
                     <dt>
+                        <strong>foreignkey-name</strong>
+                    </dt>
+                    <dd>
+                        Specifies the name of the foreignkey in the database. If this attribute is not specified,
+                        then the tool generating the database, will generate one automatically. Note that the value of
+                        this attribute is ignored by OJB.
+                        <br/>
+                    </dd>
+
+                    <dt>
+                        <strong>foreignkey-on-delete : cascade | setnull | restrict | none (default)</strong>
+                    </dt>
+                    <dd>
+                        Specifies what the database shall do, when the element object is deleted. Note that
+                        it is database dependent whether the created database actually honors these specification.
+                        Also, OJB completely ignores the value of this attribute, so be careful when mixing it
+                        with the <code>auto-</code> attributes.<br/>
+                        The typical interpretation of these values by a database are:<br/>
+                        <ul>
+                            <li><strong>cascade</strong>:&nbsp;All child rows are deleted as well.</li>
+                            <li><strong>setnull</strong>:&nbsp;The child rows are updated so that the columns in the foreignkey
+                                 are set to the SQL <code>NULL</code> value.</li>
+                            <li><strong>restrict</strong>:&nbsp;The parent row can only be deleted if it is the single
+                                parent row of all its child rows, i.e. that now child row has multiple parent rows.</li>
+                            <li><strong>none</strong>:&nbsp;Nothing will happen to the child rows.</li>
+                        </ul>
+                        <br/>
+                    </dd>
+
+                    <dt>
+                        <strong>foreignkey-on-update : cascade | setnull | restrict | none (default)</strong>
+                    </dt>
+                    <dd>
+                        Specifies what the database shall do, when the element object, or more precisely the 
+                        foreignky columns in the parent row, are updated. Note that it is database dependent whether
+                        the created database actually honors these specification. Also, OJB completely ignores the
+                        value of this attribute, so be careful when mixing it with the <code>auto-</code> attributes.<br/>
+                        The typical interpretation of these values by a database are:<br/>
+                        <ul>
+                            <li><strong>cascade</strong>:&nbsp;All child rows are updated as well.</li>
+                            <li><strong>setnull</strong>:&nbsp;The child rows are updated so that the columns in the foreignkey
+                                 are set to the SQL <code>NULL</code> value.</li>
+                            <li><strong>restrict</strong>:&nbsp;The parent row can only be updated if it is the single
+                                parent row of all its child rows, i.e. that now child row has multiple parent rows.</li>
+                            <li><strong>none</strong>:&nbsp;Nothing will happen to the child rows.</li>
+                        </ul>
+                        <br/>
+                    </dd>
+
+                    <dt>
                         <strong>indirection-table</strong>
                     </dt>
                     <dd>
@@ -2329,6 +2428,7 @@
                         attribute is ignored if used with 1:n collections (no indirection table specified).
                         <br/>
                     </dd>
+
                     <dt>
                         <strong>remote-foreignkey-documentation</strong>
                     </dt>
@@ -2337,6 +2437,57 @@
                         that point to the element type. This value can be used when the element type has no
                         corresponding collection (i.e. remote-foreignkey is specified) or if the corresponding
                         collection does not specify the <code>foreignkey-documentation</code> attribute.
+                        <br/>
+                    </dd>
+
+
+                    <dt>
+                        <strong>remote-foreignkey-name</strong>
+                    </dt>
+                    <dd>
+                        Specifies the name of the foreignkey in the indirection table in the database which points to
+                        the elements. If this attribute is not specified, then the tool generating the database, will
+                        generate one automatically. Note that the value of this attribute is ignored by OJB.
+                        <br/>
+                    </dd>
+
+                    <dt>
+                        <strong>remote-foreignkey-on-delete : cascade | setnull | restrict | none (default)</strong>
+                    </dt>
+                    <dd>
+                        Specifies what the database shall do, when the element object is deleted. Note that
+                        it is database dependent whether the created database actually honors these specification.
+                        Also, OJB completely ignores the value of this attribute, so be careful when mixing it
+                        with the <code>auto-</code> attributes.<br/>
+                        The typical interpretation of these values by a database are:<br/>
+                        <ul>
+                            <li><strong>cascade</strong>:&nbsp;All child rows are deleted as well.</li>
+                            <li><strong>setnull</strong>:&nbsp;The child rows are updated so that the columns in the foreignkey
+                                 are set to the SQL <code>NULL</code> value.</li>
+                            <li><strong>restrict</strong>:&nbsp;The parent row can only be deleted if it is the single
+                                parent row of all its child rows, i.e. that now child row has multiple parent rows.</li>
+                            <li><strong>none</strong>:&nbsp;Nothing will happen to the child rows.</li>
+                        </ul>
+                        <br/>
+                    </dd>
+
+                    <dt>
+                        <strong>remote-foreignkey-on-update : cascade | setnull | restrict | none (default)</strong>
+                    </dt>
+                    <dd>
+                        Specifies what the database shall do, when the element object, or more precisely the 
+                        foreignky columns in the parent row, are updated. Note that it is database dependent whether
+                        the created database actually honors these specification. Also, OJB completely ignores the
+                        value of this attribute, so be careful when mixing it with the <code>auto-</code> attributes.<br/>
+                        The typical interpretation of these values by a database are:<br/>
+                        <ul>
+                            <li><strong>cascade</strong>:&nbsp;All child rows are updated as well.</li>
+                            <li><strong>setnull</strong>:&nbsp;The child rows are updated so that the columns in the foreignkey
+                                 are set to the SQL <code>NULL</code> value.</li>
+                            <li><strong>restrict</strong>:&nbsp;The parent row can only be updated if it is the single
+                                parent row of all its child rows, i.e. that now child row has multiple parent rows.</li>
+                            <li><strong>none</strong>:&nbsp;Nothing will happen to the child rows.</li>
+                        </ul>
                         <br/>
                     </dd>
                 </dl>

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/PropertyHelper.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/PropertyHelper.java?rev=383345&r1=383344&r2=383345&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/PropertyHelper.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/PropertyHelper.java Sun Mar  5 07:47:13 2006
@@ -54,6 +54,9 @@
     public static final String OJB_PROPERTY_FIELDS                          = "fields";
     public static final String OJB_PROPERTY_FOREIGNKEY                      = "foreignkey";
     public static final String OJB_PROPERTY_FOREIGNKEY_DOCUMENTATION        = "foreignkey-documentation";
+    public static final String OJB_PROPERTY_FOREIGNKEY_NAME                 = "foreignkey-name";
+    public static final String OJB_PROPERTY_FOREIGNKEY_ON_DELETE            = "foreignkey-on-delete";
+    public static final String OJB_PROPERTY_FOREIGNKEY_ON_UPDATE            = "foreignkey-on-update";
     public static final String OJB_PROPERTY_GENERATE_REPOSITORY_INFO        = "generate-repository-info";
     public static final String OJB_PROPERTY_GENERATE_TABLE_INFO             = "generate-table-info";
     public static final String OJB_PROPERTY_ID                              = "id";
@@ -83,6 +86,9 @@
     public static final String OJB_PROPERTY_REFRESH                         = "refresh";
     public static final String OJB_PROPERTY_REMOTE_FOREIGNKEY               = "remote-foreignkey";
     public static final String OJB_PROPERTY_REMOTE_FOREIGNKEY_DOCUMENTATION = "remote-foreignkey-documentation";
+    public static final String OJB_PROPERTY_REMOTE_FOREIGNKEY_NAME          = "remote-foreignkey-name";
+    public static final String OJB_PROPERTY_REMOTE_FOREIGNKEY_ON_DELETE     = "remote-foreignkey-on-delete";
+    public static final String OJB_PROPERTY_REMOTE_FOREIGNKEY_ON_UPDATE     = "remote-foreignkey-on-update";
     public static final String OJB_PROPERTY_RETURN_FIELD_REF                = "return-field-ref";
     public static final String OJB_PROPERTY_ROW_READER                      = "row-reader";
     public static final String OJB_PROPERTY_SCALE                           = "scale";

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TableDef.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TableDef.java?rev=383345&r1=383344&r2=383345&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TableDef.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TableDef.java Sun Mar  5 07:47:13 2006
@@ -125,8 +125,9 @@
      * @param remoteTable   The referenced table
      * @param localColumns  The local columns
      * @param remoteColumns The remote columns
+     * @return The foreignkey which might be new or already existing
      */
-    public void addForeignkey(String relationName, String remoteTable, List localColumns, List remoteColumns)
+    public ForeignkeyDef addForeignkey(String relationName, String remoteTable, List localColumns, List remoteColumns)
     {
         ForeignkeyDef foreignkeyDef = new ForeignkeyDef(relationName, remoteTable);
 
@@ -145,11 +146,12 @@
             def = (ForeignkeyDef)it.next();
             if (foreignkeyDef.equals(def))
             {
-                return;
+                return def;
             }
         }
         foreignkeyDef.setOwner(this);
         _foreignkeys.add(foreignkeyDef);
+        return foreignkeyDef;
     }
 
     /**

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TorqueModelDef.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TorqueModelDef.java?rev=383345&r1=383344&r2=383345&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TorqueModelDef.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/model/TorqueModelDef.java Sun Mar  5 07:47:13 2006
@@ -1,6 +1,6 @@
 package xdoclet.modules.ojb.model;
 
-/* Copyright 2004-2005 The Apache Software Foundation
+/* Copyright 2004-2006 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
 
 /**
  * Represents the model used for generating the torque database schema.
+ *
+ * @author Thomas Dudziak
  */
 public class TorqueModelDef extends DefBase
 {
@@ -224,11 +226,23 @@
 
         try
         {
-            String    name         = refDef.getName();
-            ArrayList localFields  = ownerClassDef.getFields(refDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY));
-            ArrayList remoteFields = referencedClassDef.getPrimaryKeys();
-
-            tableDef.addForeignkey(name, tableName, getColumns(localFields), getColumns(remoteFields));
+            String        name         = refDef.getName();
+            ArrayList     localFields  = ownerClassDef.getFields(refDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY));
+            ArrayList     remoteFields = referencedClassDef.getPrimaryKeys();
+            ForeignkeyDef fkDef        = tableDef.addForeignkey(name, tableName, getColumns(localFields), getColumns(remoteFields));
+
+            copyPropertyIfDefined(refDef,
+                                  PropertyHelper.OJB_PROPERTY_FOREIGNKEY_NAME,
+                                  fkDef,
+                                  PropertyHelper.OJB_PROPERTY_FOREIGNKEY_NAME);
+            copyPropertyIfDefined(refDef,
+                                  PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_DELETE,
+                                  fkDef,
+                                  PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_DELETE);
+            copyPropertyIfDefined(refDef,
+                                  PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_UPDATE,
+                                  fkDef,
+                                  PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_UPDATE);
         }
         catch (NoSuchFieldException ex)
         {
@@ -318,7 +332,21 @@
                         elementTableDef = new TableDef(elementTableName);
                         addTable(elementTableDef);
                     }
-                    elementTableDef.addForeignkey(name, tableDef.getName(), getColumns(localFields), getColumns(remoteFields));
+
+                    ForeignkeyDef fkDef = elementTableDef.addForeignkey(name, tableDef.getName(), getColumns(localFields), getColumns(remoteFields));
+
+                    copyPropertyIfDefined(collDef,
+                                          PropertyHelper.OJB_PROPERTY_FOREIGNKEY_NAME,
+                                          fkDef,
+                                          PropertyHelper.OJB_PROPERTY_FOREIGNKEY_NAME);
+                    copyPropertyIfDefined(collDef,
+                                          PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_DELETE,
+                                          fkDef,
+                                          PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_DELETE);
+                    copyPropertyIfDefined(collDef,
+                                          PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_UPDATE,
+                                          fkDef,
+                                          PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_UPDATE);
                     processedTables.put(elementTableName, null);
                 }
             }
@@ -594,7 +622,20 @@
             relationName = collDef.getProperty(PropertyHelper.TORQUE_PROPERTY_RELATION_NAME);
             if ((relationName != null) && (ownerTable != null))
             {
-                tableDef.addForeignkey(relationName, ownerTable, localColumns, remoteColumns);
+                ForeignkeyDef fkDef = tableDef.addForeignkey(relationName, ownerTable, localColumns, remoteColumns);
+
+                copyPropertyIfDefined(collDef,
+                                      PropertyHelper.OJB_PROPERTY_FOREIGNKEY_NAME,
+                                      fkDef,
+                                      PropertyHelper.OJB_PROPERTY_FOREIGNKEY_NAME);
+                copyPropertyIfDefined(collDef,
+                                      PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_DELETE,
+                                      fkDef,
+                                      PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_DELETE);
+                copyPropertyIfDefined(collDef,
+                                      PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_UPDATE,
+                                      fkDef,
+                                      PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_UPDATE);
             }
         }
         localColumns.clear();
@@ -633,11 +674,40 @@
             relationName = collDef.getProperty(PropertyHelper.TORQUE_PROPERTY_INV_RELATION_NAME);
             if ((relationName != null) && (elementTable != null))
             {
-                tableDef.addForeignkey(relationName, elementTable, localColumns, remoteColumns);
+                ForeignkeyDef fkDef = tableDef.addForeignkey(relationName, elementTable, localColumns, remoteColumns);
+
+                copyPropertyIfDefined(collDef,
+                                      PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY_NAME,
+                                      fkDef,
+                                      PropertyHelper.OJB_PROPERTY_FOREIGNKEY_NAME);
+                copyPropertyIfDefined(collDef,
+                                      PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY_ON_DELETE,
+                                      fkDef,
+                                      PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_DELETE);
+                copyPropertyIfDefined(collDef,
+                                      PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY_ON_UPDATE,
+                                      fkDef,
+                                      PropertyHelper.OJB_PROPERTY_FOREIGNKEY_ON_UPDATE);
             }
         }
     }
 
+    /**
+     * Copies the value of the specified source property to the foreignkey if it is defined at the source.
+     * 
+     * @param sourceDef      The source definition containing the property
+     * @param sourcePropName The name of the property at the source object
+     * @param fkDef          The foreignkey to copy the property to
+     * @param targetPropName The name of the property at the foreignkey
+     */
+    private void copyPropertyIfDefined(DefBase sourceDef, String sourcePropName, ForeignkeyDef fkDef, String targetPropName)
+    {
+        if (sourceDef.hasProperty(sourcePropName))
+        {
+            fkDef.setProperty(targetPropName, sourceDef.getProperty(sourcePropName));
+        }
+    }
+    
     // Access methods
     
     /**

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/resources/intermediate-representation.xdt
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/resources/intermediate-representation.xdt?rev=383345&r1=383344&r2=383345&view=diff
==============================================================================
Binary files - no diff available.

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/resources/torque_xml.xdt
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/java/src/xdoclet/modules/ojb/resources/torque_xml.xdt?rev=383345&r1=383344&r2=383345&view=diff
==============================================================================
Binary files - no diff available.

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/CollectionTagForeignkeyAttributeTests.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/CollectionTagForeignkeyAttributeTests.java?rev=383345&r1=383344&r2=383345&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/CollectionTagForeignkeyAttributeTests.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/CollectionTagForeignkeyAttributeTests.java Sun Mar  5 07:47:13 2006
@@ -1,6 +1,6 @@
 package xdoclet.modules.ojb.tests;
 
-/* Copyright 2003-2005 The Apache Software Foundation
+/* Copyright 2003-2006 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
 /**
  * Tests for the ojb.collection tag with the foreignkey attribute.
  *
- * @author <a href="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
+ * @author Thomas Dudziak
  */
 public class CollectionTagForeignkeyAttributeTests extends OjbTestBase
 {
@@ -1589,6 +1589,518 @@
             "                javaName=\"aid\"\n"+
             "                type=\"INTEGER\"\n"+
             "        />\n"+
+            "    </table>\n"+
+            "</database>",
+            runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
+    }
+
+    // Test: foreignkey name specified
+    public void testForeignkeyName1()
+    {
+        addClass(
+            "test.A",
+            "package test;\n"+
+            "/** @ojb.class */\n" +
+            "public class A {\n"+
+            "  /** @ojb.field primarykey=\"true\" */\n"+
+            "  private int id;\n"+
+            "  /** @ojb.collection element-class-ref=\"test.B\"\n"+
+            "    *                 foreignkey=\"aid\"\n"+
+            "    *                 foreignkey-name=\"FKToB\"\n"+
+            "    */\n"+
+            "  private java.util.List attr;\n"+
+            "}");
+        addClass(
+            "test.B",
+            "package test;\n"+
+            "/** @ojb.class */\n"+
+            "public class B {\n"+
+            "  /** @ojb.field */\n"+
+            "  private int aid;\n"+
+            "}\n");
+
+        assertEqualsOjbDescriptorFile(
+            "<class-descriptor\n"+
+            "    class=\"test.A\"\n"+
+            "    table=\"A\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"id\"\n"+
+            "        column=\"id\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "        primarykey=\"true\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "    <collection-descriptor\n"+
+            "        name=\"attr\"\n"+
+            "        element-class-ref=\"test.B\"\n"+
+            "    >\n"+
+            "        <inverse-foreignkey field-ref=\"aid\"/>\n"+
+            "    </collection-descriptor>\n"+
+            "</class-descriptor>\n"+
+            "<class-descriptor\n"+
+            "    class=\"test.B\"\n"+
+            "    table=\"B\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"aid\"\n"+
+            "        column=\"aid\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "</class-descriptor>",
+            runOjbXDoclet(OJB_DEST_FILE));
+        assertEqualsTorqueSchemaFile(
+            "<database name=\"ojbtest\">\n"+
+            "    <table name=\"A\">\n"+
+            "        <column name=\"id\"\n"+
+            "                javaName=\"id\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "                primaryKey=\"true\"\n"+
+            "                required=\"true\"\n"+
+            "        />\n"+
+            "    </table>\n"+
+            "    <table name=\"B\">\n"+
+            "        <column name=\"aid\"\n"+
+            "                javaName=\"aid\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "        />\n"+
+            "        <foreign-key name=\"FKToB\" foreignTable=\"A\">\n"+
+            "            <reference local=\"aid\" foreign=\"id\"/>\n"+
+            "        </foreign-key>\n"+
+            "    </table>\n"+
+            "</database>",
+            runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
+    }
+
+    // Test: foreignkey name attribute is empty
+    public void testForeignkeyName2()
+    {
+        addClass(
+            "test.A",
+            "package test;\n"+
+            "/** @ojb.class */\n" +
+            "public class A {\n"+
+            "  /** @ojb.field primarykey=\"true\" */\n"+
+            "  private int id;\n"+
+            "  /** @ojb.collection element-class-ref=\"test.B\"\n"+
+            "    *                 foreignkey=\"aid\"\n"+
+            "    *                 foreignkey-name=\"\"\n"+
+            "    */\n"+
+            "  private java.util.List attr;\n"+
+            "}");
+        addClass(
+            "test.B",
+            "package test;\n"+
+            "/** @ojb.class */\n"+
+            "public class B {\n"+
+            "  /** @ojb.field */\n"+
+            "  private int aid;\n"+
+            "}\n");
+
+        assertEqualsOjbDescriptorFile(
+            "<class-descriptor\n"+
+            "    class=\"test.A\"\n"+
+            "    table=\"A\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"id\"\n"+
+            "        column=\"id\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "        primarykey=\"true\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "    <collection-descriptor\n"+
+            "        name=\"attr\"\n"+
+            "        element-class-ref=\"test.B\"\n"+
+            "    >\n"+
+            "        <inverse-foreignkey field-ref=\"aid\"/>\n"+
+            "    </collection-descriptor>\n"+
+            "</class-descriptor>\n"+
+            "<class-descriptor\n"+
+            "    class=\"test.B\"\n"+
+            "    table=\"B\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"aid\"\n"+
+            "        column=\"aid\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "</class-descriptor>",
+            runOjbXDoclet(OJB_DEST_FILE));
+        assertEqualsTorqueSchemaFile(
+            "<database name=\"ojbtest\">\n"+
+            "    <table name=\"A\">\n"+
+            "        <column name=\"id\"\n"+
+            "                javaName=\"id\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "                primaryKey=\"true\"\n"+
+            "                required=\"true\"\n"+
+            "        />\n"+
+            "    </table>\n"+
+            "    <table name=\"B\">\n"+
+            "        <column name=\"aid\"\n"+
+            "                javaName=\"aid\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "        />\n"+
+            "        <foreign-key foreignTable=\"A\">\n"+
+            "            <reference local=\"aid\" foreign=\"id\"/>\n"+
+            "        </foreign-key>\n"+
+            "    </table>\n"+
+            "</database>",
+            runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
+    }
+
+    // Test: foreignkey-on-delete specified
+    public void testForeignkeyOnDelete1()
+    {
+        addClass(
+            "test.A",
+            "package test;\n"+
+            "/** @ojb.class */\n" +
+            "public class A {\n"+
+            "  /** @ojb.field primarykey=\"true\" */\n"+
+            "  private int id;\n"+
+            "  /** @ojb.collection element-class-ref=\"test.B\"\n"+
+            "    *                 foreignkey=\"aid\"\n"+
+            "    *                 foreignkey-on-delete=\"restrict\"\n"+
+            "    */\n"+
+            "  private java.util.List attr;\n"+
+            "}");
+        addClass(
+            "test.B",
+            "package test;\n"+
+            "/** @ojb.class */\n"+
+            "public class B {\n"+
+            "  /** @ojb.field */\n"+
+            "  private int aid;\n"+
+            "}\n");
+
+        assertEqualsOjbDescriptorFile(
+            "<class-descriptor\n"+
+            "    class=\"test.A\"\n"+
+            "    table=\"A\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"id\"\n"+
+            "        column=\"id\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "        primarykey=\"true\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "    <collection-descriptor\n"+
+            "        name=\"attr\"\n"+
+            "        element-class-ref=\"test.B\"\n"+
+            "    >\n"+
+            "        <inverse-foreignkey field-ref=\"aid\"/>\n"+
+            "    </collection-descriptor>\n"+
+            "</class-descriptor>\n"+
+            "<class-descriptor\n"+
+            "    class=\"test.B\"\n"+
+            "    table=\"B\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"aid\"\n"+
+            "        column=\"aid\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "</class-descriptor>",
+            runOjbXDoclet(OJB_DEST_FILE));
+        assertEqualsTorqueSchemaFile(
+            "<database name=\"ojbtest\">\n"+
+            "    <table name=\"A\">\n"+
+            "        <column name=\"id\"\n"+
+            "                javaName=\"id\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "                primaryKey=\"true\"\n"+
+            "                required=\"true\"\n"+
+            "        />\n"+
+            "    </table>\n"+
+            "    <table name=\"B\">\n"+
+            "        <column name=\"aid\"\n"+
+            "                javaName=\"aid\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "        />\n"+
+            "        <foreign-key foreignTable=\"A\" onDelete=\"restrict\">\n"+
+            "            <reference local=\"aid\" foreign=\"id\"/>\n"+
+            "        </foreign-key>\n"+
+            "    </table>\n"+
+            "</database>",
+            runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
+    }
+
+    // Test: foreignkey-on-delete specified with empty value
+    public void testForeignkeyOnDelete2()
+    {
+        addClass(
+            "test.A",
+            "package test;\n"+
+            "/** @ojb.class */\n" +
+            "public class A {\n"+
+            "  /** @ojb.field primarykey=\"true\" */\n"+
+            "  private int id;\n"+
+            "  /** @ojb.collection element-class-ref=\"test.B\"\n"+
+            "    *                 foreignkey=\"aid\"\n"+
+            "    *                 foreignkey-on-delete=\"\"\n"+
+            "    */\n"+
+            "  private java.util.List attr;\n"+
+            "}");
+        addClass(
+            "test.B",
+            "package test;\n"+
+            "/** @ojb.class */\n"+
+            "public class B {\n"+
+            "  /** @ojb.field */\n"+
+            "  private int aid;\n"+
+            "}\n");
+
+        assertNull(runOjbXDoclet(OJB_DEST_FILE));
+        assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
+    }
+
+    // Test: foreignkey-on-delete specified with illegal value
+    public void testForeignkeyOnDelete3()
+    {
+        addClass(
+            "test.A",
+            "package test;\n"+
+            "/** @ojb.class */\n" +
+            "public class A {\n"+
+            "  /** @ojb.field primarykey=\"true\" */\n"+
+            "  private int id;\n"+
+            "  /** @ojb.collection element-class-ref=\"test.B\"\n"+
+            "    *                 foreignkey=\"aid\"\n"+
+            "    *                 foreignkey-on-delete=\"no cascade\"\n"+
+            "    */\n"+
+            "  private java.util.List attr;\n"+
+            "}");
+        addClass(
+            "test.B",
+            "package test;\n"+
+            "/** @ojb.class */\n"+
+            "public class B {\n"+
+            "  /** @ojb.field */\n"+
+            "  private int aid;\n"+
+            "}\n");
+
+        assertNull(runOjbXDoclet(OJB_DEST_FILE));
+        assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
+    }
+
+    // Test: foreignkey-on-update specified
+    public void testForeignkeyOnUpdate1()
+    {
+        addClass(
+            "test.A",
+            "package test;\n"+
+            "/** @ojb.class */\n" +
+            "public class A {\n"+
+            "  /** @ojb.field primarykey=\"true\" */\n"+
+            "  private int id;\n"+
+            "  /** @ojb.collection element-class-ref=\"test.B\"\n"+
+            "    *                 foreignkey=\"aid\"\n"+
+            "    *                 foreignkey-on-update=\"none\"\n"+
+            "    */\n"+
+            "  private java.util.List attr;\n"+
+            "}");
+        addClass(
+            "test.B",
+            "package test;\n"+
+            "/** @ojb.class */\n"+
+            "public class B {\n"+
+            "  /** @ojb.field */\n"+
+            "  private int aid;\n"+
+            "}\n");
+
+        assertEqualsOjbDescriptorFile(
+            "<class-descriptor\n"+
+            "    class=\"test.A\"\n"+
+            "    table=\"A\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"id\"\n"+
+            "        column=\"id\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "        primarykey=\"true\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "    <collection-descriptor\n"+
+            "        name=\"attr\"\n"+
+            "        element-class-ref=\"test.B\"\n"+
+            "    >\n"+
+            "        <inverse-foreignkey field-ref=\"aid\"/>\n"+
+            "    </collection-descriptor>\n"+
+            "</class-descriptor>\n"+
+            "<class-descriptor\n"+
+            "    class=\"test.B\"\n"+
+            "    table=\"B\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"aid\"\n"+
+            "        column=\"aid\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "</class-descriptor>",
+            runOjbXDoclet(OJB_DEST_FILE));
+        assertEqualsTorqueSchemaFile(
+            "<database name=\"ojbtest\">\n"+
+            "    <table name=\"A\">\n"+
+            "        <column name=\"id\"\n"+
+            "                javaName=\"id\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "                primaryKey=\"true\"\n"+
+            "                required=\"true\"\n"+
+            "        />\n"+
+            "    </table>\n"+
+            "    <table name=\"B\">\n"+
+            "        <column name=\"aid\"\n"+
+            "                javaName=\"aid\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "        />\n"+
+            "        <foreign-key foreignTable=\"A\" onUpdate=\"none\">\n"+
+            "            <reference local=\"aid\" foreign=\"id\"/>\n"+
+            "        </foreign-key>\n"+
+            "    </table>\n"+
+            "</database>",
+            runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
+    }
+
+    // Test: foreignkey-on-update specified with empty value
+    public void testForeignkeyOnUpdate2()
+    {
+        addClass(
+            "test.A",
+            "package test;\n"+
+            "/** @ojb.class */\n" +
+            "public class A {\n"+
+            "  /** @ojb.field primarykey=\"true\" */\n"+
+            "  private int id;\n"+
+            "  /** @ojb.collection element-class-ref=\"test.B\"\n"+
+            "    *                 foreignkey=\"aid\"\n"+
+            "    *                 foreignkey-on-update=\"\"\n"+
+            "    */\n"+
+            "  private java.util.List attr;\n"+
+            "}");
+        addClass(
+            "test.B",
+            "package test;\n"+
+            "/** @ojb.class */\n"+
+            "public class B {\n"+
+            "  /** @ojb.field */\n"+
+            "  private int aid;\n"+
+            "}\n");
+
+        assertNull(runOjbXDoclet(OJB_DEST_FILE));
+        assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
+    }
+
+    // Test: foreignkey-on-update specified with illegal value
+    public void testForeignkeyOnUpdate3()
+    {
+        addClass(
+            "test.A",
+            "package test;\n"+
+            "/** @ojb.class */\n" +
+            "public class A {\n"+
+            "  /** @ojb.field primarykey=\"true\" */\n"+
+            "  private int id;\n"+
+            "  /** @ojb.collection element-class-ref=\"test.B\"\n"+
+            "    *                 foreignkey=\"aid\"\n"+
+            "    *                 foreignkey-on-update=\"nothing\"\n"+
+            "    */\n"+
+            "  private java.util.List attr;\n"+
+            "}");
+        addClass(
+            "test.B",
+            "package test;\n"+
+            "/** @ojb.class */\n"+
+            "public class B {\n"+
+            "  /** @ojb.field */\n"+
+            "  private int aid;\n"+
+            "}\n");
+
+        assertNull(runOjbXDoclet(OJB_DEST_FILE));
+        assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
+    }
+
+    // Test: foreignkey-on-delete and foreignkey-on-update specified
+    public void testForeignkeyOnDeleteAndOnUpdate()
+    {
+        addClass(
+            "test.A",
+            "package test;\n"+
+            "/** @ojb.class */\n" +
+            "public class A {\n"+
+            "  /** @ojb.field primarykey=\"true\" */\n"+
+            "  private int id;\n"+
+            "  /** @ojb.collection element-class-ref=\"test.B\"\n"+
+            "    *                 foreignkey=\"aid\"\n"+
+            "    *                 foreignkey-on-delete=\"cascade\"\n"+
+            "    *                 foreignkey-on-update=\"cascade\"\n"+
+            "    */\n"+
+            "  private java.util.List attr;\n"+
+            "}");
+        addClass(
+            "test.B",
+            "package test;\n"+
+            "/** @ojb.class */\n"+
+            "public class B {\n"+
+            "  /** @ojb.field */\n"+
+            "  private int aid;\n"+
+            "}\n");
+
+        assertEqualsOjbDescriptorFile(
+            "<class-descriptor\n"+
+            "    class=\"test.A\"\n"+
+            "    table=\"A\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"id\"\n"+
+            "        column=\"id\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "        primarykey=\"true\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "    <collection-descriptor\n"+
+            "        name=\"attr\"\n"+
+            "        element-class-ref=\"test.B\"\n"+
+            "    >\n"+
+            "        <inverse-foreignkey field-ref=\"aid\"/>\n"+
+            "    </collection-descriptor>\n"+
+            "</class-descriptor>\n"+
+            "<class-descriptor\n"+
+            "    class=\"test.B\"\n"+
+            "    table=\"B\"\n"+
+            ">\n"+
+            "    <field-descriptor\n"+
+            "        name=\"aid\"\n"+
+            "        column=\"aid\"\n"+
+            "        jdbc-type=\"INTEGER\"\n"+
+            "    >\n"+
+            "    </field-descriptor>\n"+
+            "</class-descriptor>",
+            runOjbXDoclet(OJB_DEST_FILE));
+        assertEqualsTorqueSchemaFile(
+            "<database name=\"ojbtest\">\n"+
+            "    <table name=\"A\">\n"+
+            "        <column name=\"id\"\n"+
+            "                javaName=\"id\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "                primaryKey=\"true\"\n"+
+            "                required=\"true\"\n"+
+            "        />\n"+
+            "    </table>\n"+
+            "    <table name=\"B\">\n"+
+            "        <column name=\"aid\"\n"+
+            "                javaName=\"aid\"\n"+
+            "                type=\"INTEGER\"\n"+
+            "        />\n"+
+            "        <foreign-key foreignTable=\"A\" onDelete=\"cascade\" onUpdate=\"cascade\">\n"+
+            "            <reference local=\"aid\" foreign=\"id\"/>\n"+
+            "        </foreign-key>\n"+
             "    </table>\n"+
             "</database>",
             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));



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