db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r392362 - in /db/derby/code/branches/10.1/java: engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functi...
Date Fri, 07 Apr 2006 18:51:14 GMT
Author: djd
Date: Fri Apr  7 11:51:10 2006
New Revision: 392362

URL: http://svn.apache.org/viewcvs?rev=392362&view=rev
Log:
DERBY-1158 (partial) Embedded Statements that are holdable automatically downgrade to
close cursors on commit during a global transaction.
Merge of 392073 from trunk

Modified:
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/XAStatementControl.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/XATest.out
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource.out
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource30.java

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
Fri Apr  7 11:51:10 2006
@@ -55,7 +55,6 @@
      */
 	public final ResultSet executeQuery() throws SQLException
     {
-        checkHoldability();
         return wrapResultSet(getPreparedStatement().executeQuery());
     } 
 
@@ -423,7 +422,6 @@
      */
     public final boolean execute() throws SQLException
     {
-        checkHoldability();
         return getPreparedStatement().execute();
     }
 

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
Fri Apr  7 11:51:10 2006
@@ -101,14 +101,12 @@
 
     public final boolean execute(String sql) throws SQLException
 	{
-        checkHoldability();
 		return getStatement().execute(sql);
     } 
 
     public final ResultSet executeQuery(String sql) throws SQLException
 	{
-        checkHoldability();
-		return wrapResultSet(getStatement().executeQuery(sql));
+ 		return wrapResultSet(getStatement().executeQuery(sql));
     }
 
     public final int executeUpdate(String sql) throws SQLException
@@ -541,11 +539,4 @@
 		getStatement().getConnection();
 		return control;
 	}
-    
-    final void checkHoldability() throws SQLException {
-        int holdability = controlCheck().checkHoldCursors(resultSetHoldability);
-        if (holdability != resultSetHoldability)
-            throw Util.generateCsSQLException(SQLState.CANNOT_HOLD_CURSOR_XA);
-
-    }
 }

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
Fri Apr  7 11:51:10 2006
@@ -62,6 +62,14 @@
     implements EngineStatement {
 
 	private final java.sql.Connection applicationConnection;
+    
+    /**
+     * Statement reference the application is using to execute
+     * this Statement. Normally set to this, but if this was
+     * created by a Connection from an XAConnection then this
+     * will be a reference to the BrokeredStatement.
+     */
+    private EngineStatement applicationStatement;
 
 	int updateCount = -1;
 	java.sql.ResultSet results;
@@ -110,6 +118,9 @@
 
 		lcc = getEmbedConnection().getLanguageConnection();
 		applicationConnection = getEmbedConnection().getApplicationConnection();
+
+        applicationStatement = this;
+
 	}
 
 	//
@@ -1331,7 +1342,13 @@
 			batchStatements = null;
 		}
 	}
-
+    
+    /**
+     * Set the application statement for this Statement.
+    */
+    public final void setApplicationStatement(EngineStatement s) {
+        this.applicationStatement = s;
+    }
 
 	private EmbedResultSet[] dynamicResults;
 	private int currentDynamicResultSet;
@@ -1445,13 +1462,19 @@
     /**
      * Get the execute time holdability for the Statement.
      * When in a global transaction holdabilty defaults to false.
+     * @throws SQLException Error from getResultSetHoldability.
      */
-    private boolean getExecuteHoldable()
+    private boolean getExecuteHoldable() throws SQLException
     {
         if (resultSetHoldability  == JDBC30Translation.CLOSE_CURSORS_AT_COMMIT)
             return false;
         
-        return true;
+        // Simple non-XA case
+        if (applicationStatement == this)
+            return true;
+        
+        return applicationStatement.getResultSetHoldability() ==
+            JDBC30Translation.HOLD_CURSORS_OVER_COMMIT;
     }
 }
 

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/XAStatementControl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/XAStatementControl.java?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/XAStatementControl.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/XAStatementControl.java
Fri Apr  7 11:51:10 2006
@@ -25,6 +25,7 @@
 import org.apache.derby.iapi.jdbc.BrokeredStatement;
 import org.apache.derby.iapi.jdbc.BrokeredPreparedStatement;
 import org.apache.derby.iapi.jdbc.BrokeredCallableStatement;
+import org.apache.derby.iapi.jdbc.EngineStatement;
 import org.apache.derby.impl.jdbc.EmbedConnection;
 import org.apache.derby.impl.jdbc.EmbedResultSet;
 import org.apache.derby.impl.jdbc.EmbedStatement;
@@ -59,16 +60,23 @@
 		this(xaConnection);
 		this.realStatement = realStatement;
 		this.applicationStatement = applicationConnection.newBrokeredStatement(this);
+        
+        ((EmbedStatement) realStatement).setApplicationStatement(
+                applicationStatement);
 	}
 	XAStatementControl(EmbedXAConnection xaConnection, PreparedStatement realPreparedStatement,
String sql, Object generatedKeys) throws SQLException {
 		this(xaConnection);
 		this.realPreparedStatement = realPreparedStatement;
 		this.applicationStatement = applicationConnection.newBrokeredStatement(this, sql, generatedKeys);
+        ((EmbedStatement) realPreparedStatement).setApplicationStatement(
+                applicationStatement);
 	}
 	XAStatementControl(EmbedXAConnection xaConnection, CallableStatement realCallableStatement,
String sql) throws SQLException {
 		this(xaConnection);
 		this.realCallableStatement = realCallableStatement;
 		this.applicationStatement = applicationConnection.newBrokeredStatement(this, sql);
+        ((EmbedStatement) realCallableStatement).setApplicationStatement(
+                applicationStatement);
 	}
 
 	public Statement getRealStatement() throws SQLException {
@@ -91,7 +99,7 @@
 			// create new Statement
 			Statement newStatement = applicationStatement.createDuplicateStatement(xaConnection.realConnection,
realStatement);
 			((EmbedStatement) realStatement).transferBatch((EmbedStatement) newStatement);
-
+ 
 			try {
 				realStatement.close();
 			} catch (SQLException sqle) {
@@ -99,6 +107,8 @@
 
 			realStatement = newStatement;
 			realConnection = xaConnection.realConnection;
+            ((EmbedStatement) realStatement).setApplicationStatement(
+                    applicationStatement);
 		}
 		else {
 			// application connection is different, therefore the outer application
@@ -138,6 +148,8 @@
 
 			realPreparedStatement = newPreparedStatement;
 			realConnection = xaConnection.realConnection;
+            ((EmbedStatement) realPreparedStatement).setApplicationStatement(
+                        applicationStatement);
 		}
 		else {
 			// application connection is different, therefore the outer application
@@ -174,6 +186,8 @@
 
 			realCallableStatement = newCallableStatement;
 			realConnection = xaConnection.realConnection;
+            ((EmbedStatement) realCallableStatement).setApplicationStatement(
+                    applicationStatement);
 		}
 		else {
 			// application connection is different, therefore the outer application

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out
Fri Apr  7 11:51:10 2006
@@ -185,13 +185,23 @@
 BGAC 1
 DERBY-1025 Call conn.commit to avoid exception with client
 START GLOBAL TRANSACTION
-EXPECTED SQLSTATE(XJ05C): Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a
global transaction.
-EXPECTED SQLSTATE(XJ05C): Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a
global transaction.
-EXPECTED SQLSTATE(XJ05C): Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a
global transaction.
+Global transaction open ResultSets 12
 EXPECTED SQLSTATE(XJ05C): Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a
global transaction.
 Global createStatement(hold)Statement holdable CLOSE_CURSORS_AT_COMMIT 2
 01J07 :org.apache.derby.client.am.SqlWarning: ResultSetHoldability restricted to ResultSet.CLOSE_CURSORS_AT_COMMIT
for a global transaction.
 Global prepareStatement(hold)Statement holdable HOLD_CURSORS_OVER_COMMIT 1
-01J07 :org.apache.derby.client.am.SqlWarning: ResultSetHoldability restricted to ResultSet.CLOSE_CURSORS_AT_COMMIT
for a global transaction.
+After global transaction closed ResultSets 12
+Global xact Statement sdh Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement shh Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement sch Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement psdh Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement pshh Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement psch Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement sdc Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement shc Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement scc Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement psdh_d Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement pshh_d Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement psch_d Statement holdable CLOSE_CURSORS_AT_COMMIT 2
 derby966 complete
 XATest complete

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/XATest.out
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/XATest.out?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/XATest.out
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/XATest.out
Fri Apr  7 11:51:10 2006
@@ -169,14 +169,36 @@
 BGBC 0
 BGAC 1
 START GLOBAL TRANSACTION
-EXPECTED SQLSTATE(XJ05C): Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a
global transaction.
-EXPECTED SQLSTATE(XJ05C): Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a
global transaction.
-EXPECTED SQLSTATE(XJ05C): Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a
global transaction.
+Global transaction open ResultSets 12
 EXPECTED SQLSTATE(XJ05C): Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a
global transaction.
 Global createStatement(hold)Statement holdable CLOSE_CURSORS_AT_COMMIT 2
 01J07 :SQL Warning: ResultSetHoldability restricted to ResultSet.CLOSE_CURSORS_AT_COMMIT
for a global transaction.
 Global prepareStatement(hold)Statement holdable CLOSE_CURSORS_AT_COMMIT 2
 01J07 :SQL Warning: ResultSetHoldability restricted to ResultSet.CLOSE_CURSORS_AT_COMMIT
for a global transaction.
-01J07 :SQL Warning: ResultSetHoldability restricted to ResultSet.CLOSE_CURSORS_AT_COMMIT
for a global transaction.
+Global xact Statement sdh Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement shh Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement sch Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement psdh Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement pshh Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement psch Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement sdc Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement shc Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement scc Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement psdh_d Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement pshh_d Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement psch_d Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+After global transaction closed ResultSets 12
+Global xact Statement sdh Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement shh Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement sch Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement psdh Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement pshh Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement psch Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement sdc Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement shc Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement scc Statement holdable CLOSE_CURSORS_AT_COMMIT 2
+Global xact Statement psdh_d Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement pshh_d Statement holdable HOLD_CURSORS_OVER_COMMIT 1
+Global xact Statement psch_d Statement holdable CLOSE_CURSORS_AT_COMMIT 2
 derby966 complete
 XATest complete

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource.out
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource.out?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource.out
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource.out
Fri Apr  7 11:51:10 2006
@@ -383,8 +383,6 @@
   auto commit     true
   read only       false
 TESTING RE_USE OF STATEMENT OBJECTS
-THE STATEMENT OBJECTS CAN NOT BE REUSED ACROSS LOCAL/GLOBAL CONNECTIONS BECAUSE, LOCAL CONNECTION
CREATES THEM
-WITH HOLDABILITY TRUE WHEREAS GLOBAL CONNECTION CAN ONLY WORK WITH STATEMENTS WITH HOLDABILITY
FALSE
 LOCK TABLE
 END LOCK TABLE
 Statement State @ Create 
@@ -410,11 +408,11 @@
   getMaxRows() 85
 Params-local-1: ru(params) contents {3}
 sru1-local-1: ru(SN1) contents {1} {2} {3}
-Expecting exception because global transaction sru1-global-2 is trying to use a statement
with holdability true
-sru1-global-2: SQL Exception: Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for
a global transaction.
+Expecting downgrade because global transaction sru1-global-2 is using a statement with holdability
true
+sru1-global-2: ru(SN1) contents {1} {2} {3}
 sru2-global-3: ru(OAK2) contents {1} {2} {3}
-Expecting exception because global transaction sru1-global-4 is trying to use a statement
with holdability true
-sru1-global-4: SQL Exception: Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for
a global transaction.
+Expecting downgrade because global transaction sru1-global-4 is using a statement with holdability
true
+sru1-global-4: ru(SN1) contents {1} {2} {3}
 Statement State @ GLOBAL 
   getResultSetType() SCROLL_INSENSITIVE
   getResultSetConcurrency() READ_ONLY
@@ -436,8 +434,7 @@
   getFetchSize() 999
   getMaxFieldSize() 137
   getMaxRows() 85
-PASS: got exception because holdability is true on prepared statement and that is not allowed
in global transactions
-Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a global transaction.
+Params-global-1: ru(params) contents {3}
 sru1-local-5: ru(SN1) contents {1} {2} {3}
 sru2-local-6: ru(OAK2) contents {1} {2} {3}
 sru3-local-7: ru(SF3) contents {1} {2} {3}
@@ -464,7 +461,7 @@
   getMaxRows() 85
 Params-local-2: ru(params) contents {3}
 LOCK TABLE
-  xid row 0 lock count 4
+  xid row 0 lock count 14
   xid row 1 lock count 14
 END LOCK TABLE
 sru1-local-8: ru(SN1) contents {1} {2} {3}
@@ -492,7 +489,7 @@
   getMaxFieldSize() 137
   getMaxRows() 85
 LOCK TABLE
-  xid row 0 lock count 4
+  xid row 0 lock count 14
   xid row 1 lock count 12
 END LOCK TABLE
 sruBatch update counts : 1  1  2  1 :

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out
Fri Apr  7 11:51:10 2006
@@ -468,8 +468,6 @@
   auto commit     true
   read only       false
 TESTING RE_USE OF STATEMENT OBJECTS
-THE STATEMENT OBJECTS CAN NOT BE REUSED ACROSS LOCAL/GLOBAL CONNECTIONS BECAUSE, LOCAL CONNECTION
CREATES THEM
-WITH HOLDABILITY TRUE WHEREAS GLOBAL CONNECTION CAN ONLY WORK WITH STATEMENTS WITH HOLDABILITY
FALSE
 LOCK TABLE
 END LOCK TABLE
 Statement State @ Create 
@@ -503,11 +501,11 @@
     2 type 12
 Params-local-1: ru(params) contents {3}
 sru1-local-1: ru(SN1) contents {1} {2} {3}
-Expecting exception because global transaction sru1-global-2 is trying to use a statement
with holdability true
-sru1-global-2: SQL Exception: Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for
a global transaction.
+Expecting downgrade because global transaction sru1-global-2 is using a statement with holdability
true
+sru1-global-2: ru(SN1) contents {1} {2} {3}
 sru2-global-3: ru(OAK2) contents {1} {2} {3}
-Expecting exception because global transaction sru1-global-4 is trying to use a statement
with holdability true
-sru1-global-4: SQL Exception: Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for
a global transaction.
+Expecting downgrade because global transaction sru1-global-4 is using a statement with holdability
true
+sru1-global-4: ru(SN1) contents {1} {2} {3}
 Statement State @ GLOBAL 
   getResultSetType() SCROLL_INSENSITIVE
   getResultSetConcurrency() READ_ONLY
@@ -537,8 +535,7 @@
   Parameter Count 2
     1 type 12
     2 type 12
-PASS: got exception because holdability is true on prepared statement and that is not allowed
in global transactions
-Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT for a global transaction.
+Params-global-1: ru(params) contents {3}
 sru1-local-5: ru(SN1) contents {1} {2} {3}
 sru2-local-6: ru(OAK2) contents {1} {2} {3}
 sru3-local-7: ru(SF3) contents {1} {2} {3}
@@ -573,7 +570,7 @@
     2 type 12
 Params-local-2: ru(params) contents {3}
 LOCK TABLE
-  xid row 0 lock count 4
+  xid row 0 lock count 14
   xid row 1 lock count 14
 END LOCK TABLE
 sru1-local-8: ru(SN1) contents {1} {2} {3}
@@ -609,7 +606,7 @@
     1 type 12
     2 type 12
 LOCK TABLE
-  xid row 0 lock count 4
+  xid row 0 lock count 14
   xid row 1 lock count 12
 END LOCK TABLE
 sruBatch update counts : 1  1  2  1 :
@@ -844,14 +841,8 @@
 HOLDABLE PreparedStatement in global xact false connection warning ResultSetHoldability restricted
to ResultSet.CLOSE_CURSORS_AT_COMMIT for a global transaction.
 HOLDABLE CallableStatement in global xact false connection warning ResultSetHoldability restricted
to ResultSet.CLOSE_CURSORS_AT_COMMIT for a global transaction.
 STATEMENT HOLDABILITY false
-Expected SQLException (local Statement hold) Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT
for a global transaction.
-Expected SQLException (local Statement hold) Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT
for a global transaction.
 PREPARED STATEMENT HOLDABILITY false
-Expected SQLException (local PreparedStatement hold) Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT
for a global transaction.
-Expected SQLException (local PreparedStatement hold) Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT
for a global transaction.
 CALLABLE STATEMENT HOLDABILITY false
-Expected SQLException (local CallableStatement hold) Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT
for a global transaction.
-Expected SQLException (local CallableStatement hold) Cannot set holdability ResultSet.HOLD_CURSORS_OVER_COMMIT
for a global transaction.
 CONNECTION(held) HOLDABILITY true
 PASS XA HOLDABILITY TEST
 Completed checkDataSource30

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java
Fri Apr  7 11:51:10 2006
@@ -26,6 +26,8 @@
 import java.sql.SQLException;
 import java.sql.SQLWarning;
 import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.Properties;
 
 import javax.sql.XAConnection;
@@ -912,15 +914,6 @@
             // start a global xact and test those statements.
             xar.start(xid, XAResource.TMNOFLAGS);
             
-            // Statements obtained while default was hold.
-            // All should work, holability will be downgraded
-            // to close on commit for those Statements with hold set.
-            if (TestUtil.isDerbyNetClientFramework()) { // DERBY-1158
-            sdh.executeQuery("SELECT * FROM APP.FOO").close();
-            shh.executeQuery("SELECT * FROM APP.FOO").close();
-            }
-            sch.executeQuery("SELECT * FROM APP.FOO").close();
-                        
             // Statements not returning ResultSet's should be ok
             if (!TestUtil.isDerbyNetClientFramework()) { // DERBY-1159
             sdh.executeUpdate("DELETE FROM APP.FOO where A < -99");
@@ -928,22 +921,21 @@
             sch.executeUpdate("DELETE FROM APP.FOO where A < -99");
             }
             
+            ArrayList openRS = new ArrayList();
+            
+            // Statements obtained while default was hold.
+            // All should work, holability will be downgraded
+            // to close on commit for those Statements with hold set.
+            openRS.add(sdh.executeQuery("SELECT * FROM APP.FOO"));
+            openRS.add(shh.executeQuery("SELECT * FROM APP.FOO"));
+            openRS.add(sch.executeQuery("SELECT * FROM APP.FOO"));
+
             
             // PreparedStatements obtained while default was hold.
-            // Only sch should work as held cursors not supported in XA
-            try {
-                psdh.executeQuery().close();
-                System.out.println("FAIL - held Statement in global psdf");
-            } catch (SQLException e) {
-                TestUtil.dumpSQLExceptions(e, true);
-            }
-            try {
-                pshh.executeQuery().close();
-                System.out.println("FAIL - held Statement in global pshh");
-            } catch (SQLException e) {
-                TestUtil.dumpSQLExceptions(e, true);
-            }
-            psch.executeQuery().close();
+            // Holdability should be downgraded.
+            openRS.add(psdh.executeQuery());
+            openRS.add(pshh.executeQuery());
+            openRS.add(psch.executeQuery());
             
             // Statements not returning ResultSet's should be ok
             if (!TestUtil.isDerbyNetClientFramework()) { // DERBY-1159
@@ -951,31 +943,24 @@
             pshh_d.executeUpdate();
             psch_d.executeUpdate();
             }
-             
-            // Statements obtained while default was close.
-            // Only sch should work as held cursors not supported in XA
-            sdc.executeQuery("SELECT * FROM APP.FOO").close();
-            if (TestUtil.isDerbyNetClientFramework()) { // DERBY-1158
-            shc.executeQuery("SELECT * FROM APP.FOO").close();
-            }
-            scc.executeQuery("SELECT * FROM APP.FOO").close();
-            
+
             // Statements not returning ResultSet's should be ok
             if (!TestUtil.isDerbyNetClientFramework()) { // DERBY-1159
             sdc.executeUpdate("DELETE FROM APP.FOO where A < -99");
             shc.executeUpdate("DELETE FROM APP.FOO where A < -99");
             scc.executeUpdate("DELETE FROM APP.FOO where A < -99");
-            }
+            }             
+ 
+            // Statements obtained while default was close.
+            // all should return close on commit ResultSets
+            openRS.add(sdc.executeQuery("SELECT * FROM APP.FOO"));
+            openRS.add(shc.executeQuery("SELECT * FROM APP.FOO"));
+            openRS.add(scc.executeQuery("SELECT * FROM APP.FOO"));
             
             // PreparedStatements obtained while default was close.
-           psdc.executeQuery().close();
-           try {
-                pshc.executeQuery().close();
-                System.out.println("FAIL - held Statement in global");
-            } catch (SQLException e) {
-                TestUtil.dumpSQLExceptions(e, true);
-            }
-            pscc.executeQuery().close();
+            openRS.add(psdc.executeQuery());
+            openRS.add(pshc.executeQuery());
+            openRS.add(pscc.executeQuery());
             
             // Statements not returning ResultSet's should be ok
             if (!TestUtil.isDerbyNetClientFramework()) { // DERBY-1159
@@ -983,6 +968,19 @@
             pshc_d.executeUpdate();
             pscc_d.executeUpdate();
             }
+            
+            // All the ResultSets should be open. Run a simple
+            // test, clearWarnings throws an error if the ResultSet
+            // is closed. Also would be nice here to use the new
+            // JDBC 4.0 method getHoldabilty to ensure the
+            // holdability is reported correctly.
+            int orsCount = 0;
+            for (Iterator i = openRS.iterator(); i.hasNext();) {
+                ResultSet ors = (ResultSet) i.next();
+                ors.clearWarnings();
+                orsCount++;
+            }
+            System.out.println("Global transaction open ResultSets " + orsCount);
 
                    
             // Test we cannot switch the connection to holdable
@@ -1011,12 +1009,64 @@
                 ResultSet.HOLD_CURSORS_OVER_COMMIT);
             showHoldStatus("Global prepareStatement(hold)", psglobalhold);
             psglobalhold.close();
-
+            
+            if (!TestUtil.isDerbyNetClientFramework()) { //DERBY-1158 in progress
+            // Show the holdability for all the Statements while
+            // in the global transaction, all should be close on commit.
+            showHoldStatus("Global xact Statement sdh ", sdh);
+            showHoldStatus("Global xact Statement shh ", shh);
+            showHoldStatus("Global xact Statement sch ", sch);
+            
+            showHoldStatus("Global xact Statement psdh ", psdh);
+            showHoldStatus("Global xact Statement pshh ", pshh);
+            showHoldStatus("Global xact Statement psch ", psch);
+            
+            showHoldStatus("Global xact Statement sdc ", sdc);
+            showHoldStatus("Global xact Statement shc ", shc);
+            showHoldStatus("Global xact Statement scc ", scc);
+ 
+            showHoldStatus("Global xact Statement psdh_d ", psdh_d);
+            showHoldStatus("Global xact Statement pshh_d ", pshh_d);
+            showHoldStatus("Global xact Statement psch_d ", psch_d);
+            }
+ 
         
             xar.end(xid, XAResource.TMSUCCESS);
             if (xar.prepare(xid) != XAResource.XA_RDONLY)
                 System.out.println("FAIL prepare didn't indicate r/o");
             
+            // All the ResultSets should be closed. Run a simple
+            // test, clearWarnings throws an error if the ResultSet
+            // is closed.
+            int crsCount = 0;
+            for (Iterator i = openRS.iterator(); i.hasNext();) {
+                ResultSet crs = (ResultSet) i.next();
+                try {
+                    crs.clearWarnings();
+                } catch (SQLException sqle) {
+                }
+                crsCount++;
+            }
+            System.out.println("After global transaction closed ResultSets " + crsCount);
+
+            
+            // Check the statements revert to holdable as required.
+            showHoldStatus("Global xact Statement sdh ", sdh);
+            showHoldStatus("Global xact Statement shh ", shh);
+            showHoldStatus("Global xact Statement sch ", sch);
+            
+            showHoldStatus("Global xact Statement psdh ", psdh);
+            showHoldStatus("Global xact Statement pshh ", pshh);
+            showHoldStatus("Global xact Statement psch ", psch);
+ 
+            showHoldStatus("Global xact Statement sdc ", sdc);
+            showHoldStatus("Global xact Statement shc ", shc);
+            showHoldStatus("Global xact Statement scc ", scc);
+            
+            showHoldStatus("Global xact Statement psdh_d ", psdh_d);
+            showHoldStatus("Global xact Statement pshh_d ", pshh_d);
+            showHoldStatus("Global xact Statement psch_d ", psch_d);
+            
             conn.close();
             
             System.out.println("derby966 complete");
@@ -1100,6 +1150,7 @@
             System.out.println(w.getSQLState() + " :" + w.toString());
             w = w.getNextWarning();
         }
+        s.getConnection().clearWarnings();
         
     }
     /**

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
Fri Apr  7 11:51:10 2006
@@ -392,8 +392,6 @@
 
 		// now check re-use of *Statement objects across local/global connections.
 		System.out.println("TESTING RE_USE OF STATEMENT OBJECTS");
-		System.out.println("THE STATEMENT OBJECTS CAN NOT BE REUSED ACROSS LOCAL/GLOBAL CONNECTIONS
BECAUSE, LOCAL CONNECTION CREATES THEM");
-		System.out.println("WITH HOLDABILITY TRUE WHEREAS GLOBAL CONNECTION CAN ONLY WORK WITH
STATEMENTS WITH HOLDABILITY FALSE");
 		cs1 = xac.getConnection();
 
     
@@ -420,24 +418,18 @@
 		cs1.commit(); // need to commit to switch to an global connection;
 		xid = new cdsXid(1, (byte) 103, (byte) 119);
 		xar.start(xid, XAResource.TMNOFLAGS); // simple case - underlying connection is re-used
for global.
-		System.out.println("Expecting exception because global transaction sru1-global-2 is trying
to use a statement with holdability true");
+		System.out.println("Expecting downgrade because global transaction sru1-global-2 is using
a statement with holdability true");
 		queryOnStatement("sru1-global-2", cs1, sru1);
 		sruBatch.addBatch("insert into ru values 5");
 		Statement sru2 = cs1.createStatement();
 		sru2.setCursorName("OAK2");
 		queryOnStatement("sru2-global-3", cs1, sru2);
-		System.out.println("Expecting exception because global transaction sru1-global-4 is trying
to use a statement with holdability true");
+		System.out.println("Expecting downgrade because global transaction sru1-global-4 is using
a statement with holdability true");
 		queryOnStatement("sru1-global-4", cs1, sru1);
 		showStatementState("GLOBAL ", sruState);
 		showStatementState("PS GLOBAL ", psruState);
 		showStatementState("CS GLOBAL ", csruState);
-		try {
-			resultSetQuery("Params-global-1", psParams.executeQuery());
-			System.out.println("FAIL: should have gotten exception because holdability is true on
prepared statement and that is not allowed in global transactions");
-		} catch (SQLException ex) {
-			System.out.println("PASS: got exception because holdability is true on prepared statement
and that is not allowed in global transactions");
-			System.out.println(ex.getMessage());
-		}
+		resultSetQuery("Params-global-1", psParams.executeQuery());
 
 		xar.end(xid, XAResource.TMSUCCESS);
 		// now a new underlying connection is created

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource30.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource30.java?rev=392362&r1=392361&r2=392362&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource30.java
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource30.java
Fri Apr  7 11:51:10 2006
@@ -328,47 +328,22 @@
            shxa.close();
            
            
-			// check we cannot use a holdable statement set up in local mode.
+			// check we can use a holdable statement set up in local mode.
+            // holdability is downgraded, tested in XATest.java
 			System.out.println("STATEMENT HOLDABILITY " + (sh.getResultSetHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT));
-			try {
-				sh.executeQuery("select id from hold_30");
-				System.out.println("FAIL used held statement in global transaction");
-			} catch (SQLException sqle) {
-				System.out.println("Expected SQLException (local Statement hold) " + sqle.getMessage());
-			}
-			try {
-				sh.execute("select id from hold_30");
-				System.out.println("FAIL used held statement in global transaction");
-			} catch (SQLException sqle) {
-				System.out.println("Expected SQLException (local Statement hold) " + sqle.getMessage());
-			}
-			System.out.println("PREPARED STATEMENT HOLDABILITY " + (psh.getResultSetHoldability()
== ResultSet.HOLD_CURSORS_OVER_COMMIT));
-			try {
-				psh.executeQuery();
-				System.out.println("FAIL used held prepared statement in global transaction");
-			} catch (SQLException sqle) {
-				System.out.println("Expected SQLException (local PreparedStatement hold) " + sqle.getMessage());
-			}
-			try {
-				psh.execute();
-				System.out.println("FAIL used held prepared statement in global transaction");
-			} catch (SQLException sqle) {
-				System.out.println("Expected SQLException (local PreparedStatement hold) " + sqle.getMessage());
-			}
+			sh.executeQuery("select id from hold_30").close();
+			sh.execute("select id from hold_30");
+            sh.getResultSet().close();
+
+            System.out.println("PREPARED STATEMENT HOLDABILITY " + (psh.getResultSetHoldability()
== ResultSet.HOLD_CURSORS_OVER_COMMIT));
+			psh.executeQuery().close();
+			psh.execute();
+            psh.getResultSet().close();
 
 			System.out.println("CALLABLE STATEMENT HOLDABILITY " + (csh.getResultSetHoldability()
== ResultSet.HOLD_CURSORS_OVER_COMMIT));
-			try {
-				csh.executeQuery();
-				System.out.println("FAIL used held callable statement in global transaction");
-			} catch (SQLException sqle) {
-				System.out.println("Expected SQLException (local CallableStatement hold) " + sqle.getMessage());
-			}
-			try {
-				csh.execute();
-				System.out.println("FAIL used held callable statement in global transaction");
-			} catch (SQLException sqle) {
-				System.out.println("Expected SQLException (local CallableStatement hold) " + sqle.getMessage());
-			}
+			csh.executeQuery().close();
+			csh.execute();
+            csh.getResultSet().close();
 
 			// but an update works
 			sh.executeUpdate("insert into hold_30 values(10, 'init10')");



Mime
View raw message