db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1244898 - 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/om/out...
Date Thu, 16 Feb 2012 09:20:39 GMT
Author: tfischer
Date: Thu Feb 16 09:20:37 2012
New Revision: 1244898

URL: http://svn.apache.org/viewvc?rev=1244898&view=rev
Log:
TORQUE-180 save methods can also be generated in the dbObject classes instead of the peer classes
TORQUE-116 make saving and loading state publicly visible

Added:
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/isInitializedReferencingObject.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingField.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingMethods.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingField.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingMethods.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/saveMethods.vm
      - copied, changed from r1231667, db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/saveMethods.vm
Removed:
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.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/OMTableTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.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/general.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/dbObject/base/equalsHashCode.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/referencingObjectMethods.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/impl/base/basePeerImpl.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml

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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -92,6 +92,12 @@ public enum TemplateOptionName implement
     /** 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 initializer methods. */
+    OM_IS_INITIALIZED_PREFIX("torque.om.complexObjectModel.isInitializedPrefix"),
+
+    /** The name of the option for the suffix of the initializer methods. */
+    OM_IS_INITIALIZED_SUFFIX("torque.om.complexObjectModel.isInitializedSuffix"),
+
     /** The name of the option for the prefix of the filler methods. */
     OM_FILLER_PREFIX("torque.om.complexObjectModel.fillerPrefix"),
 
@@ -173,7 +179,25 @@ public enum TemplateOptionName implement
      * of the foreign field (must not be an interface).
      */
     OM_FOREIGN_FIELD_INIT_TYPE(
-            "torque.om.complexObjectModel.foreignFieldInitType");
+            "torque.om.complexObjectModel.foreignFieldInitType"),
+
+    /**
+     * The name of the option which controls whether save methods are
+     * generated at all.
+     */
+    OM_ADD_SAVE_METHODS("torque.om.addSaveMethods"),
+
+    /**
+     * The name of the option which controls whether save methods are
+     * generated in the db objects (true) or in the peers (false).
+     */
+    OM_SAVE_METHODS_IN_DB_OBJECTS("torque.om.saveMethodsInDbObjects"),
+
+    /**
+     * The name of the option for the name of the exception thrown
+     * by the save methods.
+     */
+    OM_SAVE_EXCEPTION("torque.om.saveException");
 
     /**
      * 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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -140,6 +140,27 @@ final class FieldHelper
     }
 
     /**
+     * Returns the name of the isInitialized method for a field.
+     *
+     * @param fieldName the name of the field, not null.
+     * @param controllerState the current controller state, not null.
+     *
+     * @return the isInitialized method name, not null.
+     */
+    public static String getIsInitializedName(
+            String fieldName,
+            ControllerState controllerState)
+    {
+        String initializerName
+            = controllerState.getOption(
+                    TemplateOptionName.OM_IS_INITIALIZED_PREFIX)
+                + StringUtils.capitalize(fieldName)
+                + controllerState.getOption(
+                      TemplateOptionName.OM_IS_INITIALIZED_SUFFIX);
+        return initializerName;
+    }
+
+    /**
      * Returns the name of the filler method for a field.
      *
      * @param fieldName the name of the field, not null.

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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -72,6 +72,13 @@ public enum JavaFieldAttributeName imple
     INITIALIZER_TYPE("initializerType"),
 
     /**
+     * In case the field must be initialized on first access,
+     * this contains the name of the method which returns whether the field
+     * has been initialized.
+     */
+    IS_INITIALIZED_NAME("isInitialized"),
+
+    /**
      * In case the field is a collection:
      * The name of the method used to add one object to the collection.
      */

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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -238,6 +238,14 @@ public class OMForeignKeyTransformer
                         initializerName);
             }
             {
+                String isInitializedName = FieldHelper.getIsInitializedName(
+                        getterSetterFieldName,
+                        controllerState);
+                foreignFieldElement.setAttribute(
+                        JavaFieldAttributeName.IS_INITIALIZED_NAME,
+                        isInitializedName);
+            }
+            {
                 String initType = (String) controllerState.getOption(
                         TemplateOptionName.OM_FOREIGN_FIELD_INIT_TYPE)
                     + "<" + fieldContainedType + ">";
@@ -780,9 +788,9 @@ public class OMForeignKeyTransformer
         List<SourceElement> foreignTablePrimaryKeys
                 = foreignTable.getChild(TableChildElementName.PRIMARY_KEYS)
                         .getChildren(TorqueSchemaElementName.COLUMN);
-        List<SourceElement> foreignTableForeignKeyColumns 
+        List<SourceElement> foreignTableForeignKeyColumns
             = new ArrayList<SourceElement>();
-        for (SourceElement reference 
+        for (SourceElement reference
                 : foreignKey.getChildren(TorqueSchemaElementName.REFERENCE))
         {
             SourceElement column = reference.getChild(
@@ -796,7 +804,7 @@ public class OMForeignKeyTransformer
             referencesPrimaryKey = true;
             for (int i = 0; i < foreignTablePrimaryKeys.size(); ++i)
             {
-                if (foreignTablePrimaryKeys.get(i) 
+                if (foreignTablePrimaryKeys.get(i)
                         != foreignTableForeignKeyColumns.get(i))
                 {
                     referencesPrimaryKey = false;

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableTransformer.java?rev=1244898&r1=1244897&r2=1244898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableTransformer.java Thu Feb 16 09:20:37 2012
@@ -89,6 +89,8 @@ public class OMTableTransformer extends 
         setPeerImplGetterAttribute(tableElement);
         setPeerImplSetterAttribute(tableElement);
 
+        setSaveAttributes(tableElement, controllerState);
+
         createInheritanceColumnChildIfNecessary(tableElement);
         primaryKeyTransformer.transform(tableElement, controllerState,
                 TorqueSchemaElementName.COLUMN,
@@ -455,4 +457,22 @@ public class OMTableTransformer extends 
                 TableAttributeName.PEER_IMPL_SETTER,
                 setter);
     }
+
+    protected void setSaveAttributes(
+            SourceElement tableElement,
+            ControllerState controllerState)
+    {
+        boolean saveMethodsInDbObjects = controllerState.getBooleanOption(
+                TemplateOptionName.OM_SAVE_METHODS_IN_DB_OBJECTS);
+        if (!saveMethodsInDbObjects)
+        {
+            tableElement.setAttribute(
+                    TableAttributeName.SAVE_METHOD_INPUT_TYPE,
+                    tableElement.getAttribute(
+                            TableAttributeName.DB_OBJECT_CLASS_NAME));
+            tableElement.setAttribute(
+                    TableAttributeName.SAVE_METHOD_TO_SAVE_VARIABLE,
+                    "toSave");
+        }
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.java?rev=1244898&r1=1244897&r2=1244898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.java Thu Feb 16 09:20:37 2012
@@ -80,7 +80,17 @@ public enum TableAttributeName implement
     /**
      * The name of the sequence generated for the table's primary key.
      */
-    SEQUENCE_NAME("sequenceName");
+    SEQUENCE_NAME("sequenceName"),
+
+    /**
+     * The type which is passed to the save method, if any.
+     */
+    SAVE_METHOD_INPUT_TYPE("saveMethodInputType"),
+
+    /**
+     * The variable name in which the object to save is stored, if any.
+     */
+    SAVE_METHOD_TO_SAVE_VARIABLE("saveMethodToSaveVariable");
 
 
     /** The name of the source element attribute, not null. */

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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -72,9 +72,12 @@ torque.om.bean.beanExtendsClass = 
 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
+torque.om.addSaveMethods = true
+# Whether the save methods should be created in the
+# data objects or in the peers
+torque.om.saveMethodsInDbObjects = true
+# The exception which is declared to be thrown by the save methods.
+torque.om.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
@@ -83,6 +86,13 @@ torque.om.trackModified = true
 # or an update command is used when saving, thus, trackNew needs to be set
 # to true if addSaveMethods is true 
 torque.om.trackNew = true
+# Whether it should be tracked if objects are currently saved.
+# This needs to be set to true if torque.om.complexObjectModel is true
+# and torque.om.objectIsCaching is true to prevent recursive save calls
+torque.om.trackSaving = true
+# Whether it should be tracked if objects are currently loaded
+# from the database.
+torque.om.trackLoading = true
 
 # If true, a MapInit Class is generated for each database which can be used
 # to initialize all database map classes
@@ -128,6 +138,13 @@ torque.om.complexObjectModel.adderSuffix
 torque.om.complexObjectModel.initializerPrefix = init
 torque.om.complexObjectModel.initializerSuffix = s
 
+# Prefix and Suffix for the isInitialized 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.isInitializedPrefix = is
+torque.om.complexObjectModel.isInitializedSuffix = sInitialized
+
 # Type of the instance variable on the "foreign" side of the fk
 # This type will be generified.
 torque.om.complexObjectModel.foreignFieldType = List
@@ -142,6 +159,9 @@ torque.om.complexObjectModel.generateDoS
 # Whether filler methods are generated which can efficiently read
 # data objects related by a foreign key relation for a list of other
 # data objects.
+# This setting has no effect if torque.om.objectIsCaching is NOT set to true,
+# in this case no fillers qre generated even if the property below is set
+# to true
 torque.om.complexObjectModel.generateFillers = false
 
 # Prefix and Suffix for the filler method on the "local" side of the fk

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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -60,6 +60,14 @@
       <action xsi:type="applyAction"
           outlet="torque.om.dbObject.base.newModifiedFields"/>
     </mergepoint>
+    <mergepoint name="savingField">
+      <action xsi:type="applyAction"
+          outlet="torque.om.dbObject.base.savingField"/>
+    </mergepoint>
+    <mergepoint name="loadingField">
+      <action xsi:type="applyAction"
+          outlet="torque.om.dbObject.base.loadingField"/>
+    </mergepoint>
     <mergepoint name="fieldDefinitionsReferencedObjects">
       <action xsi:type="traverseAllAction"
           element="foreign-key/local-field"
@@ -79,6 +87,14 @@
       <action xsi:type="applyAction"
           outlet="torque.om.dbObject.base.newModifiedMethods"/>
     </mergepoint>
+    <mergepoint name="savingMethods">
+      <action xsi:type="applyAction"
+          outlet="torque.om.dbObject.base.savingMethods"/>
+    </mergepoint>
+    <mergepoint name="loadingMethods">
+      <action xsi:type="applyAction"
+          outlet="torque.om.dbObject.base.loadingMethods"/>
+    </mergepoint>
     <mergepoint name="gettersSettersReferencedObjects">
       <action xsi:type="traverseAllAction"
           element="foreign-key/local-field"
@@ -95,7 +111,7 @@
     </mergepoint>
     <mergepoint name="saveMethods">
       <action xsi:type="applyAction"
-          outlet="torque.om.dbObject.base.saveMethods"/>
+          outlet="torque.om.saveMethods"/>
     </mergepoint>
     <mergepoint name="primaryKeyMethods">
       <action xsi:type="applyAction"
@@ -148,6 +164,16 @@
       path="dbObject/base/newModifiedFields.vm">
   </outlet>
 
+  <outlet name="torque.om.dbObject.base.savingField"
+      xsi:type="velocityOutlet"
+      path="dbObject/base/savingField.vm">
+  </outlet>
+
+  <outlet name="torque.om.dbObject.base.loadingField"
+      xsi:type="velocityOutlet"
+      path="dbObject/base/loadingField.vm">
+  </outlet>
+
   <outlet name="torque.om.dbObject.base.getterSetterReferencedObject"
       xsi:type="velocityOutlet"
       path="general/getterSetter.vm">
@@ -168,6 +194,16 @@
       path="dbObject/base/newModifiedMethods.vm">
   </outlet>
 
+  <outlet name="torque.om.dbObject.base.savingMethods"
+      xsi:type="velocityOutlet"
+      path="dbObject/base/savingMethods.vm">
+  </outlet>
+
+  <outlet name="torque.om.dbObject.base.loadingMethods"
+      xsi:type="velocityOutlet"
+      path="dbObject/base/loadingMethods.vm">
+  </outlet>
+
   <outlet name="torque.om.dbObject.base.getterReferencedObject"
       xsi:type="velocityOutlet"
       path="dbObject/base/getterReferencedObject.vm">
@@ -193,6 +229,10 @@
       <action xsi:type="applyAction"
           outlet="torque.om.dbObject.base.initializerReferencingObject"/>
     </mergepoint>
+    <mergepoint name="isInitialized">
+      <action xsi:type="applyAction"
+          outlet="torque.om.dbObject.base.isInitializedReferencingObject"/>
+    </mergepoint>
     <mergepoint name="referencingJoinGetters">
       <action xsi:type="applyAction"
           outlet="torque.om.dbObject.base.joinGettersReferencingObject"/>
@@ -215,6 +255,11 @@
       path="dbObject/base/initializerReferencingObject.vm">
   </outlet>
   
+  <outlet name="torque.om.dbObject.base.isInitializedReferencingObject"
+      xsi:type="velocityOutlet"
+      path="dbObject/base/isInitializedReferencingObject.vm">
+  </outlet>
+  
   <outlet name="torque.om.dbObject.base.joinGettersReferencingObject"
       xsi:type="velocityOutlet"
       path="dbObject/base/joinGetterReferencingObject.vm">
@@ -225,11 +270,6 @@
       path="dbObject/base/getByNameMethods.vm">
   </outlet>
 
-  <outlet name="torque.om.dbObject.base.saveMethods"
-      xsi:type="velocityOutlet"
-      path="dbObject/base/saveMethods.vm">
-  </outlet>
-
   <outlet name="torque.om.dbObject.base.primaryKeyMethods"
       xsi:type="velocityOutlet"
       path="dbObject/base/primaryKeyMethods.vm">

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/general.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/general.xml?rev=1244898&r1=1244897&r2=1244898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/general.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/general.xml Thu Feb 16 09:20:37 2012
@@ -79,4 +79,10 @@
       xsi:type="velocityOutlet"
       path="general/createDbObjectInstance.vm">
   </outlet>
+  
+    <outlet name="torque.om.saveMethods"
+      xsi:type="velocityOutlet"
+      path="general/saveMethods.vm">
+  </outlet>
+
 </outlets>
\ No newline at end of file

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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -91,6 +91,9 @@
     <mergepoint name="doUpdate">
       <action xsi:type="applyAction" outlet="torque.om.peer.impl.base.doUpdate"/>
     </mergepoint>
+    <mergepoint name="saveMethods">
+      <action xsi:type="applyAction" outlet="torque.om.saveMethods"/>
+    </mergepoint>
     <mergepoint name="doDelete">
       <action xsi:type="applyAction" outlet="torque.om.peer.impl.base.doDelete"/>
     </mergepoint>
@@ -320,6 +323,9 @@
     <mergepoint name="doUpdate">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.doUpdate"/>
     </mergepoint>
+    <mergepoint name="saveMethods">
+      <action xsi:type="applyAction" outlet="torque.om.peer.base.saveMethods"/>
+    </mergepoint>
     <mergepoint name="doDelete">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.doDelete"/>
     </mergepoint>
@@ -469,6 +475,11 @@
       path="peer/base/doUpdate.vm">
   </outlet>
 
+  <outlet name="torque.om.peer.base.saveMethods"
+      xsi:type="velocityOutlet"
+      path="peer/base/saveMethods.vm">
+  </outlet>
+
   <outlet name="torque.om.peer.base.doDelete"
       xsi:type="velocityOutlet"
       path="peer/base/doDelete.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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -49,12 +49,16 @@ import org.apache.torque.om.ObjectKey;
 import org.apache.torque.om.SimpleKey;
 import org.apache.torque.om.StringKey;
 import org.apache.torque.om.BooleanKey;
+#if ($addSaveMethods == true && $saveMethodsInDbObjects == "true")
 import org.apache.torque.om.Persistent;
+#end
 #if ($torqueGen.booleanOption("torque.om.addGetByNameMethods"))
 import org.apache.torque.om.ColumnAccessByName;
 #end##
 import $torqueGen.option("torque.om.criteriaClass");
+#if ($addSaveMethods == true && $saveMethodsInDbObjects == "true")
 import org.apache.torque.util.Transaction;
+#end
 import org.apache.commons.lang.ObjectUtils;
 
 
@@ -82,7 +86,11 @@ $torqueGen.mergepoint("classJavadoc")
   #set ($extendsBaseClass = "extends $baseClass" )
 #end
 public abstract class $baseDbObjectClassName $extendsBaseClass
-    implements Persistent, Serializable##
+    implements ##
+#if ($torqueGen.booleanOption("torque.om.save.addSaveMethodsInDbObjects"))
+Persistent, ##
+#end
+Serializable##
 #if ($torqueGen.booleanOption("torque.om.addIntakeRetrievable")), $torqueGen.option("torque.om.retrievableInterface")#end##
 #if ($torqueGen.booleanOption("torque.om.addGetByNameMethods")), ColumnAccessByName#end##
 
@@ -90,10 +98,15 @@ public abstract class $baseDbObjectClass
 $torqueGen.mergepoint("serialVersionUid")
 
 ## field definitions for columns
-$torqueGen.mergepoint("fieldDefinitions")
-
-$torqueGen.mergepoint("newModifiedFields")
-
+$torqueGen.mergepoint("fieldDefinitions")##
+$torqueGen.mergepoint("newModifiedFields")##
+#if ($torqueGen.booleanOption("torque.om.trackSaving"))
+$torqueGen.mergepoint("savingField")##
+#end
+#if ($torqueGen.booleanOption("torque.om.trackLoading"))
+$torqueGen.mergepoint("loadingField")##
+#end
+##
 ## field definitions for referenced objects
 #if ($torqueGen.booleanOption("torque.om.complexObjectModel"))
 $torqueGen.mergepoint("fieldDefinitionsReferencedObjects")
@@ -106,10 +119,14 @@ $torqueGen.mergepoint("fieldDefinitionsR
 
 ## getters and setters for member variables for columns 
 $torqueGen.mergepoint("gettersSetters")
-
 $torqueGen.mergepoint("newModifiedMethods")
-
-#if ($torqueGen.option("torque.om.complexObjectModel"))
+#if ($torqueGen.booleanOption("torque.om.trackSaving"))
+$torqueGen.mergepoint("savingMethods")
+#end
+#if ($trackLoading == "true")
+$torqueGen.mergepoint("loadingMethods")
+#end
+#if ($torqueGen.booleanOption("torque.om.complexObjectModel"))
 $torqueGen.mergepoint("gettersSettersReferencedObjects")
 #end
 
@@ -117,11 +134,11 @@ $torqueGen.mergepoint("gettersSettersRef
 $torqueGen.mergepoint("referencingObjectMethods")
 #end
 
-#if ($torqueGen.booleanOption("torque.om.addGetByNameMethods"))
+#if ($addGetByNameMethods == "true")
 $torqueGen.mergepoint("getByNameMethods")
 #end
 
-#if ($torqueGen.booleanOption("torque.om.save.addSaveMethods"))
+#if ($addSaveMethods == true && $saveMethodsInDbObjects == "true")
 $torqueGen.mergepoint("saveMethods")
 #end
 

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/equalsHashCode.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/equalsHashCode.vm?rev=1244898&r1=1244897&r2=1244898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/equalsHashCode.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/equalsHashCode.vm Thu Feb 16 09:20:37 2012
@@ -43,12 +43,12 @@
         {
             return false;
         }
-        Persistent persistent = (Persistent) toCompare;
-        if (getPrimaryKey() == null || persistent.getPrimaryKey() == null)
+        ${dbObjectClassName} other = (${dbObjectClassName}) toCompare;
+        if (getPrimaryKey() == null || other.getPrimaryKey() == null)
         {
             return false;
         }
-        return getPrimaryKey().equals(persistent.getPrimaryKey());
+        return getPrimaryKey().equals(other.getPrimaryKey());
     }
 
     /**

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/isInitializedReferencingObject.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/isInitializedReferencingObject.vm?rev=1244898&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/isInitializedReferencingObject.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/isInitializedReferencingObject.vm Thu Feb 16 09:20:37 2012
@@ -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 $
+##
+## This template creates the isSet method in the object for the 
+## "foreign" part of a foreign key. The initialized object collection represents
+## the "local" side of the foreign key.  
+## The template expects as input a "foreign-field" element inside a 
+## "foreign-key" element from the torque schema, which was generated 
+## by the OMTransformer.  
+##
+    /**
+     * Checks whether the cache $field for referenced objects has either been
+     * loaded from the database or has been manually initialized.
+     */
+    public boolean ${isInitialized}()
+    {
+        return ($field != null);
+    }
+

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingField.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingField.vm?rev=1244898&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingField.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingField.vm Thu Feb 16 09:20:37 2012
@@ -0,0 +1,29 @@
+## 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 the loading field for a BaseDBObject.
+##
+    /** 
+     * Flag which indicates whether this object is currently loaded
+     * from the database. 
+     */
+    private boolean loading = false;
+

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingMethods.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingMethods.vm?rev=1244898&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingMethods.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/loadingMethods.vm Thu Feb 16 09:20:37 2012
@@ -0,0 +1,44 @@
+## 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 the getters and setters for the saving field
+## for a BaseDBObject.
+##
+    /**
+     * Returns whether this object is currently being loaded from the database.
+     *
+     * @return true if this object is currently loading, false otherwise.
+     */
+    public boolean isLoading()
+    {
+        return loading;
+    }
+
+    /**
+     * Sets whether this object is currently being loaded from the database.
+     *
+     * @param loading true if this object is currently loading, false otherwise.
+     */
+    public void setLoading(boolean loading)
+    {
+        this.loading = loading;
+    }
+

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/referencingObjectMethods.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/referencingObjectMethods.vm?rev=1244898&r1=1244897&r2=1244898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/referencingObjectMethods.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/referencingObjectMethods.vm Thu Feb 16 09:20:37 2012
@@ -29,10 +29,11 @@
 #set ( $objectIsCaching = $torqueGen.booleanOption("torque.om.objectIsCaching") )
 #if ($objectIsCaching)
 $torqueGen.mergepoint("initializer")
+$torqueGen.mergepoint("isInitialized")
 $torqueGen.mergepoint("adder")
 #end
 $torqueGen.mergepoint("getter")
 #if ($objectIsCaching)
 $torqueGen.mergepoint("setter")
-#end
 $torqueGen.mergepoint("referencingJoinGetters")
+#end

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingField.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingField.vm?rev=1244898&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingField.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingField.vm Thu Feb 16 09:20:37 2012
@@ -0,0 +1,26 @@
+## 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 the saving field for a BaseDBObject.
+##
+    /** Flag which indicates whether this object is currently saving. */
+    private boolean saving = false;
+

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingMethods.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingMethods.vm?rev=1244898&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingMethods.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/savingMethods.vm Thu Feb 16 09:20:37 2012
@@ -0,0 +1,44 @@
+## 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 the getters and setters for the saving field
+## for a BaseDBObject.
+##
+    /**
+     * Returns whether this object is currently saving.
+     *
+     * @return true if this object is currently saving, false otherwise.
+     */
+    public boolean isSaving()
+    {
+        return saving;
+    }
+
+    /**
+     * Sets whether this object is currently saving.
+     *
+     * @param saving true if this object is currently saving, false otherwise.
+     */
+    public void setSaving(boolean saving)
+    {
+        this.saving = saving;
+    }
+

Copied: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/saveMethods.vm (from r1231667, db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/saveMethods.vm?p2=db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/saveMethods.vm&p1=db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm&r1=1231667&r2=1244898&rev=1244898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/general/saveMethods.vm Thu Feb 16 09:20:37 2012
@@ -19,61 +19,85 @@
 ##
 ## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
 ##
-## This template creates save methods for a BaseDbObject.
+## This template creates save methods for a BasePeer.
 ## The template expects as input a "table" element from the torque schema, 
 ## which was processed by the OMTransformer.  
 ##
 #set ( $complexObjectModel = $torqueGen.booleanOption("torque.om.complexObjectModel") )
 #set ( $objectIsCaching = $torqueGen.booleanOption("torque.om.objectIsCaching") )
-#set ( $saveException = $torqueGen.option("torque.om.save.saveException") )
+#if (${saveMethodToSaveVariable})
+  #set( $methodInputParam = "${saveMethodInputType} ${saveMethodToSaveVariable}" )
+  #set( $methodInputParamWithComma = "${saveMethodInputType} ${saveMethodToSaveVariable}, " )
+  #set( $toSaveVariableWithComma = "${saveMethodToSaveVariable}, " )
+  #set( $toSaveVariableWithDot = ${saveMethodToSaveVariable} + "." )
+  #set( $toSaveVariable = ${saveMethodToSaveVariable} ) 
+#else
+  #set( $methodInputParam = "" )
+  #set( $methodInputParamWithComma = "" )
+  #set( $toSaveVariableWithComma = "" )
+  #set( $toSaveVariableWithDot = "" )
+  #set( $toSaveVariable = "(${dbObjectClassName}) this" )
+#end
+
     /**
-     * Stores the object in the database.  If the object is new,
-     * it inserts it; otherwise an update is performed.
+     * Stores an object in the database.  If the object is new,
+     * it is inserted; otherwise an update is performed.
+     *
+     * @param toSave the object to be saved, not null.
      *
      * @throws $saveException if an error occurs during saving.
      */
-    public void save() throws $saveException
+    public void save(${methodInputParam}) throws $saveException
     {
 #if ($complexObjectModel)
-        save(${peerClassName}.DATABASE_NAME);
+        save(${toSaveVariableWithComma}${peerClassName}.DATABASE_NAME);
 #else
-        if (isModified())
+#if ($torqueGen.booleanOption("torque.om.trackSaving"))
+        try
         {
-            if (isNew())
-            {
-                ${peerClassName}.doInsert(($dbObjectClassName) this);
-                setNew(false);
-            }
-            else
+            ${toSaveVariableWithDot}setSaving(true);
+#end
+            if (${toSaveVariableWithDot}isModified())
             {
-                ${peerClassName}.doUpdate(($dbObjectClassName) this);
+                if (${toSaveVariableWithDot}isNew())
+                {
+                    ${peerClassName}.doInsert(${toSaveVariable});
+                    toSave.setNew(false);
+                }
+                else
+                {
+                    ${peerClassName}.doUpdate(${toSaveVariable});
+                }
             }
+#if ($torqueGen.booleanOption("torque.om.trackSaving"))
+        }
+        finally
+        {
+            ${toSaveVariableWithDot}setSaving(false);
         }
 #end
+#end
     }
 
     /**
-     * Stores the object in the database.  If the object is new,
-     * it inserts it; otherwise an update is performed.
-#if ($complexObjectModel)
-     * Note: this code is here because the method body is
-     * auto-generated conditionally and therefore needs to be
-     * in this file instead of in the super class, BaseObject.
-#end
+     * Stores an object in the database.  If the object is new,
+     * it is inserted; otherwise an update is performed.
      *
+     * @param toSave the object to be saved, not null.
      * @param dbName the name of the database to which the object
      *        should be saved.
      *
-     * @throws TorqueException if an error occurs during saving.
+     * @throws $saveException if an error occurs during saving.
      */
-    public void save(String dbName) throws TorqueException
+    public void save(${methodInputParamWithComma}String dbName) 
+            throws $saveException
     {
         Connection con = null;
 #if ($complexObjectModel)
         try
         {
             con = Transaction.begin(dbName);
-            save(con);
+            save(${toSaveVariableWithComma}con);
             Transaction.commit(con);
         }
         catch(TorqueException e)
@@ -82,75 +106,81 @@
             throw e;
         }
 #else
-        if (isModified())
+        if (${toSaveVariableWithDot}isModified())
         {
             try
             {
                 con = Torque.getConnection(dbName);
-                if (isNew())
+#if ($trackSaving == "true")
+                ${toSaveVariableWithDot}setSaving(true);
+#end
+                if (${toSaveVariableWithDot}isNew())
                 {
-                    ${peerClassName}.doInsert(this, con);
-                    setNew(false);
+                    ${peerClassName}.doInsert($toSaveVariable, con);
+                    ${toSaveVariableWithDot}setNew(false);
                 }
                 else
                 {
-                    ${peerClassName}.doUpdate(this, con);
+                    ${peerClassName}.doUpdate($toSaveVariable, con);
                 }
             }
             finally
             {
+#if ($trackSaving == "true")
+                ${toSaveVariableWithDot}setSaving(false);
+#end
                 Torque.closeConnection(con);
             }
         }
-  #end
+#end
     }
 
-#if ($complexObjectModel && $objectIsCaching)
-    /** flag to prevent endless save loop, if this object is referenced
-        by another object which falls in this transaction. */
-    private boolean alreadyInSave = false;
-
-#end
     /**
-     * Stores the object in the database.  If the object is new,
-     * it inserts it; otherwise an update is performed.  This method
+     * Stores an object in the database.  If the object is new,
+     * it is inserted; otherwise an update is performed.  This method
      * is meant to be used as part of a transaction, otherwise use
      * the save() method and the connection details will be handled
-     * internally
+     * internally.
      *
+     * @param toSave the object to be saved, not null.
      * @param con the connection to use for saving the object, not null.
      *
-     * @throws TorqueException if an error occurs during saving.
+     * @throws $saveException if an error occurs during saving.
      */
-    public void save(Connection con) throws TorqueException
+    public void save(${methodInputParamWithComma}Connection con) 
+            throws $saveException
     {
 #if ($complexObjectModel && $objectIsCaching)
-        if (alreadyInSave)
+        if (${toSaveVariableWithDot}isSaving())
         {
             return;
         }
+#end
+#if ($torqueGen.booleanOption("torque.om.trackSaving")
+     || ($complexObjectModel && $objectIsCaching))
         try
         {
-            alreadyInSave = true;
+            ${toSaveVariableWithDot}setSaving(true);
 #end
             // If this object has been modified, then save it to the database.
-            if (isModified())
+            if (${toSaveVariableWithDot}isModified())
             {
-                if (isNew())
+                if (${toSaveVariableWithDot}isNew())
                 {
-                    ${peerClassName}.doInsert(($dbObjectClassName) this, con);
-                    setNew(false);
+                    ${peerClassName}.doInsert($toSaveVariable, con);
+                    ${toSaveVariableWithDot}setNew(false);
                 }
                 else
                 {
-                    ${peerClassName}.doUpdate(($dbObjectClassName) this, con);
+                    ${peerClassName}.doUpdate($toSaveVariable, con);
                 }
 #if ($torqueGen.booleanOption("torque.om.useManagers"))
   #set ( $primaryKeyColumnElements = $torqueGen.getChild("primary-keys").getChildren("column") )
   #if ( $primaryKeyColumnElements.size() != 0)
                 if (isCacheOnSave())
                 {
-                    ${managerPackage}.${managerClassName}.putInstance(this);
+                    ${managerPackage}.${managerClassName}.putInstance(
+                            ${toSaveVariable});
                 }
   #end
 #end
@@ -163,43 +193,40 @@
     #set ( $otherTable = $referencingForeignKeyElement.getParent())
     #set ( $otherTableName = $otherTable.getAttribute("name"))
     #if ( !($thisTableName.equals($otherTableName)) )
-      #set ( $otherClassName = $otherTable.getAttribute("baseDbObjectClassName") )
+      #set ( $otherClassName = $otherTable.getAttribute("dbObjectClassName") )
+      #set ( $otherPeerClassName = $otherTable.getAttribute("peerClassName") )
       #set ( $relCol = "" )
       #set ( $foreignField = $referencingForeignKeyElement.getChild("foreign-field").getAttribute("field"))
+      #set ( $foreignFieldGetter = $referencingForeignKeyElement.getChild("foreign-field").getAttribute("getter"))
+      #set ( $foreignFieldIsInitialized = $referencingForeignKeyElement.getChild("foreign-field").getAttribute("isInitialized"))
+      #if (${torqueGen.booleanOption("torque.om.saveMethodsInDbObjects")})
+        #set ( $otherObjectContainsSaveMethod = ${foreignField} )
+        #set ( $otherToSaveVariableWithComma = "" )
+      #else
+        #set ( $otherObjectContainsSaveMethod = $otherPeerClassName )
+        #set ( $otherToSaveVariableWithComma = "${foreignField}, " )
+      #end
       ## if the referencing table is in an external schema, field is null.
-      ## In this case,skip the foolowing code
+      ## In this case,skip the following code
       #if ($foreignField)
-            if ($foreignField != null)
+            if (${toSaveVariableWithDot}${foreignFieldIsInitialized}())
             {
-                for (int i = 0; i < ${foreignField}.size(); i++)
+                for (${otherClassName} ${foreignField} : ${toSaveVariableWithDot}${foreignFieldGetter}())
                 {
-                    ((${otherClassName}) ${foreignField}.get(i)).save(con);
+                    ${otherObjectContainsSaveMethod}.save(${otherToSaveVariableWithComma}con);
                 }
             }
       #end
     #end
   #end
+#end
+#if ($torqueGen.booleanOption("torque.om.trackSaving")
+     || ($complexObjectModel && $objectIsCaching))
         }
         finally
         {
-            alreadyInSave = false;
+            ${toSaveVariableWithDot}setSaving(false);
         }
 #end
     }
 
-#if ($torqueGen.booleanOption("torque.om.useManagers"))
-  #set ( $primaryKeyColumnElements = $torqueGen.getChild("primary-keys").getChildren("column") )
-  #if ( $primaryKeyColumnElements.size() != 0)
-
-    /**
-     * Specify whether to cache the object after saving to the db.
-     *
-     * @return This implementation alwaqys returns true.
-     */
-    protected boolean isCacheOnSave()
-    {
-        return true;
-    }
-  #end
-#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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -56,6 +56,9 @@ $torqueGen.mergepoint("doSelect")
 $torqueGen.mergepoint("getDbObjectInstance")
 $torqueGen.mergepoint("doInsert")
 $torqueGen.mergepoint("doUpdate")
+#if ($addSaveMethods == "true" && $saveMethodsInDbObjects != "true")
+$torqueGen.mergepoint("saveMethods")
+#end
 $torqueGen.mergepoint("doDelete")
 $torqueGen.mergepoint("buildCriteria")
 $torqueGen.mergepoint("buildSelectCriteria")
@@ -63,11 +66,11 @@ $torqueGen.mergepoint("buildColumnValues
 $torqueGen.mergepoint("retrieveByPK")
 $torqueGen.mergepoint("retrieveByPKs")
 #if ($complexObjectModel == "true")
-  #if ($torqueGen.booleanOption("torque.om.complexObjectModel.generateDoSelectJoin"))
+  #if (($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateDoSelectJoin"))
 $torqueGen.mergepoint("doSelectJoin")
 $torqueGen.mergepoint("doSelectJoinAllExcept")
   #end
-  #if ($torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
+  #if (($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
 $torqueGen.mergepoint("fillReferencedObjects")
 $torqueGen.mergepoint("fillReferencingObjects")
 $torqueGen.mergepoint("fillerChunkSizeGetter")

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/saveMethods.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/saveMethods.vm?rev=1244898&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/saveMethods.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/saveMethods.vm Thu Feb 16 09:20:37 2012
@@ -0,0 +1,75 @@
+## 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 save methods for a BasePeer.
+## The template expects as input a "table" element from the torque schema, 
+## which was processed by the OMTransformer.  
+##
+#set ( $complexObjectModel = $torqueGen.booleanOption("torque.om.complexObjectModel") )
+#set ( $objectIsCaching = $torqueGen.booleanOption("torque.om.objectIsCaching") )
+#set ( $saveException = $torqueGen.option("torque.om.save.saveException") )
+    /**
+     * Stores an object in the database.  If the object is new,
+     * it is inserted; otherwise an update is performed.
+     *
+     * @param toSave the object to be saved, not null.
+     *
+     * @throws $saveException if an error occurs during saving.
+     */
+    public static void save(${dbObjectClassName} toSave) throws $saveException
+    {
+        ${peerImplGetter}().save(toSave);
+    }
+
+    /**
+     * Stores an object in the database.  If the object is new,
+     * it is inserted; otherwise an update is performed.
+     *
+     * @param toSave the object to be saved, not null.
+     * @param dbName the name of the database to which the object
+     *        should be saved.
+     *
+     * @throws $saveException if an error occurs during saving.
+     */
+    public static void save(${dbObjectClassName} toSave, String dbName) 
+            throws $saveException
+    {
+        ${peerImplGetter}().save(toSave, dbName);
+    }
+
+    /**
+     * Stores an object in the database.  If the object is new,
+     * it is inserted; otherwise an update is performed.  This method
+     * is meant to be used as part of a transaction, otherwise use
+     * the save() method and the connection details will be handled
+     * internally.
+     *
+     * @param toSave the object to be saved, not null.
+     * @param con the connection to use for saving the object, not null.
+     *
+     * @throws $saveException if an error occurs during saving.
+     */
+    public static void save(${dbObjectClassName} toSave, Connection con) 
+            throws $saveException
+    {
+        ${peerImplGetter}().save(toSave, 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=1244898&r1=1244897&r2=1244898&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 Thu Feb 16 09:20:37 2012
@@ -49,6 +49,9 @@ $torqueGen.mergepoint("doSelect")
 $torqueGen.mergepoint("getDbObjectInstance")
 $torqueGen.mergepoint("doInsert")
 $torqueGen.mergepoint("doUpdate")
+#if ($addSaveMethods == "true" && $saveMethodsInDbObjects != "true")
+$torqueGen.mergepoint("saveMethods")
+#end
 $torqueGen.mergepoint("doDelete")
 $torqueGen.mergepoint("buildCriteria")
 $torqueGen.mergepoint("buildSelectCriteria")
@@ -56,11 +59,11 @@ $torqueGen.mergepoint("buildColumnValues
 $torqueGen.mergepoint("retrieveByPK")
 $torqueGen.mergepoint("retrieveByPKs")
 #if ($complexObjectModel == "true")
-  #if ($torqueGen.booleanOption("torque.om.complexObjectModel.generateDoSelectJoin"))
+  #if (($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateDoSelectJoin"))
 $torqueGen.mergepoint("doSelectJoin")
 $torqueGen.mergepoint("doSelectJoinAllExcept")
   #end
-  #if ($torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
+  #if (($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
 $torqueGen.mergepoint("fillReferencedObjects")
 $torqueGen.mergepoint("fillReferencingObjects")
 $torqueGen.mergepoint("fillerChunkSizeGetter")

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm?rev=1244898&r1=1244897&r2=1244898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm Thu Feb 16 09:20:37 2012
@@ -87,17 +87,29 @@ $torqueGen.mergepoint("createDbObjectIns
 #else
 $torqueGen.mergepoint("createDbObjectInstance")
 #end
+#if ($trackLoading == "true")
+        try 
+        {
+            ${field}.setLoading(true);
+#end
 #set ( $n = 1 )
 #foreach ($columnElement in $torqueGen.getChildren("column"))
   #set ( $setter = $columnElement.getAttribute("setter") )
   #set ( $getter = $columnElement.getAttribute("getter") )
-       $field.${setter}(
-              ${getter}(resultSet, offset + $n));
+            ${field}.${setter}(
+                    ${getter}(resultSet, offset + $n));
   #set ( $n = $n + 1 )
 #end
-       ${field}.setNew(false);
-       ${field}.setModified(false);
-       return $field;
+            ${field}.setNew(false);
+            ${field}.setModified(false);
+#if ($trackLoading == "true")
+        }
+        finally
+        {
+            ${field}.setLoading(false);
+        }
+#end
+        return ${field};
     }
 
 $torqueGen.mergepoint("dbObjectFieldGetters")

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml?rev=1244898&r1=1244897&r2=1244898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml Thu Feb 16 09:20:37 2012
@@ -135,6 +135,8 @@
           outlet="torque.sql.ddl.sequence"/>
     </mergepoint>
     <mergepoint name="createOptions">
+      <action xsi:type="applyAction"
+          outlet="torque.sql.ddl.tableCreateOptions"/>
     </mergepoint>
   </outlet>
 
@@ -175,6 +177,11 @@
           outlet="torque.sql.ddl.columnComment"/>
      </mergepoint>
   </outlet>
+  
+  <outlet name="torque.sql.ddl.tableCreateOptions"
+      xsi:type="velocityOutlet"
+      path="ddl/${option:database}/tableCreateOptions.vm">
+  </outlet>
       
   <outlet name="torque.sql.ddl.columnComment"
       xsi:type="velocityOutlet"



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