db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r602495 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Sat, 08 Dec 2007 16:21:07 GMT
Author: dyre
Date: Sat Dec  8 08:21:05 2007
New Revision: 602495

URL: http://svn.apache.org/viewvc?rev=602495&view=rev
Log:
DERBY-3198: Using setQueryTimeout will leak sections
Patch file: derby-3198.v6.diff
Introduce a separate varable to track the Section object used by 
writeSetSpecialRegister. The Section is allocated on demand and freed 
when the Statement is closed or reset.
Adds a new test case to StatementJDBC30Test to catch future regressions.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/StatementRequestInterface.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java?rev=602495&r1=602494&r2=602495&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java Sat
Dec  8 08:21:05 2007
@@ -61,7 +61,7 @@
 
     public abstract void markClosedOnServer_();
 
-    public abstract void writeSetSpecialRegister_(java.util.ArrayList sqlsttList) throws
SqlException;
+    public abstract void writeSetSpecialRegister_(Section section, java.util.ArrayList sqlsttList)
throws SqlException;
 
     public abstract void readSetSpecialRegister_() throws SqlException;
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java?rev=602495&r1=602494&r2=602495&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java Sat Dec  8 08:21:05
2007
@@ -24,6 +24,7 @@
 
 import org.apache.derby.shared.common.reference.JDBC30Translation;
 import org.apache.derby.shared.common.reference.SQLState;
+import org.apache.derby.shared.common.sanity.SanityManager;
 
 public class Statement implements java.sql.Statement, StatementCallbackInterface{
 
@@ -225,6 +226,11 @@
         if (section_ != null) {
             section_.free();
         }
+        if (setSpecialRegisterSection_ != null) {
+            setSpecialRegisterSection_.free();
+            setSpecialRegisterSection_ = null;
+        }
+
         sqlMode_ = 0;
         sqlUpdateMode_ = 0;
         resultSetMetaData_ = null;
@@ -1296,11 +1302,27 @@
     // ----------------------- box car and callback methods ---------------------
     // All callbacks must be client-side only operations.
     // Use of MaterialStatement interface is necessary to avoid multiple inheritance problem
in Java.
-    public void writeSetSpecialRegister(java.util.ArrayList sqlsttList) throws SqlException
{
-        materialStatement_.writeSetSpecialRegister_(sqlsttList);
+    /**
+     * This variable keeps track of a Section dediacted to
+     * writeSpecialRegister. It gets initialized the first time a
+     * Section is needed, and freed when the Statement is closed.
+     */
+    private Section setSpecialRegisterSection_ = null;
+    public void writeSetSpecialRegister(java.util.ArrayList sqlsttList) 
+        throws SqlException {
+        if (setSpecialRegisterSection_ == null) {
+            setSpecialRegisterSection_ = 
+                agent_.sectionManager_.getDynamicSection
+                (java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        }
+        materialStatement_.writeSetSpecialRegister_(setSpecialRegisterSection_,
+                                                    sqlsttList);
     }
 
     public void readSetSpecialRegister() throws SqlException {
+        if (SanityManager.DEBUG) {
+            SanityManager.ASSERT(setSpecialRegisterSection_ != null);
+        }
         materialStatement_.readSetSpecialRegister_();
     }
 
@@ -1780,6 +1802,11 @@
         
         if(removeListener)
         	connection_.openStatements_.remove(this);
+
+        if (setSpecialRegisterSection_ != null) {
+            setSpecialRegisterSection_.free();
+            setSpecialRegisterSection_ = null;
+        }
     }
 
     void markPreparedStatementForAutoGeneratedKeysClosed() {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java?rev=602495&r1=602494&r2=602495&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java Sat Dec
 8 08:21:05 2007
@@ -108,8 +108,8 @@
 
     // ------------------------abstract box car methods-----------------------------------------------
 
-    public void writeSetSpecialRegister_(java.util.ArrayList sqlsttList) throws SqlException
{
-        netAgent_.statementRequest_.writeSetSpecialRegister(sqlsttList);
+    public void writeSetSpecialRegister_(Section section, java.util.ArrayList sqlsttList)
throws SqlException {
+        netAgent_.statementRequest_.writeSetSpecialRegister(section,sqlsttList);
     }
 
     public void readSetSpecialRegister_() throws SqlException {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java?rev=602495&r1=602494&r2=602495&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java Sat
Dec  8 08:21:05 2007
@@ -1762,10 +1762,7 @@
         return CodePoint.RSLSETFLG_EXTENDED_SQLDA;
     }
 
-    public void writeSetSpecialRegister(java.util.ArrayList sqlsttList) throws SqlException
{
-        Section section =
-                netAgent_.sectionManager_.getDynamicSection(java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT);
-
+    public void writeSetSpecialRegister(Section section, java.util.ArrayList sqlsttList)
throws SqlException {
         buildEXCSQLSET(section);
 
         // SQLSTT:

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/StatementRequestInterface.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/StatementRequestInterface.java?rev=602495&r1=602494&r2=602495&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/StatementRequestInterface.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/StatementRequestInterface.java
Sat Dec  8 08:21:05 2007
@@ -88,5 +88,5 @@
                                  Object[] inputs) throws SqlException;
 
 
-    public void writeSetSpecialRegister(java.util.ArrayList sqlsttList) throws SqlException;
+    public void writeSetSpecialRegister(Section section, java.util.ArrayList sqlsttList)
throws SqlException;
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java?rev=602495&r1=602494&r2=602495&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc30Test.java
Sat Dec  8 08:21:05 2007
@@ -39,6 +39,8 @@
  */
 
 public class StatementJdbc30Test extends BaseJDBCTestCase {
+    private static final String CLIENT_SUITE_NAME = 
+        "StatementJdbc30Test:client";
 
     /**
      * Create a test with the given name.
@@ -61,7 +63,7 @@
         suite.addTest(baseSuite("StatementJdbc30Test:embedded"));
         suite
                 .addTest(TestConfiguration
-                        .clientServerDecorator(baseSuite("StatementJdbc30Test:client")));
+                        .clientServerDecorator(baseSuite(CLIENT_SUITE_NAME)));
 
         return suite;
     }
@@ -71,6 +73,16 @@
 
         suite.addTestSuite(StatementJdbc30Test.class);
 
+        if  (name.equals(CLIENT_SUITE_NAME)) {
+            // These test CAN be run in embedded mode as well, but
+            // they're only meaningful in c/s mode and also take quite
+            // a bit of time to run.
+            suite.addTest(new StatementJdbc30Test
+                          ("xtestMultiExecWithQueryTimeout"));
+            suite.addTest(new StatementJdbc30Test
+                          ("xtestMaxOpenStatementsWithQueryTimeout"));
+        }
+
         return new CleanDatabaseTestSetup(suite) {
             /**
              * Creates the tables used in the test cases.
@@ -276,6 +288,40 @@
             }
         
     }
+
+    /**
+     * DERBY-3198: Verify that a statement can be executed
+     * more than 32000 times, even when query timeout is enabled.
+     */
+    public void xtestMultiExecWithQueryTimeout() throws SQLException {
+        Statement stmt = createStatement();
+        stmt.setQueryTimeout(10);
+        for (int i = 0; i < 33000; ++i) {
+            ResultSet rs = stmt.executeQuery("VALUES(1)");
+            rs.close();
+        }
+    }
+
+    /**
+     * DERBY-3198: Verify that we can have at least 16383 open Statements with
+     * query timeout. With query timeout, each Statement holds on to 2
+     * Section objects until it is closed.
+     */
+    public void xtestMaxOpenStatementsWithQueryTimeout() throws SQLException {
+        Statement[] stmts = new Statement[16500];
+        int i = 0;
+        try {
+            for (; i < 16500; ++i) {
+                stmts[i] = createStatement();
+                stmts[i].setQueryTimeout(10);
+                stmts[i].executeQuery("VALUES(1)");
+            }
+        } catch (SQLException e) {
+            assertSQLState("XJ200",e);
+            assertTrue("16383 >= (i="+ i +")", 16383 >= i);
+        }  
+    }
+
 
     /**
      * Testing stmt.getResultSetHoldability()



Mime
View raw message