You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2011/05/13 22:07:37 UTC

svn commit: r1102884 - /db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm

Author: tfischer
Date: Fri May 13 20:07:37 2011
New Revision: 1102884

URL: http://svn.apache.org/viewvc?rev=1102884&view=rev
Log:
- add javadoc
- simplify generated code in save(Connection)

Modified:
    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/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/dbObject/base/saveMethods.vm?rev=1102884&r1=1102883&r2=1102884&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/dbObject/base/saveMethods.vm Fri May 13 20:07:37 2011
@@ -30,7 +30,7 @@
      * Stores the object in the database.  If the object is new,
      * it inserts it; otherwise an update is performed.
      *
-     * @throws $saveException
+     * @throws $saveException if an error occurs during saving.
      */
     public void save() throws $saveException
     {
@@ -61,8 +61,10 @@
      * in this file instead of in the super class, BaseObject.
 #end
      *
-     * @param dbName
-     * @throws TorqueException
+     * @param dbName the name of the database to which the object
+     *        should be saved.
+     *
+     * @throws TorqueException if an error occurs during saving.
      */
     public void save(String dbName) throws TorqueException
     {
@@ -116,38 +118,41 @@
      * the save() method and the connection details will be handled
      * internally
      *
-     * @param con
-     * @throws TorqueException
+     * @param con the connection to use for saving the object, not null.
+     *
+     * @throws TorqueException if an error occurs during saving.
      */
     public void save(Connection con) throws TorqueException
     {
 #if ($complexObjectModel && $objectIsCaching)
-        if (!alreadyInSave)
+        if (alreadyInSave)
         {
-            alreadyInSave = true;
+            return;
+        }
+        alreadyInSave = true;
 #end
-            // If this object has been modified, then save it to the database.
-            if (isModified())
+        // If this object has been modified, then save it to the database.
+        if (isModified())
+        {
+            if (isNew())
             {
-                if (isNew())
-                {
-                    ${peerClassName}.doInsert(($dbObjectClassName) this, con);
-                    setNew(false);
-                }
-                else
-                {
-                    ${peerClassName}.doUpdate(($dbObjectClassName) this, con);
-                }
+                ${peerClassName}.doInsert(($dbObjectClassName) this, con);
+                setNew(false);
+            }
+            else
+            {
+                ${peerClassName}.doUpdate(($dbObjectClassName) this, 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);
-                }
+            if (isCacheOnSave())
+            {
+                ${managerPackage}.${managerClassName}.putInstance(this);
+            }
   #end
 #end
-            }
+        }
 
 #if ($complexObjectModel && $objectIsCaching)
   #set ( $referencingForeignKeyElements = $torqueGen.getChild("referencing-foreign-keys").getChildren("foreign-key") )
@@ -162,18 +167,17 @@
       ## if the referencing table is in an external schema, field is null.
       ## In this case,skip the foolowing code
       #if ($foreignField)
-            if ($foreignField != null)
+        if ($foreignField != null)
+        {
+            for (int i = 0; i < ${foreignField}.size(); i++)
             {
-                for (int i = 0; i < ${foreignField}.size(); i++)
-                {
-                    ((${otherClassName}) ${foreignField}.get(i)).save(con);
-                }
+                ((${otherClassName}) ${foreignField}.get(i)).save(con);
             }
+        }
       #end
     #end
   #end
-            alreadyInSave = false;
-        }
+        alreadyInSave = false;
 #end
     }
 
@@ -183,7 +187,8 @@
 
     /**
      * Specify whether to cache the object after saving to the db.
-     * This method returns true
+     *
+     * @return This implementation alwaqys returns true.
      */
     protected boolean isCacheOnSave()
     {



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