001: /*
002:
003: Derby - Class org.apache.derby.iapi.sql.dictionary.TablePermsDescriptor
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.services.io.StoredFormatIds;
029: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
030: import org.apache.derby.iapi.error.StandardException;
031: import org.apache.derby.impl.sql.catalog.DDdependableFinder;
032:
033: /**
034: * This class describes a row in the SYS.SYSTABLEPERMS system table, which
035: * stores the table permissions that have been granted but not revoked.
036: */
037: public class TablePermsDescriptor extends PermissionsDescriptor {
038: private UUID tableUUID;
039: private String tableName;
040: private String selectPriv;
041: private String deletePriv;
042: private String insertPriv;
043: private String updatePriv;
044: private String referencesPriv;
045: private String triggerPriv;
046:
047: public TablePermsDescriptor(DataDictionary dd, String grantee,
048: String grantor, UUID tableUUID, String selectPriv,
049: String deletePriv, String insertPriv, String updatePriv,
050: String referencesPriv, String triggerPriv)
051: throws StandardException {
052: super (dd, grantee, grantor);
053: this .tableUUID = tableUUID;
054: this .selectPriv = selectPriv;
055: this .deletePriv = deletePriv;
056: this .insertPriv = insertPriv;
057: this .updatePriv = updatePriv;
058: this .referencesPriv = referencesPriv;
059: this .triggerPriv = triggerPriv;
060: //tableUUID can be null only if the constructor with tablePermsUUID
061: //has been invoked.
062: if (tableUUID != null)
063: tableName = dd.getTableDescriptor(tableUUID).getName();
064: }
065:
066: /**
067: * This constructor just sets up the key fields of a TablePermsDescriptor
068: */
069: public TablePermsDescriptor(DataDictionary dd, String grantee,
070: String grantor, UUID tableUUID) throws StandardException {
071: this (dd, grantee, grantor, tableUUID, (String) null,
072: (String) null, (String) null, (String) null,
073: (String) null, (String) null);
074: }
075:
076: public TablePermsDescriptor(DataDictionary dd, UUID tablePermsUUID)
077: throws StandardException {
078: this (dd, null, null, null, (String) null, (String) null,
079: (String) null, (String) null, (String) null,
080: (String) null);
081: this .oid = tablePermsUUID;
082: }
083:
084: public int getCatalogNumber() {
085: return DataDictionary.SYSTABLEPERMS_CATALOG_NUM;
086: }
087:
088: /*----- getter functions for rowfactory ------*/
089: public UUID getTableUUID() {
090: return tableUUID;
091: }
092:
093: public String getSelectPriv() {
094: return selectPriv;
095: }
096:
097: public String getDeletePriv() {
098: return deletePriv;
099: }
100:
101: public String getInsertPriv() {
102: return insertPriv;
103: }
104:
105: public String getUpdatePriv() {
106: return updatePriv;
107: }
108:
109: public String getReferencesPriv() {
110: return referencesPriv;
111: }
112:
113: public String getTriggerPriv() {
114: return triggerPriv;
115: }
116:
117: public String toString() {
118: return "tablePerms: grantee=" + getGrantee()
119: + ",tablePermsUUID=" + getUUID() + ",grantor="
120: + getGrantor() + ",tableUUID=" + getTableUUID()
121: + ",selectPriv=" + getSelectPriv() + ",deletePriv="
122: + getDeletePriv() + ",insertPriv=" + getInsertPriv()
123: + ",updatePriv=" + getUpdatePriv() + ",referencesPriv="
124: + getReferencesPriv() + ",triggerPriv="
125: + getTriggerPriv();
126: }
127:
128: /**
129: * @return true iff the key part of this permissions descriptor equals the key part of another permissions
130: * descriptor.
131: */
132: public boolean equals(Object other) {
133: if (!(other instanceof TablePermsDescriptor))
134: return false;
135: TablePermsDescriptor otherTablePerms = (TablePermsDescriptor) other;
136: return super .keyEquals(otherTablePerms)
137: && tableUUID.equals(otherTablePerms.tableUUID);
138: }
139:
140: /**
141: * @return the hashCode for the key part of this permissions descriptor
142: */
143: public int hashCode() {
144: return super .keyHashCode() + tableUUID.hashCode();
145: }
146:
147: /**
148: * @see PermissionsDescriptor#checkOwner
149: */
150: public boolean checkOwner(String authorizationId)
151: throws StandardException {
152: TableDescriptor td = getDataDictionary().getTableDescriptor(
153: tableUUID);
154: if (td.getSchemaDescriptor().getAuthorizationId().equals(
155: authorizationId))
156: return true;
157: else
158: return false;
159: }
160:
161: //////////////////////////////////////////////
162: //
163: // PROVIDER INTERFACE
164: //
165: //////////////////////////////////////////////
166:
167: /**
168: * Return the name of this Provider. (Useful for errors.)
169: *
170: * @return String The name of this provider.
171: */
172: public String getObjectName() {
173: return "Table Privilege on " + tableName;
174: }
175:
176: /**
177: * Get the provider's type.
178: *
179: * @return char The provider's type.
180: */
181: public String getClassType() {
182: return Dependable.TABLE_PERMISSION;
183: }
184:
185: /**
186: @return the stored form of this provider
187:
188: @see Dependable#getDependableFinder
189: */
190: public DependableFinder getDependableFinder() {
191: return new DDdependableFinder(
192: StoredFormatIds.TABLE_PERMISSION_FINDER_V01_ID);
193: }
194: }
|