db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1754261 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/util/ torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/ torque-templates/src/main/resources/org/apache/torque/templates/om/temp...
Date Wed, 27 Jul 2016 12:27:48 GMT
Author: tv
Date: Wed Jul 27 12:27:48 2016
New Revision: 1754261

URL: http://svn.apache.org/viewvc?rev=1754261&view=rev
Log:
TORQUE-346: Second step

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.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/baseDbObjectForView.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/imports.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java?rev=1754261&r1=1754260&r2=1754261&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
Wed Jul 27 12:27:48 2016
@@ -27,7 +27,7 @@ import org.apache.torque.TorqueException
 import org.apache.torque.criteria.Criteria;
 import org.apache.torque.map.TableMap;
 import org.apache.torque.om.ObjectKey;
-import org.apache.torque.om.Persistent;
+import org.apache.torque.om.ObjectModel;
 import org.apache.torque.om.mapper.RecordMapper;
 
 /**
@@ -40,7 +40,7 @@ import org.apache.torque.om.mapper.Recor
  * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
  * @version $Id: BasePeerImpl.java 1701342 2015-09-05 02:18:04Z tfischer $
  */
-public abstract class AbstractPeerImpl<T extends Persistent> extends BasePeerImpl<T>
+public abstract class AbstractPeerImpl<T extends ObjectModel> extends BasePeerImpl<T>
 {
     /** Serial version */
     private static final long serialVersionUID = 1236684692145864194L;
@@ -191,4 +191,46 @@ public abstract class AbstractPeerImpl<T
         obj.setNew(false);
         obj.setModified(false);
     }
+
+    /**
+     * Updates an object in the database.
+     * The primary key is used to identify the object to update.
+     *
+     * @param obj the data object to update in the database.
+     *
+     * @return the number of affected rows.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public int doUpdate(T obj) throws TorqueException
+    {
+        ColumnValues columnValues = buildColumnValues(obj);
+        int result = doUpdate(columnValues);
+        obj.setModified(false);
+        return result;
+    }
+
+    /**
+     * Updates an object in the database.
+     * The primary key is used to identify the object to update.
+     * This method is to be used during a transaction,
+     * otherwise the doUpdate(T) method can be used.
+     *
+     * @param obj the data object to update in the database.
+     * @param con the connection to use, not null.
+
+     * @return the number of affected rows.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public int doUpdate(T obj, Connection con)
+        throws TorqueException
+    {
+        ColumnValues columnValues = buildColumnValues(obj);
+        int result = doUpdate(columnValues, con);
+        obj.setModified(false);
+        return result;
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.xml?rev=1754261&r1=1754260&r2=1754261&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.xml
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.xml
Wed Jul 27 12:27:48 2016
@@ -145,6 +145,9 @@
     <mergepoint name="buildSelectCriteria">
       <action xsi:type="applyAction" outlet="torque.om.peer.impl.base.buildSelectCriteria"/>
     </mergepoint>
+    <mergepoint name="buildColumnValues">
+      <action xsi:type="applyAction" outlet="torque.om.peer.impl.base.buildColumnValues"/>
+    </mergepoint>
     <mergepoint name="retrieveByPK">
       <action xsi:type="applyAction" outlet="torque.om.peer.impl.base.retrieveByPK"/>
     </mergepoint>

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=1754261&r1=1754260&r2=1754261&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
Wed Jul 27 12:27:48 2016
@@ -39,6 +39,8 @@ public abstract class $baseDbObjectClass
     implements ##
 #if ($torqueGen.booleanOption("torque.om.addSaveMethods") && $saveMethodsInDbObjects
== "true")
 Persistent, ##
+#else
+ObjectModel, ##
 #end
 Serializable##
 #if ($torqueGen.booleanOption("torque.om.addIntakeRetrievable")), $torqueGen.option("torque.om.retrievableInterface")#end##

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObjectForView.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObjectForView.vm?rev=1754261&r1=1754260&r2=1754261&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObjectForView.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObjectForView.vm
Wed Jul 27 12:27:48 2016
@@ -52,6 +52,7 @@ import org.apache.torque.om.BooleanKey;
 #if ($torqueGen.booleanOption("torque.om.addSaveMethods") && $saveMethodsInDbObjects
== "true")
 import org.apache.torque.om.Persistent;
 #end
+import org.apache.torque.om.ObjectModel;
 #if ($torqueGen.booleanOption("torque.om.addGetByNameMethods"))
 import org.apache.torque.om.ColumnAccessByName;
 #end##
@@ -89,7 +90,7 @@ $torqueGen.mergepoint("classJavadoc")
   #set ($extendsBaseClass = "extends $baseClass" )
 #end
 public abstract class $baseDbObjectClassName $extendsBaseClass
-    implements Serializable##
+    implements ObjectModel, Serializable##
 #if ($torqueGen.booleanOption("torque.om.addIntakeRetrievable")), $torqueGen.option("torque.om.retrievableInterface")#end##
 #if ($torqueGen.booleanOption("torque.om.addGetByNameMethods")), ColumnAccessByName#end##
 

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/imports.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/imports.vm?rev=1754261&r1=1754260&r2=1754261&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/imports.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/imports.vm
Wed Jul 27 12:27:48 2016
@@ -50,6 +50,8 @@ import org.apache.torque.om.StringKey;
 import org.apache.torque.om.BooleanKey;
 #if ($torqueGen.booleanOption("torque.om.addSaveMethods") && $saveMethodsInDbObjects
== "true")
 import org.apache.torque.om.Persistent;
+#else
+import org.apache.torque.om.ObjectModel;
 #end
 #if ($torqueGen.booleanOption("torque.om.addGetByNameMethods"))
 import org.apache.torque.om.ColumnAccessByName;

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.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/doUpdate.vm?rev=1754261&r1=1754260&r2=1754261&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm
Wed Jul 27 12:27:48 2016
@@ -137,10 +137,16 @@
 #end
         return rowCount;
     }
+#set( $hasVersioning = false )
+#foreach ($columnElement in $torqueGen.getChildren("column"))
+  #if($columnElement.getAttribute("version") == "true")
+    #set( $hasVersioning = true )
+  #end
+#end
+#if ($torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
 
     /**
-     * Updates an $dbObjectClassName in the database.
-     * The primary key is used to identify the object to update.
+     * Throw exception because this object has no primary key
      *
      * @param obj the data object to update in the database.
      *
@@ -151,12 +157,24 @@
      */
     public int doUpdate($dbObjectClassName obj) throws TorqueException
     {
-#if ($torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
         throw new TorqueException(
                 "doUpdate does not work for objects without primary key");
-#else
-        ColumnValues columnValues = buildColumnValues(obj);
-        int result = doUpdate(columnValues);
+    }
+#elseif ($hasVersioning )
+    /**
+     * Updates an $dbObjectClassName in the database.
+     * The primary key is used to identify the object to update.
+     *
+     * @param obj the data object to update in the database.
+     *
+     * @return the number of affected rows.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public int doUpdate($dbObjectClassName obj) throws TorqueException
+    {
+        int result = super.doUpdate(obj);
 #foreach ($columnElement in $torqueGen.getChildren("column"))
   #if($columnElement.getAttribute("version") == "true")
     #set ( $columnGetter = $columnElement.getAttribute("getter"))
@@ -164,12 +182,30 @@
         obj.${columnSetter}(obj.${columnGetter}() + 1);
   #end
 #end
-        obj.setModified(false);
         return result;
-#end
     }
+#end
+#if ($torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
 
     /**
+     * Throw exception because this object has no primary key
+     *
+     * @param obj the data object to update in the database.
+     * @param con the connection to use, not null.
+     
+     * @return the number of affected rows.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public int doUpdate($dbObjectClassName obj, Connection con)
+        throws TorqueException
+    {
+        throw new TorqueException(
+                "doUpdate does not work for objects without primary key");
+    }
+#elseif ( $hasVersioning )
+    /**
      * Updates a $dbObjectClassName in the database.
      * The primary key is used to identify the object to update.
      * This method is to be used during a transaction,
@@ -186,12 +222,7 @@
     public int doUpdate($dbObjectClassName obj, Connection con)
         throws TorqueException
     {
-  #if ($torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
-        throw new TorqueException(
-                "doUpdate does not work for objects without primary key");
-  #else
-        ColumnValues columnValues = buildColumnValues(obj);
-        int result = doUpdate(columnValues, con);
+        int result = super.doUpdate(obj, con);
 #foreach ($columnElement in $torqueGen.getChildren("column"))
   #if($columnElement.getAttribute("version") == "true")
     #set ( $columnGetter = $columnElement.getAttribute("getter"))
@@ -199,7 +230,6 @@
         obj.${columnSetter}(obj.${columnGetter}() + 1);
   #end
 #end
-        obj.setModified(false);
         return result;
-  #end
     }
+#end



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