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 da...@apache.org on 2013/08/30 20:23:09 UTC

svn commit: r1519045 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.java testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java

Author: dag
Date: Fri Aug 30 18:23:08 2013
New Revision: 1519045

URL: http://svn.apache.org/r1519045
Log:
DERBY-532: Support deferrable constraints

Patch derby-532-testAlterConstraintInvalidation.

Adds a fixture to test that prepared statement is invalidated when a
table its depends on undergoes an ALTER TABLE ALTER CONSTRAINT
statement. As it turns out, this is already handled by the common
machinery for ALTER TABLE.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.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/iapi/sql/execute/ExecPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.java?rev=1519045&r1=1519044&r2=1519045&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecPreparedStatement.java Fri Aug 30 18:23:08 2013
@@ -161,7 +161,7 @@ public interface ExecPreparedStatement 
     boolean isUpdateColumn(String columnName);
 
 	/**
-	 * set this parepared statement to be valid
+	 * set this prepared statement to be valid
 	 */
 	void setValid();
 

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=1519045&r1=1519044&r2=1519045&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 Fri Aug 30 18:23:08 2013
@@ -21,6 +21,8 @@
 
 package org.apache.derbyTesting.functionTests.tests.lang;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -30,15 +32,13 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import static junit.framework.Assert.fail;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
-
+import org.apache.derby.iapi.services.context.ContextManager;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.impl.jdbc.EmbedConnection;
+import org.apache.derby.impl.sql.GenericPreparedStatement;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import static org.apache.derbyTesting.junit.BaseJDBCTestCase.assertSQLState;
-import static org.apache.derbyTesting.junit.BaseJDBCTestCase.assertStatementError;
-import static org.apache.derbyTesting.junit.BaseJDBCTestCase.assertUpdateCount;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 
@@ -62,6 +62,9 @@ public class ConstraintCharacteristicsTe
                 "testCreateConstraintDictionaryEncodings"));
         s.addTest(new ConstraintCharacteristicsTest(
                 "testAlterConstraintDictionaryEncodings"));
+        s.addTest(new ConstraintCharacteristicsTest(
+                "testAlterConstraintInvalidation"));
+        
         suite.addTest(
             new SystemPropertyTestSetup(
                 s,
@@ -211,14 +214,43 @@ public class ConstraintCharacteristicsTe
     }
 
 
-    private static String[] tableConstraintTypes = {
+    /**
+     * Check that altering constraint characteristics invalidates prepared
+     * statements.
+     * @throws SQLException
+     */
+    public void testAlterConstraintInvalidation() throws SQLException {
+        Connection c = getConnection();
+        Statement s = c.createStatement();
+        
+        s.executeUpdate("create table t(i int, constraint c primary key(i))");
+        PreparedStatement ps = c.prepareStatement("insert into t values 3");
+        ps.execute();
+
+        s.executeUpdate("alter table t alter constraint c not enforced ");
+        
+        ContextManager contextManager = 
+                ((EmbedConnection)c).getContextManager();
+        LanguageConnectionContext lcc = 
+                (LanguageConnectionContext)contextManager.getContext(
+                "LanguageConnectionContext");
+        GenericPreparedStatement derbyPs = 
+                (GenericPreparedStatement)lcc.getLastActivation().
+                getPreparedStatement();
+
+        assertFalse(derbyPs.isValid());
+        
+        rollback();
+    }
+        
+    private final static String[] tableConstraintTypes = {
             " foreign key (i) references referenced(i)",
             " primary key(i)",
             " unique(i)",
             " check(i<3)"
         };
 
-    private static String[] columnConstraintTypes = {
+    private final static String[] columnConstraintTypes = {
             " references referenced(i)",
             " primary key",
             " unique",