1 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 47 48 public class SYSROUTINEPERMSRowFactory extends PermissionsCatalogRowFactory 49 { 50 static final String TABLENAME_STRING = "SYSROUTINEPERMS"; 51 52 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 [] uuids = 74 { 75 "2057c01b-0103-0e39-b8e7-00000010f010" ,"185e801c-0103-0e39-b8e7-00000010f010" ,"c065801d-0103-0e39-b8e7-00000010f010" ,"40f70088-010c-4c2f-c8de-0000000f43a0" ,"08264012-010c-bc85-060d-000000109ab8" }; 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 routinePermID = null; 95 DataValueDescriptor grantee = null; 96 DataValueDescriptor grantor = null; 97 String 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 } 128 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 routinePermsUUIDString = row.getColumn(ROUTINEPERMSID_COL_NUM).getString(); 139 UUID routinePermsUUID = getUUIDFactory().recreateUUID(routinePermsUUIDString); 140 String 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 } 152 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, 0, false, "CHAR", 166 true, 167 36); 168 columnList[ GRANTEE_COL_NUM - 1] = 169 new SystemColumnImpl( convertIdCase( "GRANTEE"), 170 GRANTEE_COL_NUM, 171 0, 0, false, 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, 0, false, 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, 0, false, "CHAR", true, 36); 195 columnList[ GRANTOPTION_COL_NUM - 1] = 196 new SystemColumnImpl( convertIdCase( "GRANTOPTION"), 197 GRANTOPTION_COL_NUM, 198 0, 0, false, "CHAR", true, 1); 204 } 205 return columnList; 206 } 208 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 row = getExecutionFactory().getIndexableRow( 2); 232 row.setColumn(1, getAuthorizationID( perm.getGrantee())); 233 String 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 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 } 250 public int getPrimaryKeyIndexNumber() 251 { 252 return GRANTEE_ALIAS_GRANTOR_INDEX_NUM; 253 } 254 255 267 public int orPermissions( ExecRow row, PermissionsDescriptor perm, boolean[] colsChanged) 268 throws StandardException 269 { 270 return 0; 274 } 275 276 288 public int removePermissions( ExecRow row, PermissionsDescriptor perm, boolean[] colsChanged) 289 throws StandardException 290 { 291 return -1; } 294 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 |