1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.iapi.types.TypeId; 27 import org.apache.derby.iapi.sql.dictionary.SystemColumn; 28 import org.apache.derby.catalog.TypeDescriptor; 29 30 import org.apache.derby.iapi.types.DataValueDescriptor; 31 32 import org.apache.derby.iapi.types.DataValueFactory; 33 34 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory; 35 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 36 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 37 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 38 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator; 39 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 40 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor; 41 42 import org.apache.derby.iapi.types.RowLocation; 43 44 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 45 import org.apache.derby.iapi.sql.execute.ExecRow; 46 import org.apache.derby.iapi.sql.execute.ExecutionContext; 47 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 48 49 import org.apache.derby.iapi.error.StandardException; 50 51 import org.apache.derby.iapi.services.uuid.UUIDFactory; 52 import org.apache.derby.catalog.UUID; 53 54 import org.apache.derby.catalog.IndexDescriptor; 55 56 import java.util.Properties ; 57 58 63 64 public class SYSCONGLOMERATESRowFactory extends CatalogRowFactory 65 { 66 private static final String TABLENAME_STRING = "SYSCONGLOMERATES"; 67 68 protected static final int SYSCONGLOMERATES_COLUMN_COUNT = 8; 69 protected static final int SYSCONGLOMERATES_SCHEMAID = 1; 70 protected static final int SYSCONGLOMERATES_TABLEID = 2; 71 protected static final int SYSCONGLOMERATES_CONGLOMERATENUMBER = 3; 72 protected static final int SYSCONGLOMERATES_CONGLOMERATENAME = 4; 73 protected static final int SYSCONGLOMERATES_ISINDEX = 5; 74 protected static final int SYSCONGLOMERATES_DESCRIPTOR = 6; 75 protected static final int SYSCONGLOMERATES_ISCONSTRAINT = 7; 76 protected static final int SYSCONGLOMERATES_CONGLOMERATEID = 8; 77 78 protected static final int SYSCONGLOMERATES_INDEX1_ID = 0; 79 protected static final int SYSCONGLOMERATES_INDEX2_ID = 1; 80 protected static final int SYSCONGLOMERATES_INDEX3_ID = 2; 81 82 private static final boolean[] uniqueness = { 83 false, 84 true, 85 false 86 }; 87 88 private static final int[][] indexColumnPositions = 89 { 90 {SYSCONGLOMERATES_CONGLOMERATEID}, 91 {SYSCONGLOMERATES_CONGLOMERATENAME, SYSCONGLOMERATES_SCHEMAID}, 92 {SYSCONGLOMERATES_TABLEID} 93 }; 94 95 private static final String [] uuids = 96 { 97 "80000010-00d0-fd77-3ed8-000a0a0b1900" ,"80000027-00d0-fd77-3ed8-000a0a0b1900" ,"80000012-00d0-fd77-3ed8-000a0a0b1900" ,"80000014-00d0-fd77-3ed8-000a0a0b1900" ,"80000016-00d0-fd77-3ed8-000a0a0b1900" }; 103 104 SYSCONGLOMERATESRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf, 105 boolean convertIdToLower) 106 { 107 super(uuidf,ef,dvf,convertIdToLower); 108 initInfo(SYSCONGLOMERATES_COLUMN_COUNT, 109 TABLENAME_STRING, indexColumnPositions, 110 uniqueness, uuids ); 111 } 112 113 120 public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) 121 throws StandardException 122 { 123 ExecRow row; 124 DataValueDescriptor col; 125 String tabID =null; 126 Long conglomNumber = null; 127 String conglomName = null; 128 Boolean supportsIndex = null; 129 IndexRowGenerator indexRowGenerator = null; 130 Boolean supportsConstraint = null; 131 String conglomUUIDString = null; 132 String schemaID = null; 133 ConglomerateDescriptor conglomerate = (ConglomerateDescriptor)td; 134 135 136 137 if (td != null) 138 { 139 144 if (parent != null) 145 { 146 SchemaDescriptor sd = (SchemaDescriptor)parent; 147 schemaID = sd.getUUID().toString(); 148 } 149 else 150 { 151 schemaID = conglomerate.getSchemaID().toString(); 152 } 153 tabID = conglomerate.getTableID().toString(); 154 conglomNumber = new Long ( conglomerate.getConglomerateNumber() ); 155 conglomName = conglomerate.getConglomerateName(); 156 conglomUUIDString = conglomerate.getUUID().toString(); 157 158 supportsIndex = new Boolean ( conglomerate.isIndex() ); 159 indexRowGenerator = conglomerate.getIndexDescriptor(); 160 supportsConstraint = new Boolean ( conglomerate.isConstraint() ); 161 } 162 163 166 167 168 row = getExecutionFactory().getValueRow(SYSCONGLOMERATES_COLUMN_COUNT); 169 170 171 row.setColumn(1, dvf.getCharDataValue(schemaID)); 172 173 174 row.setColumn(2, dvf.getCharDataValue(tabID)); 175 176 177 row.setColumn(3, dvf.getDataValue(conglomNumber)); 178 179 183 row.setColumn(4, (conglomName == null) ? 184 dvf.getVarcharDataValue(tabID): 185 dvf.getVarcharDataValue(conglomName)); 186 187 188 row.setColumn(5, dvf.getDataValue(supportsIndex)); 189 190 193 row.setColumn(6, 194 dvf.getDataValue( 195 (indexRowGenerator == null ? 196 (IndexDescriptor) null : 197 indexRowGenerator.getIndexDescriptor() 198 ) 199 ) 200 ); 201 202 203 row.setColumn(7, dvf.getDataValue(supportsConstraint)); 204 205 206 row.setColumn(8, dvf.getCharDataValue(conglomUUIDString)); 207 208 return row; 209 } 210 211 public ExecRow makeEmptyRow() throws StandardException 212 { 213 return makeRow(null, null); 214 } 215 216 217 222 public Properties getCreateHeapProperties() 223 { 224 Properties properties = new Properties (); 225 properties.put("derby.storage.pageSize","4096"); 227 properties.put("derby.storage.pageReservedSpace","0"); 229 properties.put("derby.storage.minimumRecordSize","1"); 230 return properties; 231 } 232 233 240 public Properties getCreateIndexProperties(int indexNumber) 241 { 242 Properties properties = new Properties (); 243 properties.put("derby.storage.pageSize","4096"); 245 return properties; 246 } 247 248 254 264 265 public TupleDescriptor buildDescriptor( 266 ExecRow row, 267 TupleDescriptor parentTupleDescriptor, 268 DataDictionary dd ) 269 throws StandardException 270 { 271 if (SanityManager.DEBUG) 272 SanityManager.ASSERT( 273 row.nColumns() == SYSCONGLOMERATES_COLUMN_COUNT, 274 "Wrong number of columns for a SYSCONGLOMERATES row"); 275 276 DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator(); 277 long conglomerateNumber; 278 String name; 279 boolean isConstraint; 280 boolean isIndex; 281 IndexRowGenerator indexRowGenerator; 282 DataValueDescriptor col; 283 ConglomerateDescriptor conglomerateDesc; 284 String conglomUUIDString; 285 UUID conglomUUID; 286 String schemaUUIDString; 287 UUID schemaUUID; 288 String tableUUIDString; 289 UUID tableUUID; 290 291 292 col = row.getColumn(1); 293 schemaUUIDString = col.getString(); 294 schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString); 295 296 297 col = row.getColumn(2); 298 tableUUIDString = col.getString(); 299 tableUUID = getUUIDFactory().recreateUUID(tableUUIDString); 300 301 302 303 col = row.getColumn(3); 304 conglomerateNumber = col.getLong(); 305 306 307 col = row.getColumn(4); 308 name = col.getString(); 309 310 311 col = row.getColumn(5); 312 isIndex = col.getBoolean(); 313 314 315 col = row.getColumn(6); 316 indexRowGenerator = new IndexRowGenerator( 317 (IndexDescriptor) col.getObject()); 318 319 320 col = row.getColumn(7); 321 isConstraint = col.getBoolean(); 322 323 324 col = row.getColumn(8); 325 conglomUUIDString = col.getString(); 326 conglomUUID = getUUIDFactory().recreateUUID(conglomUUIDString); 327 328 329 conglomerateDesc = ddg.newConglomerateDescriptor(conglomerateNumber, 330 name, 331 isIndex, 332 indexRowGenerator, 333 isConstraint, 334 conglomUUID, 335 tableUUID, 336 schemaUUID); 337 return conglomerateDesc; 338 } 339 340 349 protected UUID getConglomerateUUID(ExecRow row) 350 throws StandardException 351 { 352 DataValueDescriptor col; 353 String conglomerateUUIDString; 354 355 356 col = row.getColumn(SYSCONGLOMERATES_CONGLOMERATEID); 357 conglomerateUUIDString = col.getString(); 358 return getUUIDFactory().recreateUUID(conglomerateUUIDString); 359 } 360 361 370 protected UUID getTableUUID(ExecRow row) 371 throws StandardException 372 { 373 DataValueDescriptor col; 374 String tableUUIDString; 375 376 377 col = row.getColumn(SYSCONGLOMERATES_TABLEID); 378 tableUUIDString = col.getString(); 379 return getUUIDFactory().recreateUUID(tableUUIDString); 380 } 381 382 391 protected UUID getSchemaUUID(ExecRow row) 392 throws StandardException 393 { 394 DataValueDescriptor col; 395 String schemaUUIDString; 396 397 398 col = row.getColumn(SYSCONGLOMERATES_SCHEMAID); 399 schemaUUIDString = col.getString(); 400 return getUUIDFactory().recreateUUID(schemaUUIDString); 401 } 402 403 412 protected String getConglomerateName(ExecRow row) 413 throws StandardException 414 { 415 DataValueDescriptor col; 416 417 418 col = row.getColumn(SYSCONGLOMERATES_CONGLOMERATENAME); 419 return col.getString(); 420 } 421 422 428 public SystemColumn[] buildColumnList() 429 { 430 int index = 0; 431 SystemColumn[] columnList = new SystemColumn[SYSCONGLOMERATES_COLUMN_COUNT]; 432 433 435 436 columnList[index++] = 437 new SystemColumnImpl( 438 convertIdCase( "SCHEMAID"), SYSCONGLOMERATES_SCHEMAID, 0, 0, false, "CHAR", true, 36 ); 447 448 columnList[index++] = 449 new SystemColumnImpl( 450 convertIdCase( "TABLEID"), SYSCONGLOMERATES_TABLEID, 0, 0, false, "CHAR", true, 36 ); 459 columnList[index++] = 460 new SystemColumnImpl( 461 convertIdCase( "CONGLOMERATENUMBER"), SYSCONGLOMERATES_CONGLOMERATENUMBER, 0, 0, false, "BIGINT", true, TypeId.LONGINT_MAXWIDTH ); 470 471 columnList[index++] = 472 new SystemColumnImpl( convertIdCase( "CONGLOMERATENAME"), SYSCONGLOMERATES_CONGLOMERATENAME, 475 true ); 477 478 columnList[index++] = 479 new SystemColumnImpl( 480 convertIdCase( "ISINDEX"), SYSCONGLOMERATES_ISINDEX, 0, 0, false, "BOOLEAN", true, 1 ); 489 490 columnList[index++] = 491 new SystemColumnImpl( 492 convertIdCase( "DESCRIPTOR"), SYSCONGLOMERATES_DESCRIPTOR, 494 0, 0, true, "org.apache.derby.catalog.IndexDescriptor", false, TypeDescriptor.MAXIMUM_WIDTH_UNKNOWN 500 ); 502 503 columnList[index++] = 504 new SystemColumnImpl( 505 convertIdCase( "ISCONSTRAINT"), SYSCONGLOMERATES_ISCONSTRAINT, 507 0, 0, true, "BOOLEAN", true, 1 ); 514 515 columnList[index++] = 516 new SystemColumnImpl( 517 convertIdCase( "CONGLOMERATEID"), SYSCONGLOMERATES_CONGLOMERATEID, 519 0, 0, false, "CHAR", true, 36 ); 526 527 return columnList; 528 529 } 530 } 531 | Popular Tags |