db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r910255 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apache/derbyTesting/junit/
Date Mon, 15 Feb 2010 16:37:19 GMT
Author: rhillegas
Date: Mon Feb 15 16:37:17 2010
New Revision: 910255

URL: http://svn.apache.org/viewvc?rev=910255&view=rev
Log:
DERBY-712: Only allow RESTRICTed drops of sequences.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SequenceDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    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/SequenceGeneratorTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequencePermsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.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/iapi/sql/dictionary/SequenceDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SequenceDescriptor.java?rev=910255&r1=910254&r2=910255&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SequenceDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SequenceDescriptor.java
Mon Feb 15 16:37:17 2010
@@ -124,7 +124,7 @@
     }
 
     /**
-     * Drop this sequence descriptor
+     * Drop this sequence descriptor. Only restricted drops allowed right now.
      *
      * @throws StandardException Could not be dropped.
      */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=910255&r1=910254&r2=910255&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Mon Feb
15 16:37:17 2010
@@ -10254,9 +10254,9 @@
 }
 {
 	/*
-	 * DROP SEQUENCE <sequencename>
+	 * DROP SEQUENCE <sequencename> RESTRICT
 	 */
-	<SEQUENCE> sequenceName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH)
+	<SEQUENCE> sequenceName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH) <RESTRICT>
 	{
 		checkVersion( DataDictionary.DD_VERSION_DERBY_10_6, "SEQUENCES");
 

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=910255&r1=910254&r2=910255&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
Mon Feb 15 16:37:17 2010
@@ -95,7 +95,7 @@
     protected static  final   String  GRANT_REVOKE_NOT_ALLOWED = "42509";
     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  VIEW_DEPENDENCY = "X0Y23";
     protected static  final   String  NON_EMPTY_SCHEMA = "X0Y54";
     protected static  final   String  JAVA_EXCEPTION = "XJ001";
     protected static  final   String  ILLEGAL_UDT_CLASS = "42Z10";
@@ -105,6 +105,7 @@
     protected static  final   String  ILLEGAL_STORAGE = "42821";
     protected static  final   String  BAD_CAST = "42846";
     protected static  final   String  DUPLICATE_CLAUSE = "42XAJ";
+    protected static  final   String  FORBIDDEN_DROP_TRIGGER = "X0Y24";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -448,6 +449,47 @@
     }
 
     /**
+     * Test that a restricted drop is blocked by an object.
+     */
+    protected void verifyRestrictedDrop
+        (
+         Connection conn,
+         String createDependentObject,
+         String dropDependentObject,
+         String createStatement,
+         String dropStatement,
+         String badDropState
+         ) throws Exception
+    {
+        goodStatement
+            (
+             conn,
+             createStatement
+             );
+        goodStatement
+            (
+             conn,
+             createDependentObject
+             );
+        expectExecutionError
+            (
+             conn,
+             badDropState,
+             dropStatement
+             );
+        goodStatement
+            (
+             conn,
+             dropDependentObject
+             );
+        goodStatement
+            (
+             conn,
+             dropStatement
+             );
+    }
+
+    /**
      * <p>
      * Fill an ArrayList from an array.
      * </p>

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java?rev=910255&r1=910254&r2=910255&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java
Mon Feb 15 16:37:17 2010
@@ -533,7 +533,7 @@
         }
 
         goodStatement( conn, "values( next value for seq_07 )\n" );
-        goodStatement( conn, "drop sequence seq_07\n" );
+        goodStatement( conn, "drop sequence seq_07 restrict\n" );
         
         expectCompilationError( OBJECT_DOES_NOT_EXIST, "values ( next value for seq_07 )\n"
);
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequencePermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequencePermsTest.java?rev=910255&r1=910254&r2=910255&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequencePermsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequencePermsTest.java
Mon Feb 15 16:37:17 2010
@@ -258,7 +258,7 @@
         // view
         createStatement = "create view v_01( a, b ) as select c, next value for ruth.seq_02
from t_01\n";
         dropStatement = "drop view v_01\n";
-        badRevokeSQLState = VIEW_DEPENDS_ON_PRIVILEGE;
+        badRevokeSQLState = VIEW_DEPENDENCY;
         verifyRevokePrivilege
             (
              ruthConnection,
@@ -322,7 +322,7 @@
         expectExecutionError( dboConnection, NON_EMPTY_SCHEMA, "drop schema irma restrict\n"
);
 
         goodStatement
-            (irmaConnection, "drop sequence seq_01\n" );
+            (irmaConnection, "drop sequence seq_01 restrict\n" );
        goodStatement
             ( dboConnection, "drop schema irma restrict\n" );
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java?rev=910255&r1=910254&r2=910255&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
Mon Feb 15 16:37:17 2010
@@ -79,7 +79,7 @@
     public void test_02_DropSequence() throws SQLException {
         Statement s = createStatement();
         s.executeUpdate("CREATE SEQUENCE mySeq1");
-        s.executeUpdate("DROP SEQUENCE mySeq1");
+        s.executeUpdate("DROP SEQUENCE mySeq1 restrict");
     }
 
     public void test_03_DuplicateCreationFailure() throws SQLException {
@@ -91,7 +91,7 @@
         } catch (SQLException sqle) {
             assertSQLState("X0Y68", sqle);
         }finally{
-            s.executeUpdate("DROP SEQUENCE mySeq1"); // Drop the one created.
+            s.executeUpdate("DROP SEQUENCE mySeq1 restrict"); // Drop the one created.
         }
     }
 
@@ -103,7 +103,7 @@
 
         // should implicitly create schema ALPHA
         stmt.executeUpdate("CREATE SEQUENCE alpha_seq");
-        stmt.executeUpdate("DROP SEQUENCE alpha_seq");
+        stmt.executeUpdate("DROP SEQUENCE alpha_seq restrict");
         stmt.close();
         alphaCon.close();
         adminCon.close();
@@ -117,7 +117,7 @@
 
         // should implicitly create schema ALPHA
         stmt.executeUpdate("CREATE SEQUENCE alpha.alpha_seq");
-        stmt.executeUpdate("DROP SEQUENCE alpha.alpha_seq");
+        stmt.executeUpdate("DROP SEQUENCE alpha.alpha_seq restrict");
         stmt.close();
         alphaCon.close();
     }
@@ -128,7 +128,7 @@
 
         // should implicitly create schema ALPHA
         stmt.executeUpdate("CREATE SEQUENCE alpha.alpha_seq");
-        stmt.executeUpdate("DROP SEQUENCE alpha.alpha_seq");
+        stmt.executeUpdate("DROP SEQUENCE alpha.alpha_seq restrict");
         stmt.close();
         alphaCon.close();
     }
@@ -139,7 +139,7 @@
 
         // should implicitly create schema ALPHA
         stmt.executeUpdate("CREATE SEQUENCE alpha.alpha_seq");
-        stmt.executeUpdate("DROP SEQUENCE alpha_seq");
+        stmt.executeUpdate("DROP SEQUENCE alpha_seq restrict");
         stmt.close();
         alphaCon.close();
     }
@@ -158,10 +158,10 @@
         Statement stmtBeta = betaCon.createStatement();
 
         // should implicitly create schema ALPHA
-        assertStatementError("42507", stmtBeta, "DROP SEQUENCE alpha.alpha_seq");
+        assertStatementError("42507", stmtBeta, "DROP SEQUENCE alpha.alpha_seq restrict");
 
         // Cleanup:
-        stmtAlpha.executeUpdate("DROP SEQUENCE alpha_seq");
+        stmtAlpha.executeUpdate("DROP SEQUENCE alpha_seq restrict");
         
         stmtAlpha.close();
         stmtBeta.close();
@@ -188,7 +188,7 @@
         assertStatementError("42507", stmtBeta, "CREATE SEQUENCE alpha.alpha_seq3");
 
         // Cleanup:
-        stmtAlpha.executeUpdate("DROP SEQUENCE alpha_seq");
+        stmtAlpha.executeUpdate("DROP SEQUENCE alpha_seq restrict");
         
         stmtAlpha.close();
         stmtBeta.close();
@@ -470,5 +470,53 @@
         ps.close();
     }
 
+    /**
+     * Verify that restricted drops prevent objects from being orphaned.
+     */
+    public void test_13_restrictedDrop() throws Exception
+    {
+        Connection conn = openUserConnection(ALPHA);
+
+        goodStatement( conn, "create table t_13_a( a int )" );
+        goodStatement( conn, "create table t_13_b( a int )" );
+
+        String createStatement;
+        String dropStatement;
+        String createDependentObject;
+        String dropDependentObject;
+        String badDropState;
+
+        createStatement = "create sequence seq_13_a";
+        dropStatement = "drop sequence seq_13_a restrict";
+        createDependentObject = "create trigger trig_13 after insert on t_13_a for each row
insert into t_13_b( a ) values ( next value for seq_13_a )\n";
+        dropDependentObject = "drop trigger trig_13";
+        badDropState = FORBIDDEN_DROP_TRIGGER;
+        verifyRestrictedDrop
+            (
+             conn,
+             createDependentObject,
+             dropDependentObject,
+             createStatement,
+             dropStatement,
+             badDropState
+             );
+        
+        createStatement = "create sequence seq_13_b";
+        dropStatement = "drop sequence seq_13_b restrict";
+        createDependentObject = "create view v_13( a, b ) as select a, next value for seq_13_b
from t_13_a\n";
+        dropDependentObject = "drop view v_13";
+        badDropState = VIEW_DEPENDENCY;
+        verifyRestrictedDrop
+            (
+             conn,
+             createDependentObject,
+             dropDependentObject,
+             createStatement,
+             dropStatement,
+             badDropState
+             );
+
+    }
+
 
 }

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=910255&r1=910254&r2=910255&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
Mon Feb 15 16:37:17 2010
@@ -374,7 +374,7 @@
         // can't revoke USAGE if a view depends on it
         createStatement = "create view v_alice_02( a ) as select cast (null as ruth.price_ruth_02_a
) from sys.systables\n";
         dropStatement = "drop view v_alice_02\n";
-        badRevokeSQLState = VIEW_DEPENDS_ON_PRIVILEGE;
+        badRevokeSQLState = VIEW_DEPENDENCY;
         verifyRevokePrivilege
             (
              ruthConnection,

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=910255&r1=910254&r2=910255&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 Mon Feb 15 16:37:17
2010
@@ -389,7 +389,7 @@
 		{
             String objectName = rs.getString(mdColumn);
             String raw = dropLeadIn + JDBC.escape(schema, objectName);
-            if ( "TYPE".equals( dropType ) ) { raw = raw + " restrict "; }
+            if ( "TYPE".equals( dropType )  || "SEQUENCE".equals( dropType ) ) { raw = raw
+ " restrict "; }
             ddl.add( raw );
 		}
 		rs.close();



Mime
View raw message