db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1593949 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/metadata.properties testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java
Date Mon, 12 May 2014 12:49:16 GMT
Author: dag
Date: Mon May 12 12:49:15 2014
New Revision: 1593949

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

Patch derby-532-metadata-queries: updates the metadata queries to give
correct results in the DEFERRABILITY column returned by the calls:

- DataBaseMetaData#getImportedKeys
- DataBaseMetaData#getExportedKeys
- DataBaseMetaData#getCrossReference.

Test have been added.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties
    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/jdbc/metadata.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties?rev=1593949&r1=1593948&r2=1593949&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties Mon May
12 12:49:15 2014
@@ -579,8 +579,16 @@ SELECT CAST ('' AS VARCHAR(128)) AS PKTA
 													AS SMALLINT) AS DELETE_RULE, \
 		C2.CONSTRAINTNAME AS FK_NAME, \
 		PK_NAME, \
-		CAST (java.sql.DatabaseMetaData::importedKeyNotDeferrable \
-												AS SMALLINT) AS DEFERRABILITY \
+        CAST ( \
+         (CASE WHEN C2.STATE = 'E'\
+          THEN java.sql.DatabaseMetaData::importedKeyNotDeferrable \
+          ELSE ( \
+             CASE WHEN C2.STATE = 'i'\
+             THEN java.sql.DatabaseMetaData::importedKeyInitiallyImmediate \
+             ELSE java.sql.DatabaseMetaData::importedKeyInitiallyDeferred \
+             END) \
+          END) \
+          AS SMALLINT) AS DEFERRABILITY \
 		FROM --DERBY-PROPERTIES joinOrder=FIXED \n\
 			(SELECT C.CONSTRAINTID AS PK_ID, \
 					CONSTRAINTNAME AS PK_NAME, \
@@ -682,8 +690,16 @@ SELECT CAST ('' AS VARCHAR(128)) AS PKTA
 													AS SMALLINT) AS DELETE_RULE, \
 		FK_NAME, \
 		CONSTRAINTNAME AS PK_NAME, \
-		CAST (java.sql.DatabaseMetaData::importedKeyNotDeferrable \
-												AS SMALLINT) AS DEFERRABILITY \
+        CAST ( \
+           (CASE WHEN DEFERREDSTATE = 'E'\
+            THEN java.sql.DatabaseMetaData::importedKeyNotDeferrable \
+            ELSE ( \
+               CASE WHEN DEFERREDSTATE = 'i'\
+               THEN java.sql.DatabaseMetaData::importedKeyInitiallyImmediate \
+               ELSE java.sql.DatabaseMetaData::importedKeyInitiallyDeferred \
+               END) \
+           END) \
+           AS SMALLINT) AS DEFERRABILITY \
 		FROM --DERBY-PROPERTIES joinOrder=FIXED \n\
 			(SELECT F2.keyCONSTRAINTID AS FK_ID, \
 					FKTB_SCHEMA AS FKTABLE_SCHEM, \
@@ -692,6 +708,7 @@ SELECT CAST ('' AS VARCHAR(128)) AS PKTA
 					CONGLOMS2.DESCRIPTOR.getKeyColumnPosition( \
 												COLS2.COLUMNNUMBER) AS KEY_SEQ, \
 					C2.CONSTRAINTNAME AS FK_NAME, \
+                    C2.STATE as DEFERREDSTATE, \
 					F2.DELETERULE AS FK_UPDATERULE, \
 					F2.DELETERULE AS FK_DELETERULE \
 					FROM --DERBY-PROPERTIES joinOrder=FIXED \n\
@@ -726,6 +743,7 @@ SELECT CAST ('' AS VARCHAR(128)) AS PKTA
 						FKCOLUMN_NAME, \
 						KEY_SEQ, \
 						FK_NAME, \
+                        DEFERREDSTATE, \
 						FK_UPDATERULE, \
 						FK_DELETERULE), \
 			SYS.SYSCONSTRAINTS c --DERBY-PROPERTIES joinStrategy=NESTEDLOOP, index = 'SYSCONSTRAINTS_INDEX1'
\n\

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=1593949&r1=1593948&r2=1593949&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
Mon May 12 12:49:15 2014
@@ -457,9 +457,51 @@ public class ConstraintCharacteristicsTe
             "create table t(i int not null " +
             "    constraint c primary key deferrable initially immediate)");
         final DatabaseMetaData dbmd = s.getConnection().getMetaData();
-        final ResultSet rs = dbmd.getIndexInfo(null, null, "T", false, false);
+        ResultSet rs = dbmd.getIndexInfo(null, null, "T", false, false);
         rs.next();
         assertEquals("false", rs.getString("NON_UNIQUE"));
+
+        // Test that we get the right values for DEFERRABILITY in
+        // getImportedKeys, getExportedKeys and getCrossReference
+
+        String[] cchars = new String[]{
+            "deferrable initially immediate",
+            "deferrable initially deferred",
+            "not deferrable"
+        };
+
+        int[] dbmdState = new int[]{
+            DatabaseMetaData.importedKeyInitiallyImmediate,
+            DatabaseMetaData.importedKeyInitiallyDeferred,
+            DatabaseMetaData.importedKeyNotDeferrable,
+        };
+
+        for (int i = 0; i < cchars.length; i++) {
+            s.executeUpdate(
+                    "create table child(i int, constraint c2 foreign key(i) " +
+                    "    references t(i) " + cchars[i] + ")");
+            rs = dbmd.getImportedKeys(null, null, "CHILD");
+            rs.next();
+            assertEquals(
+                    Integer.toString(dbmdState[i]),
+                    rs.getString("DEFERRABILITY"));
+            rs.close();
+
+            rs = dbmd.getExportedKeys(null, null, "T");
+            rs.next();
+            assertEquals(
+                    Integer.toString(dbmdState[i]),
+                    rs.getString("DEFERRABILITY"));
+            rs.close();
+
+            rs = dbmd.getCrossReference(null, null, "T", null, null, "CHILD");
+            rs.next();
+            assertEquals(
+                    Integer.toString(dbmdState[i]),
+                    rs.getString("DEFERRABILITY"));
+            rs.close();
+            s.executeUpdate("drop table child");
+        }
     }
 
 



Mime
View raw message