1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.types.DataValueDescriptor; 25 26 import org.apache.derby.iapi.sql.dictionary.SystemColumn; 27 28 import org.apache.derby.iapi.types.DataValueFactory; 29 import org.apache.derby.iapi.types.RowLocation; 30 31 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory; 32 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor; 33 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 34 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 35 36 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 37 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 38 39 import org.apache.derby.iapi.services.sanity.SanityManager; 40 41 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 42 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 43 import org.apache.derby.iapi.sql.execute.ExecRow; 44 45 import org.apache.derby.iapi.error.StandardException; 46 47 import org.apache.derby.catalog.UUID; 48 import org.apache.derby.iapi.services.uuid.UUIDFactory; 49 50 57 58 class SYSTABLESRowFactory extends CatalogRowFactory 59 { 60 private static final String TABLENAME_STRING = "SYSTABLES"; 61 62 protected static final int SYSTABLES_COLUMN_COUNT = 5; 63 64 protected static final int SYSTABLES_TABLEID = 1; 65 protected static final int SYSTABLES_TABLENAME = 2; 66 protected static final int SYSTABLES_TABLETYPE = 3; 67 protected static final int SYSTABLES_SCHEMAID = 4; 68 protected static final int SYSTABLES_LOCKGRANULARITY = 5; 69 70 protected static final int SYSTABLES_INDEX1_ID = 0; 71 protected static final int SYSTABLES_INDEX1_TABLENAME = 1; 72 protected static final int SYSTABLES_INDEX1_SCHEMAID = 2; 73 74 protected static final int SYSTABLES_INDEX2_ID = 1; 75 protected static final int SYSTABLES_INDEX2_TABLEID = 1; 76 77 79 private static final String [] uuids = 80 { 81 "80000018-00d0-fd77-3ed8-000a0a0b1900" ,"80000028-00d0-fd77-3ed8-000a0a0b1900" ,"8000001a-00d0-fd77-3ed8-000a0a0b1900" ,"8000001c-00d0-fd77-3ed8-000a0a0b1900" }; 86 87 private static final int[][] indexColumnPositions = 88 { 89 { SYSTABLES_TABLENAME, SYSTABLES_SCHEMAID}, 90 { SYSTABLES_TABLEID } 91 }; 92 93 99 SYSTABLESRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf, 100 boolean convertIdToLower) 101 { 102 super(uuidf,ef,dvf,convertIdToLower); 103 initInfo(SYSTABLES_COLUMN_COUNT, TABLENAME_STRING, indexColumnPositions, (boolean[]) null, uuids); 104 } 105 106 112 119 120 public ExecRow makeRow(TupleDescriptor td, 121 TupleDescriptor parent) 122 throws StandardException 123 { 124 UUID oid; 125 String tabSType = null; 126 int tabIType; 127 ExecRow row; 128 String lockGranularity = null; 129 String tableID = null; 130 String schemaID = null; 131 String tableName = null; 132 133 134 if (td != null) 135 { 136 140 TableDescriptor descriptor = (TableDescriptor)td; 141 SchemaDescriptor schema = (SchemaDescriptor)parent; 142 143 oid = descriptor.getUUID(); 144 if ( oid == null ) 145 { 146 oid = getUUIDFactory().createUUID(); 147 descriptor.setUUID(oid); 148 } 149 tableID = oid.toString(); 150 151 if (SanityManager.DEBUG) 152 { 153 SanityManager.ASSERT(schema != null, 154 "Schema should not be null unless empty row is true"); 155 if (schema.getUUID() == null) 156 { 157 SanityManager.THROWASSERT("schema " + schema + " has a null OID"); 158 } 159 } 160 161 schemaID = schema.getUUID().toString(); 162 163 tableName = descriptor.getName(); 164 165 168 tabIType = descriptor.getTableType(); 169 switch (tabIType) 170 { 171 case TableDescriptor.BASE_TABLE_TYPE: 172 tabSType = "T"; 173 break; 174 case TableDescriptor.SYSTEM_TABLE_TYPE: 175 tabSType = "S"; 176 break; 177 case TableDescriptor.VIEW_TYPE: 178 tabSType = "V"; 179 break; 180 181 case TableDescriptor.SYNONYM_TYPE: 182 tabSType = "A"; 183 break; 184 185 default: 186 if (SanityManager.DEBUG) 187 SanityManager.THROWASSERT("invalid table type"); 188 } 189 char[] lockGChar = new char[1]; 190 lockGChar[0] = descriptor.getLockGranularity(); 191 lockGranularity = new String (lockGChar); 192 } 193 194 195 196 199 200 201 row = getExecutionFactory().getValueRow(SYSTABLES_COLUMN_COUNT); 202 203 204 row.setColumn(SYSTABLES_TABLEID, dvf.getCharDataValue(tableID)); 205 206 207 row.setColumn(SYSTABLES_TABLENAME, dvf.getVarcharDataValue(tableName)); 208 209 210 row.setColumn(SYSTABLES_TABLETYPE, dvf.getCharDataValue(tabSType)); 211 212 213 row.setColumn(SYSTABLES_SCHEMAID, dvf.getCharDataValue(schemaID)); 214 215 216 row.setColumn(SYSTABLES_LOCKGRANULARITY, dvf.getCharDataValue(lockGranularity)); 217 218 return row; 219 } 220 221 230 ExecIndexRow buildEmptyIndexRow( int indexNumber, 231 RowLocation rowLocation) 232 throws StandardException 233 { 234 int ncols = getIndexColumnCount(indexNumber); 235 ExecIndexRow row = getExecutionFactory().getIndexableRow(ncols + 1); 236 237 row.setColumn(ncols + 1, rowLocation); 238 239 switch( indexNumber ) 240 { 241 case SYSTABLES_INDEX1_ID: 242 243 row.setColumn(1, getDataValueFactory().getVarcharDataValue((String ) null)); 244 245 246 row.setColumn(2, getDataValueFactory().getCharDataValue((String ) null)); 247 248 break; 249 250 case SYSTABLES_INDEX2_ID: 251 252 row.setColumn(1, getDataValueFactory().getCharDataValue((String ) null)); 253 break; 254 } 256 return row; 257 } 258 259 265 276 277 public TupleDescriptor buildDescriptor( 278 ExecRow row, 279 TupleDescriptor parentTupleDescriptor, 280 DataDictionary dd ) 281 throws StandardException 282 { 283 if (SanityManager.DEBUG) 284 SanityManager.ASSERT(row.nColumns() == SYSTABLES_COLUMN_COUNT, "Wrong number of columns for a SYSTABLES row"); 285 286 DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator(); 287 288 String tableUUIDString; 289 String schemaUUIDString; 290 int tableTypeEnum; 291 String lockGranularity; 292 String tableName, tableType; 293 DataValueDescriptor col; 294 UUID tableUUID; 295 UUID schemaUUID; 296 SchemaDescriptor schema; 297 TableDescriptor tabDesc; 298 299 300 col = row.getColumn(SYSTABLES_TABLEID); 301 tableUUIDString = col.getString(); 302 tableUUID = getUUIDFactory().recreateUUID(tableUUIDString); 303 304 305 306 col = row.getColumn(SYSTABLES_TABLENAME); 307 tableName = col.getString(); 308 309 310 col = row.getColumn(SYSTABLES_TABLETYPE); 311 tableType = col.getString(); 312 if (SanityManager.DEBUG) 313 { 314 SanityManager.ASSERT(tableType.length() == 1, "Fourth column type incorrect"); 315 } 316 switch (tableType.charAt(0)) 317 { 318 case 'T' : 319 tableTypeEnum = TableDescriptor.BASE_TABLE_TYPE; 320 break; 321 case 'S' : 322 tableTypeEnum = TableDescriptor.SYSTEM_TABLE_TYPE; 323 break; 324 case 'V' : 325 tableTypeEnum = TableDescriptor.VIEW_TYPE; 326 break; 327 case 'A' : 328 tableTypeEnum = TableDescriptor.SYNONYM_TYPE; 329 break; 330 default: 331 if (SanityManager.DEBUG) 332 SanityManager.THROWASSERT("Fourth column value invalid"); 333 tableTypeEnum = -1; 334 } 335 336 337 col = row.getColumn(SYSTABLES_SCHEMAID); 338 schemaUUIDString = col.getString(); 339 schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString); 340 341 schema = dd.getSchemaDescriptor(schemaUUID, null); 342 343 344 col = row.getColumn(SYSTABLES_LOCKGRANULARITY); 345 lockGranularity = col.getString(); 346 if (SanityManager.DEBUG) 347 { 348 SanityManager.ASSERT(lockGranularity.length() == 1, "Fifth column type incorrect"); 349 } 350 351 tabDesc = ddg.newTableDescriptor(tableName, schema, tableTypeEnum, lockGranularity.charAt(0)); 353 tabDesc.setUUID(tableUUID); 354 return tabDesc; 355 } 356 357 366 protected String getTableName(ExecRow row) 367 throws StandardException 368 { 369 DataValueDescriptor col; 370 371 col = row.getColumn(SYSTABLES_TABLENAME); 372 return col.getString(); 373 } 374 375 376 382 public SystemColumn[] buildColumnList() 383 { 384 SystemColumn[] columnList = new SystemColumn[SYSTABLES_COLUMN_COUNT]; 385 386 388 columnList[0] = new SystemColumnImpl( 389 convertIdCase( "TABLEID"), SYSTABLES_TABLEID, 0, 0, false, "CHAR", true, 36 ); 398 399 columnList[1] = new SystemColumnImpl( convertIdCase( "TABLENAME"), SYSTABLES_TABLENAME, false ); 404 405 columnList[2] = new SystemColumnImpl( 406 convertIdCase( "TABLETYPE"), SYSTABLES_TABLETYPE, 0, 0, false, "CHAR", true, 1 ); 415 416 columnList[3] = new SystemColumnImpl( 417 convertIdCase( "SCHEMAID"), SYSTABLES_SCHEMAID, 0, 0, false, "CHAR", true, 36 ); 426 427 columnList[4] = new SystemColumnImpl( 428 convertIdCase( "LOCKGRANULARITY"), SYSTABLES_LOCKGRANULARITY, 0, 0, false, "CHAR", true, 1 ); 437 438 return columnList; 439 } 440 441 } 442 | Popular Tags |