Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BFFCDD815 for ; Mon, 3 Sep 2012 11:14:24 +0000 (UTC) Received: (qmail 7368 invoked by uid 500); 3 Sep 2012 11:14:24 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 7186 invoked by uid 500); 3 Sep 2012 11:14:19 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 7160 invoked by uid 99); 3 Sep 2012 11:14:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2012 11:14:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2012 11:14:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 540ED238890D; Mon, 3 Sep 2012 11:13:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1380202 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/depend/ testing/org/apache/derbyTesting/functionTests/tests/lang/ tools/org/apa... Date: Mon, 03 Sep 2012 11:13:32 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120903111333.540ED238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rhillegas Date: Mon Sep 3 11:13:31 2012 New Revision: 1380202 URL: http://svn.apache.org/viewvc?rev=1380202&view=rev Log: DERBY-672: Adding GRANT/REVOKE support for user-defined aggregates. Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java (with props) Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/PermDescriptor.java db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/StatementGenericPermission.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PrivilegeNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_GrantRevoke.java db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/PermDescriptor.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/PermDescriptor.java?rev=1380202&r1=1380201&r2=1380202&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/PermDescriptor.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/PermDescriptor.java Mon Sep 3 11:13:31 2012 @@ -161,6 +161,10 @@ public class PermDescriptor extends Perm { return dd.getSequenceDescriptor( objectID ); } + else if ( PermDescriptor.AGGREGATE_TYPE.equals( objectType ) ) + { + return dd.getAliasDescriptor( objectID ); + } else if ( PermDescriptor.UDT_TYPE.equals( objectType ) ) { return dd.getAliasDescriptor( objectID ); Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/StatementGenericPermission.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/StatementGenericPermission.java?rev=1380202&r1=1380201&r2=1380202&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/StatementGenericPermission.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/StatementGenericPermission.java Mon Sep 3 11:13:31 2012 @@ -93,6 +93,7 @@ public final class StatementGenericPermi public PrivilegedSQLObject getPrivilegedObject( DataDictionary dd ) throws StandardException { if ( PermDescriptor.UDT_TYPE.equals( _objectType ) ) { return dd.getAliasDescriptor( _objectID ); } + else if ( PermDescriptor.AGGREGATE_TYPE.equals( _objectType ) ) { return dd.getAliasDescriptor( _objectID ); } else if ( PermDescriptor.SEQUENCE_TYPE.equals( _objectType ) ) { return dd.getSequenceDescriptor( _objectID ); } else { Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java?rev=1380202&r1=1380201&r2=1380202&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java Mon Sep 3 11:13:31 2012 @@ -318,6 +318,21 @@ public class AggregateNode extends Unary instantiateAggDef(); + // if this is a user-defined aggregate + if ( (uad != null) && (uad instanceof UserAggregateDefinition) ) + { + AliasDescriptor ad = ((UserAggregateDefinition) uad).getAliasDescriptor(); + + // set up dependency on the user-defined aggregate and compile a check for USAGE + // priv if needed + getCompilerContext().createDependency( ad ); + + if ( isPrivilegeCollectionRequired() ) + { + getCompilerContext().addRequiredUsagePriv( ad ); + } + } + /* Add ourselves to the aggregateVector before we do anything else */ aggregateVector.add(this); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PrivilegeNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PrivilegeNode.java?rev=1380202&r1=1380201&r2=1380202&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PrivilegeNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PrivilegeNode.java Mon Sep 3 11:13:31 2012 @@ -49,6 +49,7 @@ public class PrivilegeNode extends Query public static final int ROUTINE_PRIVILEGES = 1; public static final int SEQUENCE_PRIVILEGES = 2; public static final int UDT_PRIVILEGES = 3; + public static final int AGGREGATE_PRIVILEGES = 4; // // State initialized when the node is instantiated @@ -260,6 +261,17 @@ public class PrivilegeNode extends Query dependencyProvider = proc; break; + case AGGREGATE_PRIVILEGES: + + dependencyProvider = getDataDictionary().getAliasDescriptor + ( sd.getUUID().toString(), objectName.getTableName(), AliasInfo.ALIAS_NAME_SPACE_AGGREGATE_AS_CHAR ); + if ( dependencyProvider == null ) + { + throw StandardException.newException + (SQLState.LANG_OBJECT_NOT_FOUND, "DERBY AGGREGATE", objectName.getFullTableName()); + } + break; + case SEQUENCE_PRIVILEGES: dependencyProvider = getDataDictionary().getSequenceDescriptor( sd, objectName.getTableName() ); @@ -308,6 +320,7 @@ public class PrivilegeNode extends Query case ROUTINE_PRIVILEGES: return routineDesignator.makePrivilegeInfo(); + case AGGREGATE_PRIVILEGES: case SEQUENCE_PRIVILEGES: case UDT_PRIVILEGES: return new GenericPrivilegeInfo( (PrivilegedSQLObject) dependencyProvider, privilege, restrict ); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java?rev=1380202&r1=1380201&r2=1380202&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java Mon Sep 3 11:13:31 2012 @@ -84,6 +84,15 @@ public class UserAggregateDefinition imp _alias = alias; } + /////////////////////////////////////////////////////////////////////////////////// + // + // BEHAVIOR + // + /////////////////////////////////////////////////////////////////////////////////// + + /** Get the wrapped alias descriptor */ + public AliasDescriptor getAliasDescriptor() { return _alias; } + /** * Determines the result datatype and verifies that the input datatype is correct. * 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=1380202&r1=1380201&r2=1380202&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 Sep 3 11:13:31 2012 @@ -14095,6 +14095,11 @@ usableObjects() throws StandardException { } { + + { + return ReuseFactory.getInteger( PrivilegeNode.AGGREGATE_PRIVILEGES); + } +| { return ReuseFactory.getInteger( PrivilegeNode.SEQUENCE_PRIVILEGES); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java?rev=1380202&r1=1380201&r2=1380202&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java Mon Sep 3 11:13:31 2012 @@ -872,6 +872,9 @@ public class BasicDependencyManager impl case DROP_UDT: return "DROP TYPE"; + case DROP_AGGREGATE: + return "DROP DERBY AGGREGATE"; + default: if (SanityManager.DEBUG) { Added: 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=1380202&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java Mon Sep 3 11:13:31 2012 @@ -0,0 +1,331 @@ +/* + + Derby - Class org.apache.derbyTesting.functionTests.tests.lang.UDAPermsTest + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package org.apache.derbyTesting.functionTests.tests.lang; + +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Connection; +import java.sql.Statement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.DriverManager; +import java.util.ArrayList; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.apache.derby.iapi.util.StringUtil; +import org.apache.derby.catalog.DefaultInfo; +import org.apache.derbyTesting.junit.BaseJDBCTestCase; +import org.apache.derbyTesting.junit.JDBC; +import org.apache.derbyTesting.junit.DatabasePropertyTestSetup; +import org.apache.derbyTesting.junit.JDBC; +import org.apache.derbyTesting.junit.TestConfiguration; +import org.apache.derbyTesting.junit.CleanDatabaseTestSetup; +import org.apache.derbyTesting.junit.JDBC; + +import org.apache.derby.catalog.types.RoutineAliasInfo; + +/** + *

+ * Test permissions on user-defined aggregates. See DERBY-672. + *

+ */ +public class UDAPermsTest extends GeneratedColumnsHelper +{ + /////////////////////////////////////////////////////////////////////////////////// + // + // CONSTANTS + // + /////////////////////////////////////////////////////////////////////////////////// + + private static final String TEST_DBO = "TEST_DBO"; + private static final String RUTH = "RUTH"; + private static final String ALICE = "ALICE"; + private static final String FRANK = "FRANK"; + private static final String[] LEGAL_USERS = { TEST_DBO, ALICE, RUTH, FRANK }; + + /////////////////////////////////////////////////////////////////////////////////// + // + // STATE + // + /////////////////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////////////////// + // + // CONSTRUCTOR + // + /////////////////////////////////////////////////////////////////////////////////// + + /** + * Create a new instance. + */ + + public UDAPermsTest(String name) + { + super(name); + } + + /////////////////////////////////////////////////////////////////////////////////// + // + // JUnit BEHAVIOR + // + /////////////////////////////////////////////////////////////////////////////////// + + + /** + * Construct top level suite in this JUnit test + */ + public static Test suite() + { + TestSuite suite = (TestSuite) TestConfiguration.embeddedSuite(UDAPermsTest.class); + + Test cleanTest = new CleanDatabaseTestSetup( suite ); + Test authenticatedTest = DatabasePropertyTestSetup.builtinAuthentication + ( cleanTest, LEGAL_USERS, "udaPermissions" ); + Test authorizedTest = TestConfiguration.sqlAuthorizationDecorator( authenticatedTest ); + + return authorizedTest; + } + + /////////////////////////////////////////////////////////////////////////////////// + // + // TESTS + // + /////////////////////////////////////////////////////////////////////////////////// + + /** + *

+ * Test that you need USAGE privilege on an aggregate in order to invoke it. + * and in order to declare objects which mention that type. + *

+ */ + public void test_001_basicGrant() + throws Exception + { + Connection dboConnection = openUserConnection( TEST_DBO ); + Connection ruthConnection = openUserConnection( RUTH ); + Connection aliceConnection = openUserConnection( ALICE ); + + // + // Create an aggregate and table. + // + goodStatement + ( + ruthConnection, + "create derby aggregate mode_01 for int\n" + + "external name 'org.apache.derbyTesting.functionTests.tests.lang.ModeAggregate'\n" + ); + goodStatement + ( + ruthConnection, + "create table mode_inputs_01( a int, b int )\n" + ); + goodStatement + ( + ruthConnection, + "insert into mode_inputs_01( a, b ) values ( 1, 1 ), ( 1, 2 ), ( 1, 2 ), ( 1, 2 ), ( 2, 3 ), ( 2, 3 ), ( 2, 4 )\n" + ); + goodStatement + ( + ruthConnection, + "grant select on mode_inputs_01 to public\n" + ); + + expectExecutionError + ( + aliceConnection, + LACK_USAGE_PRIV, + "select a, ruth.mode_01( b ) from ruth.mode_inputs_01 group by a\n" + ); + expectExecutionError + ( + aliceConnection, + LACK_USAGE_PRIV, + "create view v_alice_01( a, modeOfA ) as select a, ruth.mode_01( b ) from ruth.mode_inputs_01 group by a\n" + ); + + // + // The DBO however is almighty. + // + assertResults + ( + dboConnection, + "select a, ruth.mode_01( b ) from ruth.mode_inputs_01 group by a", + new String[][] + { + { "1", "2" }, + { "2", "3" }, + }, + false + ); + goodStatement + ( + dboConnection, + "create view v_dbo_01( a, modeOfA ) as select a, ruth.mode_01( b ) from ruth.mode_inputs_01 group by a\n" + ); + assertResults + ( + dboConnection, + "select * from v_dbo_01", + new String[][] + { + { "1", "2" }, + { "2", "3" }, + }, + false + ); + + // + // Now grant USAGE on the user-defined aggregate. User Alice should now have all the + // privileges she needs. + // + goodStatement + ( + ruthConnection, + "grant usage on derby aggregate mode_01 to public\n" + ); + + assertResults + ( + aliceConnection, + "select a, ruth.mode_01( b ) from ruth.mode_inputs_01 group by a", + new String[][] + { + { "1", "2" }, + { "2", "3" }, + }, + false + ); + + goodStatement + ( + aliceConnection, + "create view v_alice_01( a, modeOfA ) as select a, ruth.mode_01( b ) from ruth.mode_inputs_01 group by a\n" + ); + assertResults + ( + aliceConnection, + "select * from v_alice_01", + new String[][] + { + { "1", "2" }, + { "2", "3" }, + }, + false + ); + + } + + /** + *

+ * Test that USAGE privilege can't be revoked if it would make objects + * unusable by their owners. + *

+ */ + public void test_002_basicRevoke() + throws Exception + { + Connection dboConnection = openUserConnection( TEST_DBO ); + Connection ruthConnection = openUserConnection( RUTH ); + Connection aliceConnection = openUserConnection( ALICE ); + + // + // Create an aggregate and table. + // + goodStatement + ( + ruthConnection, + "create derby aggregate mode_02 for int\n" + + "external name 'org.apache.derbyTesting.functionTests.tests.lang.ModeAggregate'\n" + ); + goodStatement + ( + ruthConnection, + "create table mode_inputs_02( a int, b int )\n" + ); + goodStatement + ( + ruthConnection, + "grant select on mode_inputs_02 to public\n" + ); + goodStatement + ( + ruthConnection, + "insert into mode_inputs_02( a, b ) values ( 1, 1 ), ( 1, 2 ), ( 1, 2 ), ( 1, 2 ), ( 2, 3 ), ( 2, 3 ), ( 2, 4 )\n" + ); + + // only RESTRICTed revocations allowed + expectCompilationError( ruthConnection, SYNTAX_ERROR, "revoke usage on derby aggregate mode_02 from ruth\n" ); + + // can't revoke USAGE from owner + expectCompilationError + ( + ruthConnection, + GRANT_REVOKE_NOT_ALLOWED, + "revoke usage on derby aggregate mode_02 from ruth restrict\n" + ); + + String grantUsage = "grant usage on derby aggregate mode_02 to alice\n"; + String revokeUsage = "revoke usage on derby aggregate mode_02 from alice restrict\n"; + String createStatement; + String dropStatement; + String badRevokeSQLState; + + // can't revoke USAGE if a view depends on it + createStatement = + "create view v_alice_02( a, modeOfA ) as select a, ruth.mode_02( b ) from ruth.mode_inputs_02 group by a" + ; + dropStatement = "drop view v_alice_02\n"; + badRevokeSQLState = VIEW_DEPENDENCY; + verifyRevokePrivilege + ( + ruthConnection, + aliceConnection, + grantUsage, + revokeUsage, + createStatement, + dropStatement, + badRevokeSQLState + ); + + // can't revoke USAGE if a trigger depends on it + goodStatement( aliceConnection, "create table t_source_02( a int )\n" ); + goodStatement( aliceConnection, "create table t_target_02( a int )\n" ); + createStatement = + "create trigger t_insert_trigger_02\n" + + "after insert on t_source_02\n" + + "for each row\n" + + "insert into t_target_02( a ) select ruth.mode_02( b ) from ruth.mode_inputs_02\n"; + dropStatement = "drop trigger t_insert_trigger_02\n"; + badRevokeSQLState = OPERATION_FORBIDDEN; + verifyRevokePrivilege + ( + ruthConnection, + aliceConnection, + grantUsage, + revokeUsage, + createStatement, + dropStatement, + badRevokeSQLState + ); + } + +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java ------------------------------------------------------------------------------ svn:eol-style = native 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=1380202&r1=1380201&r2=1380202&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 Mon Sep 3 11:13:31 2012 @@ -766,4 +766,55 @@ public class UserDefinedAggregatesTest ); } + /** + *

+ * Test restricted drops of aggregates. + *

+ */ + public void test_07_restrictedDrops() throws Exception + { + Connection conn = getConnection(); + + goodStatement + ( conn, + "create derby aggregate mode_07 for int external name 'org.apache.derbyTesting.functionTests.tests.lang.ModeAggregate'" ); + goodStatement + ( conn, + "create table mode_inputs_07( a int, b int )" ); + + // restricted drop blocked by a view + goodStatement + ( conn, + "create view v_dbo_07( a, modeOfA ) as select a, mode_07( b ) from mode_inputs_07 group by a" ); + expectExecutionError + ( conn, VIEW_DEPENDENCY, "drop derby aggregate mode_07 restrict" ); + goodStatement + ( conn, + "drop view v_dbo_07" ); + + // restricted drop blocked by a trigger + goodStatement + ( conn, + "create table t_source_07( a int )" ); + goodStatement + ( conn, + "create table t_target_07( a int )" ); + goodStatement + ( conn, + "create trigger t_insert_trigger_07\n" + + "after insert on t_source_07\n" + + "for each row\n" + + "insert into t_target_07( a ) select mode_07( b ) from mode_inputs_07\n" + ); + expectExecutionError + ( conn, FORBIDDEN_DROP_TRIGGER, "drop derby aggregate mode_07 restrict" ); + goodStatement + ( conn, + "drop trigger t_insert_trigger_07" ); + + // blocking objects dropped. aggregate is now droppable + goodStatement( conn, "drop derby aggregate mode_07 restrict" ); + + } + } Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=1380202&r1=1380201&r2=1380202&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Mon Sep 3 11:13:31 2012 @@ -194,6 +194,7 @@ public class _Suite extends BaseTestCase // requires Java 5 (generics) suite.addTest(UserDefinedAggregatesTest.suite()); + suite.addTest(UDAPermsTest.suite()); } suite.addTest(BigDataTest.suite()); Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_GrantRevoke.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_GrantRevoke.java?rev=1380202&r1=1380201&r2=1380202&view=diff ============================================================================== --- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_GrantRevoke.java (original) +++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_GrantRevoke.java Mon Sep 3 11:13:31 2012 @@ -59,6 +59,12 @@ public class DB_GrantRevoke { "SYS.SYSPERMS P, SYS.SYSSEQUENCES SEQ, SYS.SYSSCHEMAS S WHERE SEQ.SCHEMAID = " + "S.SCHEMAID AND P.OBJECTID = SEQ.SEQUENCEID"); generateSequencePrivs(rs); + + // Generate aggregate privilege statements + rs = stmt.executeQuery("SELECT P.GRANTEE, S.SCHEMANAME, A.ALIAS, P.PERMISSION, P.OBJECTTYPE FROM " + + "SYS.SYSPERMS P, SYS.SYSALIASES A, SYS.SYSSCHEMAS S WHERE A.SCHEMAID = " + + "S.SCHEMAID AND P.OBJECTID = A.ALIASID AND A.ALIASTYPE='G'"); + generateAggregatePrivs(rs); } rs = stmt.executeQuery("SELECT GRANTEE, SCHEMANAME, TABLENAME, SELECTPRIV, " + @@ -387,6 +393,40 @@ public class DB_GrantRevoke { firstTime = false; } } + /** ************************************************ + * Generate aggregate privilege statements + * + * @param rs ResultSet holding required information + ****/ + public static void generateAggregatePrivs(ResultSet rs) throws SQLException + { + boolean firstTime = true; + while (rs.next()) { + String authName = dblook.addQuotes + (dblook.expandDoubleQuotes(rs.getString(1))); + String schemaName = dblook.addQuotes + (dblook.expandDoubleQuotes(rs.getString(2))); + String aliasName = dblook.addQuotes + (dblook.expandDoubleQuotes(rs.getString(3))); + String fullName = schemaName + "." + aliasName; + String permission = rs.getString(4); + String objectType = rs.getString(5); + + if (dblook.isIgnorableSchema(schemaName)) + continue; + + if (firstTime) { + Logs.reportString("----------------------------------------------"); + Logs.reportMessage("DBLOOK_AggregatePrivHeader"); + Logs.reportString("----------------------------------------------\n"); + } + + Logs.writeToNewDDL(genericPrivStatement(fullName, authName, permission, objectType )); + Logs.writeStmtEndToNewDDL(); + Logs.writeNewlineToNewDDL(); + firstTime = false; + } + } private static String genericPrivStatement(String fullName, String authName, String permission, String objectType ) throws SQLException { Modified: db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties?rev=1380202&r1=1380201&r2=1380202&view=diff ============================================================================== --- db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties (original) +++ db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties Mon Sep 3 11:13:31 2012 @@ -321,6 +321,7 @@ DBLOOK_ColumnPrivHeader=GRANT statements DBLOOK_RoutinePrivHeader=GRANT statements for routines DBLOOK_SequencePrivHeader=GRANT statements for sequences DBLOOK_UDTPrivHeader=GRANT statements for user defined types +DBLOOK_AggregatePrivHeader=GRANT statements for aggregates DBLOOK_Role_definitions_header=CREATE statements for roles DBLOOK_Role_grants_header=GRANT statements for roles