db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1401303 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Tue, 23 Oct 2012 14:30:01 GMT
Author: rhillegas
Date: Tue Oct 23 14:30:01 2012
New Revision: 1401303

URL: http://svn.apache.org/viewvc?rev=1401303&view=rev
Log:
DERBY-672: Add support and tests for dependencies between user-defined types and aggregates.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DDLConstantAction.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java

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=1401303&r1=1401302&r2=1401303&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
Tue Oct 23 14:30:01 2012
@@ -30,6 +30,7 @@ import org.apache.derby.catalog.AliasInf
 import org.apache.derby.catalog.DependableFinder;
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.catalog.TypeDescriptor;
+import org.apache.derby.catalog.types.AggregateAliasInfo;
 import org.apache.derby.catalog.types.RoutineAliasInfo;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
@@ -988,22 +989,30 @@ abstract class DDLConstantAction impleme
          )
         throws StandardException
     {
+        RoutineAliasInfo      routineInfo = null;
+        AggregateAliasInfo  aggInfo = null;
+        
         // nothing to do if this is not a routine
         switch ( ad.getAliasType() )
         {
+		case AliasInfo.ALIAS_TYPE_AGGREGATE_AS_CHAR:
+            aggInfo = (AggregateAliasInfo) ad.getAliasInfo();
+            break;
+
 		case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 		case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
+            routineInfo = (RoutineAliasInfo) ad.getAliasInfo();
             break;
 
         default: return;
         }
         
 		TransactionController tc = lcc.getTransactionExecute();
-        RoutineAliasInfo      aliasInfo = (RoutineAliasInfo) ad.getAliasInfo();
         HashMap               addUdtMap = new HashMap();
         HashMap               dropUdtMap = new HashMap();
         HashMap               udtMap = adding ? addUdtMap : dropUdtMap;
-        TypeDescriptor        rawReturnType = aliasInfo.getReturnType();
+        TypeDescriptor        rawReturnType = aggInfo != null ?
+            aggInfo.getReturnType() : routineInfo.getReturnType();
 
         if ( rawReturnType != null )
         {
@@ -1028,7 +1037,8 @@ abstract class DDLConstantAction impleme
             }
         }
 
-        TypeDescriptor[]      paramTypes = aliasInfo.getParameterTypes();
+        TypeDescriptor[]      paramTypes = aggInfo != null ?
+            new TypeDescriptor[] { aggInfo.getForType() } : routineInfo.getParameterTypes();
         if ( paramTypes != null )
         {
             int paramCount = paramTypes.length;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java?rev=1401303&r1=1401302&r2=1401303&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java
Tue Oct 23 14:30:01 2012
@@ -328,4 +328,115 @@ public class UDAPermsTest extends Genera
              );
     }
     
+   /**
+     * <p>
+     * Test that you need USAGE privilege on user-defined types in order to use them in
+     * user-defined aggregates.
+     * </p>
+     */
+    public  void    test_003_typePrivs()
+        throws Exception
+    {
+        Connection  ruthConnection = openUserConnection( RUTH );
+        Connection  aliceConnection = openUserConnection( ALICE );
+
+        // can't revoke USAGE on a type if an aggregate's input/return depends on it
+        goodStatement
+            (
+             ruthConnection,
+             "create type Price external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java"
+             );
+
+        String grantUsage = "grant usage on type Price to public";
+        String revokeUsage = "revoke usage on type Price from public restrict";
+        String createStatement =
+            "create derby aggregate priceMode for ruth.Price\n" +
+            "external name 'org.apache.derbyTesting.functionTests.tests.lang.GenericMode'\n";
+        String dropStatement = "drop derby aggregate priceMode restrict";
+        String badRevokeSQLState = ROUTINE_DEPENDS_ON_TYPE;
+
+        verifyRevokePrivilege
+            (
+             ruthConnection,
+             aliceConnection,
+             grantUsage,
+             revokeUsage,
+             createStatement,
+             dropStatement,
+             badRevokeSQLState
+             );
+        
+        // can't revoke USAGE on a type if an aggregate's input depends on it
+        goodStatement
+            (
+             ruthConnection,
+             "create type Price_input external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java"
+             );
+        goodStatement
+            (
+             ruthConnection,
+             "create type Price_return external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java"
+             );
+        goodStatement
+            (
+             ruthConnection,
+             "grant usage on type Price_return to public"
+             );
+
+        grantUsage = "grant usage on type Price_input to public";
+        revokeUsage = "revoke usage on type Price_input from public restrict";
+        createStatement =
+            "create derby aggregate priceMode for ruth.Price_input returns ruth.Price_return\n"
+
+            "external name 'org.apache.derbyTesting.functionTests.tests.lang.GenericMode'\n";
+        dropStatement = "drop derby aggregate priceMode restrict";
+        badRevokeSQLState = ROUTINE_DEPENDS_ON_TYPE;
+        
+        verifyRevokePrivilege
+            (
+             ruthConnection,
+             aliceConnection,
+             grantUsage,
+             revokeUsage,
+             createStatement,
+             dropStatement,
+             badRevokeSQLState
+             );
+        
+        // can't revoke USAGE on a type if an aggregate's return value depends on it
+        goodStatement
+            (
+             ruthConnection,
+             "create type Price_input_2 external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java"
+             );
+        goodStatement
+            (
+             ruthConnection,
+             "create type Price_return_2 external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java"
+             );
+        goodStatement
+            (
+             ruthConnection,
+             "grant usage on type Price_input_2 to public"
+             );
+
+        grantUsage = "grant usage on type Price_return_2 to public";
+        revokeUsage = "revoke usage on type Price_return_2 from public restrict";
+        createStatement =
+            "create derby aggregate priceMode for ruth.Price_input_2 returns ruth.Price_return_2\n"
+
+            "external name 'org.apache.derbyTesting.functionTests.tests.lang.GenericMode'\n";
+        dropStatement = "drop derby aggregate priceMode restrict";
+        badRevokeSQLState = ROUTINE_DEPENDS_ON_TYPE;
+        
+        verifyRevokePrivilege
+            (
+             ruthConnection,
+             aliceConnection,
+             grantUsage,
+             revokeUsage,
+             createStatement,
+             dropStatement,
+             badRevokeSQLState
+             );
+    }
+    
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java?rev=1401303&r1=1401302&r2=1401303&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java
Tue Oct 23 14:30:01 2012
@@ -74,6 +74,7 @@ public class UserDefinedAggregatesTest  
     public static final String MISSING_CLASS = "42ZC8";
     public static final String AGG_IN_ON_CLAUSE = "42Z07";
     public static final String BAD_CONSTRAINT = "42Y01";
+    public static final String DEPENDENCY_VIOLATION = "X0Y30";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -2258,4 +2259,54 @@ public class UserDefinedAggregatesTest  
         
     }
 
+    /**
+     * <p>
+     * Verify that you can't drop a user-defined type if a user-defined aggregate depends
on it.
+     * </p>
+     */
+    public void test_17_udtDependencies() throws Exception
+    {
+        Connection conn = getConnection();
+
+        goodStatement
+            (
+             conn,
+             "create type Price_17 external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java"
+             );
+        goodStatement
+            (
+             conn,
+             "create type Price_17_2 external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java"
+             );
+        goodStatement
+            (
+             conn,
+             "create derby aggregate priceMode_17 for Price_17 returns Price_17_2\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.GenericMode'\n"
+             );
+
+        // can't drop the types because the aggregate depends on them
+        expectExecutionError
+            ( conn, DEPENDENCY_VIOLATION, "drop type Price_17 restrict" );
+        expectExecutionError
+            ( conn, DEPENDENCY_VIOLATION, "drop type Price_17_2 restrict" );
+
+        // once you drop the aggregate, you can drop the types
+        goodStatement
+            (
+             conn,
+             "drop derby aggregate priceMode_17 restrict"
+             );
+        goodStatement
+            (
+             conn,
+             "drop type Price_17 restrict"
+             );
+        goodStatement
+            (
+             conn,
+             "drop type Price_17_2 restrict"
+             );
+    }
+
 }



Mime
View raw message