db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1555724 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java
Date Mon, 06 Jan 2014 12:09:31 GMT
Author: dag
Date: Mon Jan  6 12:09:30 2014
New Revision: 1555724

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

Patch _*derby-532-upgrade-1b*_. It checks that deferrable constraints
cannot be used unless hard upgrade has happened.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java?rev=1555724&r1=1555723&r2=1555724&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java
Mon Jan  6 12:09:30 2014
@@ -22,7 +22,6 @@ package org.apache.derbyTesting.function
 
 import java.sql.SQLException;
 import java.sql.Statement;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import org.apache.derbyTesting.junit.JDBC;
@@ -42,6 +41,7 @@ public class Changes10_11 extends Upgrad
 
     private static  final   String  SYNTAX_ERROR = "42X01";
     private static  final   String  HARD_UPGRADE_REQUIRED = "XCL47";
+    private static  final   String  NOT_IMPLEMENTED = "0A000";
 
     //////////////////////////////////////////////////////////////////
     //
@@ -272,4 +272,103 @@ public class Changes10_11 extends Upgrad
                 break;
         }
     }
+
+    /**
+     * Test how deferrable constraints work across upgrade and
+     * downgrade. Regression test for DERBY-532.
+     * 
+     * @throws java.sql.SQLException
+     */
+    public void testDeferrableConstraints() throws SQLException {
+        if (!oldAtLeast(10, 4)) {
+            // Support for nullable UNIQUE constraints wasn't added before
+            // 10.4
+            return;
+        }
+
+        setAutoCommit(false);
+        Statement st = createStatement();
+        
+        String[] cDeferrableCol = new String[]{
+            "create table t532(i int not null primary key deferrable)",
+            "create table t532(i int unique deferrable)",
+            "create table t532(i int not null unique deferrable)"};
+
+        String[] cDeferrableColNotYet = new String[]{
+            "create table t532(i int references referenced(i) deferrable)",
+            "create table t532(i int check(i>3) deferrable)"};
+
+        String[] cDeferrableTab = new String[]{
+            "create table t532(i int not null, constraint c primary key(i) deferrable)",
+            "create table t532(i int, constraint c unique(i) deferrable)",
+            "create table t532(i int not null, constraint c unique(i) " + 
+                "deferrable)"};
+        
+        String[] cDeferrableTabNotYet = new String[]{
+            "create table t532(i int, constraint c foreign key(i) " + 
+                "references referenced(i) deferrable)",
+            "create table t532(i int, constraint c check(i>3) deferrable)"};
+
+        st.executeUpdate("create table referenced(i int primary key)");
+        commit();
+        
+        try {
+            switch (getPhase()) {
+            
+            case PH_CREATE:
+                for (String s : cDeferrableCol) {
+                    assertStatementError(SYNTAX_ERROR, st, s);
+                    assertStatementError(SYNTAX_ERROR, st, s);
+                }
+                
+                for (String s : cDeferrableColNotYet) {
+                    assertStatementError(SYNTAX_ERROR, st, s);
+                    assertStatementError(SYNTAX_ERROR, st, s);
+                }
+                break;
+                
+            case PH_POST_SOFT_UPGRADE:
+                for (String s : cDeferrableCol) {
+                    assertStatementError(SYNTAX_ERROR, st, s);
+                    assertStatementError(SYNTAX_ERROR, st, s);
+                }
+
+                for (String s : cDeferrableColNotYet) {
+                    assertStatementError(SYNTAX_ERROR, st, s);
+                    assertStatementError(SYNTAX_ERROR, st, s);
+                }
+                break;
+                
+            case PH_SOFT_UPGRADE:
+                for (String s : cDeferrableCol) {
+                    assertStatementError(HARD_UPGRADE_REQUIRED, st, s);
+                    assertStatementError(HARD_UPGRADE_REQUIRED, st, s);
+                }
+                
+                for (String s : cDeferrableColNotYet) {
+                    assertStatementError(HARD_UPGRADE_REQUIRED, st, s);
+                    assertStatementError(HARD_UPGRADE_REQUIRED, st, s);
+                }
+                break;
+                
+            case PH_HARD_UPGRADE:
+                for (String s : cDeferrableCol) {
+                    st.execute(s);
+                    rollback();
+                    st.execute(s);
+                    rollback();
+                }
+
+                for (String s : cDeferrableColNotYet) {
+                    assertStatementError(NOT_IMPLEMENTED, st, s);
+                    assertStatementError(NOT_IMPLEMENTED, st, s);
+                }
+                
+                break;
+            }
+        } finally {
+            st.executeUpdate("drop table referenced");
+            commit();
+        }
+    }
 }



Mime
View raw message