KickJava   Java API By Example, From Geeks To Geeks.

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


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

38 public class ColPermsDescriptor extends PermissionsDescriptor
39 {
40     private UUID tableUUID;
41     private String JavaDoc type;
42     private FormatableBitSet columns;
43     private String JavaDoc tableName;
44     
45     public ColPermsDescriptor( DataDictionary dd,
46                                String JavaDoc grantee,
47                                String JavaDoc grantor,
48                                UUID tableUUID,
49                                String JavaDoc type,
50                                FormatableBitSet columns) throws StandardException
51     {
52         super (dd, grantee, grantor);
53         this.tableUUID = tableUUID;
54         this.type = type;
55         this.columns = columns;
56         //tableUUID can be null only if the constructor with colPermsUUID
57
//has been invoked.
58
if (tableUUID != null)
59             tableName = dd.getTableDescriptor(tableUUID).getName();
60     }
61
62     /**
63      * This constructor just initializes the key fields of a ColPermsDescriptor
64      */

65     public ColPermsDescriptor( DataDictionary dd,
66                                String JavaDoc grantee,
67                                String JavaDoc grantor,
68                                UUID tableUUID,
69                                String JavaDoc type) throws StandardException
70     {
71         this( dd, grantee, grantor, tableUUID, type, (FormatableBitSet) null);
72     }
73     
74     public ColPermsDescriptor( DataDictionary dd,
75             UUID colPermsUUID) throws StandardException
76     {
77         super(dd,null,null);
78         this.oid = colPermsUUID;
79     }
80     
81     public int getCatalogNumber()
82     {
83         return DataDictionary.SYSCOLPERMS_CATALOG_NUM;
84     }
85     
86     /*----- getter functions for rowfactory ------*/
87     public UUID getTableUUID() { return tableUUID;}
88     public String JavaDoc getType() { return type;}
89     public FormatableBitSet getColumns() { return columns;}
90
91     public String JavaDoc toString()
92     {
93         return "colPerms: grantee=" + getGrantee() +
94         ",colPermsUUID=" + getUUID() +
95             ",grantor=" + getGrantor() +
96           ",tableUUID=" + getTableUUID() +
97           ",type=" + getType() +
98           ",columns=" + getColumns();
99     }
100
101     /**
102      * @return true iff the key part of this permissions descriptor equals the key part of another permissions
103      * descriptor.
104      */

105     public boolean equals( Object JavaDoc other)
106     {
107         if( !( other instanceof ColPermsDescriptor))
108             return false;
109         ColPermsDescriptor otherColPerms = (ColPermsDescriptor) other;
110         return super.keyEquals( otherColPerms) &&
111           tableUUID.equals( otherColPerms.tableUUID) &&
112           ((type == null) ? (otherColPerms.type == null) : type.equals( otherColPerms.type));
113     }
114     
115     /**
116      * @return the hashCode for the key part of this permissions descriptor
117      */

118     public int hashCode()
119     {
120         return super.keyHashCode() + tableUUID.hashCode() +
121         ((type == null) ? 0 : type.hashCode());
122     }
123     
124     /**
125      * @see PermissionsDescriptor#checkOwner
126      */

127     public boolean checkOwner(String JavaDoc authorizationId) throws StandardException
128     {
129         TableDescriptor td = getDataDictionary().getTableDescriptor(tableUUID);
130         if (td.getSchemaDescriptor().getAuthorizationId().equals(authorizationId))
131             return true;
132         else
133             return false;
134     }
135
136     //////////////////////////////////////////////
137
//
138
// PROVIDER INTERFACE
139
//
140
//////////////////////////////////////////////
141

142     /**
143      * Return the name of this Provider. (Useful for errors.)
144      *
145      * @return String The name of this provider.
146      */

147     public String JavaDoc getObjectName()
148     {
149         return "Column Privilege on " + tableName;
150     }
151
152     /**
153      * Get the provider's type.
154      *
155      * @return char The provider's type.
156      */

157     public String JavaDoc getClassType()
158     {
159         return Dependable.COLUMNS_PERMISSION;
160     }
161
162     /**
163         @return the stored form of this provider
164
165             @see Dependable#getDependableFinder
166      */

167     public DependableFinder getDependableFinder()
168     {
169         return new DDdependableFinder(StoredFormatIds.COLUMNS_PERMISSION_FINDER_V01_ID);
170     }
171
172 }
173
Popular Tags