KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.TablePermsDescriptor
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.services.io.StoredFormatIds;
29 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
30 import org.apache.derby.iapi.error.StandardException;
31 import org.apache.derby.impl.sql.catalog.DDdependableFinder;
32
33 /**
34  * This class describes a row in the SYS.SYSTABLEPERMS system table, which
35  * stores the table permissions that have been granted but not revoked.
36  */

37 public class TablePermsDescriptor extends PermissionsDescriptor
38 {
39     private UUID tableUUID;
40     private String JavaDoc tableName;
41     private String JavaDoc selectPriv;
42     private String JavaDoc deletePriv;
43     private String JavaDoc insertPriv;
44     private String JavaDoc updatePriv;
45     private String JavaDoc referencesPriv;
46     private String JavaDoc triggerPriv;
47     
48     public TablePermsDescriptor( DataDictionary dd,
49                                  String JavaDoc grantee,
50                                  String JavaDoc grantor,
51                                  UUID tableUUID,
52                                  String JavaDoc selectPriv,
53                                  String JavaDoc deletePriv,
54                                  String JavaDoc insertPriv,
55                                  String JavaDoc updatePriv,
56                                  String JavaDoc referencesPriv,
57                                  String JavaDoc triggerPriv) throws StandardException
58     {
59         super (dd, grantee, grantor);
60         this.tableUUID = tableUUID;
61         this.selectPriv = selectPriv;
62         this.deletePriv = deletePriv;
63         this.insertPriv = insertPriv;
64         this.updatePriv = updatePriv;
65         this.referencesPriv = referencesPriv;
66         this.triggerPriv = triggerPriv;
67         //tableUUID can be null only if the constructor with tablePermsUUID
68
//has been invoked.
69
if (tableUUID != null)
70             tableName = dd.getTableDescriptor(tableUUID).getName();
71     }
72
73     /**
74      * This constructor just sets up the key fields of a TablePermsDescriptor
75      */

76     public TablePermsDescriptor( DataDictionary dd,
77                                  String JavaDoc grantee,
78                                  String JavaDoc grantor,
79                                  UUID tableUUID) throws StandardException
80     {
81         this( dd, grantee, grantor, tableUUID,
82               (String JavaDoc) null, (String JavaDoc) null, (String JavaDoc) null, (String JavaDoc) null, (String JavaDoc) null, (String JavaDoc) null);
83     }
84     
85     public TablePermsDescriptor( DataDictionary dd,
86             UUID tablePermsUUID) throws StandardException
87             {
88         this( dd, null, null, null,
89                 (String JavaDoc) null, (String JavaDoc) null, (String JavaDoc) null, (String JavaDoc) null, (String JavaDoc) null, (String JavaDoc) null);
90         this.oid = tablePermsUUID;
91             }
92
93     public int getCatalogNumber()
94     {
95         return DataDictionary.SYSTABLEPERMS_CATALOG_NUM;
96     }
97     
98     /*----- getter functions for rowfactory ------*/
99     public UUID getTableUUID() { return tableUUID;}
100     public String JavaDoc getSelectPriv() { return selectPriv;}
101     public String JavaDoc getDeletePriv() { return deletePriv;}
102     public String JavaDoc getInsertPriv() { return insertPriv;}
103     public String JavaDoc getUpdatePriv() { return updatePriv;}
104     public String JavaDoc getReferencesPriv() { return referencesPriv;}
105     public String JavaDoc getTriggerPriv() { return triggerPriv;}
106
107     public String JavaDoc toString()
108     {
109         return "tablePerms: grantee=" + getGrantee() +
110         ",tablePermsUUID=" + getUUID() +
111             ",grantor=" + getGrantor() +
112           ",tableUUID=" + getTableUUID() +
113           ",selectPriv=" + getSelectPriv() +
114           ",deletePriv=" + getDeletePriv() +
115           ",insertPriv=" + getInsertPriv() +
116           ",updatePriv=" + getUpdatePriv() +
117           ",referencesPriv=" + getReferencesPriv() +
118           ",triggerPriv=" + getTriggerPriv();
119     }
120
121     /**
122      * @return true iff the key part of this permissions descriptor equals the key part of another permissions
123      * descriptor.
124      */

125     public boolean equals( Object JavaDoc other)
126     {
127         if( !( other instanceof TablePermsDescriptor))
128             return false;
129         TablePermsDescriptor otherTablePerms = (TablePermsDescriptor) other;
130         return super.keyEquals( otherTablePerms) && tableUUID.equals( otherTablePerms.tableUUID);
131     }
132     
133     /**
134      * @return the hashCode for the key part of this permissions descriptor
135      */

136     public int hashCode()
137     {
138         return super.keyHashCode() + tableUUID.hashCode();
139     }
140     
141     /**
142      * @see PermissionsDescriptor#checkOwner
143      */

144     public boolean checkOwner(String JavaDoc authorizationId) throws StandardException
145     {
146         TableDescriptor td = getDataDictionary().getTableDescriptor(tableUUID);
147         if (td.getSchemaDescriptor().getAuthorizationId().equals(authorizationId))
148             return true;
149         else
150             return false;
151     }
152
153     //////////////////////////////////////////////
154
//
155
// PROVIDER INTERFACE
156
//
157
//////////////////////////////////////////////
158

159     /**
160      * Return the name of this Provider. (Useful for errors.)
161      *
162      * @return String The name of this provider.
163      */

164     public String JavaDoc getObjectName()
165     {
166         return "Table Privilege on " + tableName;
167     }
168
169     /**
170      * Get the provider's type.
171      *
172      * @return char The provider's type.
173      */

174     public String JavaDoc getClassType()
175     {
176         return Dependable.TABLE_PERMISSION;
177     }
178
179     /**
180         @return the stored form of this provider
181
182             @see Dependable#getDependableFinder
183      */

184     public DependableFinder getDependableFinder()
185     {
186         return new DDdependableFinder(StoredFormatIds.TABLE_PERMISSION_FINDER_V01_ID);
187     }
188 }
189
Popular Tags