db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r389825 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/jdbc/ jdbc/
Date Wed, 29 Mar 2006 16:41:58 GMT
Author: djd
Date: Wed Mar 29 08:41:57 2006
New Revision: 389825

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

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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java?rev=389825&r1=389824&r2=389825&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java Wed
Mar 29 08:41:57 2006
@@ -38,6 +38,7 @@
 import org.apache.derby.iapi.reference.JDBC30Translation;
 import org.apache.derby.iapi.error.PublicAPI;
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.shared.common.reference.SQLState;
 
 /**
  * This is a rudimentary connection that delegates
@@ -536,9 +537,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)
     	{
@@ -560,5 +563,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/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java?rev=389825&r1=389824&r2=389825&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java Wed
Mar 29 08:41:57 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/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java?rev=389825&r1=389824&r2=389825&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
Wed Mar 29 08:41:57 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/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java?rev=389825&r1=389824&r2=389825&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java
Wed Mar 29 08:41:57 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/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java?rev=389825&r1=389824&r2=389825&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java Wed Mar
29 08:41:57 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/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=389825&r1=389824&r2=389825&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 Mar 29
08:41:57 2006
@@ -74,16 +74,25 @@
 		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 (xaRes.getCurrentXid () != null)
-				throw Util.generateCsSQLException(SQLState.CANNOT_HOLD_CURSOR_XA);
+			if (xaRes.getCurrentXid () != 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/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=389825&r1=389824&r2=389825&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 Mar
29 08:41:57 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);
+ 	}
 }



Mime
View raw message