db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r889822 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Fri, 11 Dec 2009 21:32:26 GMT
Author: rhillegas
Date: Fri Dec 11 21:32:26 2009
New Revision: 889822

URL: http://svn.apache.org/viewvc?rev=889822&view=rev
Log:
DERBY-651: Wire UDT dependency dropping logic into DROP TABLE.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DDLConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropTableConstantAction.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=889822&r1=889821&r2=889822&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
Fri Dec 11 21:32:26 2009
@@ -511,7 +511,7 @@
 		}
 
         // adjust dependencies on user defined types
-        adjustUDTDependencies( lcc, dd, td, columnInfo );
+        adjustUDTDependencies( lcc, dd, td, columnInfo, false );
 
 		/* Create/Drop any constraints */
 		if (constraintActions != null)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java?rev=889822&r1=889821&r2=889822&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java
Fri Dec 11 21:32:26 2009
@@ -370,7 +370,7 @@
         //
         // The table itself can depend on the user defined types of its columns.
         //
-        adjustUDTDependencies( lcc, dd, td, columnInfo );
+        adjustUDTDependencies( lcc, dd, td, columnInfo, false );
         
 		if ( tableType == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE )
 		{

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DDLConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DDLConstantAction.java?rev=889822&r1=889821&r2=889822&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DDLConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DDLConstantAction.java
Fri Dec 11 21:32:26 2009
@@ -820,17 +820,18 @@
     protected   void    adjustUDTDependencies
         (
          LanguageConnectionContext  lcc,
-         DataDictionary     dd,
-         TableDescriptor    td,
-         ColumnInfo[]        columnInfos
+         DataDictionary             dd,
+         TableDescriptor            td,
+         ColumnInfo[]               columnInfos,
+         boolean                    dropWholeTable
          )
         throws StandardException
     {
-        if ( columnInfos == null ) { return; }
+        if ( (!dropWholeTable) && (columnInfos == null) ) { return; }
 
 		TransactionController tc = lcc.getTransactionExecute();
 
-        int changedColumnCount = columnInfos.length;
+        int changedColumnCount = columnInfos == null ? 0 : columnInfos.length;
         HashMap addUdtMap = new HashMap();
         HashMap dropUdtMap = new HashMap();
         HashSet addColumnNames = new HashSet();
@@ -864,8 +865,9 @@
             }
         }
 
-        // nothing to do if there are no columns of udt type
-        if ( (addUdtMap.size() == 0) && (dropUdtMap.size() == 0) ) { return; }
+        // nothing to do if there are no changed columns of udt type
+        // and this is not a DROP TABLE command
+        if ( (!dropWholeTable) && (addUdtMap.size() == 0) && (dropUdtMap.size()
== 0) ) { return; }
 
         //
         // Now prune from the add list all udt descriptors for which we already have dependencies.
@@ -894,10 +896,13 @@
 
             String key = ad.getObjectID().toString();
 
-            // ha, it is a UDT. remove the UDT from the list of dependencies to
-            // add and drop
-            if ( addUdtMap.get( key ) != null ) { addUdtMap.remove( key ); }
-            if ( dropUdtMap.get( key ) != null ) { dropUdtMap.remove( key ); }
+            // ha, it is a UDT.
+            if ( dropWholeTable ) { dropUdtMap.put( key, ad ); }
+            else
+            {
+                if ( addUdtMap.get( key ) != null ) { addUdtMap.remove( key ); }
+                if ( dropUdtMap.get( key ) != null ) { dropUdtMap.remove( key ); }
+            }
         }
 
         // again, nothing to do if there are no columns of udt type

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropTableConstantAction.java?rev=889822&r1=889821&r2=889822&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropTableConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropTableConstantAction.java
Fri Dec 11 21:32:26 2009
@@ -266,6 +266,12 @@
 
 		dm.invalidateFor(td, DependencyManager.DROP_TABLE, lcc);
 
+        //
+        // The table itself can depend on the user defined types of its columns.
+        // Drop all of those dependencies now.
+        //
+        adjustUDTDependencies( lcc, dd, td, null, true );
+
 		/* Drop the table */
 		dd.dropTableDescriptor(td, sd, tc);
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java?rev=889822&r1=889821&r2=889822&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
Fri Dec 11 21:32:26 2009
@@ -350,9 +350,68 @@
         goodStatement
             ( conn,
               "drop type Price_03_a restrict\n" );
-
     }
 
+    /**
+     * <p>
+     * Dropping a whole table which has udt columns.
+     * </p>
+     */
+    public void test_04_dropTable() throws Exception
+    {
+        Connection conn = getConnection();
+
+        goodStatement
+            ( conn,
+              "create type price_orphan external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java\n" );
+        goodStatement
+            ( conn,
+              "create type price_orphan2 external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java\n" );
+        goodStatement
+            ( conn,
+              "create type price_orphan3 external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java\n" );
+        goodStatement
+            ( conn,
+              "create type price_orphan4 external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java\n" );
+        goodStatement
+            ( conn,
+              "create table t_orphan( a price_orphan )\n" );
+        goodStatement
+            ( conn,
+              "create table t_orphan2( a price_orphan2, b int, c price_orphan2 )\n" );
+        goodStatement
+            ( conn,
+              "create table t_orphan3( a price_orphan3, b int, c price_orphan4 )\n" );
+        
+        expectExecutionError( conn, TABLE_DEPENDS_ON_TYPE, "drop type price_orphan restrict\n"
);
+        goodStatement
+            ( conn,
+              "drop table t_orphan\n" );
+        goodStatement
+            ( conn,
+              "drop type price_orphan restrict\n" );
+        
+        expectExecutionError( conn, TABLE_DEPENDS_ON_TYPE, "drop type price_orphan2 restrict\n"
);
+        goodStatement
+            ( conn,
+              "drop table t_orphan2\n" );
+        goodStatement
+            ( conn,
+              "drop type price_orphan2 restrict\n" );
+        
+        expectExecutionError( conn, TABLE_DEPENDS_ON_TYPE, "drop type price_orphan3 restrict\n"
);
+        expectExecutionError( conn, TABLE_DEPENDS_ON_TYPE, "drop type price_orphan4 restrict\n"
);
+        goodStatement
+            ( conn,
+              "drop table t_orphan3\n" );
+        goodStatement
+            ( conn,
+              "drop type price_orphan3 restrict\n" );
+        goodStatement
+            ( conn,
+              "drop type price_orphan4 restrict\n" );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS



Mime
View raw message