KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > catalog > SYSROUTINEPERMSRowFactory


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.SYSROUTINEPERMSRowFactory
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.impl.sql.catalog;
23
24 import org.apache.derby.iapi.sql.dictionary.SystemColumn;
25 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
26 import org.apache.derby.iapi.sql.dictionary.RoutinePermsDescriptor;
27 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
28 import org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor;
29
30 import org.apache.derby.iapi.error.StandardException;
31
32 import org.apache.derby.iapi.services.sanity.SanityManager;
33 import org.apache.derby.iapi.sql.execute.ExecRow;
34 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
35 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
36 import org.apache.derby.iapi.types.DataValueFactory;
37 import org.apache.derby.iapi.types.RowLocation;
38 import org.apache.derby.iapi.types.DataValueDescriptor;
39 import org.apache.derby.iapi.types.StringDataValue;
40 import org.apache.derby.iapi.services.uuid.UUIDFactory;
41 import org.apache.derby.catalog.UUID;
42
43 /**
44  * Factory for creating a SYSROUTINEPERMS row.
45  *
46  */

47
48 public class SYSROUTINEPERMSRowFactory extends PermissionsCatalogRowFactory
49 {
50     static final String JavaDoc TABLENAME_STRING = "SYSROUTINEPERMS";
51
52     // Column numbers for the SYSROUTINEPERMS table. 1 based
53
private static final int ROUTINEPERMSID_COL_NUM = 1;
54     private static final int GRANTEE_COL_NUM = 2;
55     private static final int GRANTOR_COL_NUM = 3;
56     private static final int ALIASID_COL_NUM = 4;
57     private static final int GRANTOPTION_COL_NUM = 5;
58     private static final int COLUMN_COUNT = 5;
59
60     static final int GRANTEE_ALIAS_GRANTOR_INDEX_NUM = 0;
61     public static final int ROUTINEPERMSID_INDEX_NUM = 1;
62     public static final int ALIASID_INDEX_NUM = 2;
63
64     private static final int[][] indexColumnPositions =
65     {
66         { GRANTEE_COL_NUM, ALIASID_COL_NUM, GRANTOR_COL_NUM},
67         { ROUTINEPERMSID_COL_NUM },
68         { ALIASID_COL_NUM }
69     };
70
71     private static final boolean[] indexUniqueness = { true, true, false };
72
73     private static final String JavaDoc[] uuids =
74     {
75         "2057c01b-0103-0e39-b8e7-00000010f010" // catalog UUID
76
,"185e801c-0103-0e39-b8e7-00000010f010" // heap UUID
77
,"c065801d-0103-0e39-b8e7-00000010f010" // index1
78
,"40f70088-010c-4c2f-c8de-0000000f43a0" // index2
79
,"08264012-010c-bc85-060d-000000109ab8" // index3
80
};
81
82     private SystemColumn[] columnList;
83
84     public SYSROUTINEPERMSRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf,
85                                      boolean convertIdToLower)
86     {
87         super(uuidf,ef,dvf,convertIdToLower);
88         initInfo( COLUMN_COUNT, TABLENAME_STRING, indexColumnPositions, indexUniqueness, uuids);
89     }
90
91     public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException
92     {
93         UUID oid;
94         String JavaDoc routinePermID = null;
95         DataValueDescriptor grantee = null;
96         DataValueDescriptor grantor = null;
97         String JavaDoc routineID = null;
98         
99         if( td == null)
100         {
101             grantee = getNullAuthorizationID();
102             grantor = getNullAuthorizationID();
103         }
104         else
105         {
106             RoutinePermsDescriptor rpd = (RoutinePermsDescriptor) td;
107             oid = rpd.getUUID();
108             if ( oid == null )
109             {
110                 oid = getUUIDFactory().createUUID();
111                 rpd.setUUID(oid);
112             }
113             routinePermID = oid.toString();
114             grantee = getAuthorizationID( rpd.getGrantee());
115             grantor = getAuthorizationID( rpd.getGrantor());
116             if( rpd.getRoutineUUID() != null)
117                 routineID = rpd.getRoutineUUID().toString();
118         }
119         ExecRow row = getExecutionFactory().getValueRow( COLUMN_COUNT);
120         row.setColumn( ROUTINEPERMSID_COL_NUM, dvf.getCharDataValue(routinePermID));
121         row.setColumn( GRANTEE_COL_NUM, grantee);
122         row.setColumn( GRANTOR_COL_NUM, grantor);
123         row.setColumn( ALIASID_COL_NUM, dvf.getCharDataValue( routineID));
124         row.setColumn( GRANTOPTION_COL_NUM, dvf.getCharDataValue( "N"));
125         return row;
126     } // end of makeRow
127

128     /** builds a tuple descriptor from a row */
129     public TupleDescriptor buildDescriptor(ExecRow row,
130                                            TupleDescriptor parentTuple,
131                                            DataDictionary dataDictionary)
132         throws StandardException
133     {
134         if( SanityManager.DEBUG)
135             SanityManager.ASSERT( row.nColumns() == COLUMN_COUNT,
136                                   "Wrong size row passed to SYSROUTINEPERMSRowFactory.buildDescriptor");
137
138         String JavaDoc routinePermsUUIDString = row.getColumn(ROUTINEPERMSID_COL_NUM).getString();
139         UUID routinePermsUUID = getUUIDFactory().recreateUUID(routinePermsUUIDString);
140         String JavaDoc aliasUUIDString = row.getColumn( ALIASID_COL_NUM).getString();
141         UUID aliasUUID = getUUIDFactory().recreateUUID(aliasUUIDString);
142
143         RoutinePermsDescriptor routinePermsDesc =
144             new RoutinePermsDescriptor( dataDictionary,
145                     getAuthorizationID( row, GRANTEE_COL_NUM),
146                     getAuthorizationID( row, GRANTOR_COL_NUM),
147                     aliasUUID);
148         routinePermsDesc.setUUID(routinePermsUUID);
149             return routinePermsDesc;
150     } // end of buildDescriptor
151

152     /** builds a column list for the catalog */
153     public SystemColumn[] buildColumnList()
154     {
155         if (columnList == null)
156         {
157             columnList = new SystemColumn[ COLUMN_COUNT];
158
159             columnList[ ROUTINEPERMSID_COL_NUM - 1] =
160                 new SystemColumnImpl( convertIdCase( "ROUTINEPERMSID"),
161                                       ROUTINEPERMSID_COL_NUM,
162                                       0, // precision
163
0, // scale
164
false, // nullability
165
"CHAR",
166                                       true,
167                                       36);
168             columnList[ GRANTEE_COL_NUM - 1] =
169               new SystemColumnImpl( convertIdCase( "GRANTEE"),
170                                     GRANTEE_COL_NUM,
171                                     0, // precision
172
0, // scale
173
false, // nullability
174
AUTHORIZATION_ID_TYPE,
175                                     AUTHORIZATION_ID_IS_BUILTIN_TYPE,
176                                     AUTHORIZATION_ID_LENGTH);
177             columnList[ GRANTOR_COL_NUM - 1] =
178               new SystemColumnImpl( convertIdCase( "GRANTOR"),
179                                     GRANTOR_COL_NUM,
180                                     0, // precision
181
0, // scale
182
false, // nullability
183
AUTHORIZATION_ID_TYPE,
184                                     AUTHORIZATION_ID_IS_BUILTIN_TYPE,
185                                     AUTHORIZATION_ID_LENGTH);
186             columnList[ ALIASID_COL_NUM - 1] =
187               new SystemColumnImpl( convertIdCase( "ALIASID"),
188                                     ALIASID_COL_NUM,
189                                     0, // precision
190
0, // scale
191
false, // nullability
192
"CHAR", // dataType
193
true, // built-in type
194
36);
195             columnList[ GRANTOPTION_COL_NUM - 1] =
196               new SystemColumnImpl( convertIdCase( "GRANTOPTION"),
197                                     GRANTOPTION_COL_NUM,
198                                     0, // precision
199
0, // scale
200
false, // nullability
201
"CHAR", // dataType
202
true, // built-in type
203
1);
204         }
205         return columnList;
206     } // end of buildColumnList
207

208     /**
209      * builds an index key row given for a given index number.
210      */

211     public ExecIndexRow buildIndexKeyRow( int indexNumber,
212                                           PermissionsDescriptor perm)
213         throws StandardException
214     {
215         ExecIndexRow row = null;
216         
217         switch( indexNumber)
218         {
219         case GRANTEE_ALIAS_GRANTOR_INDEX_NUM:
220             // RESOLVE We do not support the FOR GRANT OPTION, so rougine permission rows are unique on the
221
// grantee and alias UUID columns. The grantor column will always have the name of the owner of the
222
// routine. So the index key, used for searching the index, only has grantee and alias UUID columns.
223
// It does not have a grantor column.
224
//
225
// If we support FOR GRANT OPTION then there may be multiple routine permissions rows for a
226
// (grantee, aliasID) combination. Since there is only one kind of routine permission (execute)
227
// execute permission checking need not worry about multiple routine permission rows for a
228
// (grantee, aliasID) combination, it only cares whether there are any. Grant and revoke must
229
// look through multiple rows to see if the current user has grant/revoke permission and use
230
// the full key in checking for the pre-existence of the permission being granted or revoked.
231
row = getExecutionFactory().getIndexableRow( 2);
232             row.setColumn(1, getAuthorizationID( perm.getGrantee()));
233             String JavaDoc routineUUIDStr = ((RoutinePermsDescriptor) perm).getRoutineUUID().toString();
234             row.setColumn(2, getDataValueFactory().getCharDataValue( routineUUIDStr));
235             break;
236         case ROUTINEPERMSID_INDEX_NUM:
237             row = getExecutionFactory().getIndexableRow( 1);
238             String JavaDoc routinePermsUUIDStr = perm.getObjectID().toString();
239             row.setColumn(1, getDataValueFactory().getCharDataValue( routinePermsUUIDStr));
240             break;
241         case ALIASID_INDEX_NUM:
242             row = getExecutionFactory().getIndexableRow( 1);
243             routineUUIDStr = ((RoutinePermsDescriptor) perm).getRoutineUUID().toString();
244             row.setColumn(1, getDataValueFactory().getCharDataValue( routineUUIDStr));
245             break;
246         }
247         return row;
248     } // end of buildIndexKeyRow
249

250     public int getPrimaryKeyIndexNumber()
251     {
252         return GRANTEE_ALIAS_GRANTOR_INDEX_NUM;
253     }
254
255     /**
256      * Or a set of permissions in with a row from this catalog table
257      *
258      * @param row an existing row
259      * @param perm a permission descriptor of the appropriate class for this PermissionsCatalogRowFactory class.
260      * @param colsChanged An array with one element for each column in row. It is updated to
261      * indicate which columns in row were changed
262      *
263      * @return The number of columns that were changed.
264      *
265      * @exception StandardException standard error policy
266      */

267     public int orPermissions( ExecRow row, PermissionsDescriptor perm, boolean[] colsChanged)
268         throws StandardException
269     {
270         // There is only one kind of routine permission: execute or not. So the row would not exist
271
// unless execute permission is there.
272
// This changes if we implement WITH GRANT OPTION.
273
return 0;
274     }
275
276     /**
277      * Remove a set of permissions from a row from this catalog table
278      *
279      * @param row an existing row
280      * @param perm a permission descriptor of the appropriate class for this PermissionsCatalogRowFactory class.
281      * @param colsChanged An array with one element for each column in row. It is updated to
282      * indicate which columns in row were changed
283      *
284      * @return -1 if there are no permissions left in the row, otherwise the number of columns that were changed.
285      *
286      * @exception StandardException standard error policy
287      */

288     public int removePermissions( ExecRow row, PermissionsDescriptor perm, boolean[] colsChanged)
289         throws StandardException
290     {
291         return -1; // There is only one kind of routine privilege so delete the whole row.
292
} // end of removePermissions
293

294     /**
295      * @see PermissionsCatalogRowFactory#setUUIDOfThePassedDescriptor
296      */

297     public void setUUIDOfThePassedDescriptor(ExecRow row, PermissionsDescriptor perm)
298     throws StandardException
299     {
300         DataValueDescriptor existingPermDVD = row.getColumn(ROUTINEPERMSID_COL_NUM);
301         perm.setUUID(getUUIDFactory().recreateUUID(existingPermDVD.getString()));
302     }
303 }
304
Popular Tags