db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r536516 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Date Wed, 09 May 2007 13:30:52 GMT
Author: kahatlen
Date: Wed May  9 06:30:51 2007
New Revision: 536516

URL: http://svn.apache.org/viewvc?view=rev&rev=536516
Log:
DERBY-2584: Creating a database with JPOX SchemaTool sometimes gives
ArrayIndexOutOfBoundsException when getIndexInfo() is called

Make sure meta-data queries are properly written to the database when
the first attempt to compile them fails with a lock timeout.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java?view=diff&rev=536516&r1=536515&r2=536516
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SPSDescriptor.java
Wed May  9 06:30:51 2007
@@ -700,6 +700,12 @@
 					nestedTC = null;
 				}
 
+				// DERBY-2584: If the first attempt to compile the query fails,
+				// we need to reset initiallyCompilable to make sure the
+				// prepared plan is fully stored to disk. Save the initial
+				// value here.
+				final boolean compilable = initiallyCompilable;
+
 				try
 				{
 					prepareAndRelease(lcc, null, nestedTC);
@@ -717,6 +723,7 @@
 						}
 						// if we couldn't do this with a nested xaction, retry with
 						// parent-- we need to wait this time!
+						initiallyCompilable = compilable;
 						prepareAndRelease(lcc, null, null);
 						updateSYSSTATEMENTS(lcc, RECOMPILE, null);
 					}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?view=diff&rev=536516&r1=536515&r2=536516
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Wed May  9 06:30:51 2007
@@ -47,6 +47,7 @@
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.TestConfiguration;
 import org.apache.derby.shared.common.reference.JDBC40Translation;
@@ -199,7 +200,20 @@
      * Default suite for running this test.
      */
     public static Test suite() {
-        return TestConfiguration.defaultSuite(DatabaseMetaDataTest.class);
+        TestSuite suite = new TestSuite("DatabaseMetaDataTest");
+        suite.addTest(
+            TestConfiguration.defaultSuite(DatabaseMetaDataTest.class));
+        // Test for DERBY-2584 needs a fresh database to ensure that the
+        // meta-data queries haven't already been compiled. No need to run the
+        // test in client/server mode since it only tests the compilation of
+        // meta-data queries.
+        suite.addTest(
+            TestConfiguration.singleUseDatabaseDecorator(
+                // until DERBY-177 is fixed, set lock timeout to prevent the
+                // test from waiting one minute
+                DatabasePropertyTestSetup.setLockTimeouts(
+                    new DatabaseMetaDataTest("initialCompilationTest"), 2, 4)));
+        return suite;
     }
     
     /**
@@ -223,6 +237,30 @@
     private final DatabaseMetaData getDMD() throws SQLException
     {
         return getConnection().getMetaData();
+    }
+
+    /**
+     * Tests that a meta-data query is compiled and stored correctly even when
+     * there's a lock on the system tables (DERBY-2584). This test must run on
+     * a fresh database (that is, <code>getIndexInfo</code> must not have been
+     * prepared and stored in <code>SYS.SYSSTATEMENTS</code>).
+     */
+    public void initialCompilationTest() throws SQLException {
+        Connection c = getConnection();
+        c.setAutoCommit(false);
+        c.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
+        Statement s = createStatement();
+        // First get shared row locks on the SYSSTATEMENTS table.
+        JDBC.assertDrainResults(
+            s.executeQuery("SELECT * FROM SYS.SYSSTATEMENTS"));
+        s.close();
+        // Execute getIndexInfo() for the first time. Because of the shared
+        // locks on SYSSTATEMENTS, the query is compiled in the main
+        // transaction.
+        getDMD().getIndexInfo(null, null, "T", false, false).close();
+        // Re-use the previously compiled query from disk. Fails with
+        // ArrayIndexOutOfBoundsException before DERBY-2584.
+        getDMD().getIndexInfo(null, null, "T", false, false).close();
     }
 
     /**



Mime
View raw message