db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1062315 - in /db/torque/torque4/trunk: torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/ torque-test/src/main/schema/ torque-test/src/test/java/org/apache/torque/
Date Sun, 23 Jan 2011 03:40:46 GMT
Author: tfischer
Date: Sun Jan 23 03:40:45 2011
New Revision: 1062315

URL: http://svn.apache.org/viewvc?rev=1062315&view=rev
Log:
Fix: When saving a new object with an autogenerated primary key, but the primary key attribute
was set explicitly on the object before saving, the set primary key should be used instead
of replacing it by a new autogenerated key

Modified:
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/buildColumnValues.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/doInsert.vm
    db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/buildColumnValues.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/buildColumnValues.vm?rev=1062315&r1=1062314&r2=1062315&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/buildColumnValues.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/buildColumnValues.vm
Sun Jan 23 03:40:45 2011
@@ -45,8 +45,15 @@
   #set ( $columnSchemaType = $columnElement.getAttribute("schemaType") )
   #set ( $columnFieldName = $columnElement.getAttribute("field") )
   #set ( $columnFieldType = $columnElement.getAttribute("fieldType") )
+  #set ( $javaType = $columnElement.getAttribute("javaType") )
   #if ($primaryKey && !$idMethod.equals("none"))
+    #if ("boolean" == $columnFieldType)
         if (!${field}.isNew())
+    #elseif ("primitive" == $javaType)
+        if (!${field}.isNew() || ${field}.$getter() != 0)
+    #else
+        if (!${field}.isNew() || ${field}.$getter() != null)
+    #end
         {
     #if ($columnType == "DATE" && $columnFieldType == "java.util.Date")
             java.util.Date $columnFieldName = ${field}.${getter}();

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/doInsert.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/doInsert.vm?rev=1062315&r1=1062314&r2=1062315&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/doInsert.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/doInsert.vm
Sun Jan 23 03:40:45 2011
@@ -61,8 +61,12 @@
   #if ($idMethod.equals("none") || $torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
         ${peerClassName}.doInsert(${peerClassName}.buildColumnValues(obj), con);
   #else
-        obj.setPrimaryKey(${peerClassName}.doInsert(
-                ${peerClassName}.buildColumnValues(obj), con));
+        ObjectKey primaryKey = ${peerClassName}.doInsert(
+                ${peerClassName}.buildColumnValues(obj), con);
+        if (primaryKey != null)
+        {
+            obj.setPrimaryKey(primaryKey);
+        }
   #end
         obj.setNew(false);
         obj.setModified(false);

Modified: db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml?rev=1062315&r1=1062314&r2=1062315&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml (original)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml Sun Jan 23 03:40:45
2011
@@ -222,6 +222,11 @@
     <column name="name" size="100" type="VARCHAR"/>
   </table>
 
+  <table name="integer_object_pk">
+    <column name="id" type="INTEGER" primaryKey="true" required="true" javaType="object"/>
+    <column name="name" size="100" type="VARCHAR"/>
+  </table>
+
   <table name="bit_test" idMethod="none">
     <column name="id" required="true" primaryKey="true" type="CHAR" size="10" />
     <column name="bit_value" required="true" type="BIT" />

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1062315&r1=1062314&r2=1062315&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java Sun
Jan 23 03:40:45 2011
@@ -83,6 +83,8 @@ import org.apache.torque.test.Inheritanc
 import org.apache.torque.test.InheritanceChildD;
 import org.apache.torque.test.InheritanceTest;
 import org.apache.torque.test.InheritanceTestPeer;
+import org.apache.torque.test.IntegerObjectPk;
+import org.apache.torque.test.IntegerObjectPkPeer;
 import org.apache.torque.test.IntegerPk;
 import org.apache.torque.test.IntegerPkPeer;
 import org.apache.torque.test.LargePk;
@@ -189,6 +191,30 @@ public class DataTest extends BaseRuntim
         bc.setBintValue(false);
         bc.setBcharValue(false);
         bc.save();
+        
+        // check a primitive id can be set manually
+        Author author = new Author();
+        author.setAuthorId(2000);
+        author.setName("Author 2000");
+        author.save();
+        assertEquals(2000, author.getAuthorId());
+        criteria = new Criteria();
+        criteria.add(AuthorPeer.AUTHOR_ID, 2000);
+        List<Author> authorList = AuthorPeer.doSelect(criteria);
+        assertEquals(1, authorList.size());
+        
+        // check an object id can be set manually
+        criteria = new Criteria();
+        IntegerObjectPkPeer.doDelete(criteria);
+        IntegerObjectPk integerObjectPk = new IntegerObjectPk();
+        integerObjectPk.setId(3001);
+        integerObjectPk.save();
+        assertEquals(new Integer(3001), integerObjectPk.getId());
+        criteria = new Criteria();
+        criteria.add(IntegerObjectPkPeer.ID, 3001);
+        List<IntegerObjectPk> integerObjectPkList 
+                = IntegerObjectPkPeer.doSelect(criteria);
+        assertEquals(1, integerObjectPkList.size());
     }
 
     /**



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