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 02:03:32 UTC

svn commit: r392128 - in /db/derby/code/branches/10.1/java/engine/org/apache/derby: iapi/jdbc/ jdbc/

Author: djd
Date: Thu Apr  6 17:03:30 2006
New Revision: 392128

URL: http://svn.apache.org/viewcvs?rev=392128&view=rev
Log:
DERBY-1158 (partial) Re-factor check holdability methods in the brokered stament
and connection control to support downgrading the holdability when needed. This
commit still implements at the user level throwing an exception for requesting
holdable ResultSets in a global transaction. A subsequent commit will change to
creting a warning on the Connection when creating a Statement with holdable ResultSets.
Merge of 389825 from trunk

Modified:
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.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

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java?rev=392128&r1=392127&r2=392128&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java Thu Apr  6 17:03:30 2006
@@ -28,6 +28,7 @@
 import java.sql.SQLException;
 import java.sql.SQLWarning;
 
+import org.apache.derby.client.am.SqlState;
 import org.apache.derby.impl.jdbc.Util;
 
 import java.io.ObjectOutput;
@@ -36,6 +37,7 @@
 import java.lang.reflect.*;
 
 import org.apache.derby.iapi.reference.JDBC30Translation;
+import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.error.PublicAPI;
 import org.apache.derby.iapi.error.StandardException;
 
@@ -538,9 +540,11 @@
             int resultSetType, int resultSetConcurrency,
             int resultSetHoldability) throws SQLException {
     	try {
-    		control.checkHoldCursors(resultSetHoldability);
+            resultSetHoldability = statementHoldabilityCheck(resultSetHoldability);
+    		
     		return control.wrapStatement(
-    			getRealConnection().prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability), sql, null);
+    			getRealConnection().prepareStatement(sql, resultSetType,
+                        resultSetConcurrency, resultSetHoldability), sql, null);
     	}
     	catch (SQLException se)
     	{
@@ -562,5 +566,29 @@
     		notifyException(se);
     		throw se;
     	}
+    }
+    
+    /*
+    ** Methods private to the class.
+    */
+    
+    /**
+     * Check the result set holdability when creating a statement
+     * object. Section 16.1.3.1 of JDBC 4.0 (proposed final draft)
+     * says the driver may change the holdabilty and add a SQLWarning
+     * to the Connection object.
+     * 
+     * This work-in-progress implementation throws an exception
+     * to match the old behaviour just as part of incremental development.
+     */
+    final int statementHoldabilityCheck(int resultSetHoldability)
+        throws SQLException
+    {
+        int holdability = control.checkHoldCursors(resultSetHoldability, true);
+        if (holdability != resultSetHoldability)
+            throw Util.generateCsSQLException(SQLState.CANNOT_HOLD_CURSOR_XA);
+        
+        return holdability;
+        
     }
 }

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java?rev=392128&r1=392127&r2=392128&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java Thu Apr  6 17:03:30 2006
@@ -43,8 +43,9 @@
                                  int resultSetHoldability)
 								 throws SQLException {
 		try {
-			control.checkHoldCursors(resultSetHoldability);
-			return control.wrapStatement(getRealConnection().createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
+            resultSetHoldability = statementHoldabilityCheck(resultSetHoldability);
+			return control.wrapStatement(getRealConnection().createStatement(resultSetType,
+                    resultSetConcurrency, resultSetHoldability));
 		}
 		catch (SQLException se)
 		{
@@ -58,9 +59,10 @@
                                      int resultSetHoldability)
 									 throws SQLException {
 		try {
-			control.checkHoldCursors(resultSetHoldability);
+            resultSetHoldability = statementHoldabilityCheck(resultSetHoldability);
 			return control.wrapStatement(
-				getRealConnection().prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability), sql);
+				getRealConnection().prepareCall(sql, resultSetType,
+                        resultSetConcurrency, resultSetHoldability), sql);
 		}
 		catch (SQLException se)
 		{
@@ -129,7 +131,7 @@
 		throws SQLException
 	{
 		try {
-			control.checkHoldCursors(holdability);
+			holdability = control.checkHoldCursors(holdability, false);
 			getRealConnection().setHoldability(holdability);
 			stateHoldability = holdability;
 		}

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java?rev=392128&r1=392127&r2=392128&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java Thu Apr  6 17:03:30 2006
@@ -64,8 +64,11 @@
 
 	/**
 		Can cursors be held across commits.
+        @param downgrade true to downgrade the holdability,
+        false to throw an exception.
 	*/
-	public void checkHoldCursors(int holdability) throws SQLException;
+	public int checkHoldCursors(int holdability, boolean downgrade)
+        throws SQLException;
 
 	/**
 		Returns true if isolation level has been set using JDBC/SQL.

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java?rev=392128&r1=392127&r2=392128&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java Thu Apr  6 17:03:30 2006
@@ -29,8 +29,11 @@
 {
 	/**
 		Can cursors be held across commits.
+        Returns the holdability that should be
+        used which may be different from the passed
+        in holdabilty.
 	*/
-	public void checkHoldCursors(int holdability) throws SQLException;
+	public int checkHoldCursors(int holdability) throws SQLException;
 
 	/**
 		Return the real JDBC statement for the brokered statement

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java?rev=392128&r1=392127&r2=392128&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java Thu Apr  6 17:03:30 2006
@@ -379,7 +379,10 @@
 	/**
 		Are held cursors allowed.
 	*/
-	public void checkHoldCursors(int holdability) throws SQLException {
+	public int checkHoldCursors(int holdability, boolean downgrade)
+        throws SQLException
+    {
+        return holdability;
 	}
 
 	/**

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=392128&r1=392127&r2=392128&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 Thu Apr  6 17:03:30 2006
@@ -724,16 +724,26 @@
 		super.checkAutoCommit(autoCommit);
 	}
 	/**
-		Are held cursors allowed.
+		Are held cursors allowed. If the connection is attached to
+        a global transaction then downgrade the result set holdabilty
+        to CLOSE_CURSORS_AT_COMMIT if downgrade is true, otherwise
+        throw an exception.
+        If the connection is in a local transaction then the
+        passed in holdabilty is returned.
 	*/
-	public void checkHoldCursors(int holdability) throws SQLException {
-
+	public int  checkHoldCursors(int holdability, boolean downgrade)
+        throws SQLException
+    {
 		if (holdability == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) {		
-			if (currentXid != null)
-				throw Util.generateCsSQLException(SQLState.CANNOT_HOLD_CURSOR_XA);
+
+			if (currentXid != null) {
+                if (downgrade)
+                    return JDBC30Translation.CLOSE_CURSORS_AT_COMMIT;
+                throw Util.generateCsSQLException(SQLState.CANNOT_HOLD_CURSOR_XA);
+            }
 		}
 
-		super.checkHoldCursors(holdability);
+		return super.checkHoldCursors(holdability, downgrade);
 	}
 
 	/**

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=392128&r1=392127&r2=392128&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 Thu Apr  6 17:03:30 2006
@@ -197,7 +197,7 @@
 	/**
 		Can cursors be held across commits.
 	*/
-	public void checkHoldCursors(int holdability) throws SQLException {
-		xaConnection.checkHoldCursors(holdability);
-	}
+	public int checkHoldCursors(int holdability) throws SQLException {
+		return xaConnection.checkHoldCursors(holdability, false);
+ 	}
 }