db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r410671 - in /db/torque: site/trunk/xdocs/changes.xml templates/trunk/src/templates/om/Object.vm templates/trunk/src/templates/om/ObjectWithManager.vm
Date Wed, 31 May 2006 21:13:55 GMT
Author: tfischer
Date: Wed May 31 14:13:55 2006
New Revision: 410671

URL: http://svn.apache.org/viewvc?rev=410671&view=rev
Log:
Added methods for shallow copies into Object.vm and ObjectWithManager.vm
Implements TORQUE-23
Thanks to Thoralf Rickert for an early version of the patch.

Modified:
    db/torque/site/trunk/xdocs/changes.xml
    db/torque/templates/trunk/src/templates/om/Object.vm
    db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm

Modified: db/torque/site/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/db/torque/site/trunk/xdocs/changes.xml?rev=410671&r1=410670&r2=410671&view=diff
==============================================================================
--- db/torque/site/trunk/xdocs/changes.xml (original)
+++ db/torque/site/trunk/xdocs/changes.xml Wed May 31 14:13:55 2006
@@ -29,6 +29,9 @@
 
   <release version="3.2.1-dev" date="in SVN">
   
+    <action type="add" dev="tfischer" issue="TORQUE-23" due-to="Thoralf Rickert">
+      Added methods for shallow copies into the generated objects.
+    </action>
     <action type="fix" dev="tfischer" issue="TORQUE-6" due-to="Joerg Friedrich">
       Fixed foreign key constraint generation for Firebird.
     </action>

Modified: db/torque/templates/trunk/src/templates/om/Object.vm
URL: http://svn.apache.org/viewvc/db/torque/templates/trunk/src/templates/om/Object.vm?rev=410671&r1=410670&r2=410671&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/Object.vm (original)
+++ db/torque/templates/trunk/src/templates/om/Object.vm Wed May 31 14:13:55 2006
@@ -1592,11 +1592,60 @@
   #else
     public $table.JavaName copy() throws TorqueException
     {
+    #if ($complexObjectModel)
+        return copy(true);
+    #else
         return copyInto(new ${table.JavaName}());
+    #end
     }
   #end
 
+  #if ($complexObjectModel)
+    #if (!$table.isAbstract())
+    /**
+     * Makes a copy of this object.
+     * It creates a new object filling in the simple attributes.
+     * If the parameter deepcopy is true, it then fills all the
+     * association collections and sets the related objects to
+     * isNew=true.
+     *
+     * @param deepcopy whether to copy the associated objects.
+     */
+    public $table.JavaName copy(boolean deepcopy) throws TorqueException
+    {
+        return copyInto(new ${table.JavaName}(), deepcopy);
+    }
+    #end
+  #end
+
+  #if ($complexObjectModel)
+    /**
+     * Fills the copyObj with the contents of this object.
+     * The associated objects are also copied and treated as new objects.
+     * @param copyObj the object to fill.
+     */
+    protected $table.JavaName copyInto($table.JavaName copyObj) throws TorqueException
+    {
+        return copyInto(copyObj, true);
+    }
+  #end
+    
+    /**
+     * Fills the copyObj with the contents of this object.
+  #if ($complexObjectModel)
+     * If deepcopy is true, The associated objects are also copied 
+     * and treated as new objects.
+  #end
+     * @param copyObj the object to fill.
+  #if ($complexObjectModel)
+     * @param deepcopy whether the associated objects should be copied.
+  #end
+     */
+  #if ($complexObjectModel)
+    protected $table.JavaName copyInto($table.JavaName copyObj, boolean deepcopy) throws
TorqueException
+  #else
     protected $table.JavaName copyInto($table.JavaName copyObj) throws TorqueException
+  #end
     {
   #foreach ($col in $table.Columns)
         copyObj.${col.SetterName}($col.UncapitalisedJavaName);
@@ -1624,6 +1673,8 @@
   #end
 
   #if ($complexObjectModel)
+        if (deepcopy) 
+        {
     #foreach ($fk in $table.Referrers)
       #set ( $tblFK = $fk.Table )
       #if ( !($tblFK.Name.equals($table.Name)) )
@@ -1645,24 +1696,25 @@
             #set ( $pCollNameNoS = "${className}RelatedBy$relCol" )
           #end
 
-        List#if($enableJava5Features)<$className>#end v${pCollName} = get${pCollName}();
-          ## v can be null if the generator property
-          ## torque.silentDbFetch is set to false
-        if (v${pCollName} != null)
-        {
-            for (int i = 0; i < v${pCollName}.size(); i++)
+            List#if($enableJava5Features)<$className>#end v${pCollName} = get${pCollName}();
+              ## v can be null if the generator property
+              ## torque.silentDbFetch is set to false
+            if (v${pCollName} != null)
             {
-                ${className} obj = #if(!$enableJava5Features)($className)#end v${pCollName}.get(i);
-                copyObj.add$pCollNameNoS(obj.copy());
+                for (int i = 0; i < v${pCollName}.size(); i++)
+                {
+                    ${className} obj = #if(!$enableJava5Features)($className)#end v${pCollName}.get(i);
+                    copyObj.add$pCollNameNoS(obj.copy());
+                }
+            }
+            else
+            {
+                copyObj.coll${pCollName} = null;
             }
-        }
-        else
-        {
-            copyObj.coll${pCollName} = null;
-        }
         #end
       #end
     #end
+        }
   #end
         return copyObj;
     }

Modified: db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm
URL: http://svn.apache.org/viewvc/db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm?rev=410671&r1=410670&r2=410671&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm (original)
+++ db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm Wed May 31 14:13:55 2006
@@ -1610,11 +1610,60 @@
   #else
     public $table.JavaName copy() throws TorqueException
     {
+    #if ($complexObjectModel)
+        return copy(true);
+    #else
         return copyInto(new ${table.JavaName}());
+    #end
     }
   #end
 
+  #if ($complexObjectModel)
+    #if (!$table.isAbstract())
+    /**
+     * Makes a copy of this object.
+     * It creates a new object filling in the simple attributes.
+     * If the parameter deepcopy is true, it then fills all the
+     * association collections and sets the related objects to
+     * isNew=true.
+     *
+     * @param deepcopy whether to copy the associated objects.
+     */
+    public $table.JavaName copy(boolean deepcopy) throws TorqueException
+    {
+        return copyInto(new ${table.JavaName}(), deepcopy);
+    }
+    #end
+  #end
+
+  #if ($complexObjectModel)
+    /**
+     * Fills the copyObj with the contents of this object.
+     * The associated objects are also copied and treated as new objects.
+     * @param copyObj the object to fill.
+     */
+    protected $table.JavaName copyInto($table.JavaName copyObj) throws TorqueException
+    {
+        return copyInto(copyObj, true);
+    }
+  #end
+    
+    /**
+     * Fills the copyObj with the contents of this object.
+  #if ($complexObjectModel)
+     * If deepcopy is true, The associated objects are also copied 
+     * and treated as new objects.
+  #end
+     * @param copyObj the object to fill.
+  #if ($complexObjectModel)
+     * @param deepcopy whether the associated objects should be copied.
+  #end
+     */
+  #if ($complexObjectModel)
+    protected $table.JavaName copyInto($table.JavaName copyObj, boolean deepcopy) throws
TorqueException
+  #else
     protected $table.JavaName copyInto($table.JavaName copyObj) throws TorqueException
+  #end
     {
   #foreach ($col in $table.Columns)
         copyObj.${col.SetterName}($col.UncapitalisedJavaName);
@@ -1623,8 +1672,8 @@
   #foreach ($col in $table.Columns)
     #if ($col.isPrimaryKey())
       #if($col.Primitive)
-        #set ($fktype = $col.JavaNative)
-        #set ($casttype = "")
+		#set ($fktype = $col.JavaNative)
+	    #set ($casttype = "")
         #if ($fktype == "short")
           #set ($casttype = "(short)")
         #elseif($fktype == "byte")
@@ -1642,6 +1691,8 @@
   #end
 
   #if ($complexObjectModel)
+        if (deepcopy) 
+        {
     #foreach ($fk in $table.Referrers)
       #set ( $tblFK = $fk.Table )
       #if ( !($tblFK.Name.equals($table.Name)) )
@@ -1663,24 +1714,25 @@
             #set ( $pCollNameNoS = "${className}RelatedBy$relCol" )
           #end
 
-        List#if($enableJava5Features)<$className>#end v${pCollName} = get${pCollName}();
-          ## v can be null if the generator property
-          ## torque.silentDbFetch is set to false
-        if (v${pCollName} != null)
-        {
-            for (int i = 0; i < v${pCollName}.size(); i++)
+            List#if($enableJava5Features)<$className>#end v${pCollName} = get${pCollName}();
+              ## v can be null if the generator property
+              ## torque.silentDbFetch is set to false
+            if (v${pCollName} != null)
             {
-                ${className} obj = #if(!$enableJava5Features)($className)#end v${pCollName}.get(i);
-                copyObj.add$pCollNameNoS(obj.copy());
+                for (int i = 0; i < v${pCollName}.size(); i++)
+                {
+                    ${className} obj = #if(!$enableJava5Features)($className)#end v${pCollName}.get(i);
+                    copyObj.add$pCollNameNoS(obj.copy());
+                }
+            }
+            else
+            {
+                copyObj.coll${pCollName} = null;
             }
-        }
-        else
-        {
-            copyObj.coll${pCollName} = null;
-        }
         #end
       #end
     #end
+        }
   #end
         return copyObj;
     }



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