db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1548032 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests: jdbcapi/DatabaseMetaDataTest.java upgradeTests/Changes10_11.java
Date Thu, 05 Dec 2013 07:41:45 GMT
Author: kahatlen
Date: Thu Dec  5 07:41:45 2013
New Revision: 1548032

URL: http://svn.apache.org/r1548032
Log:
DERBY-2041: Trigger should register a dependency on tables and columns used in its body

Add an upgrade test to verify how the dependencies are handled after
upgrade and downgrade.

Skip some cross checking between getColumns() and ResultSetMetaData
for views in DatabaseMetaDataTest, since those checks only pass for
tables. The upgrade test case adds a view that upsets the meta-data
test. (This is the first upgrade test that uses views.)

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
    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/jdbcapi/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?rev=1548032&r1=1548031&r2=1548032&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Thu Dec  5 07:41:45 2013
@@ -1874,13 +1874,28 @@ public class DatabaseMetaDataTest extend
     {
         int col = rs.getInt("ORDINAL_POSITION");
         Version dataVersion = getDataVersion( getConnection() );
-        
-        assertEquals("RSMD.getCatalogName",
-                rsmdt.getCatalogName(col), rs.getString("TABLE_CAT"));
-        assertEquals("RSMD.getSchemaName",
-                rsmdt.getSchemaName(col), rs.getString("TABLE_SCHEM"));
-        assertEquals("RSMD.getTableName",
-                rsmdt.getTableName(col), rs.getString("TABLE_NAME"));
+
+        String catalogName = rs.getString("TABLE_CAT");
+        String schemaName = rs.getString("TABLE_SCHEM");
+        String tableName = rs.getString("TABLE_NAME");
+
+        // Check that the catalog/schema/table names reported by the
+        // ResultSetMetaData are correct. Note that for views, RSMD will
+        // return data for the underlying table, not for the view itself.
+        // Therefore, skip the check for views.
+        ResultSet views =
+            rs.getStatement().getConnection().getMetaData().getTables(
+                    catalogName, schemaName, tableName, JDBC.GET_TABLES_VIEW);
+        boolean isView = JDBC.assertDrainResults(views) > 0;
+
+        if (!isView) {
+            assertEquals("RSMD.getCatalogName",
+                         catalogName, rsmdt.getCatalogName(col));
+            assertEquals("RSMD.getSchemaName",
+                         schemaName, rsmdt.getSchemaName(col));
+            assertEquals("RSMD.getTableName",
+                         tableName, rsmdt.getTableName(col));
+        }
         
         assertEquals("COLUMN_NAME",
                 rsmdt.getColumnName(col), rs.getString("COLUMN_NAME"));

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=1548032&r1=1548031&r2=1548032&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
Thu Dec  5 07:41:45 2013
@@ -104,4 +104,127 @@ public class Changes10_11 extends Upgrad
                 break;
         }
     }
+
+    /**
+     * Test how dropping trigger dependencies works across upgrade and
+     * downgrade. Regression test for DERBY-2041.
+     */
+    public void testDropTriggerDependencies() throws SQLException {
+        if (!oldAtLeast(10, 2)) {
+            // Support for SYNONYMS was added in 10.1. Support for CALL
+            // statements in trigger actions was added in 10.2. Since this
+            // test case uses both of those features, skip it on the oldest
+            // versions.
+            return;
+        }
+
+        setAutoCommit(false);
+        Statement s = createStatement();
+        switch (getPhase()) {
+            case PH_CREATE:
+                // Let's create some objects to use in the triggers.
+                s.execute("create table d2041_t(x int)");
+                s.execute("create table d2041_table(x int)");
+                s.execute("create table d2041_synonym_table(x int)");
+                s.execute("create synonym d2041_synonym "
+                        + "for d2041_synonym_table");
+                s.execute("create view d2041_view(x) as values 1");
+                s.execute("create function d2041_func(i int) returns int "
+                        + "language java parameter style java "
+                        + "external name 'java.lang.Math.abs' no sql");
+                s.execute("create procedure d2041_proc() "
+                        + "language java parameter style java "
+                        + "external name 'java.lang.Thread.yield' no sql");
+
+                // Create the triggers with the old version.
+                createDerby2041Triggers(s);
+                commit();
+                break;
+            case PH_SOFT_UPGRADE:
+                // Drop the trigger dependencies. Since the triggers were
+                // created with the old version, the dependencies were not
+                // registered, so expect the DROP operations to succeed.
+                dropDerby2041TriggerDeps(s, false);
+
+                // The triggers still exist, so it is possible to drop them.
+                dropDerby2041Triggers(s);
+
+                // We want to use the objects further, so roll back the
+                // DROP operations.
+                rollback();
+
+                // Recreate the triggers with the new version.
+                dropDerby2041Triggers(s);
+                createDerby2041Triggers(s);
+                commit();
+
+                // Dropping the dependencies now should fail.
+                dropDerby2041TriggerDeps(s, true);
+                break;
+            case PH_POST_SOFT_UPGRADE:
+                // After downgrade, the behaviour isn't quite consistent. The
+                // dependencies were registered when the triggers were created
+                // with the new version, but the old versions only have code
+                // to detect some of the dependencies. So some will fail and
+                // others will succeed.
+
+                // Dependencies on tables and synonyms are detected.
+                assertStatementError("X0Y25", s, "drop table d2041_table");
+                assertStatementError("X0Y25", s, "drop synonym d2041_synonym");
+
+                // Dependencies on views, functions and procedures are not
+                // detected.
+                s.execute("drop view d2041_view");
+                s.execute("drop function d2041_func");
+                s.execute("drop procedure d2041_proc");
+
+                // Restore the database state.
+                rollback();
+                break;
+            case PH_HARD_UPGRADE:
+                // In hard upgrade, we should be able to detect the
+                // dependencies registered when the triggers were created
+                // in the soft-upgraded database.
+                dropDerby2041TriggerDeps(s, true);
+        }
+    }
+
+    private void createDerby2041Triggers(Statement s) throws SQLException {
+        s.execute("create trigger d2041_tr1 after insert on d2041_t "
+                + "for each row mode db2sql insert into d2041_table values 1");
+        s.execute("create trigger d2041_tr2 after insert on d2041_t "
+                + "for each row mode db2sql "
+                + "insert into d2041_synonym values 1");
+        s.execute("create trigger d2041_tr3 after insert on d2041_t "
+                + "for each row mode db2sql select * from d2041_view");
+        s.execute("create trigger d2041_tr4 after insert on d2041_t "
+                + "for each row mode db2sql values d2041_func(1)");
+        s.execute("create trigger d2041_tr5 after insert on d2041_t "
+                + "for each row mode db2sql call d2041_proc()");
+    }
+
+    private void dropDerby2041Triggers(Statement s) throws SQLException {
+        for (int i = 1; i <= 5; i++) {
+            s.execute("drop trigger d2041_tr" + i);
+        }
+    }
+
+    private void dropDerby2041TriggerDeps(Statement s, boolean expectFailure)
+            throws SQLException {
+        String[] stmts = {
+            "drop table d2041_table",
+            "drop synonym d2041_synonym",
+            "drop view d2041_view",
+            "drop function d2041_func",
+            "drop procedure d2041_proc",
+        };
+
+        for (String stmt : stmts) {
+            if (expectFailure) {
+                assertStatementError("X0Y25", s, stmt);
+            } else {
+                assertUpdateCount(s, 0, stmt);
+            }
+        }
+    }
 }



Mime
View raw message