db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r892485 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/catalog/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apache/derbyTesting/junit/
Date Sat, 19 Dec 2009 16:37:31 GMT
Author: rhillegas
Date: Sat Dec 19 16:37:31 2009
New Revision: 892485

URL: http://svn.apache.org/viewvc?rev=892485&view=rev
Log:
DERBY-651: Prevent a schema from being dropped if it contains any UDTs.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTPermsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=892485&r1=892484&r2=892485&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Sat Dec 19 16:37:31 2009
@@ -2239,7 +2239,16 @@
 			return false;
 		}
 
-        // This catalog was added in 10.6. Don't look for this catalog if we
+        // don't orphan routines or UDTs
+		if (isSchemaReferenced(tc, getNonCoreTI(SYSALIASES_CATALOG_NUM),
+					SYSALIASESRowFactory.SYSALIASES_INDEX1_ID,
+					1,
+					schemaIdOrderable))
+		{
+			return false;
+		}
+
+        // These catalogs were added in 10.6. Don't look for these catalogs if we
         // have soft-upgraded from an older release.
         if( dictionaryVersion.majorVersionNumber >= DataDictionary.DD_VERSION_DERBY_10_6)
         {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java?rev=892485&r1=892484&r2=892485&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
Sat Dec 19 16:37:31 2009
@@ -93,6 +93,7 @@
     protected static  final   String  ROUTINE_DEPENDS_ON_TYPE = "X0Y30";
     protected static  final   String  TABLE_DEPENDS_ON_TYPE = "X0Y29";
     protected static  final   String  VIEW_DEPENDS_ON_PRIVILEGE = "X0Y23";
+    protected static  final   String  NON_EMPTY_SCHEMA = "X0Y54";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTPermsTest.java?rev=892485&r1=892484&r2=892485&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTPermsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTPermsTest.java
Sat Dec 19 16:37:31 2009
@@ -59,7 +59,8 @@
     private static  final   String      TEST_DBO = "TEST_DBO";
     private static  final   String      RUTH = "RUTH";
     private static  final   String      ALICE = "ALICE";
-    private static  final   String[]    LEGAL_USERS = { TEST_DBO, ALICE, RUTH  };
+    private static  final   String      FRANK = "FRANK";
+    private static  final   String[]    LEGAL_USERS = { TEST_DBO, ALICE, RUTH, FRANK  };
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -405,4 +406,31 @@
              );
     }
     
+  /**
+     * <p>
+     * Test that you can't drop a schema if it contains a UDT or routine.
+     * </p>
+     */
+    public  void    test_003_dropSchema()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+        Connection  frankConnection = openUserConnection( FRANK );
+
+        goodStatement
+            ( frankConnection, "create function f_frank_03( a int ) returns int language
java parameter style java no sql external name 'foo.bar.Wibble'\n" );
+        expectExecutionError( dboConnection, NON_EMPTY_SCHEMA, "drop schema frank restrict\n"
);
+
+        goodStatement
+            (frankConnection, "drop function f_frank_03\n" );
+        goodStatement
+            ( frankConnection, "create type price_frank_03_a external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java\n" );
+        expectExecutionError( dboConnection, NON_EMPTY_SCHEMA, "drop schema frank restrict\n"
);
+
+        goodStatement
+            ( frankConnection, "drop type price_frank_03_a restrict\n" );
+        goodStatement
+            ( dboConnection, "drop schema frank restrict\n" );
+    }
+    
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?rev=892485&r1=892484&r2=892485&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Sat Dec 19 16:37:31
2009
@@ -238,13 +238,13 @@
         PreparedStatement psf = conn.prepareStatement(
                 "SELECT ALIAS FROM SYS.SYSALIASES A, SYS.SYSSCHEMAS S" +
                 " WHERE A.SCHEMAID = S.SCHEMAID " +
-                " AND CHAR(A.ALIASTYPE) = 'F' " +
+                " AND CHAR(A.ALIASTYPE) = ? " +
                 " AND S.SCHEMANAME = ?");
-        psf.setString(1, schema);
+        psf.setString(1, "F" );
+        psf.setString(2, schema);
         ResultSet rs = psf.executeQuery();
         dropUsingDMD(s, rs, schema, "ALIAS", "FUNCTION");        
-        psf.close();
-  
+
 		// Procedures
 		rs = dmd.getProcedures((String) null,
 				schema, (String) null);
@@ -300,6 +300,13 @@
                 GET_TABLES_TABLE);        
         dropUsingDMD(s, rs, schema, "TABLE_NAME", "TABLE");
 
+        // drop UDTs
+        psf.setString(1, "A" );
+        psf.setString(2, schema);
+        rs = psf.executeQuery();
+        dropUsingDMD(s, rs, schema, "ALIAS", "TYPE");        
+        psf.close();
+  
         // Synonyms - need work around for DERBY-1790 where
         // passing a table type of SYNONYM fails.
         rs = dmd.getTables((String) null, schema, (String) null,
@@ -342,7 +349,9 @@
 		while (rs.next())
 		{
             String objectName = rs.getString(mdColumn);
-            ddl.add(dropLeadIn + JDBC.escape(schema, objectName));
+            String raw = dropLeadIn + JDBC.escape(schema, objectName);
+            if ( "TYPE".equals( dropType ) ) { raw = raw + " restrict "; }
+            ddl.add( raw );
 		}
 		rs.close();
         if (ddl.isEmpty())



Mime
View raw message