You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2006/04/14 18:30:00 UTC

svn commit: r394134 - in /db/derby/code/trunk/java: client/org/apache/derby/client/net/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/ testing/org/apache/d...

Author: kmarsden
Date: Fri Apr 14 09:30:00 2006
New Revision: 394134

URL: http://svn.apache.org/viewcvs?rev=394134&view=rev
Log:
DERBY-1025 - [xa] client XAResource.start() does not commit an active local transaction when auto commit is true

Contributed by Deepa Remesh

------------------------------------------------
Summary:
------------------------------------------------
* Modifies NetXAResource.start to check if the connection is in autocommit mode and flow an auto commit.
* Uncomments the tests for this issue in jdbcapi/XATest.java and jdbcapi/checkDataSource.java


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java?rev=394134&r1=394133&r2=394134&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java Fri Apr 14 09:30:00 2006
@@ -553,6 +553,17 @@
         if (conn_.isPhysicalConnClosed()) {
             connectionClosedFailure();
         }
+        
+        // DERBY-1025 - Flow an auto-commit if in auto-commit mode before 
+        // entering a global transaction
+        try {
+        	if(conn_.autoCommit_)
+        		conn_.flowAutoCommit();
+        } catch (SqlException sqle) {
+        	rc = XAException.XAER_RMERR;
+            exceptionsOnXA = org.apache.derby.client.am.Utils.accumulateSQLException
+                    (sqle, exceptionsOnXA);
+        } 
 
         // update the XACallInfo
         NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out?rev=394134&r1=394133&r2=394134&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource.out Fri Apr 14 09:30:00 2006
@@ -55,7 +55,7 @@
 ConnectionPoolDataSource <closedstmt>.execute() null - Invalid operation: statement closed
 Changes rolled back OK in auto closed pooled connection
 EVENT(1):connectionClosed
-expected java.sql.SQLException: Invalid operation: result set closed
+expected java.sql.SQLException: 'ResultSet' already closed.
 expected java.sql.SQLException: Invalid operation: statement closed
 Start testPoolReset ConnectionPoolDataSource
 IDENTITY_VAL_LOCAL=1
@@ -454,6 +454,14 @@
 XAResource.prepare : XAException - XAER_RMFAIL : Connection is Closed.
 XAResource.isSameRM : XAException - XAER_RMFAIL : Connection is Closed.
 Patricio update count 1
+conn4 autcommit true
+acxs 1
+acxs 2
+autocommitxastart expected 'ResultSet' already closed.
+acxs 1
+acxs 2
+autocommitxastart expected  : XAException - XAER_DUPID : Error executing a XAResource.start(), Server returned XAER_DUPID
+acxs 3
 testing jira 95 for DataSource; ok - expected exception: XCY00
 testing jira 95 for XADataSource; ok - expected exception: XCY00
 Completed checkDataSource

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out?rev=394134&r1=394133&r2=394134&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDataSource30.out Fri Apr 14 09:30:00 2006
@@ -67,7 +67,7 @@
 ConnectionPoolDataSource <closedstmt>.execute() null - Invalid operation: statement closed
 Changes rolled back OK in auto closed pooled connection
 EVENT(1):connectionClosed
-expected java.sql.SQLException: Invalid operation: result set closed
+expected java.sql.SQLException: 'ResultSet' already closed.
 expected java.sql.SQLException: Invalid operation: statement closed
 Start testPoolReset ConnectionPoolDataSource
 IDENTITY_VAL_LOCAL=1
@@ -549,6 +549,14 @@
 XAResource.prepare : XAException - XAER_RMFAIL : Connection is Closed.
 XAResource.isSameRM : XAException - XAER_RMFAIL : Connection is Closed.
 Patricio update count 1
+conn4 autcommit true
+acxs 1
+acxs 2
+autocommitxastart expected 'ResultSet' already closed.
+acxs 1
+acxs 2
+autocommitxastart expected  : XAException - XAER_DUPID : Error executing a XAResource.start(), Server returned XAER_DUPID
+acxs 3
 testing jira 95 for DataSource; ok - expected exception: XCY00
 testing jira 95 for XADataSource; ok - expected exception: XCY00
 START XA HOLDABILITY TEST
@@ -575,7 +583,7 @@
 X@1 id 1
 X@2 id 2
 Expected SQLException No current connection. : 
-Expected SQLException Invalid operation: result set closed
+Expected SQLException 'ResultSet' already closed.
 resume XA transaction and keep using rs
 Check holdability of various jdbc objects after resuming XA transaction
 CONNECTION(xa) HOLDABILITY false
@@ -587,8 +595,8 @@
 STATEMENT(this one was created with default holdability after the global transaction was resumed. Check it's holdability) HOLDABILITY false
 PREPAREDSTATEMENT(this one was created with default holdability after the global transaction was resumed. Check it's holdability) HOLDABILITY false
 CALLABLESTATEMENT(this one was created with default holdability after the global transaction was resumed. Check it's holdability) HOLDABILITY false
-Expected SQLException Invalid operation: result set closed
-Expected SQLException Invalid operation: result set closed
+Expected SQLException 'ResultSet' already closed.
+Expected SQLException 'ResultSet' already closed.
 Set connection to hold 
 CONNECTION(held) HOLDABILITY true
 **Test holdability state for: PooledConnection **

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out?rev=394134&r1=394133&r2=394134&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out Fri Apr 14 09:30:00 2006
@@ -183,7 +183,6 @@
 Non-held ResultSet correctly closed after commit
 BGBC 0
 BGAC 1
-DERBY-1025 Call conn.commit to avoid exception with client
 START GLOBAL TRANSACTION
 Global transaction open ResultSets 12
 EXPECTED SQLSTATE(XJ05C): Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a global transaction.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java?rev=394134&r1=394133&r2=394134&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java Fri Apr 14 09:30:00 2006
@@ -904,16 +904,15 @@
             rs.next(); System.out.println("BGBC " + rs.getInt(1));
             conn.commit();
             rs.next(); System.out.println("BGAC " + rs.getInt(1));
-            
+            rs.close();
+           
+            // ensure a transaction is active to test DERBY-1025
+            rs = sdh.executeQuery("SELECT * FROM APP.FOO");
+           
             // This switch to global is ok because conn
             // is in auto-commit mode, thus the start performs
             // an implicit commit to complete the local transaction.
             
-            // DERBY-1025 Client only bug
-            if (TestUtil.isDerbyNetClientFramework()) {
-                System.out.println("DERBY-1025 Call conn.commit to avoid exception with client");
-                conn.commit();
-            }
             System.out.println("START GLOBAL TRANSACTION");
             // start a global xact and test those statements.
             xar.start(xid, XAResource.TMNOFLAGS);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java?rev=394134&r1=394133&r2=394134&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java Fri Apr 14 09:30:00 2006
@@ -88,14 +88,6 @@
 	// Tests for setting isolation level this way only run in embedded for now.
 	private boolean canSetIsolationWithStatement = TestUtil.isEmbeddedFramework();
 	  
-	 	
-	// DERBY-1025 client  XAResource.start() does not commit an active local transaction 
-	// when auto commit is true. Embedded XAResource.start() implementation commits 
-	// the active local transaction on the Connection associated with the XAResource.
-	// Client incorrectly throws an error.
-	// run only for embedded for now.
-	private static boolean autocommitCommitsOnXa_Start =TestUtil.isEmbeddedFramework();
-	
 	//	 DERBY-1148 - Client Connection state does not
 	// get set properly when joining a global transaction.
 	private static boolean isolationSetProperlyOnJoin = TestUtil.isEmbeddedFramework();
@@ -625,51 +617,48 @@
 		conn3.close();
 		xac3.close();
 
-		if (autocommitCommitsOnXa_Start)
-		{
-			// test that an xastart in auto commit mode commits the existing work.(beetle 5178)
-			XAConnection xac4 = dsx.getXAConnection();
-			Xid xid4a = new cdsXid(4, (byte) 23, (byte) 76);
-			Connection conn4 = xac4.getConnection();
-			System.out.println("conn4 autcommit " + conn4.getAutoCommit());
-
-			Statement s4 = conn4.createStatement();
-			s4.executeUpdate("create table autocommitxastart(i int)");
-			s4.executeUpdate("insert into autocommitxastart values 1,2,3,4,5");
-
-			ResultSet rs4 = s4.executeQuery("select i from autocommitxastart");
-			rs4.next(); System.out.println("acxs " + rs4.getInt(1));
-			rs4.next(); System.out.println("acxs " + rs4.getInt(1));
+		// test that an xastart in auto commit mode commits the existing work.(beetle 5178)
+		XAConnection xac4 = dsx.getXAConnection();
+		Xid xid4a = new cdsXid(4, (byte) 23, (byte) 76);
+		Connection conn4 = xac4.getConnection();
+		System.out.println("conn4 autcommit " + conn4.getAutoCommit());
 
-			xac4.getXAResource().start(xid4a, XAResource.TMNOFLAGS);
-			xac4.getXAResource().end(xid4a, XAResource.TMSUCCESS);
+		Statement s4 = conn4.createStatement();
+		s4.executeUpdate("create table autocommitxastart(i int)");
+		s4.executeUpdate("insert into autocommitxastart values 1,2,3,4,5");
+
+		ResultSet rs4 = s4.executeQuery("select i from autocommitxastart");
+		rs4.next(); System.out.println("acxs " + rs4.getInt(1));
+		rs4.next(); System.out.println("acxs " + rs4.getInt(1));
 
-			try {
-				rs4.next(); System.out.println("acxs " + rs.getInt(1));
-			} catch (SQLException sqle) {
-				System.out.println("autocommitxastart expected " + sqle.getMessage());
-			}
-
-			conn4.setAutoCommit(false);
-
-			rs4 = s4.executeQuery("select i from autocommitxastart");
-			rs4.next(); System.out.println("acxs " + rs4.getInt(1));
-			rs4.next(); System.out.println("acxs " + rs4.getInt(1));
-
-			try {
-				xac4.getXAResource().start(xid4a, XAResource.TMNOFLAGS);
-			} catch (XAException xae) {
-				showXAException("autocommitxastart expected ", xae);
-			}
-			rs4.next(); System.out.println("acxs " + rs4.getInt(1));
-			rs4.close();
-
-			conn4.rollback();
-			conn4.close();
-			xac4.close();
+		xac4.getXAResource().start(xid4a, XAResource.TMNOFLAGS);
+		xac4.getXAResource().end(xid4a, XAResource.TMSUCCESS);
+
+		try {
+			rs4.next(); System.out.println("acxs " + rs.getInt(1));
+		} catch (SQLException sqle) {
+			System.out.println("autocommitxastart expected " + sqle.getMessage());
+		}
+
+		conn4.setAutoCommit(false);
+
+		rs4 = s4.executeQuery("select i from autocommitxastart");
+		rs4.next(); System.out.println("acxs " + rs4.getInt(1));
+		rs4.next(); System.out.println("acxs " + rs4.getInt(1));
 		
+		try {
+			xac4.getXAResource().start(xid4a, XAResource.TMNOFLAGS);
+		} catch (XAException xae) {
+			showXAException("autocommitxastart expected ", xae);
 		}
+		rs4.next(); System.out.println("acxs " + rs4.getInt(1));
+		rs4.close();
 
+		conn4.rollback();
+		conn4.close();
+		xac4.close();
+		
+		
 		// test jira-derby 95 - a NullPointerException was returned when passing
 		// an incorrect database name (a url in this case) - should now give error XCY00
 		Connection dmc95 = ij.startJBMS();