db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r584530 - in /db/torque: site/trunk/xdocs/changes.xml templates/trunk/src/templates/om/Peer.vm test/trunk/test-project/src/java/org/apache/torque/DataTest.java
Date Sun, 14 Oct 2007 11:25:47 GMT
Author: tfischer
Date: Sun Oct 14 04:25:46 2007
New Revision: 584530

URL: http://svn.apache.org/viewvc?rev=584530&view=rev
Log:
An exception is now thrown on an attempt to update a modified object without a primary key.
The previous behaviour was to fail silently.
Fixes TORQUE-69.

Modified:
    db/torque/site/trunk/xdocs/changes.xml
    db/torque/templates/trunk/src/templates/om/Peer.vm
    db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java

Modified: db/torque/site/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/db/torque/site/trunk/xdocs/changes.xml?rev=584530&r1=584529&r2=584530&view=diff
==============================================================================
--- db/torque/site/trunk/xdocs/changes.xml (original)
+++ db/torque/site/trunk/xdocs/changes.xml Sun Oct 14 04:25:46 2007
@@ -31,6 +31,10 @@
 
   <body>
   <release version="3.3-RC3" date="in SVN">
+    <action type="change" dev="tfischer" issue="TORQUE-69">
+      An exception is now thrown on an attempt to update a modified object
+      without a primary key. The previous behaviour was to fail silently.
+    </action>
     <action type="fix" dev="tfischer" issue="TORQUE-103" due-to="Jonathan Purvis">
       Corrected invalid cast in TorqueRuntimeException.splitStackTrace.
     </action>

Modified: db/torque/templates/trunk/src/templates/om/Peer.vm
URL: http://svn.apache.org/viewvc/db/torque/templates/trunk/src/templates/om/Peer.vm?rev=584530&r1=584529&r2=584530&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/Peer.vm (original)
+++ db/torque/templates/trunk/src/templates/om/Peer.vm Sun Oct 14 04:25:46 2007
@@ -697,8 +697,13 @@
      */
     public static void doUpdate($table.JavaName obj) throws TorqueException
     {
+  #if ($table.PrimaryKey.size() == 0)
+        throw new TorqueException(
+                "doUpdate does not work for objects without primary key");
+  #else
         doUpdate(buildCriteria(obj));
         obj.setModified(false);
+  #end
     }
 
     /**
@@ -746,8 +751,13 @@
     public static void doUpdate($table.JavaName obj, Connection con)
         throws TorqueException
     {
+  #if ($table.PrimaryKey.size() == 0)
+        throw new TorqueException(
+                "doUpdate does not work for objects without primary key");
+  #else
         doUpdate(buildCriteria(obj), con);
         obj.setModified(false);
+  #end
     }
 
     /**

Modified: db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java?rev=584530&r1=584529&r2=584530&view=diff
==============================================================================
--- db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java (original)
+++ db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java Sun Oct 14
04:25:46 2007
@@ -79,6 +79,8 @@
 import org.apache.torque.test.MultiPkForeignKey;
 import org.apache.torque.test.MultiPkForeignKeyPeer;
 import org.apache.torque.test.MultiPkPeer;
+import org.apache.torque.test.Nopk;
+import org.apache.torque.test.NopkPeer;
 import org.apache.torque.test.NullValueTable;
 import org.apache.torque.test.NullValueTablePeer;
 import org.apache.torque.test.RAb;
@@ -86,6 +88,7 @@
 import org.apache.torque.util.BasePeer;
 import org.apache.torque.util.CountHelper;
 import org.apache.torque.util.Criteria;
+import org.apache.torque.util.Transaction;
 
 import com.workingdogs.village.Record;
 
@@ -748,6 +751,82 @@
         assertEquals("Second Author's name should be \"OtherName\"",
                 "OtherName",
                 ((Author) authors.get(1)).getName());
+        
+        // Test doUpdate methods in Peer explicitly
+        Connection connection = Transaction.begin(AuthorPeer.DATABASE_NAME);
+        author.setName("NewName2");
+        AuthorPeer.doUpdate(author);
+        Transaction.commit(connection);
+        
+        criteria.clear();
+        criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
+        
+        authors = AuthorPeer.doSelect(criteria);
+        assertEquals("List should contain 2 authors", 2, authors.size());
+        assertEquals("First Author's name should be \"NewName2\"",
+                "NewName2",
+                ((Author) authors.get(0)).getName());
+        assertEquals("Second Author's name should be \"OtherName\"",
+                "OtherName",
+                ((Author) authors.get(1)).getName());
+
+        author.setName("NewName3");
+        AuthorPeer.doUpdate(author);
+        
+        criteria.clear();
+        criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
+        
+        authors = AuthorPeer.doSelect(criteria);
+        assertEquals("List should contain 2 authors", 2, authors.size());
+        assertEquals("First Author's name should be \"NewName3\"",
+                "NewName3",
+                ((Author) authors.get(0)).getName());
+        assertEquals("Second Author's name should be \"OtherName\"",
+                "OtherName",
+                ((Author) authors.get(1)).getName());
+
+        // Test updates for objects without primary keys. As we do not store
+        // information which values were modified, we throw an Exception at 
+        // the attempt.
+        
+        Nopk nopk = new Nopk();
+        nopk.setName("name");
+        nopk.save();
+        
+        // check that save does not throw an error if nothing is modified
+        nopk.save();
+        
+        nopk.setName("otherName");
+        try
+        {
+            nopk.save();
+            fail("A Torque exception should be thrown");
+        }
+        catch (TorqueException e)
+        {
+        }
+        
+        // check the doPupdate Peer methods themselves
+        try
+        {
+            NopkPeer.doUpdate(new Nopk());
+            fail("A Torque exception should be thrown (2)");
+        }
+        catch (TorqueException e)
+        {
+        }
+
+        connection = Transaction.begin(NopkPeer.DATABASE_NAME);
+        try
+        {
+            NopkPeer.doUpdate(new Nopk(),connection);
+            fail("A Torque exception should be thrown (3)");
+        }
+        catch (TorqueException e)
+        {
+        }
+        Transaction.safeRollback(connection);
+        
     }
     
     /**



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