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 ma...@apache.org on 2009/09/12 00:19:43 UTC

svn commit: r814057 - in /db/derby/code/branches/10.1: ./ java/engine/org/apache/derby/iapi/jdbc/ java/engine/org/apache/derby/jdbc/ java/testing/org/apache/derbyTesting/functionTests/master/ java/testing/org/apache/derbyTesting/functionTests/master/De...

Author: mamta
Date: Fri Sep 11 22:19:41 2009
New Revision: 814057

URL: http://svn.apache.org/viewvc?rev=814057&view=rev
Log:
DERBY-4310

Backport changes to 10.1 codeline. Had to hand write the tests in XATest because that test has not been converted to junit test in 10.1 codeline and hence the merge on it didn't work.

Modified:
    db/derby/code/branches/10.1/   (props changed)
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement.java
    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/iapi/jdbc/BrokeredStatementControl.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/tests/jdbcapi/XATest.java

Propchange: db/derby/code/branches/10.1/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri Sep 11 22:19:41 2009
@@ -0,0 +1,2 @@
+/db/derby/code/branches/10.2:813882
+/db/derby/code/trunk:800523

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement.java?rev=814057&r1=814056&r2=814057&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement.java Fri Sep 11 22:19:41 2009
@@ -59,6 +59,10 @@
         return getCallableStatement().wasNull();
     }
 
+    public final void close() throws SQLException {
+        control.closeRealCallableStatement();
+    }
+    
     public final String getString(int parameterIndex)
         throws SQLException
     {

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java?rev=814057&r1=814056&r2=814057&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 Sep 11 22:19:41 2009
@@ -87,6 +87,11 @@
         return getPreparedStatement().executeUpdate();
     }
 
+	public void close() throws SQLException
+	{
+	    control.closeRealPreparedStatement();
+	}
+	
     /**
      * Set a parameter to SQL NULL.
      *

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java?rev=814057&r1=814056&r2=814057&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 Sep 11 22:19:41 2009
@@ -126,9 +126,9 @@
      * ResultSet, if one exists, is also closed.
 	 * @exception SQLException thrown on failure.
      */
-	public final void close() throws SQLException
+	public void close() throws SQLException
     {
-		getStatement().close();
+		control.closeRealStatement();
     }
 
     public final Connection getConnection()

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatementControl.java?rev=814057&r1=814056&r2=814057&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 Fri Sep 11 22:19:41 2009
@@ -36,6 +36,26 @@
 	public int checkHoldCursors(int holdability) throws SQLException;
 
 	/**
+	 * Close the real JDBC Statement when this is controlling a Statement.
+	 * @throws SQLException
+	 */
+	public void closeRealStatement() throws SQLException;
+	
+	/**
+	 * Close the real JDBC CallableStatement when this is controlling a
+	 * CallableStatement. 
+	 * @throws SQLException
+	 */
+	public void closeRealCallableStatement() throws SQLException;
+	
+	/**
+	 * Close the real JDBC CallableStatement when this is controlling a
+	 * PreparedStatement. 
+	 * @throws SQLException
+	 */
+	public void closeRealPreparedStatement() throws SQLException;
+	
+	/**
 		Return the real JDBC statement for the brokered statement
 		when this is controlling a Statement.
 	*/

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/XAStatementControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/XAStatementControl.java?rev=814057&r1=814056&r2=814057&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 Sep 11 22:19:41 2009
@@ -79,6 +79,27 @@
                 applicationStatement);
 	}
 
+	/**
+	 * Close the realStatement within this control. 
+	 */
+	public void closeRealStatement() throws SQLException {
+		realStatement.close();
+	}
+	
+	/**
+	 * Close the realCallableStatement within this control. 
+	 */
+	public void closeRealCallableStatement() throws SQLException {
+		realCallableStatement.close();
+	}
+	
+	/**
+	 * Close the realPreparedStatement within this control. 
+	 */
+	public void closeRealPreparedStatement() throws SQLException {
+		realPreparedStatement.close();
+	}
+	
 	public Statement getRealStatement() throws SQLException {
 
 		// 

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out?rev=814057&r1=814056&r2=814057&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 Sep 11 22:19:41 2009
@@ -202,4 +202,6 @@
 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
+derby4310PreparedStatement
+derby4310CallableStatement
 XATest complete

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/XATest.out
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/XATest.out?rev=814057&r1=814056&r2=814057&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 Sep 11 22:19:41 2009
@@ -201,4 +201,6 @@
 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
+derby4310PreparedStatement
+derby4310CallableStatement
 XATest complete

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java?rev=814057&r1=814056&r2=814057&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 Sep 11 22:19:41 2009
@@ -21,6 +21,7 @@
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
 
 import java.sql.Connection;
+import java.sql.CallableStatement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -76,6 +77,11 @@
         
         // DERBY-966 holdability testing
         derby966(dsx);
+        
+        // DERBY-4310 closing of statement with an embedded XAConnection
+        // should not cause recompile of statement
+        derby4310PreparedStatement(dsx);
+        derby4310CallableStatement(dsx);
 
         System.out.println("XATest complete");
     }
@@ -775,6 +781,125 @@
 
     }
     
+    /** 
+     * Dummy method for derby4310CallableStatement
+     */
+    public static void zeroArg() {  }
+    
+    /**
+     * This test checks the fix on DERBY-4310, for not repreparing 
+     * CallableStatements upon calling close() on them.
+     */
+    public static void derby4310CallableStatement(XADataSource xads) 
+    throws Exception 
+    {
+        System.out.println("derby4310CallableStatement");
+        try {
+            XAConnection xac = xads.getXAConnection();
+            XAResource xar = xac.getXAResource();
+
+            Xid xid = XATestUtil.getXid(4310, 9, 49);
+
+            /* Create the procedure based on XATest.zeroArg() */
+            Connection conn = xac.getConnection();
+            Statement s = conn.createStatement();
+            s.executeUpdate("CREATE PROCEDURE ZA() LANGUAGE JAVA "+
+                            "EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.jdbcapi.XATest.zeroArg' "+
+                            "PARAMETER STYLE JAVA");
+            conn.commit();
+            
+            /* Prepare and execute CallableStatement based on the procedure above */
+            CallableStatement cs = conn.prepareCall("CALL ZA()");
+            cs.execute();
+
+            /* Start and end a transaction on the XAResource object */
+            xar.start(xid, XAResource.TMNOFLAGS);
+            xar.end(xid, XAResource.TMSUCCESS);
+
+            /* Drop the procedure on a parallel, regular connection */
+            Connection conn2 = ij.startJBMS();
+            Statement s2 = conn2.createStatement();
+            s2.execute("DROP PROCEDURE ZA");
+            conn2.commit();
+            conn2.close();
+            
+            try {
+                /* Try to close the prepared statement. This would throw an exception
+                 * before the fix, claiming that the table was not found. */
+                cs.close();
+            } finally {
+                /* Rollback the transaction and close the connections */
+                xar.rollback(xid);
+                conn.close();
+                xac.close();
+            }
+        } catch (SQLException e) {
+            TestUtil.dumpSQLExceptions(e);
+            e.printStackTrace(System.out);
+        } catch (XAException e) {
+            XATestUtil.dumpXAException("derby4310CallableStatement", e);
+        }
+    }
+    
+    /**
+     * This test checks the fix on DERBY-4310, for not repreparing 
+     * PreparedStatements upon calling close() on them.
+     * @param xads
+     */
+    private static void derby4310PreparedStatement(XADataSource xads)
+    throws Exception
+    {
+        System.out.println("derby4310PreparedStatement");
+        try {
+            XAConnection xac = xads.getXAConnection();
+            XAResource xar = xac.getXAResource();
+
+            Xid xid = XATestUtil.getXid(4310, 9, 48);
+            
+            Connection conn = xac.getConnection();
+            
+            /* Create the table and insert some records into it. */
+            Statement s = conn.createStatement();
+            s.executeUpdate("CREATE TABLE foo4310_PS (I INT)");
+            conn.createStatement().executeUpdate("insert into APP.foo4310_PS values (0)");
+            conn.createStatement().executeUpdate("insert into APP.foo4310_PS values (1)");
+            conn.createStatement().executeUpdate("insert into APP.foo4310_PS values (2)");
+            conn.commit();
+            
+            /* Prepare and execute the statement to be tested */
+            PreparedStatement ps = conn.prepareStatement("SELECT * FROM APP.foo4310_PS");
+            ps.executeQuery().close();
+
+            /* Start and end a transaction on the XAResource object */
+            xar.start(xid, XAResource.TMNOFLAGS);
+            xar.end(xid, XAResource.TMSUCCESS);
+
+            /* Drop the table on a parallel, regular connection */
+            Connection conn2 = ij.startJBMS();
+            Statement s2 = conn2.createStatement();
+            s2.execute("DROP TABLE foo4310_PS");
+            conn2.commit();
+            conn2.close();
+
+            
+            try {
+                /* Try to close the prepared statement. This would throw an exception
+                 * before the fix, claiming that the table was not found. */
+                ps.close();
+            } finally {
+                /* Rollback the transaction and close the connections */
+                xar.rollback(xid);
+                conn.close();
+                xac.close();
+            }
+        } catch (SQLException e) {
+            TestUtil.dumpSQLExceptions(e);
+            e.printStackTrace(System.out);
+        } catch (XAException e) {
+            XATestUtil.dumpXAException("derby4310PreparedStatement", e);
+        }
+    }
+
     /**
      * Derby-966 holdability and global/location transactions.
      * (work in progress)