db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r1210686 - in /db/derby/code/trunk/java: engine/org/apache/derby/jdbc/EmbedXAResource.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java
Date Mon, 05 Dec 2011 22:35:35 GMT
Author: myrnavl
Date: Mon Dec  5 22:35:34 2011
New Revision: 1210686

URL: http://svn.apache.org/viewvc?rev=1210686&view=rev
Log:
DERBY-1016; javax.transaction.xa.forget (Xid) raises XAER_NOTA exception instead of XA_PROTO
on a prepared transaction
  patch contributed by Jayaram Subramanian (rsjay1976 at gmail dot com).

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java?rev=1210686&r1=1210685&r2=1210686&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java Mon Dec  5
22:35:34 2011
@@ -420,9 +420,8 @@ class EmbedXAResource implements XAResou
             
         }
         
-        throw new XAException(tranState.isPrepared
-            ? XAException.XAER_NOTA 
-            : XAException.XAER_PROTO);
+        // DERBY-1016; if the transaction exists throw XAER_PROTO on forget
+        throw new XAException(XAException.XAER_PROTO);
     }    
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java?rev=1210686&r1=1210685&r2=1210686&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java
Mon Dec  5 22:35:34 2011
@@ -427,6 +427,75 @@ public class XATransactionTest extends B
         }
     }
 
+    /**
+     * This fixture triggers DERBY-1016. It creates an XA transaction, executes
+     * an update over it and then prepares the transaction. Trying to forget
+     * after preparing should throw XAER_PROTO and not XAER_NOTA.
+     */
+    public void testForgetExceptionDerby1016PROTO() throws XAException, SQLException {  
   
+        XADataSource xads = J2EEDataSource.getXADataSource();
+        J2EEDataSource.setBeanProperty(xads, "databaseName", "wombat");
+        
+        XAConnection xaconn = xads.getXAConnection();
+        XAResource xar = xaconn.getXAResource();
+        Xid xid = createXid(93,18);
+        xar.start(xid, XAResource.TMNOFLAGS);
+        Connection conn = xaconn.getConnection();
+        Statement s = conn.createStatement();
+        s.executeUpdate("CREATE TABLE Derby1016 (I INT)");
+        xar.end(xid, XAResource.TMSUCCESS);
+        xar.prepare(xid);
+        try {
+            xar.forget(xid);
+            fail("FAIL: prepared XA-Transaction forgotten");
+        } catch (XAException XAeForget) {
+            assertEquals("FAIL: Got unexpected exception "
+                          + XAeForget.getMessage()   + " errorCode: " 
+                          + XAeForget.errorCode  + "  calling forget on a prepared transaction",
+                        XAException.XAER_PROTO, XAeForget.errorCode);
+        } finally {
+            s.close();
+            xar.rollback(xid);
+            conn.close(); 
+            xaconn.close();
+        }
+    }
+ 
+    /**
+     * Further test case prompted by DERBY-1016. Tests that XAER_NOTA is thrown
+     * if no transaction exists.
+     */
+    public void testForgetExceptionDerby1016NOTA() throws XAException, SQLException {   
  
+        XADataSource xads = J2EEDataSource.getXADataSource();
+        J2EEDataSource.setBeanProperty(xads, "databaseName", "wombat");
+        
+        XAConnection xaconn = xads.getXAConnection();
+        XAResource xar = xaconn.getXAResource();
+        Xid xid = createXid(93,18);
+        xar.start(xid, XAResource.TMNOFLAGS);
+        Connection conn = xaconn.getConnection();
+        Statement s = conn.createStatement();
+        s.executeUpdate("CREATE TABLE Derby1016 (I INT)");
+        xar.end(xid, XAResource.TMSUCCESS);
+        xar.prepare(xid);
+        xar.commit(xid, false);
+        try {
+            // since the transaction was committed, it should no longer exist
+            // thus, forget should now throw an XAER_NOTA
+            xar.forget(xid);
+            fail("FAIL: able to forget committed XA-Transaction");
+        } catch (XAException XAeForget) {
+            assertEquals("FAIL: Got unexpected exception "
+                          + XAeForget.getMessage()   + " errorCode: " 
+                          + XAeForget.errorCode  + "  calling forget on a committed transaction",
+                        XAException.XAER_NOTA, XAeForget.errorCode);
+        } finally {
+            s.close();
+            conn.close(); 
+            xaconn.close();
+        }
+    }
+
     /* ------------------- end helper methods  -------------------------- */
 
     /** Create the Xid object for global transaction identification



Mime
View raw message