001: /*
002:
003: Derby - Class org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor
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.sql.dictionary.DataDictionary;
030: import org.apache.derby.iapi.services.io.FormatableBitSet;
031: import org.apache.derby.iapi.services.io.StoredFormatIds;
032: import org.apache.derby.impl.sql.catalog.DDdependableFinder;
033:
034: /**
035: * This class describes a row in the SYS.SYSCOLPERMS system table, which keeps
036: * the column permissions that have been granted but not revoked.
037: */
038: public class ColPermsDescriptor extends PermissionsDescriptor {
039: private UUID tableUUID;
040: private String type;
041: private FormatableBitSet columns;
042: private String tableName;
043:
044: public ColPermsDescriptor(DataDictionary dd, String grantee,
045: String grantor, UUID tableUUID, String type,
046: FormatableBitSet columns) throws StandardException {
047: super (dd, grantee, grantor);
048: this .tableUUID = tableUUID;
049: this .type = type;
050: this .columns = columns;
051: //tableUUID can be null only if the constructor with colPermsUUID
052: //has been invoked.
053: if (tableUUID != null)
054: tableName = dd.getTableDescriptor(tableUUID).getName();
055: }
056:
057: /**
058: * This constructor just initializes the key fields of a ColPermsDescriptor
059: */
060: public ColPermsDescriptor(DataDictionary dd, String grantee,
061: String grantor, UUID tableUUID, String type)
062: throws StandardException {
063: this (dd, grantee, grantor, tableUUID, type,
064: (FormatableBitSet) null);
065: }
066:
067: public ColPermsDescriptor(DataDictionary dd, UUID colPermsUUID)
068: throws StandardException {
069: super (dd, null, null);
070: this .oid = colPermsUUID;
071: }
072:
073: public int getCatalogNumber() {
074: return DataDictionary.SYSCOLPERMS_CATALOG_NUM;
075: }
076:
077: /*----- getter functions for rowfactory ------*/
078: public UUID getTableUUID() {
079: return tableUUID;
080: }
081:
082: public String getType() {
083: return type;
084: }
085:
086: public FormatableBitSet getColumns() {
087: return columns;
088: }
089:
090: public String toString() {
091: return "colPerms: grantee=" + getGrantee() + ",colPermsUUID="
092: + getUUID() + ",grantor=" + getGrantor()
093: + ",tableUUID=" + getTableUUID() + ",type=" + getType()
094: + ",columns=" + getColumns();
095: }
096:
097: /**
098: * @return true iff the key part of this permissions descriptor equals the key part of another permissions
099: * descriptor.
100: */
101: public boolean equals(Object other) {
102: if (!(other instanceof ColPermsDescriptor))
103: return false;
104: ColPermsDescriptor otherColPerms = (ColPermsDescriptor) other;
105: return super .keyEquals(otherColPerms)
106: && tableUUID.equals(otherColPerms.tableUUID)
107: && ((type == null) ? (otherColPerms.type == null)
108: : type.equals(otherColPerms.type));
109: }
110:
111: /**
112: * @return the hashCode for the key part of this permissions descriptor
113: */
114: public int hashCode() {
115: return super .keyHashCode() + tableUUID.hashCode()
116: + ((type == null) ? 0 : type.hashCode());
117: }
118:
119: /**
120: * @see PermissionsDescriptor#checkOwner
121: */
122: public boolean checkOwner(String authorizationId)
123: throws StandardException {
124: TableDescriptor td = getDataDictionary().getTableDescriptor(
125: tableUUID);
126: if (td.getSchemaDescriptor().getAuthorizationId().equals(
127: 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 getObjectName() {
145: return "Column Privilege on " + tableName;
146: }
147:
148: /**
149: * Get the provider's type.
150: *
151: * @return char The provider's type.
152: */
153: public String getClassType() {
154: return Dependable.COLUMNS_PERMISSION;
155: }
156:
157: /**
158: @return the stored form of this provider
159:
160: @see Dependable#getDependableFinder
161: */
162: public DependableFinder getDependableFinder() {
163: return new DDdependableFinder(
164: StoredFormatIds.COLUMNS_PERMISSION_FINDER_V01_ID);
165: }
166:
167: }
|