db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1139579 [1/2] - in /db/torque/torque4/trunk/torque-templates/src/main: java/org/apache/torque/templates/ java/org/apache/torque/templates/transformer/om/ resources/org/apache/torque/templates/om/conf/ resources/org/apache/torque/templates/...
Date Sat, 25 Jun 2011 18:36:04 GMT
Author: tfischer
Date: Sat Jun 25 18:36:03 2011
New Revision: 1139579

URL: http://svn.apache.org/viewvc?rev=1139579&view=rev
Log:
TORQUE-161:
Create filler methods for related objects

Added:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/ForeignKeyAttributeName.java
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/foreignKeyGetter.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeGetter.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencingObjects.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillerChunkSizeGetter.vm
Modified:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/FieldHelper.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/JavaFieldAttributeName.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peer.xml
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/imports.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/retrieveByPKs.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/retrieveByPKs.vm

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java Sat Jun 25 18:36:03 2011
@@ -72,7 +72,102 @@ public enum TemplateOptionName implement
     OM_MANAGER_CLASS_NAME_PREFIX("torque.om.className.managerClassNamePrefix"),
 
     /** The suffix of the name of the manager class. */
-    OM_MANAGER_CLASS_NAME_SUFFIX("torque.om.className.managerClassNameSuffix");
+    OM_MANAGER_CLASS_NAME_SUFFIX("torque.om.className.managerClassNameSuffix"),
+
+    /** The name of the option for the prefix of the adder methods. */
+    OM_ADDER_PREFIX("torque.om.complexObjectModel.adderPrefix"),
+
+    /** The name of the option for the suffix of the adder methods. */
+    OM_ADDER_SUFFIX("torque.om.complexObjectModel.adderSuffix"),
+
+    /** The name of the option for the prefix of the initializer methods. */
+    OM_INITIALIZER_PREFIX("torque.om.complexObjectModel.initializerPrefix"),
+
+    /** The name of the option for the suffix of the initializer methods. */
+    OM_INITIALIZER_SUFFIX("torque.om.complexObjectModel.initializerSuffix"),
+
+    /** The name of the option for the prefix of the filler methods. */
+    OM_FILLER_PREFIX("torque.om.complexObjectModel.fillerPrefix"),
+
+    /** The name of the option for the suffix of the filler methods. */
+    OM_FILLER_SUFFIX("torque.om.complexObjectModel.fillerSuffix"),
+
+    /**
+     * The name of the option for the part added to the referencing
+     * direction if naming conflicts occur.
+     */
+    OM_FILLER_REFERENCING_DISTICTION(
+            "torque.om.complexObjectModel.fillerReferencingDistinction"),
+
+    /**
+     * The name of the option containing the prefix for the local field name
+     * of a foreign-key reference.
+     */
+    OM_LOCAL_FIELD_NAME_PREFIX(
+            "torque.om.complexObjectModel.localFieldNamePrefix"),
+
+    /**
+     * The name of the option containing the suffix for the local field name
+     * of a foreign-key reference.
+     */
+    OM_LOCAL_FIELD_NAME_SUFFIX(
+            "torque.om.complexObjectModel.localFieldNameSuffix"),
+
+    /**
+     * The name of the option containing the prefix
+     * for the getter of the foreign key.
+     */
+    OM_FOREIGN_KEY_GETTER_PREFIX("torque.om.foreignKeyGetterPrefix"),
+
+    /**
+     * The name of the option containing the suffix
+     * for the getter of the foreign key.
+     */
+    OM_FOREIGN_KEY_GETTER_SUFFIX("torque.om.foreignKeyGetterSuffix"),
+    /**
+     * The name of the option for the part between referenced table name
+     * and referencing column name
+     * (only used if the same foreign table is referenced several times)
+     * as used in the local field name.
+     */
+    OM_LOCAL_FIELD_NAME_RELATED_BY(
+            "torque.om.complexObjectModel.localFieldNameRelatedBy"),
+
+    /**
+     * The name of the option containing the prefix for the foreign field name
+     * of a foreign-key reference.
+     */
+    OM_FOREIGN_FIELD_NAME_PREFIX(
+            "torque.om.complexObjectModel.foreignFieldNamePrefix"),
+
+    /**
+     * The name of the option containing the suffix for the foreign field name
+     * of a foreign-key reference.
+     */
+    OM_FOREIGN_FIELD_NAME_SUFFIX(
+            "torque.om.complexObjectModel.foreignFieldNameSuffix"),
+
+    /**
+     * The name of the option for the part between referenced table name
+     * and referencing column name
+     * (only used if the same local table is referenced several times)
+     * as used in the foreign field name.
+     */
+    OM_FOREIGN_FIELD_NAME_RELATED_BY(
+          "torque.om.complexObjectModel.foreignFieldNameRelatedBy"),
+
+    /**
+     * The name of the option for the java type for the foreign field
+     * (can be an interface),
+     */
+    OM_FOREIGN_FIELD_TYPE("torque.om.complexObjectModel.foreignFieldType"),
+
+    /**
+     * The name of the option for the java type for the initial value
+     * of the foreign field (must not be an interface).
+     */
+    OM_FOREIGN_FIELD_INIT_TYPE(
+            "torque.om.complexObjectModel.foreignFieldInitType");
 
     /**
      * The fully qualified name of the option.

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/FieldHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/FieldHelper.java?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/FieldHelper.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/FieldHelper.java Sat Jun 25 18:36:03 2011
@@ -84,30 +84,83 @@ final class FieldHelper
     }
 
     /**
+     * Returns the name of the field from a setter name.
+     * Removes the "set" prefix and decapitalizes the remainder.
+     *
+     * @param setterName the name of the setterName, not null, length > 3.
+     *
+     * @return the field name, not null.
+     */
+    public static String getFieldNameFromSetterName(String setterName)
+    {
+        String fieldName = StringUtils.uncapitalize(setterName.substring(3));
+        return fieldName;
+    }
+
+    /**
      * Returns the name of the adder method for a field.
-     * Uses "add" as prefix.
      *
      * @param fieldName the name of the field, not null.
+     * @param controllerState the current controller state, not null.
      *
      * @return the adder method name, not null.
      */
-    public static String getAdderName(String fieldName)
+    public static String getAdderName(
+            String fieldName,
+            ControllerState controllerState)
     {
-        String setterName = "add" + StringUtils.capitalize(fieldName);
-        return setterName;
+        String adderName
+            = controllerState.getOption(
+                    TemplateOptionName.OM_ADDER_PREFIX)
+                + StringUtils.capitalize(fieldName)
+                + controllerState.getOption(
+                      TemplateOptionName.OM_ADDER_SUFFIX);
+        return adderName;
     }
 
     /**
      * Returns the name of the initializer method for a field.
-     * Uses "init" as prefix and "s" as suffix.
      *
      * @param fieldName the name of the field, not null.
+     * @param controllerState the current controller state, not null.
+     *
+     * @return the initializer method name, not null.
+     */
+    public static String getInitializerName(
+            String fieldName,
+            ControllerState controllerState)
+    {
+        String initializerName
+            = controllerState.getOption(
+                    TemplateOptionName.OM_INITIALIZER_PREFIX)
+                + StringUtils.capitalize(fieldName)
+                + controllerState.getOption(
+                      TemplateOptionName.OM_INITIALIZER_SUFFIX);
+        return initializerName;
+    }
+
+    /**
+     * Returns the name of the filler method for a field.
+     *
+     * @param fieldName the name of the field, not null.
+     * @param distinctionPart a possible distinction addition for resolving
+     *        naming conflicts, not null.
+     * @param controllerState the current controller state, not null.
      *
      * @return the initializer method name, not null.
      */
-    public static String getInitializerName(String fieldName)
+    public static String getFillerName(
+            String fieldName,
+            String distinctionPart,
+            ControllerState controllerState)
     {
-        String setterName = "init" + StringUtils.capitalize(fieldName) + "s";
-        return setterName;
+        String fillerName
+            = controllerState.getOption(
+                    TemplateOptionName.OM_FILLER_PREFIX)
+                + distinctionPart
+                + StringUtils.capitalize(fieldName)
+                + controllerState.getOption(
+                  TemplateOptionName.OM_FILLER_SUFFIX);
+        return fillerName;
     }
 }

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/ForeignKeyAttributeName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/ForeignKeyAttributeName.java?rev=1139579&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/ForeignKeyAttributeName.java (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/ForeignKeyAttributeName.java Sat Jun 25 18:36:03 2011
@@ -0,0 +1,71 @@
+package org.apache.torque.templates.transformer.om;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.generator.source.SourceAttributeName;
+
+/**
+ * Contains the attribute names of the foreign-key
+ * source element which are not defined in the Torque schema.
+ * These attributes might be created in the transformation.
+ * 
+ * @version $Id: $
+ */
+public enum ForeignKeyAttributeName implements SourceAttributeName
+{
+    /**
+     * The name of the getter method for the foreign key object.
+     */
+    FOREIGN_KEY_GETTER("foreignKeyGetter"),
+    /**
+     * The name of the attribute containing the information whether
+     * the foreign key references the primary key of the foreign table.
+     */
+    REFERENCES_PRIMARY_KEY("referencesPrimaryKey");
+
+    /** The name of the source element, not null. */
+    private String name;
+
+    /**
+     * Constructor.
+     *
+     * @param name the name of the source element, not null.
+     */
+    private ForeignKeyAttributeName(String name)
+    {
+        this.name = name;
+    }
+
+    /**
+     * Returns the name of the referenced source element.
+     *
+     * @return the name of the referenced source element.
+     */
+    public String getName()
+    {
+        return name;
+    }
+
+    @Override
+    public String toString()
+    {
+        return name;
+    }
+}

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/JavaFieldAttributeName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/JavaFieldAttributeName.java?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/JavaFieldAttributeName.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/JavaFieldAttributeName.java Sat Jun 25 18:36:03 2011
@@ -78,6 +78,12 @@ public enum JavaFieldAttributeName imple
     ADDER_NAME("adder"),
 
     /**
+     * In case the field can be filled somehow:
+     * The name of the method used to fill the field.
+     */
+    FILLER_NAME("filler"),
+
+    /**
      * The access modifier (e.g. "public" ...) for the getter method
      **/
     GETTER_ACCESS_MODIFIER("getterAccessModifer"),

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java Sat Jun 25 18:36:03 2011
@@ -19,14 +19,14 @@ package org.apache.torque.templates.tran
  * under the License.
  */
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.torque.generator.GeneratorException;
 import org.apache.torque.generator.control.ControllerState;
 import org.apache.torque.generator.source.SourceElement;
-import org.apache.torque.generator.source.SourcePath;
 import org.apache.torque.generator.source.transform.SourceTransformerException;
+import org.apache.torque.templates.TemplateOptionName;
 import org.apache.torque.templates.TorqueSchemaAttributeName;
 import org.apache.torque.templates.TorqueSchemaElementName;
 
@@ -64,66 +64,6 @@ import org.apache.torque.templates.Torqu
  */
 public class OMForeignKeyTransformer
 {
-    /**
-     * The name of the option containing the prefix for the local field name
-     * of a foreign-key reference.
-     */
-    private static final String LOCAL_FIELD_NAME_PREFIX_OPTION
-            = "torque.om.complexObjectModel.localFieldNamePrefix";
-
-    /**
-     * The name of the option containing the suffix for the local field name
-     * of a foreign-key reference.
-     */
-    private static final String LOCAL_FIELD_NAME_SUFFIX_OPTION
-            = "torque.om.complexObjectModel.localFieldNameSuffix";
-
-    /**
-     * The name of the option for the filler between referenced table name
-     * and referencing column name
-     * (only used if the same foreign table is referenced several times)
-     * as used in the local field name.
-     */
-    private static final String LOCAL_FIELD_NAME_RELATED_BY_OPTION
-            = "torque.om.complexObjectModel.localFieldNameRelatedBy";
-
-    /**
-     * The name of the option containing the prefix for the foreign field name
-     * of a foreign-key reference.
-     */
-    private static final String FOREIGN_FIELD_NAME_PREFIX_OPTION
-        = "torque.om.complexObjectModel.foreignFieldNamePrefix";
-
-    /**
-     * The name of the option containing the suffix for the foreign field name
-     * of a foreign-key reference.
-     */
-    private static final String FOREIGN_FIELD_NAME_SUFFIX_OPTION
-        = "torque.om.complexObjectModel.foreignFieldNameSuffix";
-
-    /**
-     * The name of the option for the filler between referenced table name
-     * and referencing column name
-     * (only used if the same local table is referenced several times)
-     * as used in the foreign field name.
-     */
-    private static final String FOREIGN_FIELD_NAME_RELATED_BY_OPTION
-        = "torque.om.complexObjectModel.foreignFieldNameRelatedBy";
-
-    /**
-     * The name of the option for the java type for the foreign field
-     * (can be an interface),
-     */
-    private static final String FOREIGN_FIELD_TYPE_OPTION
-        = "torque.om.complexObjectModel.foreignFieldType";
-
-    /**
-     * The name of the option for the java type for the initial value
-     * of the foreign field (must not be an interface).
-     */
-    private static final String FOREIGN_FIELD_INIT_TYPE_OPTION
-        = "torque.om.complexObjectModel.foreignFieldInitType";
-
     public void transform(
             SourceElement foreignKey,
             ControllerState controllerState)
@@ -172,6 +112,25 @@ public class OMForeignKeyTransformer
             addForeignField(foreignKey, controllerState);
             addForeignFieldInBean(foreignKey, controllerState);
         }
+
+        setForeignKeyAttributes(foreignKey, controllerState);
+    }
+
+    /**
+     * Second pass of the transformation. Performs all steps which require that
+     * the first pass is complete.
+     *
+     * @param foreignKey the element to transform, not null.
+     * @param controllerState the controller state, not null.
+     *
+     * @throws SourceTransformerException if the transformation fails
+     */
+    public void transformSecondPass(
+            SourceElement foreignKey,
+            ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        modifyForeignFieldSecondPass(foreignKey, controllerState);
     }
 
    /**
@@ -196,11 +155,11 @@ public class OMForeignKeyTransformer
         {
             // the field name for the variable used
             String foreignFieldName = (String) controllerState.getOption(
-                        FOREIGN_FIELD_NAME_PREFIX_OPTION)
+                        TemplateOptionName.OM_FOREIGN_FIELD_NAME_PREFIX)
                     + localTable.getAttribute(
                             TableAttributeName.DB_OBJECT_CLASS_NAME)
                     + controllerState.getOption(
-                        FOREIGN_FIELD_NAME_SUFFIX_OPTION)
+                            TemplateOptionName.OM_FOREIGN_FIELD_NAME_SUFFIX)
                     + referencedBySuffix;
             // the field name to create the name of the getter and setter
             String getterSetterFieldName
@@ -235,7 +194,7 @@ public class OMForeignKeyTransformer
                     fieldContainedType);
 
             String fieldType = (String) controllerState.getOption(
-                        FOREIGN_FIELD_TYPE_OPTION)
+                    TemplateOptionName.OM_FOREIGN_FIELD_TYPE)
                     + "<" + fieldContainedType + ">";
             foreignFieldElement.setAttribute(
                     JavaFieldAttributeName.FIELD_TYPE,
@@ -264,21 +223,23 @@ public class OMForeignKeyTransformer
             }
             {
                 String adderName = FieldHelper.getAdderName(
-                        getterSetterFieldName);
+                        getterSetterFieldName,
+                        controllerState);
                 foreignFieldElement.setAttribute(
                         JavaFieldAttributeName.ADDER_NAME,
                         adderName);
             }
             {
                 String initializerName = FieldHelper.getInitializerName(
-                        getterSetterFieldName);
+                        getterSetterFieldName,
+                        controllerState);
                 foreignFieldElement.setAttribute(
                         JavaFieldAttributeName.INITIALIZER_NAME,
                         initializerName);
             }
             {
                 String initType = (String) controllerState.getOption(
-                        FOREIGN_FIELD_INIT_TYPE_OPTION)
+                        TemplateOptionName.OM_FOREIGN_FIELD_INIT_TYPE)
                     + "<" + fieldContainedType + ">";
                 foreignFieldElement.setAttribute(
                         JavaFieldAttributeName.INITIALIZER_TYPE,
@@ -286,6 +247,15 @@ public class OMForeignKeyTransformer
 
             }
             {
+                String fillerName = FieldHelper.getFillerName(
+                        getterSetterFieldName,
+                        "",
+                        controllerState);
+                foreignFieldElement.setAttribute(
+                        JavaFieldAttributeName.FILLER_NAME,
+                        fillerName);
+            }
+            {
                 // Name for a getter in the foreign table to
                 // retrieve entries in the foreign table plus the joined
                 // entries in the local table.
@@ -334,13 +304,84 @@ public class OMForeignKeyTransformer
     }
 
     /**
+     * Adds the the filler attribute to a foreign-field element.
+     * This method checks for naming conflicts with the local fields of the
+     * referenced table and modifies the filler name accordingly if a conflict
+     * is found.
+     * The name of all filler attributes of the local-field elements
+     * must be set when this method is called.
+     *
+     * @param foreignKey the foreign-key element which foreign-field
+     *        element should be modified.
+     * @param controllerState the current controller state.
+     */
+    private void modifyForeignFieldSecondPass(
+            SourceElement foreignKey,
+            ControllerState controllerState)
+    {
+        SourceElement foreignFieldElement
+            = foreignKey.getChild(ForeignKeyChildElementName.FOREIGN_FIELD);
+        if (foreignFieldElement == null)
+        {
+            return;
+        }
+        String setterName = (String) foreignFieldElement.getAttribute(
+                JavaFieldAttributeName.SETTER_NAME);
+        // setter gets a "s" appended, remove that
+        String regularSetterName
+                = setterName.substring(0, setterName.length() - 1);
+        String fieldName
+                = FieldHelper.getFieldNameFromSetterName(regularSetterName);
+        String fillerName = FieldHelper.getFillerName(
+                fieldName,
+                "",
+                controllerState);
+         // check whether there is a local-field in the referenced table
+        // which has the same filler name
+        SourceElement referencedTable = foreignKey.getChild(
+                TorqueSchemaElementName.TABLE);
+        boolean fillerNamingConflictFound = false;
+        for (SourceElement referencedTableForeignKey
+                : referencedTable.getChildren(
+                        TorqueSchemaElementName.FOREIGN_KEY))
+        {
+            SourceElement referencedTableLocalField
+                    = referencedTableForeignKey.getChild(
+                            ForeignKeyChildElementName.LOCAL_FIELD);
+            if (referencedTableLocalField == null)
+            {
+                continue;
+            }
+            String referencedTableFiller
+                    = (String) referencedTableLocalField.getAttribute(
+                            JavaFieldAttributeName.FILLER_NAME);
+            if (fillerName.equals(referencedTableFiller))
+            {
+                fillerNamingConflictFound = true;
+                break;
+            }
+        }
+        if (fillerNamingConflictFound)
+        {
+            fillerName = FieldHelper.getFillerName(
+                    fieldName,
+                    (String) controllerState.getOption(
+                        TemplateOptionName.OM_FILLER_REFERENCING_DISTICTION),
+                    controllerState);
+        }
+        foreignFieldElement.setAttribute(
+                JavaFieldAttributeName.FILLER_NAME,
+                fillerName);
+    }
+
+    /**
      * Create a foreign-field-in-bean element which describes the referenced
      * instances of the local table bean object in the foreign table bean class.
      * As more than one foreign bean can point to this bean,
      * the field needs to be a collection.
      *
      * @param foreignKey the foreign-key element
-     *        to which the local-field-in-bean element should be added.
+     *        to which the foreign-field-in-bean element should be added.
      * @param controllerState the current controller state.
      */
     private void addForeignFieldInBean(
@@ -359,11 +400,11 @@ public class OMForeignKeyTransformer
         // the field name for the variable used
         String foreignFieldInBeanName
                 = (String) controllerState.getOption(
-                        FOREIGN_FIELD_NAME_PREFIX_OPTION)
+                        TemplateOptionName.OM_FOREIGN_FIELD_NAME_PREFIX)
                     + localTable.getAttribute(
                             TableAttributeName.BEAN_CLASS_NAME)
                     + controllerState.getOption(
-                        FOREIGN_FIELD_NAME_SUFFIX_OPTION)
+                            TemplateOptionName.OM_FOREIGN_FIELD_NAME_SUFFIX)
                     + referencedBySuffix;
         SourceElement foreignFieldInBeanElement
                 = new SourceElement(
@@ -383,7 +424,7 @@ public class OMForeignKeyTransformer
                 fieldContainedType);
 
         String fieldType = (String) controllerState.getOption(
-                    FOREIGN_FIELD_TYPE_OPTION)
+                TemplateOptionName.OM_FOREIGN_FIELD_TYPE)
                 + "<" + fieldContainedType + ">";
         foreignFieldInBeanElement.setAttribute(
                 JavaFieldAttributeName.FIELD_TYPE,
@@ -391,7 +432,7 @@ public class OMForeignKeyTransformer
 
         {
             String initType = (String) controllerState.getOption(
-                        FOREIGN_FIELD_INIT_TYPE_OPTION)
+                    TemplateOptionName.OM_FOREIGN_FIELD_INIT_TYPE)
                     + "<" + fieldContainedType + ">";
             foreignFieldInBeanElement.setAttribute(
                     JavaFieldAttributeName.INITIALIZER_TYPE,
@@ -445,11 +486,11 @@ public class OMForeignKeyTransformer
                     + referencedBySuffix;
         // the field name for the variable used
         String localBeanFieldName = (String) controllerState.getOption(
-                    LOCAL_FIELD_NAME_PREFIX_OPTION)
+                TemplateOptionName.OM_LOCAL_FIELD_NAME_PREFIX)
                 + foreignTable.getAttribute(
                         TableAttributeName.BEAN_CLASS_NAME)
                 + controllerState.getOption(
-                            LOCAL_FIELD_NAME_SUFFIX_OPTION)
+                        TemplateOptionName.OM_LOCAL_FIELD_NAME_SUFFIX)
                 + referencedBySuffix;
         SourceElement localFieldInBeanElement
                 = new SourceElement(
@@ -505,11 +546,11 @@ public class OMForeignKeyTransformer
                 foreignKey, controllerState);
         // the field name for the variable used
         String localFieldName = (String) controllerState.getOption(
-                    LOCAL_FIELD_NAME_PREFIX_OPTION)
+                TemplateOptionName.OM_LOCAL_FIELD_NAME_PREFIX)
                 + foreignTable.getAttribute(
                         TableAttributeName.DB_OBJECT_CLASS_NAME)
                 + controllerState.getOption(
-                            LOCAL_FIELD_NAME_SUFFIX_OPTION)
+                        TemplateOptionName.OM_LOCAL_FIELD_NAME_SUFFIX)
                 + referencedBySuffix;
         // the field name to create the getter and setter names
         String getterSetterFieldName
@@ -549,6 +590,15 @@ public class OMForeignKeyTransformer
                     JavaFieldAttributeName.SETTER_NAME,
                     setterName);
         }
+        {
+            String fillerName = FieldHelper.getFillerName(
+                    getterSetterFieldName,
+                    "",
+                    controllerState);
+            localFieldElement.setAttribute(
+                    JavaFieldAttributeName.FILLER_NAME,
+                    fillerName);
+        }
         foreignKey.getChildren().add(localFieldElement);
     }
 
@@ -586,7 +636,7 @@ public class OMForeignKeyTransformer
                     .equals(localTableName))
         {
             result.append((String) controllerState.getOption(
-                    LOCAL_FIELD_NAME_RELATED_BY_OPTION));
+                    TemplateOptionName.OM_LOCAL_FIELD_NAME_RELATED_BY));
             for (SourceElement reference : foreignKey.getChildren(
                     TorqueSchemaElementName.REFERENCE))
             {
@@ -636,7 +686,7 @@ public class OMForeignKeyTransformer
         if (referencingSameTable.size() > 1)
         {
             result.append((String) controllerState.getOption(
-                    FOREIGN_FIELD_NAME_RELATED_BY_OPTION));
+                    TemplateOptionName.OM_FOREIGN_FIELD_NAME_RELATED_BY));
             for (SourceElement reference : foreignKey.getChildren(
                     TorqueSchemaElementName.REFERENCE))
             {
@@ -707,6 +757,58 @@ public class OMForeignKeyTransformer
         }
     }
 
+    private void setForeignKeyAttributes(
+            SourceElement foreignKey,
+            ControllerState controllerState)
+    {
+        SourceElement foreignTable = foreignKey.getChild(
+                TorqueSchemaElementName.TABLE);
+        String referencedBySuffix = getLocalReferencedBySuffix(
+                foreignKey, controllerState);
+        String foreignKeyGetterName = (String) controllerState.getOption(
+                TemplateOptionName.OM_FOREIGN_KEY_GETTER_PREFIX)
+            + foreignTable.getAttribute(
+                    TableAttributeName.DB_OBJECT_CLASS_NAME)
+            + controllerState.getOption(
+                    TemplateOptionName.OM_FOREIGN_KEY_GETTER_SUFFIX)
+            + referencedBySuffix;
+        foreignKey.setAttribute(
+                ForeignKeyAttributeName.FOREIGN_KEY_GETTER,
+                foreignKeyGetterName);
+
+        boolean referencesPrimaryKey = false;
+        List<SourceElement> foreignTablePrimaryKeys
+                = foreignTable.getChild(TableChildElementName.PRIMARY_KEYS)
+                        .getChildren(TorqueSchemaElementName.COLUMN);
+        List<SourceElement> foreignTableForeignKeyColumns 
+            = new ArrayList<SourceElement>();
+        for (SourceElement reference 
+                : foreignKey.getChildren(TorqueSchemaElementName.REFERENCE))
+        {
+            SourceElement column = reference.getChild(
+                    ReferenceChildElementName.FOREIGN_COLUMN)
+                        .getChild(TorqueSchemaElementName.COLUMN);
+            foreignTableForeignKeyColumns.add(column);
+        }
+        if (foreignTablePrimaryKeys.size() ==
+                foreignTableForeignKeyColumns.size())
+        {
+            referencesPrimaryKey = true;
+            for (int i = 0; i < foreignTablePrimaryKeys.size(); ++i)
+            {
+                if (foreignTablePrimaryKeys.get(i) 
+                        != foreignTableForeignKeyColumns.get(i))
+                {
+                    referencesPrimaryKey = false;
+                    break;
+                }
+            }
+        }
+        foreignKey.setAttribute(
+                ForeignKeyAttributeName.REFERENCES_PRIMARY_KEY,
+                referencesPrimaryKey);
+    }
+
     private void getParentPath(
             SourceElement sourceElement,
             StringBuilder result)

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java Sat Jun 25 18:36:03 2011
@@ -106,8 +106,8 @@ public class OMTransformer implements So
 
         // load referenced external schemata
         loadExternalSchemaTransformer.transform(root, controllerState);
-        
-        SourceElement allTablesRoot 
+
+        SourceElement allTablesRoot
                 = root.getChild(DatabaseChildElementName.ALL_TABLES);
         for (SourceElement tableElement : allTablesRoot.getChildren(
                 TorqueSchemaElementName.TABLE))
@@ -135,6 +135,19 @@ public class OMTransformer implements So
                         controllerState);
             }
         }
+
+        for (SourceElement tableElement : allTablesRoot.getChildren(
+                TorqueSchemaElementName.TABLE))
+        {
+            for (SourceElement foreignKeyElement : tableElement.getChildren(
+                    TorqueSchemaElementName.FOREIGN_KEY))
+            {
+                foreignKeyTransformer.transformSecondPass(
+                        foreignKeyElement,
+                        controllerState);
+            }
+        }
+
         return root;
     }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties Sat Jun 25 18:36:03 2011
@@ -15,39 +15,79 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# If true, Torque puts time stamps in generated om files.
+# This also triggers the generation of "serialVersionUID"-constants
+# in the classes that implement Serializable (object, peer and manager).
+# The version is equal to the generation timestamp. 
 torque.om.addTimeStamp = true
 
-torque.om.addIntakeRetrievable = true
+# If true, the data objects will implement Intake's Retrievable interface
+torque.om.addIntakeRetrievable = false
+# Defines the Retrievable interface.
+# (set to org.apache.fulcrum.intake.Retrievable if you are using Fulcrum) 
 torque.om.retrievableInterface = org.apache.turbine.om.Retrievable
 
-# replaces torque.correctGetters
+# If true, Torque generates isX getter methods for boolean columns
+# instead of getX methods.
 torque.om.useIsForBooleanGetters = true;
 
+# If true, Torque generates data objects with getters and setters 
+# for referenced and referencing objects connected by foreign key relations.
 torque.om.complexObjectModel = true
+# If true, Torque generates data objects that cache their foreign key
+# relationships. 
+# This option has no effect if torque.om.complexObjectModel is set to false.
 torque.om.objectIsCaching = true
 
+# If true, Torque silently fetches data objects related by foreign key relations
+# if the objects are accessed by invoking a getter on a related data object
+# and the field read from the getter is not yet initialized.
+# If false, Torque simply returns null if the related objects have not
+# yet been read.
+# This option has no effect if torque.om.objectIsCaching is set to false.
 torque.om.silentDbFetch = true
 
+# If true, Torque adds methods to get database fields by name/position.
 torque.om.addGetByNameMethods = true
 
+# If true, Torque generates a bean object for each data object, 
+# plus methods to convert data objects to beans and vice versa.
 torque.om.generateBeans = false
+# A fully qualified class name (e.g. org.apache.struts.action.ActionForm)
+# that the generated base bean classes will extend. 
 torque.om.bean.beanExtendsClass = 
 
+# Whether Manager classes should be generated which cache data objects
+# using JCS.
 torque.om.useManagers = false
 
+# Whether a save method is generated in the data object classes.
 torque.om.save.addSaveMethods = true
+# The exception which is declared to be thrown by the save method.
 torque.om.save.saveException = TorqueException
+# Whether the data object should track whether it has been modified
+# after it has been loaded from the database or saved to the database
 torque.om.trackModified = true
-# trackNew needs to be set to true if addSaveMethods is true 
+# Whether new data objects (i.e. constructed but not yet persisted) should be 
+# tracked. The information is needed by torque to decide whether an insert
+# or an update command is used when saving, thus, trackNew needs to be set
+# to true if addSaveMethods is true 
 torque.om.trackNew = true
 
-torque.om.generateMapInit = true
+# If true, a MapInit Class is generated for each database which can be used
+# to initialize all database map classes
+torque.om.generateMapInit = false
 torque.om.mapInit.mapInitClassNamePrefix = 
 torque.om.mapInit.mapInitClassNameSuffix = MapInit
 torque.om.mapInit.mapInitPackage = org.apache.torque.linkage
 
-# Settings for the fields representing objects which are referenced by
-# foreign keys.
+# Settings for foreign key methods
+# Prefix and Suffix for the getter of the foreign key
+torque.om.foreignKeyGetterPrefix = getForeignKeyFor
+torque.om.foreignKeyGetterSuffix = 
+
+# Settings for the fields and methods representing objects 
+# which are referenced by foreign keys.
 #
 # Prefix and Suffix for the instance variable on the "local" side of the fk
 # Field Name is ${prefix}${referencedObjectClass}${suffix}
@@ -63,6 +103,20 @@ torque.om.complexObjectModel.foreignFiel
 torque.om.complexObjectModel.foreignFieldNameSuffix = s
 torque.om.complexObjectModel.foreignFieldNameRelatedBy = RelatedBy
 
+# Prefix and Suffix for the adder method on the "local" side of the fk
+# Method name is ${prefix}${referencedObjectClass}${suffix}
+# If necessary ${torque.om.complexObjectModel.localFieldNameRelatedBy} 
+# followed by the column names is appended to this. 
+torque.om.complexObjectModel.adderPrefix = add
+torque.om.complexObjectModel.adderSuffix = 
+
+# Prefix and Suffix for the initializer method on the "local" side of the fk
+# Method name is ${prefix}${referencedObjectClass}${suffix}
+# If necessary ${torque.om.complexObjectModel.localFieldNameRelatedBy} 
+# followed by the column names is appended to this. 
+torque.om.complexObjectModel.initializerPrefix = init
+torque.om.complexObjectModel.initializerSuffix = s
+
 # Type of the instance variable on the "foreign" side of the fk
 # This type will be generified.
 torque.om.complexObjectModel.foreignFieldType = List
@@ -70,46 +124,99 @@ torque.om.complexObjectModel.foreignFiel
 # initialized with in the init method
 torque.om.complexObjectModel.foreignFieldInitType = ArrayList
 
-# new options
+# Whether doSelectJoin methods are generated which fetch related objects
+# in one database query
+torque.om.complexObjectModel.generateDoSelectJoin = true
+
+# Whether filler methods are generated which can efficiently read
+# data objects related by a foreign key relation for a list of other
+# data objects.
+torque.om.complexObjectModel.generateFillers = false
+
+# Prefix and Suffix for the filler method on the "local" side of the fk
+# Method name is ${prefix}${referencedObjectClass}${suffix}
+# If necessary ${torque.om.complexObjectModel.localFieldNameRelatedBy} 
+# followed by the column names is appended to this. 
+torque.om.complexObjectModel.fillerPrefix = fill
+torque.om.complexObjectModel.fillerSuffix = s
+# The part which is added to the filler methods in the case that
+# filler methods for referencing and referenced objects have the same name
+torque.om.complexObjectModel.fillerReferencingDistinction = Referencing
+
+# The default chunk size for the filler methods.
+torque.om.complexObjectModel.defaultFillerChunkSize=999
+
+# The default base class for all data objects.
+# can be overridden by setting the baseClass attribute on a table.
 torque.om.dbObjectDefaultBaseClass = org.apache.torque.om.BaseObject
+# The base class for all Peer classes
 torque.om.basePeerBaseClass = org.apache.torque.util.BasePeer
+# The base class for all Peer implementation classes
 torque.om.basePeerImplBaseClass = org.apache.torque.util.BasePeerImpl
 
+# Prefixes and suffixes for the java names of the generated classes
+#
+# Prefix and suffix for the base data object classes
 torque.om.className.baseDbObjectClassNamePrefix = Base
 torque.om.className.baseDbObjectClassNameSuffix =
+# Prefix and suffix for the peer classes
 torque.om.className.peerClassNamePrefix =
 torque.om.className.peerClassNameSuffix = Peer
+# Prefix and suffix for the peer implementation classes
 torque.om.className.peerImplClassNamePrefix = 
 torque.om.className.peerImplClassNameSuffix = PeerImpl
+# Prefix and suffix for the base peer classes
 torque.om.className.basePeerClassNamePrefix = Base
 torque.om.className.basePeerClassNameSuffix = Peer
+# Prefix and suffix for the base peer implementation classes
 torque.om.className.basePeerImplClassNamePrefix = Base
 torque.om.className.basePeerImplClassNameSuffix = PeerImpl
+# Prefix and suffix for the manager classes
 torque.om.className.managerClassNamePrefix =
 torque.om.className.managerClassNameSuffix = Manager
+# Prefix and suffix for the manager base classes
 torque.om.className.baseManagerClassNamePrefix = Base
 torque.om.className.baseManagerClassNameSuffix = Manager
+# Prefix and suffix for the bean classes
 torque.om.className.beanClassNamePrefix =
 torque.om.className.beanClassNameSuffix = Bean
+# Prefix and suffix for the base bean classes
 torque.om.className.baseBeanClassNamePrefix = Base
 torque.om.className.baseBeanClassNameSuffix = Bean
+# Prefix and suffix for the map builder classes
 torque.om.className.mapBuilderClassNamePrefix =
 torque.om.className.mapBuilderClassNameSuffix = MapBuilder
+# Prefix and suffix for the record mapper classes
 torque.om.className.recordMapperClassNamePrefix =
 torque.om.className.recordMapperClassNameSuffix = RecordMapper
+# Prefix and suffix for the base record mapper classes
 torque.om.className.baseRecordMapperClassNamePrefix = Base
 torque.om.className.baseRecordMapperClassNameSuffix = RecordMapper
 
+# Suffixes for the package names of the generated classes
+#
+# package suffix for the data object classes
 torque.om.package.dbObjectPackageSuffix =
+# package suffix for the base data object classes
 torque.om.package.baseDbObjectPackageSuffix =
+# package suffix for the peer classes
 torque.om.package.peerPackageSuffix =
+# package suffix for the base peer classes
 torque.om.package.basePeerPackageSuffix =
+# package suffix for the reccord mapper classes
 torque.om.package.recordMapperPackageSuffix =
+# package suffix for the base reccord mapper classes
 torque.om.package.baseRecordMapperPackageSuffix =
+# package suffix for the manager classes
 torque.om.package.managerPackageSuffix = .manager
+# package suffix for the base manager classes
 torque.om.package.baseManagerPackageSuffix = .manager.base
+# package suffix for the bean classes
 torque.om.package.beanPackageSuffix = .bean
+# package suffix for the base bean classes
 torque.om.package.baseBeanPackageSuffix = .bean
+# package suffix for the map builder classes
 torque.om.package.mapPackageSuffix = .map
 
+# Default column type if the column type is not set for a column
 torque.om.column.defaultType = VARCHAR

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml Sat Jun 25 18:36:03 2011
@@ -93,6 +93,11 @@
       <action xsi:type="applyAction"
           outlet="torque.om.dbObject.base.primaryKeyMethods"/>
     </mergepoint>
+    <mergepoint name="foreignKeyGetters">
+      <action xsi:type="traverseAllAction"
+          element="foreign-key"
+          outlet="torque.om.dbObject.base.foreignKeyGetter"/>
+    </mergepoint>
      <mergepoint name="copyMethods">
       <action xsi:type="applyAction"
           outlet="torque.om.dbObject.base.copyMethods"/>
@@ -208,6 +213,11 @@
       path="dbObject/base/primaryKeyMethods.vm">
   </outlet>
 
+  <outlet name="torque.om.dbObject.base.foreignKeyGetter"
+      xsi:type="velocityOutlet"
+      path="dbObject/base/foreignKeyGetter.vm">
+  </outlet>
+
   <outlet name="torque.om.dbObject.base.copyMethods"
       xsi:type="velocityOutlet"
       path="dbObject/base/copyMethods.vm">

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peer.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peer.xml?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peer.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peer.xml Sat Jun 25 18:36:03 2011
@@ -113,10 +113,26 @@
       <action xsi:type="applyAction" outlet="torque.om.peer.impl.base.retrieveByPKs"/>
     </mergepoint>
     <mergepoint name="doSelectJoin">
-      <action xsi:type="traverseAllAction" element="foreign-key/foreign-field" outlet="torque.om.peer.impl.base.doSelectJoin"/>
+      <action xsi:type="traverseAllAction" element="foreign-key/foreign-field"
+          outlet="torque.om.peer.impl.base.doSelectJoin"/>
     </mergepoint>
     <mergepoint name="doSelectJoinAllExcept">
-      <action xsi:type="traverseAllAction" element="foreign-key/foreign-field" outlet="torque.om.peer.impl.base.doSelectJoinAllExcept"/>
+      <action xsi:type="traverseAllAction" element="foreign-key/foreign-field"
+          outlet="torque.om.peer.impl.base.doSelectJoinAllExcept"/>
+    </mergepoint>
+    <mergepoint name="fillReferencedObjects">
+      <action xsi:type="traverseAllAction"
+          element="foreign-key/local-field"
+          outlet="torque.om.peer.impl.base.fillReferencedObject"/>
+    </mergepoint>
+    <mergepoint name="fillReferencingObjects">
+      <action xsi:type="traverseAllAction"
+          element="referencing-foreign-keys/foreign-key/foreign-field"
+          outlet="torque.om.peer.impl.base.fillReferencingObjects"/>
+    </mergepoint>
+    <mergepoint name="fillerChunkSizeGetter">
+      <action xsi:type="applyAction"
+          outlet="torque.om.peer.impl.base.fillerChunkSizeGetter"/>
     </mergepoint>
     <mergepoint name="getTableMap">
       <action xsi:type="applyAction" outlet="torque.om.peer.impl.base.getTableMap"/>
@@ -222,6 +238,21 @@
       path="peer/impl/base/doSelectJoinAllExcept.vm">
   </outlet>
 
+  <outlet name="torque.om.peer.impl.base.fillReferencedObject"
+      xsi:type="velocityOutlet"
+      path="peer/impl/base/fillReferencedObject.vm">
+  </outlet>
+
+  <outlet name="torque.om.peer.impl.base.fillReferencingObjects"
+      xsi:type="velocityOutlet"
+      path="peer/impl/base/fillReferencingObjects.vm">
+  </outlet>
+
+  <outlet name="torque.om.peer.impl.base.fillerChunkSizeGetter"
+      xsi:type="velocityOutlet"
+      path="peer/impl/base/fillerChunkSizeGetter.vm">
+  </outlet>
+
   <outlet name="torque.om.peer.impl.base.getTableMap"
       xsi:type="velocityOutlet"
       path="peer/impl/base/getTableMap.vm">
@@ -322,10 +353,26 @@
       <action xsi:type="applyAction" outlet="torque.om.peer.base.retrieveByPKs"/>
     </mergepoint>
     <mergepoint name="doSelectJoin">
-      <action xsi:type="traverseAllAction" element="foreign-key/foreign-field" outlet="torque.om.peer.base.doSelectJoin"/>
+      <action xsi:type="traverseAllAction" element="foreign-key/foreign-field"
+          outlet="torque.om.peer.base.doSelectJoin"/>
     </mergepoint>
     <mergepoint name="doSelectJoinAllExcept">
-      <action xsi:type="traverseAllAction" element="foreign-key/foreign-field" outlet="torque.om.peer.base.doSelectJoinAllExcept"/>
+      <action xsi:type="traverseAllAction" element="foreign-key/foreign-field"
+          outlet="torque.om.peer.base.doSelectJoinAllExcept"/>
+    </mergepoint>
+    <mergepoint name="fillReferencedObjects">
+      <action xsi:type="traverseAllAction"
+          element="foreign-key/local-field"
+          outlet="torque.om.peer.base.fillReferencedObject"/>
+    </mergepoint>
+    <mergepoint name="fillReferencingObjects">
+      <action xsi:type="traverseAllAction"
+          element="referencing-foreign-keys/foreign-key/foreign-field"
+          outlet="torque.om.peer.base.fillReferencingObjects"/>
+    </mergepoint>
+    <mergepoint name="fillerChunkSizeGetter">
+      <action xsi:type="applyAction"
+          outlet="torque.om.peer.base.fillerChunkSizeGetter"/>
     </mergepoint>
     <mergepoint name="getTableMap">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.getTableMap"/>
@@ -505,6 +552,21 @@
       path="peer/base/doSelectJoinAllExcept.vm">
   </outlet>
 
+  <outlet name="torque.om.peer.base.fillReferencedObject"
+      xsi:type="velocityOutlet"
+      path="peer/base/fillReferencedObject.vm">
+  </outlet>
+
+  <outlet name="torque.om.peer.base.fillReferencingObjects"
+      xsi:type="velocityOutlet"
+      path="peer/base/fillReferencingObjects.vm">
+  </outlet>
+
+  <outlet name="torque.om.peer.base.fillerChunkSizeGetter"
+      xsi:type="velocityOutlet"
+      path="peer/base/fillerChunkSizeGetter.vm">
+  </outlet>
+
   <outlet name="torque.om.peer.base.getTableMap"
       xsi:type="velocityOutlet"
       path="peer/base/getTableMap.vm">

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm Sat Jun 25 18:36:03 2011
@@ -77,8 +77,8 @@ $torqueGen.mergepoint("classJavadoc")
   #set ($extendsBaseClass = "extends $baseClass" )
 #end
 public abstract class $baseDbObjectClassName $extendsBaseClass
-#if ($torqueGen.booleanOption("torque.addIntakeRetrievable"))
-    implements $torqueGen.option("torque.retrievableInterface")
+#if ($torqueGen.booleanOption("torque.om.addIntakeRetrievable"))
+    implements $torqueGen.option("torque.om.retrievableInterface")
 #end
 {
 $torqueGen.mergepoint("serialVersionUid")
@@ -116,6 +116,7 @@ $torqueGen.mergepoint("saveMethods")
 #end
 
 $torqueGen.mergepoint("primaryKeyMethods")
+$torqueGen.mergepoint("foreignKeyGetters")
 $torqueGen.mergepoint("copyMethods")
 $torqueGen.mergepoint("peerGetter")
 $torqueGen.mergepoint("tableMapGetter")

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/foreignKeyGetter.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/foreignKeyGetter.vm?rev=1139579&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/foreignKeyGetter.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/foreignKeyGetter.vm Sat Jun 25 18:36:03 2011
@@ -0,0 +1,64 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##   http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied.  See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## This template creates primary key methods.  
+## The template expects as input a "table" element from the torque schema, 
+## which was processed by the OMTransformer.  
+##
+#set ( $referenceElements = $torqueGen.getChildren("reference"))
+#set ( $foreignTableElement = $torqueGen.getChild("table"))
+#set ( $foreignDbObjectClassName = $foreignTableElement.getAttribute("dbObjectClassName"))
+    /**
+     * Returns an id that differentiates the referenced ${foreignDbObjectClassName} object
+     * from all other ${foreignDbObjectClassName} objects.
+     */
+    public ObjectKey ${foreignKeyGetter}()
+    {
+#if ($referenceElements.size() == 1)
+  #set ( $columnElement = $referenceElements.get(0).getChild("local-column").getChild("column") )
+  #set ( $columnDefaultValue = $columnElement.getAttribute("defaultValue") )
+  #set ( $columnType = $columnElement.getAttribute("fieldType") )
+  #set ( $columnIsPrimitive = $columnElement.getAttribute("primitive") )
+  #set ( $getter = $columnElement.getAttribute("getter") )
+  #if ($columnIsPrimitive)
+        ${columnType} foreignKey = ${getter}();
+        if (foreignKey == ${columnDefaultValue})
+        {
+            return null;
+        }
+        return SimpleKey.keyFor(foreignKey);
+  #else
+        return SimpleKey.keyFor(${getter}());
+  #end
+#elseif ($referenceElements.size() > 1)
+        SimpleKey[] pks = new SimpleKey[$referenceElements.size()];
+  #set ($i = 0)
+  #foreach ($referenceElement in $referenceElements)
+    #set ($columnElement = $referenceElement.getChild("local-column").getChild("column"))
+    #set ( $getter = $columnElement.getAttribute("getter") )
+        pks[$i] = SimpleKey.keyFor(${getter}());
+    #set ($i = $i + 1)
+  #end
+        return new ComboKey(pks);
+#else
+        return null;
+#end
+    }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm Sat Jun 25 18:36:03 2011
@@ -64,8 +64,15 @@ $torqueGen.mergepoint("buildColumnValues
 $torqueGen.mergepoint("retrieveByPK")
 $torqueGen.mergepoint("retrieveByPKs")
 #if ($complexObjectModel == "true")
+  #if ($torqueGen.booleanOption("torque.om.complexObjectModel.generateDoSelectJoin"))
 $torqueGen.mergepoint("doSelectJoin")
 $torqueGen.mergepoint("doSelectJoinAllExcept")
+  #end
+  #if ($torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
+$torqueGen.mergepoint("fillReferencedObjects")
+$torqueGen.mergepoint("fillReferencingObjects")
+$torqueGen.mergepoint("fillerChunkSizeGetter")
+  #end
 #end
 $torqueGen.mergepoint("getTableMap")
 $torqueGen.mergepoint("setDbName")

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm?rev=1139579&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm Sat Jun 25 18:36:03 2011
@@ -0,0 +1,72 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##   http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied.  See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Creates the fillXXX methods for the base peer implementation.
+## 
+## This template expects the current source element to be a "foreign-field" 
+## element from the schema, processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+#set ( $foreignKeyElement = $torqueGen.getParent() )
+#set ( $localTableElement = $foreignKeyElement.getParent() )
+#set ( $peerImplGetter = $localTableElement.getAttribute("peerImplGetter") )
+#set ( $localDbObjectClassName = $localTableElement.getAttribute("dbObjectClassName") )
+#set ( $foreignTableElement = $foreignKeyElement.getChild("table") )
+#if ($foreignTableElement.getChild("primary-keys").getChildren().size() > 0)
+    /** 
+     * Fills the referenced ${fieldType} objects in the ${field} fields
+     * of the objects in <code>toFill</code> by reading the database.
+     *
+     * @param toFill Contains the objects to fill, not null, may not contain null.
+     *
+     * @return all read ${fieldType} objects.
+     *
+     * @throws TorqueException if an error querying the database occurs.
+     * @throws NullPointerException if toFill is null or contains null elements.
+     */
+    public static List<${fieldType}> ${filler}(
+            Collection<${localDbObjectClassName}> toFill) 
+        throws TorqueException
+    {
+        return ${peerImplGetter}().${filler}(toFill);
+    }
+
+    /** 
+     * Fills the referenced ${fieldType} objects in the ${field} fields
+     * of the objects in <code>toFill</code> by reading the database.
+     *
+     * @param toFill Contains the objects to fill, not null, may not contain null.
+     * @param connection the database connection to use, not null.
+     *
+     * @return all read ${fieldType} objects.
+     *
+     * @throws TorqueException if an error querying the database occurs.
+     * @throws NullPointerException if toFill is null or contains null elements.
+     */
+    public static List<${fieldType}> ${filler}(
+            Collection<${localDbObjectClassName}> toFill,
+            Connection connection) 
+        throws TorqueException
+    {
+        return ${peerImplGetter}().${filler}(toFill, connection);
+    }
+#end

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm?rev=1139579&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm Sat Jun 25 18:36:03 2011
@@ -0,0 +1,72 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##   http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied.  See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Creates the fillXXX methods for the base peer implementation.
+## 
+## This template expects the current source element to be a "foreign-field" 
+## element from the schema, processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+#set ( $foreignKeyElement = $torqueGen.getParent() )
+#set ( $localTableElement = $foreignKeyElement.getChild("table") )
+#set ( $peerImplGetter = $localTableElement.getAttribute("peerImplGetter") )
+#set ( $localDbObjectClassName = $localTableElement.getAttribute("dbObjectClassName") )
+#set ( $foreignTableElement = $foreignKeyElement.getParent() )
+#if ($foreignTableElement.getChild("primary-keys").getChildren().size() > 0)
+    /** 
+     * Fills the referenced ${fieldContainedType} objects in the ${field} fields
+     * of the objects in <code>toFill</code> by reading the database.
+     *
+     * @param toFill Contains the objects to fill, not null, may not contain null.
+     *
+     * @return all read ${fieldType} objects.
+     *
+     * @throws TorqueException if an error querying the database occurs.
+     * @throws NullPointerException if toFill is null or contains null elements.
+     */
+    public static List<${fieldContainedType}> ${filler}(
+            Collection<${localDbObjectClassName}> toFill) 
+        throws TorqueException
+    {
+        return ${peerImplGetter}().${filler}(toFill);
+    }
+
+    /** 
+     * Fills the referenced ${fieldContainedType} objects in the ${field} fields
+     * of the objects in <code>toFill</code> by reading the database.
+     *
+     * @param toFill Contains the objects to fill, not null, may not contain null.
+     * @param connection the database connection to use, not null.
+     *
+     * @return all read ${fieldType} objects.
+     *
+     * @throws TorqueException if an error querying the database occurs.
+     * @throws NullPointerException if toFill is null or contains null elements.
+     */
+    public static List<${fieldContainedType}> ${filler}(
+            Collection<${localDbObjectClassName}> toFill,
+            Connection connection) 
+        throws TorqueException
+    {
+        return ${peerImplGetter}().${filler}(toFill, connection);
+    }
+#end

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeGetter.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeGetter.vm?rev=1139579&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeGetter.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeGetter.vm Sat Jun 25 18:36:03 2011
@@ -0,0 +1,37 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##   http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied.  See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Creates the fillXXX methods for the base peer implementation.
+## 
+## This template expects the current source element to be a "foreign-field" 
+## element from the schema, processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+    /** 
+     * Returns the chunk size for the filler methods.
+     *
+     * @return the chunk size for the filler methods.
+     */
+    protected static int getFillerChunkSize()
+    {
+        return ${peerImplGetter}().getFillerChunkSize();
+    }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/imports.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/imports.vm?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/imports.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/imports.vm Sat Jun 25 18:36:03 2011
@@ -27,24 +27,15 @@
 ## The options and the attributes of the current source element must be set
 ## as velocity variables.  
 ##
-import java.sql.Blob;
-import java.sql.Clob;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.ResultSet;
-import java.sql.PreparedStatement;
-import java.sql.Types;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.commons.logging.Log;

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/retrieveByPKs.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/retrieveByPKs.vm?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/retrieveByPKs.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/retrieveByPKs.vm Sat Jun 25 18:36:03 2011
@@ -36,7 +36,7 @@
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public static List<${dbObjectClassName}> retrieveByPKs(List<ObjectKey> pks)
+    public static List<${dbObjectClassName}> retrieveByPKs(Collection<ObjectKey> pks)
         throws TorqueException
     {
         return ${peerImplGetter}().retrieveByPKs(pks);
@@ -50,7 +50,7 @@
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public static List<${dbObjectClassName}> retrieveByPKs(List<ObjectKey> pks, Connection con)
+    public static List<${dbObjectClassName}> retrieveByPKs(Collection<ObjectKey> pks, Connection con)
         throws TorqueException
     {
         return ${peerImplGetter}().retrieveByPKs(pks,con);

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm?rev=1139579&r1=1139578&r2=1139579&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm Sat Jun 25 18:36:03 2011
@@ -56,8 +56,15 @@ $torqueGen.mergepoint("buildColumnValues
 $torqueGen.mergepoint("retrieveByPK")
 $torqueGen.mergepoint("retrieveByPKs")
 #if ($complexObjectModel == "true")
+  #if ($torqueGen.booleanOption("torque.om.complexObjectModel.generateDoSelectJoin"))
 $torqueGen.mergepoint("doSelectJoin")
 $torqueGen.mergepoint("doSelectJoinAllExcept")
+  #end
+  #if ($torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
+$torqueGen.mergepoint("fillReferencedObjects")
+$torqueGen.mergepoint("fillReferencingObjects")
+$torqueGen.mergepoint("fillerChunkSizeGetter")
+  #end
 #end
 $torqueGen.mergepoint("getTableMap")
 $torqueGen.mergepoint("setDbName")

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm?rev=1139579&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm Sat Jun 25 18:36:03 2011
@@ -0,0 +1,215 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##   http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied.  See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Creates the fillXXX methods for referenced Objects for the base peer
+## implementation.
+## 
+## This template expects the current source element to be a "local-field" 
+## element from the schema, processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+#set ( $foreignKeyElement = $torqueGen.getParent() )
+#set ( $foreignKeyGetter = $foreignKeyElement.getAttribute("foreignKeyGetter") )
+#set ( $referencesPrimaryKey = $foreignKeyElement.getAttribute("referencesPrimaryKey") )
+#set ( $foreignKeyReferences = $foreignKeyElement.getChildren("reference") )
+#set ( $localTableElement = $foreignKeyElement.getParent() )
+#set ( $localTableField = $localTableElement.getAttribute("field") )
+#set ( $localDbObjectClassName = $localTableElement.getAttribute("dbObjectClassName") )
+#set ( $localPeerClassName = $localTableElement.getAttribute("peerClassName") )
+#set ( $foreignTableElement = $foreignKeyElement.getChild("table") )
+#set ( $foreignTablePeerClassName = $foreignTableElement.getAttribute("peerClassName") )
+#set ( $foreignTableName = $foreignTableElement.getAttribute("name") )
+    /** 
+     * Fills the referenced ${fieldType} objects in the ${field} fields
+     * of the objects in <code>toFill</code> by reading the database.
+     *
+     * @param toFill Contains the objects to fill, not null,
+     *        may not contain null.
+     *
+     * @return all read ${fieldType} objects.
+     *
+     * @throws TorqueException if an error querying the database occurs.
+     * @throws NullPointerException if toFill is null or contains null elements.
+     */
+    public List<${fieldType}> ${filler}(
+            Collection<${localDbObjectClassName}> toFill) 
+        throws TorqueException
+    {
+        Connection connection = null;
+        try
+        {
+            connection = Transaction.beginOptional(
+                    ${localPeerClassName}.DATABASE_NAME,
+                    true);
+            List<${fieldType}> result = ${filler}(toFill, connection);
+            Transaction.commit(connection);
+            connection = null;
+            return result;
+        }
+        finally
+        {
+            if (connection != null)
+            {
+                Transaction.safeRollback(connection);
+            }
+        }
+    }
+
+    /** 
+     * Fills the referenced ${fieldType} objects in the ${field} fields
+     * of the objects in <code>toFill</code> by reading the database.
+     *
+     * @param toFill Contains the objects to fill, not null,
+     *        may not contain null.
+     * @param connection the database connection to use, not null.
+     *
+     * @return all read ${fieldType} objects.
+     *
+     * @throws TorqueException if an error querying the database occurs.
+     * @throws NullPointerException if toFill is null or contains null elements.
+     */
+    public List<${fieldType}> ${filler}(
+            Collection<${localDbObjectClassName}> toFill,
+            Connection connection) 
+        throws TorqueException
+    {
+        Set<ObjectKey> foreignKeySet = new HashSet<ObjectKey>();
+        for (${localDbObjectClassName} current${localDbObjectClassName} : toFill)
+        {
+            ObjectKey foreignKey = current${localDbObjectClassName}.${foreignKeyGetter}();
+            if (foreignKey != null)
+            {
+                foreignKeySet.add(foreignKey);
+            }
+        }
+
+        int fillerChunkSize = getFillerChunkSize();
+        Iterator<ObjectKey> foreignKeyIt = foreignKeySet.iterator();
+        List<ObjectKey> foreignKeyListChunk
+                = new ArrayList<ObjectKey>(fillerChunkSize);;
+        Map<ObjectKey, ${fieldType}> referencedKeyTo${fieldType}Map 
+                = new HashMap<ObjectKey, ${fieldType}>();
+        while (foreignKeyIt.hasNext())
+        {
+            ObjectKey currentKey = foreignKeyIt.next();
+            foreignKeyListChunk.add(currentKey);
+            if (foreignKeyListChunk.size() < fillerChunkSize 
+                && foreignKeyIt.hasNext())
+            {
+                continue;
+            }
+
+#if ($referencesPrimaryKey)
+            List<${fieldType}> referenced${fieldType}List
+                 = ${foreignTablePeerClassName}.retrieveByPKs(
+                     foreignKeyListChunk,
+                     connection);
+#else
+            Criteria criteria = new Criteria();
+  #if ($foreignKeyReferences.size() == 1)
+    #set ( $columnElement = $foreignKeyReferences.get(0).getChild("foreign-column").getChild("column") )
+    #set ( $peerColumnName = $columnElement.getAttribute("peerColumnName"))
+            criteria.addIn(${foreignTablePeerClassName}.${peerColumnName}, foreignKeyListChunk);
+  #else
+            for (ObjectKey foreignKey : foreignKeyListChunk)
+            {
+                SimpleKey[] keys = (SimpleKey[]) foreignKey.getValue();
+    #set ( $i = 0 )
+    #foreach ($referenceElement in $foreignKeyReferences)
+    #set ( $columnElement = $referenceElement.getChild("foreign-column").getChild("column") )
+      #set ( $peerColumnName = $columnElement.getAttribute("peerColumnName"))
+                    Criteria.Criterion c$i = criteria.getNewCriterion(
+                        ${foreignTablePeerClassName}.${peerColumnName}, keys[$i], Criteria.EQUAL);
+      #set ( $j = $i - 1 )
+      #if ($i > 0)
+                        c${j}.and(c${i});
+      #end
+      #set ( $i = $i + 1 )
+    #end
+                criteria.or(c0);
+            }
+  #end
+            List<${fieldType}> referenced${fieldType}List
+                 = ${foreignTablePeerClassName}.doSelect(
+                     criteria,
+                     connection);
+#end
+
+            for (${fieldType} referencedObject : referenced${fieldType}List)
+            {
+#if ($referencesPrimaryKey)
+                referencedKeyTo${fieldType}Map.put(
+                        referencedObject.getPrimaryKey(),
+                        referencedObject);
+#else
+  #if ($foreignKeyReferences.size() == 1)
+    #set ( $columnElement = $foreignKeyReferences.get(0).getChild("foreign-column").getChild("column") )
+    #set ( $getter = $columnElement.getAttribute("getter") )
+                ObjectKey foreignKey = SimpleKey.keyFor(referencedObject.${getter}());
+  #else
+                SimpleKey[] keyElementArray = new SimpleKey[$foreignKeyReferences.size()];
+    #set ($i = 0)
+    #foreach ($referenceElement in $foreignKeyReferences)
+      #set ( $columnElement = $referenceElement.getChild("foreign-column").getChild("column") )
+      #set ( $getter = $columnElement.getAttribute("getter") )
+                keyElementArray[$i] = SimpleKey.keyFor(
+                        referencedObject.${getter}());
+      #set ($i = $i + 1)
+    #end
+                ObjectKey foreignKey = new ComboKey(keyElementArray);
+  #end
+                referencedKeyTo${fieldType}Map.put(
+                        foreignKey,
+                        referencedObject);
+#end
+            }
+            foreignKeyListChunk.clear();
+        }
+
+        List<${fieldType}> result = new ArrayList<${fieldType}>();
+        for (${localDbObjectClassName} objectToFill : toFill)
+        {
+            ObjectKey foreignKey = objectToFill.${foreignKeyGetter}();
+            if (foreignKey == null)
+            {
+                continue;
+            }
+            ${fieldType} referenced = referencedKeyTo${fieldType}Map.get(
+                    foreignKey);
+            if (referenced == null)
+            {
+                throw new NoRowsException("No result found for key " 
+                    + foreignKey + " in table ${foreignTableName}");
+            }
+            // copy the referenced object for the case that more than one
+            // toFill object references the same object; in this case
+            // every toFillObject should have its own instance of the referenced
+            // object to remain consistent with the other Torque reference
+            // treatment
+            ${fieldType} referencedCopy = referenced.copy(false);
+            // copy does not set primary key
+            referencedCopy.setPrimaryKey(referenced.getPrimaryKey());
+            objectToFill.${setter}(referencedCopy);
+            result.add(referencedCopy);
+        }
+        return result;
+    }



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


Mime
View raw message