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 dj...@apache.org on 2006/04/07 19:41:26 UTC

svn commit: r392342 - 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/

Author: djd
Date: Fri Apr  7 10:41:23 2006
New Revision: 392342

URL: http://svn.apache.org/viewcvs?rev=392342&view=rev
Log:
DERBY-1158 (partial) Re-factor some code to enable BrokeredStatement.getResultSetHoldability()
to return CLOSE_CURSORS_ON_COMMIT when in a global transaction.
Merge of 391842 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/EmbedXAConnection.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/checkDataSource30.out

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=392342&r1=392341&r2=392342&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 10:41:23 2006
@@ -55,7 +55,7 @@
      */
 	public final ResultSet executeQuery() throws SQLException
     {
-		controlCheck().checkHoldCursors(resultSetHoldability);
+        checkHoldability();
         return wrapResultSet(getPreparedStatement().executeQuery());
     } 
 
@@ -423,7 +423,7 @@
      */
     public final boolean execute() throws SQLException
     {
-		controlCheck().checkHoldCursors(resultSetHoldability);
+        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=392342&r1=392341&r2=392342&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 10:41:23 2006
@@ -21,10 +21,13 @@
 package org.apache.derby.iapi.jdbc;
 
 import org.apache.derby.iapi.reference.JDBC30Translation;
+import org.apache.derby.iapi.reference.SQLState;
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.error.PublicAPI;
 import org.apache.derby.iapi.services.info.JVMInfo;
+import org.apache.derby.impl.jdbc.Util;
+
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -98,13 +101,13 @@
 
     public final boolean execute(String sql) throws SQLException
 	{
-		controlCheck().checkHoldCursors(resultSetHoldability);
+        checkHoldability();
 		return getStatement().execute(sql);
     } 
 
     public final ResultSet executeQuery(String sql) throws SQLException
 	{
-		controlCheck().checkHoldCursors(resultSetHoldability);
+        checkHoldability();
 		return wrapResultSet(getStatement().executeQuery(sql));
     }
 
@@ -461,10 +464,21 @@
         return wrapResultSet(getStatement().getGeneratedKeys());
     }
 
+    /**
+     * Return the holdability of ResultSets created by this Statement.
+     * If this Statement is active in a global transaction the
+     * CLOSE_CURSORS_ON_COMMIT will be returned regardless of
+     * the holdability it was created with. In a local transaction
+     * the original create holdabilty will be returned.
+     */
 	public final int getResultSetHoldability()
         throws SQLException
 	{
-		return ((EngineStatement) getStatement()).getResultSetHoldability();
+        int holdability =
+            ((EngineStatement) getStatement()).getResultSetHoldability();
+        
+        // Holdability might be downgraded.
+        return controlCheck().checkHoldCursors(holdability);
 	}
 
 	/*
@@ -478,7 +492,8 @@
 		if (jdbcLevel == 2)
 			newStatement = conn.createStatement(resultSetType, resultSetConcurrency);
 		else
-			newStatement = conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+			newStatement = conn.createStatement(resultSetType, resultSetConcurrency,
+                    resultSetHoldability);
 
 		setStatementState(oldStatement, newStatement);
 
@@ -526,4 +541,11 @@
 		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=392342&r1=392341&r2=392342&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 10:41:23 2006
@@ -1100,8 +1100,10 @@
 				{
 					a.setCursorName(cursorName);
 				}
-
-				a.setResultSetHoldability(resultSetHoldability != JDBC30Translation.CLOSE_CURSORS_AT_COMMIT);
+                
+                boolean executeHoldable = getExecuteHoldable();
+ 
+				a.setResultSetHoldability(executeHoldable);
 
 				//reset the activation to clear warnings
 				//and clear existing result sets in case this has been cached
@@ -1439,6 +1441,17 @@
         // then next then close a commit would not be forced on the close.
 		commitIfAutoCommit();
 	}
-
+    
+    /**
+     * Get the execute time holdability for the Statement.
+     * When in a global transaction holdabilty defaults to false.
+     */
+    private boolean getExecuteHoldable()
+    {
+        if (resultSetHoldability  == JDBC30Translation.CLOSE_CURSORS_AT_COMMIT)
+            return false;
+        
+        return true;
+    }
 }
 

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java?rev=392342&r1=392341&r2=392342&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java Fri Apr  7 10:41:23 2006
@@ -737,9 +737,10 @@
 		if (holdability == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) {		
 
 			if (currentXid != null) {
-                if (downgrade)
-                    return JDBC30Translation.CLOSE_CURSORS_AT_COMMIT;
-                throw Util.generateCsSQLException(SQLState.CANNOT_HOLD_CURSOR_XA);
+                if (!downgrade)
+                    throw Util.generateCsSQLException(SQLState.CANNOT_HOLD_CURSOR_XA);
+                
+                holdability = JDBC30Translation.CLOSE_CURSORS_AT_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=392342&r1=392341&r2=392342&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 10:41:23 2006
@@ -198,6 +198,6 @@
 		Can cursors be held across commits.
 	*/
 	public int checkHoldCursors(int holdability) throws SQLException {
-		return xaConnection.checkHoldCursors(holdability, false);
+		return xaConnection.checkHoldCursors(holdability, true);
  	}
 }

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=392342&r1=392341&r2=392342&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 10:41:23 2006
@@ -515,7 +515,7 @@
   getFetchSize() 444
   getMaxFieldSize() 713
   getMaxRows() 19
-  getResultSetHoldability() HOLD_CURSORS_OVER_COMMIT 
+  getResultSetHoldability() CLOSE_CURSORS_AT_COMMIT 
 Statement State @ PS GLOBAL 
   getResultSetType() SCROLL_INSENSITIVE
   getResultSetConcurrency() READ_ONLY
@@ -523,7 +523,7 @@
   getFetchSize() 888
   getMaxFieldSize() 317
   getMaxRows() 91
-  getResultSetHoldability() HOLD_CURSORS_OVER_COMMIT 
+  getResultSetHoldability() CLOSE_CURSORS_AT_COMMIT 
   Parameter Count 1
     1 type 4
 Statement State @ CS GLOBAL 
@@ -533,7 +533,7 @@
   getFetchSize() 999
   getMaxFieldSize() 137
   getMaxRows() 85
-  getResultSetHoldability() HOLD_CURSORS_OVER_COMMIT 
+  getResultSetHoldability() CLOSE_CURSORS_AT_COMMIT 
   Parameter Count 2
     1 type 12
     2 type 12
@@ -814,7 +814,7 @@
 H@3 id 3
 CONNECTION(xa) HOLDABILITY false
 STATEMENT(this one was created with holdability false, outside the global transaction. Check it's holdability inside global transaction) HOLDABILITY false
-STATEMENT(this one was created with holdability true, outside the global transaction. Check it's holdability inside global transaction) HOLDABILITY true
+STATEMENT(this one was created with holdability true, outside the global transaction. Check it's holdability inside global transaction) HOLDABILITY false
 STATEMENT(this one was created with default holdability inside this global transaction. Check it's holdability) HOLDABILITY false
 PREPAREDSTATEMENT(this one was created with default holdability inside this global transaction. Check it's holdability) HOLDABILITY false
 CALLABLESTATEMENT(this one was created with default holdability inside this global transaction. Check it's holdability) HOLDABILITY false
@@ -826,7 +826,7 @@
 Check holdability of various jdbc objects after resuming XA transaction
 CONNECTION(xa) HOLDABILITY false
 STATEMENT(this one was created with holdability false, outside the global transaction. Check it's holdability inside global transaction) HOLDABILITY false
-STATEMENT(this one was created with holdability true, outside the global transaction. Check it's holdability inside global transaction) HOLDABILITY true
+STATEMENT(this one was created with holdability true, outside the global transaction. Check it's holdability inside global transaction) HOLDABILITY false
 STATEMENT(this one was created with default holdability inside the global transaction when it was first started. Check it's holdability) HOLDABILITY false
 PREPAREDSTATEMENT(this one was created with default holdability inside the global transaction when it was first started. Check it's holdability) HOLDABILITY false
 CALLABLESTATEMENT(this one was created with default holdability inside the global transaction when it was first started. Check it's holdability) HOLDABILITY false
@@ -843,13 +843,13 @@
 HOLDABLE Statement in global xact false connection warning ResultSetHoldability restricted to ResultSet.CLOSE_CURSORS_AT_COMMIT for a global transaction.
 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 true
+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 true
+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 true
+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