001: /*
002:
003: Derby - Class org.apache.derby.iapi.sql.dictionary.RoutinePermsDescriptor
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.sql.dictionary;
023:
024: import org.apache.derby.catalog.Dependable;
025: import org.apache.derby.catalog.DependableFinder;
026: import org.apache.derby.catalog.UUID;
027:
028: import org.apache.derby.iapi.error.StandardException;
029: import org.apache.derby.iapi.services.io.StoredFormatIds;
030: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
031: import org.apache.derby.impl.sql.catalog.DDdependableFinder;
032:
033: /**
034: * This class describes rows in the SYS.SYSROUTINEPERMS system table, which keeps track of the routine
035: * (procedure and function) permissions that have been granted but not revoked.
036: */
037: public class RoutinePermsDescriptor extends PermissionsDescriptor {
038: private UUID routineUUID;
039: private String routineName;
040: private boolean hasExecutePermission;
041:
042: public RoutinePermsDescriptor(DataDictionary dd, String grantee,
043: String grantor, UUID routineUUID,
044: boolean hasExecutePermission) throws StandardException {
045: super (dd, grantee, grantor);
046: this .routineUUID = routineUUID;
047: this .hasExecutePermission = hasExecutePermission;
048: //routineUUID can be null only if the constructor with routineePermsUUID
049: //has been invoked.
050: if (routineUUID != null)
051: routineName = dd.getAliasDescriptor(routineUUID)
052: .getObjectName();
053: }
054:
055: public RoutinePermsDescriptor(DataDictionary dd, String grantee,
056: String grantor, UUID routineUUID) throws StandardException {
057: this (dd, grantee, grantor, routineUUID, true);
058: }
059:
060: /**
061: * This constructor just sets up the key fields of a RoutinePermsDescriptor.
062: */
063: public RoutinePermsDescriptor(DataDictionary dd, String grantee,
064: String grantor) throws StandardException {
065: this (dd, grantee, grantor, (UUID) null);
066: }
067:
068: public RoutinePermsDescriptor(DataDictionary dd,
069: UUID routineePermsUUID) throws StandardException {
070: this (dd, null, null, null, true);
071: this .oid = routineePermsUUID;
072: }
073:
074: public int getCatalogNumber() {
075: return DataDictionary.SYSROUTINEPERMS_CATALOG_NUM;
076: }
077:
078: /*----- getter functions for rowfactory ------*/
079: public UUID getRoutineUUID() {
080: return routineUUID;
081: }
082:
083: public boolean getHasExecutePermission() {
084: return hasExecutePermission;
085: }
086:
087: public String toString() {
088: return "routinePerms: grantee=" + getGrantee()
089: + ",routinePermsUUID=" + getUUID() + ",grantor="
090: + getGrantor() + ",routineUUID=" + getRoutineUUID();
091: }
092:
093: /**
094: * @return true iff the key part of this permissions descriptor equals the key part of another permissions
095: * descriptor.
096: */
097: public boolean equals(Object other) {
098: if (!(other instanceof RoutinePermsDescriptor))
099: return false;
100: RoutinePermsDescriptor otherRoutinePerms = (RoutinePermsDescriptor) other;
101: return super .keyEquals(otherRoutinePerms)
102: && routineUUID.equals(otherRoutinePerms.routineUUID);
103: }
104:
105: /**
106: * @return the hashCode for the key part of this permissions descriptor
107: */
108: public int hashCode() {
109: return super .keyHashCode() + routineUUID.hashCode();
110: }
111:
112: /**
113: * @see PermissionsDescriptor#checkOwner
114: */
115: public boolean checkOwner(String authorizationId)
116: throws StandardException {
117: UUID sd = getDataDictionary().getAliasDescriptor(routineUUID)
118: .getSchemaUUID();
119: if (getDataDictionary().getSchemaDescriptor(sd, null)
120: .getAuthorizationId().equals(authorizationId))
121: return true;
122: else
123: return false;
124: }
125:
126: //////////////////////////////////////////////
127: //
128: // PROVIDER INTERFACE
129: //
130: //////////////////////////////////////////////
131:
132: /**
133: * Return the name of this Provider. (Useful for errors.)
134: *
135: * @return String The name of this provider.
136: */
137: public String getObjectName() {
138: return "Routine Privilege on " + routineName;
139: }
140:
141: /**
142: * Get the provider's type.
143: *
144: * @return char The provider's type.
145: */
146: public String getClassType() {
147: return Dependable.ROUTINE_PERMISSION;
148: }
149:
150: /**
151: @return the stored form of this provider
152:
153: @see Dependable#getDependableFinder
154: */
155: public DependableFinder getDependableFinder() {
156: return new DDdependableFinder(
157: StoredFormatIds.ROUTINE_PERMISSION_FINDER_V01_ID);
158: }
159: }
|