db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r578941 - in /db/torque: site/trunk/xdocs/changes.xml templates/trunk/src/templates/om/Object.vm templates/trunk/src/templates/om/ObjectWithManager.vm
Date Mon, 24 Sep 2007 20:10:52 GMT
Author: tfischer
Date: Mon Sep 24 13:10:50 2007
New Revision: 578941

URL: http://svn.apache.org/viewvc?rev=578941&view=rev
Log:
added copy(...) and add<ForeignKey>(..) methods which take connection parameters.
Thanks to Tobias Hilka for the patch.
Resolves TORQUE-99.

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=578941&r1=578940&r2=578941&view=diff
==============================================================================
--- db/torque/site/trunk/xdocs/changes.xml (original)
+++ db/torque/site/trunk/xdocs/changes.xml Mon Sep 24 13:10:50 2007
@@ -31,6 +31,10 @@
 
   <body>
   <release version="3.3-RC3" date="in SVN">
+    <action type="add" dev="tfischer" issue="TORQUE-99" due-to="Tobias Hilka">
+      Added copy(..) and add<ForeignKey>(..) methods with a connection 
+      parameter.
+    </action>
     <action type="update" dev="tv">
       Updated JCS dependency to version 1.3 and fixed related deprecation 
       issues.

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=578941&r1=578940&r2=578941&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/Object.vm (original)
+++ db/torque/templates/trunk/src/templates/om/Object.vm Mon Sep 24 13:10:50 2007
@@ -649,6 +649,19 @@
     }
 
     /**
+     * Method called to associate a $tblFK.JavaName object to this object
+     * through the $className foreign key attribute using connection.
+     *
+     * @param l $className
+     * @throws TorqueException
+     */
+    public void add${relColMs}($className l, Connection con) throws TorqueException
+    {
+        get${relCol}(con).add(l);
+        l.set${interfaceName}${suffix}(($table.JavaName) this);
+    }
+
+    /**
      * The criteria used to select the current contents of $collName
      */
     private Criteria last${relCol}Criteria = null;
@@ -1312,7 +1325,6 @@
     {
   #set ($i = 0)
   #foreach ($col in $table.Columns)
-    #set ( $cup=$col.PeerJavaName )
     if (position == $i)
         {
             return setByName("${col.JavaName}", value);
@@ -1776,6 +1788,23 @@
   #end
 
   #if ($complexObjectModel)
+    /**
+     * Makes a copy of this object using connection.
+     * It creates a new object filling in the simple attributes.
+     * It then fills all the association collections and sets the
+     * related objects to isNew=true.
+     *
+     * @param con the database connection to read associated objects.
+     */
+    #if ($table.isAbstract())
+    public abstract $table.JavaName copy(Connection con) throws TorqueException;
+    #else
+    public $table.JavaName copy(Connection con) throws TorqueException
+    {
+        return copy(true, con);
+    }
+    #end
+
     #if (!$table.isAbstract())
     /**
      * Makes a copy of this object.
@@ -1790,13 +1819,29 @@
     {
         return copyInto(new ${table.JavaName}(), deepcopy);
     }
+
+    /**
+     * Makes a copy of this object using connection.
+     * 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.
+     * @param con the database connection to read associated objects.
+     */
+    public $table.JavaName copy(boolean deepcopy, Connection con) throws TorqueException
+    {
+        return copyInto(new ${table.JavaName}(), deepcopy, con);
+    }
     #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
@@ -1805,11 +1850,27 @@
     }
   #end
 
+  
+  #if ($complexObjectModel)
+    /**
+     * Fills the copyObj with the contents of this object using connection.
+     * The associated objects are also copied and treated as new objects.
+     *
+     * @param copyObj the object to fill.
+     * @param con the database connection to read associated objects.
+     */
+    protected $table.JavaName copyInto($table.JavaName copyObj, Connection con) throws TorqueException
+    {
+        return copyInto(copyObj, true, con);
+    }
+  #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)
@@ -1893,6 +1954,92 @@
   #end
         return copyObj;
     }
+        
+    
+  #if ($complexObjectModel)
+    /**
+     * Fills the copyObj with the contents of this object using connection.
+     * If deepcopy is true, The associated objects are also copied
+     * and treated as new objects.
+     *
+     * @param copyObj the object to fill.
+     * @param deepcopy whether the associated objects should be copied.
+     * @param con the database connection to read associated objects.
+     */
+    protected $table.JavaName copyInto($table.JavaName copyObj, boolean deepcopy, Connection
con) throws TorqueException
+    {
+    #foreach ($col in $table.Columns)
+        copyObj.${col.SetterName}($col.UncapitalisedJavaName);
+    #end
+
+    #foreach ($col in $table.Columns)
+      #if ($col.isPrimaryKey())
+        #if($col.Primitive)
+          #set ($fktype = $col.JavaNative)
+          #set ($casttype = "")
+          #if ($fktype == "short")
+            #set ($casttype = "(short)")
+          #elseif($fktype == "byte")
+            #set ($casttype = "(byte)")
+          #end
+          #set ($coldefval = "0")
+          #set ($coldefval = $col.DefaultValue)
+        copyObj.${col.SetterName}($casttype $coldefval);
+        #else
+          #set ( $pkid = "null" )
+          #set ( $cjtype = $col.JavaNative )
+        copyObj.${col.SetterName}((${cjtype})${pkid});
+        #end
+      #end
+    #end
+
+        if (deepcopy)
+        {
+    #foreach ($fk in $table.Referrers)
+      #set ( $tblFK = $fk.Table )
+      #if ( !($tblFK.Name.equals($table.Name)) )
+        #set ( $className = $tblFK.JavaName )
+        #set ( $relCol = "" )
+        #foreach ($columnName in $fk.LocalColumns)
+          #set ( $column = $tblFK.getColumn($columnName) )
+          #if ($column.isMultipleFK())
+            #set ( $relCol = "$relCol$column.JavaName" )
+          #end
+        #end
+
+        #if ($objectIsCaching)
+          #if ($relCol == "")
+            #set ( $pCollName = "${className}s" )
+            #set ( $pCollNameNoS = "${className}" )
+          #else
+            #set ( $pCollName = "${className}sRelatedBy$relCol" )
+            #set ( $pCollNameNoS = "${className}RelatedBy$relCol" )
+          #end
+
+        List#if($enableJava5Features)<$className>#end v${pCollName} = get${pCollName}(con);
+          ## 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++)
+            {
+                ${className} obj = #if(!$enableJava5Features)($className)#end v${pCollName}.get(i);
+                copyObj.add$pCollNameNoS(obj.copy(con), con);
+            }
+        }
+        else
+        {
+            copyObj.coll${pCollName} = null;
+        }
+        #end
+      #end
+    #end
+        }
+        return copyObj;
+    }
+  #end
+    
+    
 #end
 
 #if (!$table.isAlias())

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=578941&r1=578940&r2=578941&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm (original)
+++ db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm Mon Sep 24 13:10:50 2007
@@ -666,6 +666,19 @@
     }
 
     /**
+     * Method called to associate a $tblFK.JavaName object to this object
+     * through the $className foreign key attribute using connection.
+     *
+     * @param l $className
+     * @throws TorqueException
+     */
+    public void add${relColMs}($className l, Connection con) throws TorqueException
+    {
+        get${relCol}(con).add(l);
+        l.set${interfaceName}${suffix}(($table.JavaName) this);
+    }
+
+    /**
      * The criteria used to select the current contents of $collName
      */
     private Criteria last${relCol}Criteria = null;
@@ -1820,6 +1833,23 @@
   #end
 
   #if ($complexObjectModel)
+    /**
+     * Makes a copy of this object using connection.
+     * It creates a new object filling in the simple attributes.
+     * It then fills all the association collections and sets the
+     * related objects to isNew=true.
+     *
+     * @param con the database connection to read associated objects.
+     */
+    #if ($table.isAbstract())
+    public abstract $table.JavaName copy(Connection con) throws TorqueException;
+    #else
+    public $table.JavaName copy(Connection con) throws TorqueException
+    {
+        return copy(true, con);
+    }
+    #end
+
     #if (!$table.isAbstract())
     /**
      * Makes a copy of this object.
@@ -1834,13 +1864,29 @@
     {
         return copyInto(new ${table.JavaName}(), deepcopy);
     }
+
+    /**
+     * Makes a copy of this object using connection.
+     * 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.
+     * @param con the database connection to read associated objects.
+     */
+    public $table.JavaName copy(boolean deepcopy, Connection con) throws TorqueException
+    {
+        return copyInto(new ${table.JavaName}(), deepcopy, con);
+    }
     #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
@@ -1849,11 +1895,27 @@
     }
   #end
 
+  
+  #if ($complexObjectModel)
+    /**
+     * Fills the copyObj with the contents of this object using connection.
+     * The associated objects are also copied and treated as new objects.
+     *
+     * @param copyObj the object to fill.
+     * @param con the database connection to read associated objects.
+     */
+    protected $table.JavaName copyInto($table.JavaName copyObj, Connection con) throws TorqueException
+    {
+        return copyInto(copyObj, true, con);
+    }
+  #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)
@@ -1937,6 +1999,90 @@
   #end
         return copyObj;
     }
+        
+    
+  #if ($complexObjectModel)
+    /**
+     * Fills the copyObj with the contents of this object using connection.
+     * If deepcopy is true, The associated objects are also copied
+     * and treated as new objects.
+     *
+     * @param copyObj the object to fill.
+     * @param deepcopy whether the associated objects should be copied.
+     * @param con the database connection to read associated objects.
+     */
+    protected $table.JavaName copyInto($table.JavaName copyObj, boolean deepcopy, Connection
con) throws TorqueException
+    {
+    #foreach ($col in $table.Columns)
+        copyObj.${col.SetterName}($col.UncapitalisedJavaName);
+    #end
+
+    #foreach ($col in $table.Columns)
+      #if ($col.isPrimaryKey())
+        #if($col.Primitive)
+          #set ($fktype = $col.JavaNative)
+          #set ($casttype = "")
+          #if ($fktype == "short")
+            #set ($casttype = "(short)")
+          #elseif($fktype == "byte")
+            #set ($casttype = "(byte)")
+          #end
+          #set ($coldefval = "0")
+          #set ($coldefval = $col.DefaultValue)
+        copyObj.${col.SetterName}($casttype $coldefval);
+        #else
+          #set ( $pkid = "null" )
+          #set ( $cjtype = $col.JavaNative )
+        copyObj.${col.SetterName}((${cjtype})${pkid});
+        #end
+      #end
+    #end
+
+        if (deepcopy)
+        {
+    #foreach ($fk in $table.Referrers)
+      #set ( $tblFK = $fk.Table )
+      #if ( !($tblFK.Name.equals($table.Name)) )
+        #set ( $className = $tblFK.JavaName )
+        #set ( $relCol = "" )
+        #foreach ($columnName in $fk.LocalColumns)
+          #set ( $column = $tblFK.getColumn($columnName) )
+          #if ($column.isMultipleFK())
+            #set ( $relCol = "$relCol$column.JavaName" )
+          #end
+        #end
+
+        #if ($objectIsCaching)
+          #if ($relCol == "")
+            #set ( $pCollName = "${className}s" )
+            #set ( $pCollNameNoS = "${className}" )
+          #else
+            #set ( $pCollName = "${className}sRelatedBy$relCol" )
+            #set ( $pCollNameNoS = "${className}RelatedBy$relCol" )
+          #end
+
+        List#if($enableJava5Features)<$className>#end v${pCollName} = get${pCollName}(con);
+          ## 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++)
+            {
+                ${className} obj = #if(!$enableJava5Features)($className)#end v${pCollName}.get(i);
+                copyObj.add$pCollNameNoS(obj.copy(con), con);
+            }
+        }
+        else
+        {
+            copyObj.coll${pCollName} = null;
+        }
+        #end
+      #end
+    #end
+        }
+        return copyObj;
+    }
+  #end
 #end
 
 #if (!$table.isAlias())



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