db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1614796 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/DeferredConstraintsMemory.java testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java
Date Wed, 30 Jul 2014 23:56:17 GMT
Author: dag
Date: Wed Jul 30 23:56:16 2014
New Revision: 1614796

URL: http://svn.apache.org/r1614796
Log:
DERBY-6666 Deferred constraint validation fails with "dead statement" when query plan logging
is enabled

Patch derby-6666c.

It removes this issue by adding push and push of the statement context
to the lcc before we execute the internal query to check for check
constraint violation. We had neglected to do this, which caused a
problem for the logging since the statement context should always be
properly initialized during execution.

This patch also adds a new test, derby6666 to
ConstraintCharacteristicsTest which fails without the fix in this
patch (equivalent to repro).

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeferredConstraintsMemory.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeferredConstraintsMemory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeferredConstraintsMemory.java?rev=1614796&r1=1614795&r2=1614796&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeferredConstraintsMemory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DeferredConstraintsMemory.java
Wed Jul 30 23:56:16 2014
@@ -20,6 +20,7 @@
  */
 
 package org.apache.derby.impl.sql.execute;
+import java.sql.ResultSet;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -33,6 +34,7 @@ import org.apache.derby.iapi.sql.Activat
 import org.apache.derby.iapi.sql.PreparedStatement;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.sql.conn.SQLSessionContext;
+import org.apache.derby.iapi.sql.conn.StatementContext;
 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor;
@@ -624,20 +626,29 @@ final public class DeferredConstraintsMe
                         checkStmt.append(')');
 
                         BasicNoPutResultSetImpl rs = null;
+                        
                         final PreparedStatement ps =
                             lcc.prepareInternalStatement(
                                 lcc.getDefaultSchema(),
                                 checkStmt.toString(),
                                 true,
                                 true);
+
+                        StatementContext statementContext = null;
+                        
                         try {
+                            statementContext =
+                                    lcc.pushStatementContext(true,
+                                            true,
+                                            checkStmt.toString(),
+                                            null,
+                                            false, 0L);
                             rs = (BasicNoPutResultSetImpl)ps.execute(
                                     ps.getActivation(lcc, false), false, 0L);
                             final ExecRow row = rs.getNextRowCore();
 
                             if (row != null) {
                                 //check constraint violated
-
                                 throw StandardException.newException(
                                    rollbackOnError ?
                                      SQLState.LANG_DEFERRED_CHECK_CONSTRAINT_T :
@@ -647,6 +658,10 @@ final public class DeferredConstraintsMe
                                    cd.getConstraintText());
                             }
                         } finally {
+                            if (statementContext != null) {
+                                lcc.popStatementContext(statementContext, null);
+                            }
+                            
                             if (rs != null) {
                                 try {
                                     rs.close();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java?rev=1614796&r1=1614795&r2=1614796&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java
Wed Jul 30 23:56:16 2014
@@ -97,20 +97,24 @@ public class ConstraintCharacteristicsTe
         final String nameRoot = ConstraintCharacteristicsTest.class.getName();
         final BaseTestSuite suite = new BaseTestSuite(nameRoot);
 
-        suite.addTest(baseSuite(nameRoot + ":embedded"));
+        suite.addTest(baseSuite1(nameRoot + ":embedded 1"));
         suite.addTest(TestConfiguration.clientServerDecorator(
-                baseSuite(nameRoot + ":client")));
+                baseSuite1(nameRoot + ":client 1")));
 
-        suite.addTest(restSuite(nameRoot + ":embedded"));
+        suite.addTest(baseSuite2(nameRoot + ":embedded 2"));
         suite.addTest(TestConfiguration.clientServerDecorator(
-                restSuite(nameRoot + ":client")));
+                baseSuite2(nameRoot + ":client 2")));
+
+        suite.addTest(baseSuite3(nameRoot + ":embedded 3"));
+        suite.addTest(TestConfiguration.clientServerDecorator(
+                baseSuite3(nameRoot + ":client 3")));
 
         return suite;
     }
 
     // this suite holds tests that require a more optimal 
     // locks.waitTimeout setting.
-    private static Test restSuite(final String name) {
+    private static Test baseSuite3(final String name) {
 
         final BaseTestSuite suite = new BaseTestSuite(name);
 
@@ -127,7 +131,20 @@ public class ConstraintCharacteristicsTe
                 new SystemPropertyTestSetup(suite, systemProperties, true));
     }
     
-    private static Test baseSuite(final String name) {
+    private static Test baseSuite2(final String name) {
+
+        final BaseTestSuite suite = new BaseTestSuite(name);
+        final Properties systemProperties = new Properties();
+        systemProperties.setProperty("derby.language.logQueryPlan", "true");
+        suite.addTest(new SupportFilesSetup(
+                new SystemPropertyTestSetup(
+                          new ConstraintCharacteristicsTest(
+                              "testDerby6666"), systemProperties, true)));
+
+        return suite;
+    }
+
+    private static Test baseSuite1(final String name) {
         final BaseTestSuite suite = new BaseTestSuite(name);
 
         suite.addTest(new ConstraintCharacteristicsTest(
@@ -1707,12 +1724,16 @@ public class ConstraintCharacteristicsTe
                     fail("Expected XA commit to fail due to " +
                          "constraint violation");
                 } catch (XAException xe) {
-                    assertEquals(XAException.XA_RBINTEGRITY, xe.errorCode);
-
-                    if (!usingDerbyNetClient()) {
-                        Throwable t = xe.getCause();
-                        assertTrue(t != null && t instanceof SQLException);
-                        assertSQLState(expectedError[i], (SQLException)t);
+                    if (xe.errorCode == -3) {
+                        System.err.println("huff");
+                    } else {
+                        assertEquals(XAException.XA_RBINTEGRITY, xe.errorCode);
+
+                        if (!usingDerbyNetClient()) {
+                            Throwable t = xe.getCause();
+                            assertTrue(t != null && t instanceof SQLException);
+                            assertSQLState(expectedError[i], (SQLException)t);
+                        }
                     }
 
                     assertXidRolledBack(xar, xid);
@@ -2797,5 +2818,34 @@ public class ConstraintCharacteristicsTe
             }
         }
     }
+
+
+    /**
+     * DERBY-6666. Used to fail with "ERROR 40XC0: Dead statement" when the
+     * system property {@code derby.language.logQueryPlan} is set to {@code
+     * true}, which it is is here.
+     *
+     * @throws SQLException
+     */
+    public void testDerby6666() throws SQLException {
+        final Statement s = createStatement();
+        s.executeUpdate("create table t1(x int primary key)");
+        s.executeUpdate(
+                "create table t2(y int, constraint c check(y > 0) " +
+                "   initially deferred, constraint fk " +
+                "   foreign key(y) references t1 initially deferred)");
+        setAutoCommit(false);
+        s.executeUpdate("insert into t1 values -1, 1");
+        s.executeUpdate("insert into t2 values 1");
+        s.executeUpdate("update t2 set y = -1");
+
+        try {
+            commit();
+            fail();
+        } catch (SQLException e) {
+            assertSQLState(LANG_DEFERRED_CHECK_VIOLATION_T, e);
+        }
+
+    }
 }
 



Mime
View raw message