KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > sql > dictionary > RoutinePermsDescriptor


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.RoutinePermsDescriptor
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.sql.dictionary;
23
24 import org.apache.derby.catalog.Dependable;
25 import org.apache.derby.catalog.DependableFinder;
26 import org.apache.derby.catalog.UUID;
27
28 import org.apache.derby.iapi.error.StandardException;
29 import org.apache.derby.iapi.services.io.StoredFormatIds;
30 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
31 import org.apache.derby.impl.sql.catalog.DDdependableFinder;
32
33 /**
34  * This class describes rows in the SYS.SYSROUTINEPERMS system table, which keeps track of the routine
35  * (procedure and function) permissions that have been granted but not revoked.
36  */

37 public class RoutinePermsDescriptor extends PermissionsDescriptor
38 {
39     private UUID routineUUID;
40     private String JavaDoc routineName;
41     private boolean hasExecutePermission;
42     
43     public RoutinePermsDescriptor( DataDictionary dd,
44                                    String JavaDoc grantee,
45                                    String JavaDoc grantor,
46                                    UUID routineUUID,
47                                    boolean hasExecutePermission) throws StandardException
48     {
49         super (dd, grantee, grantor);
50         this.routineUUID = routineUUID;
51         this.hasExecutePermission = hasExecutePermission;
52         //routineUUID can be null only if the constructor with routineePermsUUID
53
//has been invoked.
54
if (routineUUID != null)
55             routineName = dd.getAliasDescriptor(routineUUID).getObjectName();
56     }
57     
58     public RoutinePermsDescriptor( DataDictionary dd,
59                                    String JavaDoc grantee,
60                                    String JavaDoc grantor,
61                                    UUID routineUUID) throws StandardException
62     {
63         this( dd, grantee, grantor, routineUUID, true);
64     }
65
66     /**
67      * This constructor just sets up the key fields of a RoutinePermsDescriptor.
68      */

69     public RoutinePermsDescriptor( DataDictionary dd,
70                                    String JavaDoc grantee,
71                                    String JavaDoc grantor) throws StandardException
72     {
73         this( dd, grantee, grantor, (UUID) null);
74     }
75        
76     public RoutinePermsDescriptor( DataDictionary dd, UUID routineePermsUUID)
77     throws StandardException
78     {
79         this( dd, null, null, null, true);
80         this.oid = routineePermsUUID;
81     }
82     
83     public int getCatalogNumber()
84     {
85         return DataDictionary.SYSROUTINEPERMS_CATALOG_NUM;
86     }
87     
88     /*----- getter functions for rowfactory ------*/
89     public UUID getRoutineUUID() { return routineUUID;}
90     public boolean getHasExecutePermission() { return hasExecutePermission;}
91
92     public String JavaDoc toString()
93     {
94         return "routinePerms: grantee=" + getGrantee() +
95         ",routinePermsUUID=" + getUUID() +
96           ",grantor=" + getGrantor() +
97           ",routineUUID=" + getRoutineUUID();
98     }
99
100     /**
101      * @return true iff the key part of this permissions descriptor equals the key part of another permissions
102      * descriptor.
103      */

104     public boolean equals( Object JavaDoc other)
105     {
106         if( !( other instanceof RoutinePermsDescriptor))
107             return false;
108         RoutinePermsDescriptor otherRoutinePerms = (RoutinePermsDescriptor) other;
109         return super.keyEquals( otherRoutinePerms) &&
110           routineUUID.equals( otherRoutinePerms.routineUUID);
111     }
112     
113     /**
114      * @return the hashCode for the key part of this permissions descriptor
115      */

116     public int hashCode()
117     {
118         return super.keyHashCode() + routineUUID.hashCode();
119     }
120     
121     /**
122      * @see PermissionsDescriptor#checkOwner
123      */

124     public boolean checkOwner(String JavaDoc authorizationId) throws StandardException
125     {
126         UUID sd = getDataDictionary().getAliasDescriptor(routineUUID).getSchemaUUID();
127         if (getDataDictionary().getSchemaDescriptor(sd, null).getAuthorizationId().equals(authorizationId))
128             return true;
129         else
130             return false;
131     }
132
133     //////////////////////////////////////////////
134
//
135
// PROVIDER INTERFACE
136
//
137
//////////////////////////////////////////////
138

139     /**
140      * Return the name of this Provider. (Useful for errors.)
141      *
142      * @return String The name of this provider.
143      */

144     public String JavaDoc getObjectName()
145     {
146         return "Routine Privilege on " + routineName;
147     }
148
149     /**
150      * Get the provider's type.
151      *
152      * @return char The provider's type.
153      */

154     public String JavaDoc getClassType()
155     {
156         return Dependable.ROUTINE_PERMISSION;
157     }
158
159     /**
160         @return the stored form of this provider
161
162             @see Dependable#getDependableFinder
163      */

164     public DependableFinder getDependableFinder()
165     {
166         return new DDdependableFinder(StoredFormatIds.ROUTINE_PERMISSION_FINDER_V01_ID);
167     }
168 }
169
Popular Tags