db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1517382 - 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/doc/templates/ resources/org/apache/torque/templates/...
Date Sun, 25 Aug 2013 21:01:06 GMT
Author: tfischer
Date: Sun Aug 25 21:01:05 2013
New Revision: 1517382

URL: http://svn.apache.org/r1517382
Log:
TORQUE-293 generate correct joinGetters for database objects

Added:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMJoinGetterTransformer.java
Removed:
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/doc/templates/
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/JavaFieldAttributeName.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.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/java/org/apache/torque/templates/transformer/om/TableChildElementName.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/templates/dbObject/base/joinGetterReferencingObject.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/getter.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=1517382&r1=1517381&r2=1517382&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
Sun Aug 25 21:01:05 2013
@@ -219,7 +219,23 @@ public enum TemplateOptionName implement
      * The name of the option for the mode used in optimistic locking.
      * The value must be one of selectForUpdate, simpleSelect.
      */
-    OM_OPTIMISTIC_LOCKING_MODE("torque.om.optimisticLocking.mode");
+    OM_OPTIMISTIC_LOCKING_MODE("torque.om.optimisticLocking.mode"),
+
+    /**
+     * Whether joinGetter methods are generated in the data object classes
+     * which fetch related objects in one database query.
+     */
+    OM_GENERATE_JOIN_GETTERS("torque.om.complexObjectModel.generateJoinGetters"),
+
+    /**
+     * The separator in the joinGetter Methods between the two name parts.
+     */
+    OM_JOIN_GETTER_SEPARATOR("torque.om.complexObjectModel.joinGetterSeparator"),
+
+    /**
+     * The visibility of the joinGetter methods.
+     */
+    OM_JOIN_GETTER_VISIBILITY("torque.om.complexObjectModel.joinGetterVisibility");
 
     /**
      * The fully qualified name of the option.
@@ -231,7 +247,7 @@ public enum TemplateOptionName implement
      *
      * @param name the fully qualified name of the option, not null.
      */
-    private TemplateOptionName(String name)
+    private TemplateOptionName(final String name)
     {
         this.name = name;
     }
@@ -260,8 +276,8 @@ public enum TemplateOptionName implement
      *
      * @throws SourceTransformerException if a required option is not set.
      */
-    public static void checkRequiredOptions(ControllerState controllerState,
-            TemplateOptionName... requiredOptions)
+    public static void checkRequiredOptions(final ControllerState controllerState,
+            final TemplateOptionName... requiredOptions)
         throws SourceTransformerException
     {
         for (TemplateOptionName templateOption : requiredOptions)

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=1517382&r1=1517381&r2=1517382&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
Sun Aug 25 21:01:05 2013
@@ -99,7 +99,7 @@ public enum JavaFieldAttributeName imple
     /**
      * The access modifier (e.g. "public" ...) for the getter method
      **/
-    GETTER_ACCESS_MODIFIER("getterAccessModifer"),
+    GETTER_ACCESS_MODIFIER("getterAccessModifier"),
 
     /**
      * The access modifier (e.g. "public" ...) for the setter method
@@ -145,7 +145,7 @@ public enum JavaFieldAttributeName imple
      *
      * @param name the name of the source element attribute, not null.
      */
-    private JavaFieldAttributeName(String name)
+    private JavaFieldAttributeName(final String name)
     {
         this.name = name;
     }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java?rev=1517382&r1=1517381&r2=1517382&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
Sun Aug 25 21:01:05 2013
@@ -99,9 +99,9 @@ public class OMColumnTransformer
     }
 
     public void transform(
-            SourceElement columnElement,
-            ControllerState controllerState,
-            int columnPosition)
+            final SourceElement columnElement,
+            final ControllerState controllerState,
+            final int columnPosition)
         throws SourceTransformerException
     {
         checkElementName(columnElement);
@@ -158,7 +158,7 @@ public class OMColumnTransformer
      *
      * @param columnElement the column element, not null.
      */
-    protected void setJavaTypeAttribute(SourceElement columnElement)
+    protected void setJavaTypeAttribute(final SourceElement columnElement)
     {
         if (columnElement.getAttribute(TorqueSchemaAttributeName.JAVA_TYPE)
                 != null)
@@ -184,7 +184,7 @@ public class OMColumnTransformer
      *
      * @param columnElement the column element, not null.
      */
-    protected void setAttributeDefaultValues(SourceElement columnElement)
+    protected void setAttributeDefaultValues(final SourceElement columnElement)
     {
         // set autoincrement attribute
         if (columnElement.getAttribute(TorqueSchemaAttributeName.AUTO_INCREMENT)
@@ -251,8 +251,8 @@ public class OMColumnTransformer
     }
 
     protected void setDomainAttributes(
-                SourceElement columnElement,
-                ControllerState controllerState)
+                final SourceElement columnElement,
+                final ControllerState controllerState)
             throws SourceTransformerException
     {
         SqlType domain = SchemaTypeHelper.getDomain(
@@ -295,12 +295,12 @@ public class OMColumnTransformer
     }
 
     /**
-     * Sets the attributes getterAccessModifer and setterAccessModifer
+     * Sets the attributes getterAccessModifier and setterAccessModifer
      * on the column element.
      *
      * @param columnElement the column element, not null.
      */
-    protected void setAccessModifierAttributes(SourceElement columnElement)
+    protected void setAccessModifierAttributes(final SourceElement columnElement)
     {
         boolean isProtected = "true".equals(
                  columnElement.getAttribute(
@@ -333,8 +333,8 @@ public class OMColumnTransformer
      * @return the java type of the column
      */
     protected JavaType getFieldJavaType(
-                SourceElement columnElement,
-                SchemaType schemaType)
+                final SourceElement columnElement,
+                final SchemaType schemaType)
             throws SourceTransformerException
     {
         JavaType result;
@@ -368,7 +368,7 @@ public class OMColumnTransformer
      *
      * @throws IllegalArgumentException if the element name is wrong.
      */
-    protected void checkElementName(SourceElement columnElement)
+    protected void checkElementName(final SourceElement columnElement)
     {
         if (!TorqueSchemaElementName.COLUMN.getName().equals(
                 columnElement.getName()))
@@ -385,7 +385,7 @@ public class OMColumnTransformer
      *
      * @throws SourceTransformerException if the name attribute does not exist.
      */
-    protected void checkColumnNameExists(SourceElement columnElement)
+    protected void checkColumnNameExists(final SourceElement columnElement)
             throws SourceTransformerException
     {
         String columnName
@@ -407,7 +407,7 @@ public class OMColumnTransformer
      *
      * @param columnElement the column element, not null.
      */
-    protected void setJavaNameAttribute(SourceElement columnElement)
+    protected void setJavaNameAttribute(final SourceElement columnElement)
     {
         if (columnElement.getAttribute(TorqueSchemaAttributeName.JAVA_NAME)
                 != null)
@@ -429,7 +429,7 @@ public class OMColumnTransformer
      *
      * @param columnElement the column element, not null.
      */
-    protected void setFieldNameAttribute(SourceElement columnElement)
+    protected void setFieldNameAttribute(final SourceElement columnElement)
     {
         if (columnElement.getAttribute(JavaFieldAttributeName.FIELD_NAME)
                 != null)
@@ -451,7 +451,7 @@ public class OMColumnTransformer
      *
      * @param columnElement the column element, not null.
      */
-    protected void setPeerColumnNameAttribute(SourceElement columnElement)
+    protected void setPeerColumnNameAttribute(final SourceElement columnElement)
     {
         if (columnElement.getAttribute(ColumnAttributeName.PEER_COLUMN_NAME)
                 != null)
@@ -476,7 +476,7 @@ public class OMColumnTransformer
      *
      * @param columnElement the column element, not null.
      */
-    protected void setQualifiedColumnNameAttribute(SourceElement columnElement)
+    protected void setQualifiedColumnNameAttribute(final SourceElement columnElement)
     {
         if (columnElement.getAttribute(ColumnAttributeName.QUALIFIED_COLUMN_NAME)
                 != null)
@@ -504,9 +504,9 @@ public class OMColumnTransformer
      * @param controllerState the controller state, not null.
      */
     protected void setGetterNameAttribute(
-            SourceElement columnElement,
-            JavaType javaType,
-            ControllerState controllerState)
+            final SourceElement columnElement,
+            final JavaType javaType,
+            final ControllerState controllerState)
     {
         if (columnElement.getAttribute(JavaFieldAttributeName.GETTER_NAME)
                 != null)
@@ -531,7 +531,7 @@ public class OMColumnTransformer
      *
      * @param columnElement the column element, not null.
      */
-    protected void setSetterNameAttribute(SourceElement columnElement)
+    protected void setSetterNameAttribute(final SourceElement columnElement)
     {
         if (columnElement.getAttribute(JavaFieldAttributeName.SETTER_NAME)
                 != null)
@@ -555,8 +555,8 @@ public class OMColumnTransformer
      *        column, not null.
      */
     protected void setPrimitiveTypeAttribute(
-            SourceElement columnElement,
-            JavaType javaType)
+            final SourceElement columnElement,
+            final JavaType javaType)
     {
         if (columnElement.getAttribute(ColumnAttributeName.PRIMITIVE_TYPE)
                 != null)
@@ -578,8 +578,8 @@ public class OMColumnTransformer
      *        column, not null.
      */
     protected void setNumberTypeAttribute(
-            SourceElement columnElement,
-            JavaType javaType)
+            final SourceElement columnElement,
+            final JavaType javaType)
     {
         if (columnElement.getAttribute(ColumnAttributeName.NUMBER_TYPE)
                 != null)
@@ -606,9 +606,9 @@ public class OMColumnTransformer
      *         is encountered
      */
     protected void setDefaultValueAttribute(
-                SourceElement columnElement,
-                JavaType javaType,
-                ControllerState controllerState)
+                final SourceElement columnElement,
+                final JavaType javaType,
+                final ControllerState controllerState)
             throws SourceTransformerException
     {
         // special case inheritance by class name
@@ -677,10 +677,10 @@ public class OMColumnTransformer
      * @throws SourceTransformerException if an illegal default value is used.
      */
     protected String getDefaultValueWithDefaultSet(
-                JavaType javaType,
-                String defaultValue,
-                boolean useDatabaseDefaultValue,
-                SourceElement columnElement)
+                final JavaType javaType,
+                final String defaultValue,
+                final boolean useDatabaseDefaultValue,
+                final SourceElement columnElement)
             throws SourceTransformerException
     {
         boolean primitiveFieldType = javaType.isPrimitive();
@@ -842,7 +842,7 @@ public class OMColumnTransformer
      *
      * @throws SourceTransformerException if the date cannot be parsed.
      */
-    public static Date getDefaultValueAsDate(String defaultValue)
+    public static Date getDefaultValueAsDate(final String defaultValue)
             throws SourceTransformerException
     {
         try
@@ -871,7 +871,7 @@ public class OMColumnTransformer
      *
      * @return The java default value.
      */
-    protected String getDefaultValueWithoutDefaultSet(JavaType javaType)
+    protected String getDefaultValueWithoutDefaultSet(final JavaType javaType)
             throws SourceTransformerException
     {
         String fieldDefaultValue;
@@ -930,7 +930,7 @@ public class OMColumnTransformer
      * @param columnElement the column element, not null.
      */
     protected void setUseDatabaseDefaultValueAttribute(
-            SourceElement columnElement)
+            final SourceElement columnElement)
     {
         if (columnElement.getAttribute(
                     TorqueSchemaAttributeName.USE_DATABASE_DEFAULT_VALUE)
@@ -953,8 +953,8 @@ public class OMColumnTransformer
      * @param schemaType the schema type of the column, not null.
      */
     protected void setResultSetGetterAttribute(
-            SourceElement columnElement,
-            SchemaType schemaType)
+            final SourceElement columnElement,
+            final SchemaType schemaType)
     {
         ResultSetGetter resultSetGetter = null;
         Object originalValue = columnElement.getAttribute(
@@ -989,8 +989,8 @@ public class OMColumnTransformer
      * @param schemaType the schema type of the column, not null.
      */
     protected void setSampleObjectAttribute(
-            SourceElement columnElement,
-            SchemaType schemaType)
+            final SourceElement columnElement,
+            final SchemaType schemaType)
     {
         if (columnElement.getAttribute(ColumnAttributeName.SAMPLE_OBJECT)
                 != null)

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=1517382&r1=1517381&r2=1517382&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
Sun Aug 25 21:01:05 2013
@@ -65,8 +65,8 @@ import org.apache.torque.templates.Torqu
 public class OMForeignKeyTransformer
 {
     public void transform(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
         throws SourceTransformerException
     {
         if (!TorqueSchemaElementName.FOREIGN_KEY.getName().equals(
@@ -126,8 +126,8 @@ public class OMForeignKeyTransformer
      * @throws SourceTransformerException if the transformation fails
      */
     public void transformSecondPass(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
         throws SourceTransformerException
     {
         modifyForeignFieldSecondPass(foreignKey, controllerState);
@@ -144,8 +144,8 @@ public class OMForeignKeyTransformer
      * @param controllerState the current controller state.
     */
     private void addForeignField(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
     {
         SourceElement localTable = foreignKey.getParent();
         SourceElement foreignTable = foreignKey.getChild(
@@ -274,24 +274,6 @@ public class OMForeignKeyTransformer
                         setAndSaveMethodName);
             }
             {
-                // Name for a getter in the foreign table to
-                // retrieve entries in the foreign table plus the joined
-                // entries in the local table.
-                String joinGetterFieldName
-                        = StringUtils.capitalize(getterSetterFieldName)
-                        + "sJoin"
-                        + foreignTable.getAttribute(
-                            TorqueSchemaAttributeName.JAVA_NAME);
-                String joinGetterName = FieldHelper.getGetterName(
-                        joinGetterFieldName,
-                        fieldType,
-                        controllerState);
-                foreignFieldElement.setAttribute(
-                        ForeignKeyChildAttributeName
-                            .FOREIGN_FIELD_JOIN_GETTER,
-                        joinGetterName);
-            }
-            {
                 // Name for the doSelectJoinXXX method in the Peer Class
                 // of the foreign table.
                 String peerJoinSelectMethodName
@@ -334,8 +316,8 @@ public class OMForeignKeyTransformer
      * @param controllerState the current controller state.
      */
     private void modifyForeignFieldSecondPass(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
     {
         SourceElement foreignFieldElement
             = foreignKey.getChild(ForeignKeyChildElementName.FOREIGN_FIELD);
@@ -403,8 +385,8 @@ public class OMForeignKeyTransformer
      * @param controllerState the current controller state.
      */
     private void addForeignFieldInBean(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
     {
         SourceElement localTable = foreignKey.getParent();
         String referencedBySuffix = getForeignReferencedBySuffix(
@@ -491,8 +473,8 @@ public class OMForeignKeyTransformer
      * @param controllerState the current controller state.
      */
     private void addLocalFieldInBean(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
     {
         SourceElement foreignTable = foreignKey.getChild(
                 TorqueSchemaElementName.TABLE);
@@ -555,8 +537,8 @@ public class OMForeignKeyTransformer
      * @param controllerState the current controller state.
      */
     private void addLocalField(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
     {
         SourceElement foreignTable = foreignKey.getChild(
                 TorqueSchemaElementName.TABLE);
@@ -637,8 +619,8 @@ public class OMForeignKeyTransformer
      *         Not null.
      */
     private String getLocalReferencedBySuffix(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
     {
         SourceElement localTable = foreignKey.getParent();
         String localTableName = (String) localTable.getAttribute(
@@ -691,9 +673,9 @@ public class OMForeignKeyTransformer
      * @return the qualifying suffix, or the empty String if none is needed.
      *         Not null.
      */
-    private String getForeignReferencedBySuffix(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+    static String getForeignReferencedBySuffix(
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
     {
         SourceElement localTable = foreignKey.getParent();
         String foreignTableName = (String) foreignKey.getAttribute(
@@ -736,8 +718,8 @@ public class OMForeignKeyTransformer
      * @param reference the refenced element to enrich.
      */
     private void createForeignElementForReference(
-            SourceElement foreignTable,
-            SourceElement reference)
+            final SourceElement foreignTable,
+            final SourceElement reference)
     {
         {
             String foreignColumnName = (String)
@@ -761,8 +743,8 @@ public class OMForeignKeyTransformer
      * @param reference the refenced element to enrich.
      */
     protected void createLocalElementForReference(
-            SourceElement localTable,
-            SourceElement reference)
+            final SourceElement localTable,
+            final SourceElement reference)
     {
         {
             String localColumnName = (String)
@@ -779,8 +761,8 @@ public class OMForeignKeyTransformer
     }
 
     private void setForeignKeyAttributes(
-            SourceElement foreignKey,
-            ControllerState controllerState)
+            final SourceElement foreignKey,
+            final ControllerState controllerState)
     {
         SourceElement foreignTable = foreignKey.getChild(
                 TorqueSchemaElementName.TABLE);
@@ -831,8 +813,8 @@ public class OMForeignKeyTransformer
     }
 
     private void getParentPath(
-            SourceElement sourceElement,
-            StringBuilder result)
+            final SourceElement sourceElement,
+            final StringBuilder result)
     {
         SourceElement parent = sourceElement.getParent();
         if (parent == null)

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMJoinGetterTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMJoinGetterTransformer.java?rev=1517382&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMJoinGetterTransformer.java
(added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMJoinGetterTransformer.java
Sun Aug 25 21:01:05 2013
@@ -0,0 +1,174 @@
+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 static org.apache.torque.templates.TemplateOptionName.OM_GENERATE_JOIN_GETTERS;
+import static org.apache.torque.templates.TemplateOptionName.OM_JOIN_GETTER_SEPARATOR;
+import static org.apache.torque.templates.TemplateOptionName.OM_JOIN_GETTER_VISIBILITY;
+
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.transform.SourceTransformerException;
+import org.apache.torque.templates.TorqueSchemaElementName;
+
+/**
+ * Creates the joinGetter Elements on a table.
+ * The OMReferencingForeignKeyTableTransformer needs to be run
+ * before this transformation
+ * The structure before transformation is:
+ *
+ * table
+ *   foreign-key
+ *     ...
+ *     table (the referenced table in the foreign key)
+ *   foreign-key
+ *     ...
+ *     table
+ *   ...
+ *   referencing-foreign-keys
+ *     foreign-key (a foreign key where the foreignTable is the current table)
+ *       ...
+ *       table (the referenced table in the foreign key, i.e this table.)
+ *     foreign-key
+ *       ...
+ *       table
+ *   ...
+ *
+ * The structure after transformation is
+ * table
+ *   foreign-key
+ *     ...
+ *     table (the referenced table in the foreign key)
+ *   foreign-key
+ *     ...
+ *     table
+ *   ...
+ *   referencing-foreign-keys
+ *     foreign-key (a foreign key where the foreignTable is the current table)
+ *       ...
+ *       table (the referenced table in the foreign key, i.e this table.)
+ *     foreign-key
+ *       ...
+ *       table
+ *   ...
+ *   joinGetter name=".."
+ *     local
+ *       foreign-key (a foreign key referencing the table)
+ *     remote
+ *       foreign-key (a foreign key of the referenced table)
+ *
+ *   ...
+ */
+public class OMJoinGetterTransformer
+{
+    public void transform(
+            final SourceElement tableElement,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        if (!controllerState.getBooleanOption(OM_GENERATE_JOIN_GETTERS))
+        {
+            return;
+        }
+
+        checkElementName(tableElement);
+        SourceElement referencingForeignKeys = tableElement.getChild(
+                TableChildElementName.REFERENCING_FOREIGN_KEYS);
+        for (SourceElement foreignKey
+                : referencingForeignKeys.getChildren(
+                        TorqueSchemaElementName.FOREIGN_KEY))
+        {
+            SourceElement foreignTable = foreignKey.getParent();
+            for (SourceElement remoteForeignKey
+                    : foreignTable.getChildren(
+                            TorqueSchemaElementName.FOREIGN_KEY))
+            {
+                if (remoteForeignKey == foreignKey)
+                {
+                    continue;
+                }
+                SourceElement remoteForeignTable = remoteForeignKey.getChild(
+                        TorqueSchemaElementName.TABLE);
+
+                String localReferencedBySuffix
+                        = OMForeignKeyTransformer.getForeignReferencedBySuffix(
+                                foreignKey, controllerState);
+                String localGetterSetterFieldName
+                    = (String) foreignTable.getAttribute(
+                            TableAttributeName.DB_OBJECT_CLASS_NAME)
+                        + localReferencedBySuffix;
+                String foreignReferencedBySuffix
+                        = OMForeignKeyTransformer.getForeignReferencedBySuffix(
+                                remoteForeignKey, controllerState);
+                String foreignGetterSetterFieldName
+                    = (String) remoteForeignTable.getAttribute(
+                            TableAttributeName.DB_OBJECT_CLASS_NAME)
+                        + foreignReferencedBySuffix;
+                String joinGetterFieldName = localGetterSetterFieldName
+                        + controllerState.getStringOption(OM_JOIN_GETTER_SEPARATOR)
+                        + foreignGetterSetterFieldName;
+                String joinGetterName = FieldHelper.getGetterName(
+                        joinGetterFieldName,
+                        null,
+                        controllerState);
+                SourceElement joinGetterElement = new SourceElement(
+                        TableChildElementName.JOIN_GETTER);
+                tableElement.getChildren().add(joinGetterElement);
+                joinGetterElement.setAttribute(
+                        JavaFieldAttributeName.GETTER_NAME, joinGetterName);
+                joinGetterElement.setAttribute(
+                        JavaFieldAttributeName.GETTER_ACCESS_MODIFIER,
+                        controllerState.getStringOption(
+                                OM_JOIN_GETTER_VISIBILITY));
+
+                SourceElement localElement = new SourceElement(
+                        TableChildElementName.LOCAL);
+                joinGetterElement.getChildren().add(localElement);
+                localElement.getChildren().add(foreignKey);
+
+
+                SourceElement foreignElement = new SourceElement(
+                        TableChildElementName.FOREIGN);
+                joinGetterElement.getChildren().add(foreignElement);
+                foreignElement.getChildren().add(remoteForeignKey);
+            }
+        }
+    }
+
+
+    /**
+     * Checks that the name of the table element is correct.
+     *
+     * @param columnElement the table element, not null.
+     *
+     * @throws IllegalArgumentException if the element name is wrong.
+     */
+    protected void checkElementName(final SourceElement tableElement)
+    {
+        if (!TorqueSchemaElementName.TABLE.getName().equals(
+                tableElement.getName())
+            && !TorqueSchemaElementName.VIEW.getName().equals(
+                    tableElement.getName()))
+        {
+            throw new IllegalArgumentException("Illegal element Name "
+                    + tableElement.getName());
+        }
+    }
+}

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=1517382&r1=1517381&r2=1517382&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
Sun Aug 25 21:01:05 2013
@@ -99,6 +99,10 @@ public class OMTransformer implements So
     private static final SourceTransformer includeSchemaTransformer
             = new IncludeSchemaTransformer();
 
+    /** The transformer which creates the joinGetters. */
+    private static OMJoinGetterTransformer joinGetterTransformer
+            = new OMJoinGetterTransformer();
+
     static
     {
         try
@@ -185,6 +189,13 @@ public class OMTransformer implements So
             }
         }
 
+        for (final SourceElement tableOrViewElement : allTablesAndViews)
+        {
+            joinGetterTransformer.transform(
+                    tableOrViewElement,
+                    controllerState);
+        }
+
         return root;
     }
 

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableChildElementName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableChildElementName.java?rev=1517382&r1=1517381&r2=1517382&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableChildElementName.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableChildElementName.java
Sun Aug 25 21:01:05 2013
@@ -41,7 +41,22 @@ public enum TableChildElementName implem
     /**
      * Contains all primary key columns of the table.
      */
-    PRIMARY_KEYS("primary-keys");
+    PRIMARY_KEYS("primary-keys"),
+
+    /**
+     * A getter to join a table remote by two foreign key relations.
+     */
+    JOIN_GETTER("join-getter"),
+
+    /**
+     * The local elements of the JOIN_GETTER.
+     */
+    LOCAL("local"),
+
+    /**
+     * The foreign elements of the JOIN_GETTER.
+     */
+    FOREIGN("foreign");
 
     /** The name of the source element, not null. */
     private String name;
@@ -51,7 +66,7 @@ public enum TableChildElementName implem
      *
      * @param name the name of the source element, not null.
      */
-    private TableChildElementName(String name)
+    private TableChildElementName(final String name)
     {
         this.name = name;
     }

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=1517382&r1=1517381&r2=1517382&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
Sun Aug 25 21:01:05 2013
@@ -165,10 +165,18 @@ torque.om.complexObjectModel.foreignFiel
 # initialized with in the init method
 torque.om.complexObjectModel.foreignFieldInitType = ArrayList
 
-# Whether doSelectJoin methods are generated which fetch related objects
-# in one database query
+# Whether doSelectJoin methods are generated in the Peer classes 
+# which fetch related objects in one database query
 torque.om.complexObjectModel.generateDoSelectJoin = true
 
+# Whether joinGetter methods are generated in the data object classes 
+# which fetch related objects in one database query
+torque.om.complexObjectModel.generateJoinGetters = true
+# The separator in the joinGetter Methods between the two name parts
+torque.om.complexObjectModel.joinGetterSeparator = sJoin
+# The visibility of the joinGetter methods
+torque.om.complexObjectModel.joinGetterVisibility = protected
+
 # Whether filler methods are generated which can efficiently read
 # data objects related by a foreign key relation for a list of other
 # data objects.

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=1517382&r1=1517381&r2=1517382&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
Sun Aug 25 21:01:05 2013
@@ -112,6 +112,9 @@
       <action xsi:type="traverseAllAction"
           element="referencing-foreign-keys/foreign-key/foreign-field"
           outlet="torque.om.dbObject.base.referencingObjectMethods"/>
+      <action xsi:type="traverseAllAction"
+          element="join-getter"
+          outlet="torque.om.dbObject.base.joinGettersReferencingObject"/>
     </mergepoint>
     <mergepoint name="getByNameMethods">
       <action xsi:type="applyAction"
@@ -357,10 +360,6 @@
       <action xsi:type="applyAction"
           outlet="torque.om.dbObject.base.isInitializedReferencingObject"/>
     </mergepoint>
-    <mergepoint name="referencingJoinGetters">
-      <action xsi:type="applyAction"
-          outlet="torque.om.dbObject.base.joinGettersReferencingObject"/>
-    </mergepoint>
     <mergepoint name="setter" />
   </outlet>
 

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/joinGetterReferencingObject.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/joinGetterReferencingObject.vm?rev=1517382&r1=1517381&r2=1517382&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/joinGetterReferencingObject.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/joinGetterReferencingObject.vm
Sun Aug 25 21:01:05 2013
@@ -27,7 +27,12 @@
 ## by the OMTransformer.  
 ##
 #set ( $silentDbFetch = $torqueGen.booleanOption("torque.om.silentDbFetch") )
-#set ( $foreignKeyElement = $torqueGen.getParent() )
+#set ( $foreignKeyElement = $torqueGen.getChild("local").getChild("foreign-key") )
+#set ( $foreignField = $foreignKeyElement.getChild("foreign-field") )
+#set ( $field = $foreignField.getAttribute("field") )
+#set ( $fieldType = $foreignField.getAttribute("fieldType") )
+#set ( $criteriaCacheField = $foreignField.getAttribute("criteriaCacheField") )
+#set ( $initializer = $foreignField.getAttribute("initializer") )
 #set ( $otherTable = $foreignKeyElement.getParent() )
 #set ( $otherTablePeerClass = $otherTable.getAttribute("peerClassName") )
 #set ( $otherTablePeerPackage = $otherTable.getAttribute("peerPackage") )
@@ -35,6 +40,8 @@
 #set ( $thisTableElement = $foreignKeyElement.getChild("table") )
 #set ( $thisObjectClassName = $thisTableElement.getAttribute("baseDbObjectClassName") )
 #set ( $referenceElements = $foreignKeyElement.getChildren("reference") )
+#set ( $otherForeignField = $torqueGen.getChild("foreign").getChild("foreign-key").getChild("foreign-field")
)
+#set ( $otherPeerJoinSelectMethod = $otherForeignField.getAttribute("peerJoinSelectMethod")
)
 #if ($silentDbFetch)
     /**
      * If this collection has already been initialized with
@@ -46,10 +53,29 @@
      * This method is protected by default in order to keep the public
      * api reasonable.  You can change the access modifier to public
      * by overriding this method in the child class.
+     *
+     * @param criteria the criteria to use when filling the collection.
      */
-    protected $fieldType ${joinGetter}(Criteria criteria) throws TorqueException
+    ${getterAccessModifier} $fieldType ${getter}(Criteria criteria) throws TorqueException
     {
-        return ${joinGetter}(criteria, null);
+        Connection connection = null;
+        try
+        {
+            connection = Transaction.begin(criteria.getDbName());
+
+            $fieldType result = ${getter}(criteria, connection);
+
+            Transaction.commit(connection);
+            connection = null;
+            return result;
+        }
+        finally
+        {
+            if (connection != null)
+            {
+                Transaction.safeRollback(connection);
+            }
+        }
     }
 
 #end
@@ -64,7 +90,7 @@
      * api reasonable.  You can change the access modifier to public
      * by overriding this method in the child class.
      */
-    protected $fieldType ${joinGetter}(Criteria criteria, Connection connection)
+    ${getterAccessModifier} $fieldType ${getter}(Criteria criteria, Connection connection)
         throws TorqueException
     {
         if ($field == null)
@@ -80,9 +106,9 @@
   #set ( $thisTableColumnElement = $referenceElement.getChild("foreign-column").getChild("column")
)
   #set ( $otherTablePeerColumnName = $otherTableColumnElement.getAttribute("peerColumnName")
)
   #set ( $thisTableColumnGetter = $thisTableColumnElement.getAttribute("getter") )
-                criteria.and(${otherTablePeerName}.${otherTablePeerColumnName}, ${thisTableColumnGetter}()
);
+                criteria.and(${otherTablePeerName}.${otherTablePeerColumnName}, ${thisTableColumnGetter}());
 #end
-                $field = ${otherTablePeerName}.${peerJoinSelectMethod}(criteria, connection);
+                $field = ${otherTablePeerName}.${otherPeerJoinSelectMethod}(criteria, connection);
             }
         }
         else
@@ -95,14 +121,15 @@
   #set ( $thisTableColumnElement = $referenceElement.getChild("foreign-column").getChild("column")
)
   #set ( $otherTablePeerColumnName = $otherTableColumnElement.getAttribute("peerColumnName")
)
   #set ( $thisTableColumnGetter = $thisTableColumnElement.getAttribute("getter") )
-            criteria.and(${otherTablePeerName}.${otherTablePeerColumnName}, ${thisTableColumnGetter}()
);
+            criteria.and(${otherTablePeerName}.${otherTablePeerColumnName}, ${thisTableColumnGetter}());
 #end
             if (!${criteriaCacheField}.equals(criteria))
             {
-                $field = ${otherTablePeerName}.${peerJoinSelectMethod}(criteria, connection);
+                $field = ${otherTablePeerName}.${otherPeerJoinSelectMethod}(criteria, connection);
             }
         }
         $criteriaCacheField = criteria;
 
         return $field;
     }
+

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/getter.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/getter.vm?rev=1517382&r1=1517381&r2=1517382&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/getter.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/getter.vm
Sun Aug 25 21:01:05 2013
@@ -37,7 +37,7 @@
      *
      * @return $fieldType
      */
-    $getterAccessModifer $fieldType ${getter}()$getterThrows 
+    $getterAccessModifier $fieldType ${getter}()$getterThrows 
     {
         $torqueGen.mergepoint("methodStart")
         return $field;



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