db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r391842 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/master/
Date Wed, 05 Apr 2006 23:08:35 GMT
Author: djd
Date: Wed Apr  5 16:08:33 2006
New Revision: 391842

URL: http://svn.apache.org/viewcvs?rev=391842&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.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/XAStatementControl.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java?rev=391842&r1=391841&r2=391842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
Wed Apr  5 16:08:33 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/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java?rev=391842&r1=391841&r2=391842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java Wed
Apr  5 16:08:33 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/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java?rev=391842&r1=391841&r2=391842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java Wed Apr
 5 16:08:33 2006
@@ -1151,8 +1151,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
@@ -1527,6 +1529,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/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java?rev=391842&r1=391841&r2=391842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java Wed Apr 
5 16:08:33 2006
@@ -86,9 +86,10 @@
     {
 		if (holdability == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) {		
 			if (xaRes.getCurrentXid () != 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/trunk/java/engine/org/apache/derby/jdbc/XAStatementControl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/XAStatementControl.java?rev=391842&r1=391841&r2=391842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/XAStatementControl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/XAStatementControl.java Wed Apr
 5 16:08:33 2006
@@ -203,6 +203,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/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out?rev=391842&r1=391841&r2=391842&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/checkDataSource30.out
Wed Apr  5 16:08:33 2006
@@ -535,7 +535,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
@@ -543,7 +543,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 
@@ -553,7 +553,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
@@ -834,7 +834,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
@@ -846,7 +846,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
@@ -863,13 +863,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



Mime
View raw message