db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1622639 - in /db/derby/code/branches/10.11: ./ java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java
Date Fri, 05 Sep 2014 08:35:16 GMT
Author: kahatlen
Date: Fri Sep  5 08:35:16 2014
New Revision: 1622639

URL: http://svn.apache.org/r1622639
Log:
DERBY-6724: NPE if insert statement needs recompilation after having fired a trigger

Merged revision 1622631 from trunk.

Modified:
    db/derby/code/branches/10.11/   (props changed)
    db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java
    db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java

Propchange: db/derby/code/branches/10.11/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1622631

Modified: db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java?rev=1622639&r1=1622638&r2=1622639&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java
(original)
+++ db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java
Fri Sep  5 08:35:16 2014
@@ -23,7 +23,6 @@ package org.apache.derby.impl.sql.execut
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Vector;
@@ -233,20 +232,21 @@ class InternalTriggerExecutionContext
 	protected void cleanup()
 		throws StandardException
 	{
-		lcc.popTriggerExecutionContext(this);
+        if (lcc != null) {
+            lcc.popTriggerExecutionContext(this);
+        }
 
 		/*
 		** Explicitly close all result sets that we have
 		** given out to the user.  
 	 	*/
-		for (Enumeration<java.sql.ResultSet> e = resultSetVector.elements();
-			 e.hasMoreElements(); )
-		{
-			java.sql.ResultSet rs = e.nextElement();
-			try
-			{
-				rs.close();
-			} catch (SQLException se) {}
+        if (resultSetVector != null) {
+            for (ResultSet rs : resultSetVector) {
+                try {
+                    rs.close();
+                } catch (SQLException se) {
+                }
+            }
 		}
 		resultSetVector = null;
 	

Modified: db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java?rev=1622639&r1=1622638&r2=1622639&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java
(original)
+++ db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java
Fri Sep  5 08:35:16 2014
@@ -41,6 +41,14 @@ import org.apache.derbyTesting.junit.SQL
  * execution.
  */
 public class StalePlansTest extends BaseJDBCTestCase {
+    /**
+     * The value of derby.language.stalePlanCheckInterval to use in this
+     * test. The default value is 100, but we use 10 to reduce the number
+     * of times the test has to execute statements to get to the desired
+     * state.
+     */
+    private static final int STALE_PLAN_CHECK_INTERVAL = 10;
+
     public StalePlansTest(String name) {
         super(name);
     }
@@ -53,7 +61,8 @@ public class StalePlansTest extends Base
         Properties props = new Properties();
         // Check for stale plans on every 10th execution (default 100) to
         // reduce the number of times we need to execute each statement.
-        props.setProperty("derby.language.stalePlanCheckInterval", "10");
+        props.setProperty("derby.language.stalePlanCheckInterval",
+                          String.valueOf(STALE_PLAN_CHECK_INTERVAL));
         Test suite = new DatabasePropertyTestSetup(
             new BaseTestSuite(StalePlansTest.class), props, true);
         return new CleanDatabaseTestSetup(suite);
@@ -296,4 +305,29 @@ public class StalePlansTest extends Base
         insert2.close();
         ps.close();
     }
+
+    /**
+     * Regression test case for DERBY-6724, where an INSERT statement would
+     * fail with a NullPointerException if it had fired a trigger, and it
+     * was detected during execution that the statement plan was stale and
+     * had to be recompiled.
+     */
+    public void testDerby6724() throws SQLException {
+        Statement s = createStatement();
+        s.execute("create table d6724_t(x int)");
+        s.execute("create trigger d6724_tr after insert on d6724_t values 1");
+        s.execute("insert into d6724_t values 1");
+
+        // Before DERBY-6724 this statement would fail with an NPE in the
+        // (STALE_PLAN_CHECK_INTERVAL+1)'th execution.
+        PreparedStatement ps = prepareStatement(
+                "insert into d6724_t select * from d6724_t");
+        for (int i = 0; i < STALE_PLAN_CHECK_INTERVAL + 1; i++) {
+            // Execute the statement and verify that the correct number of
+            // rows are inserted. The number doubles for each execution.
+            assertUpdateCount(ps, 1 << i);
+        }
+
+        rollback();
+    }
 }



Mime
View raw message