1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.reference.Property; 25 26 import org.apache.derby.iapi.types.DataTypeDescriptor; 27 import org.apache.derby.iapi.types.TypeId; 28 import org.apache.derby.iapi.types.DataValueDescriptor; 29 30 import org.apache.derby.iapi.store.raw.RawStoreFactory; 31 32 import org.apache.derby.iapi.types.TypeId; 33 import org.apache.derby.iapi.sql.dictionary.SystemColumn; 34 import org.apache.derby.catalog.TypeDescriptor; 35 36 import org.apache.derby.iapi.types.DataValueFactory; 37 import org.apache.derby.iapi.types.RowLocation; 38 39 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory; 40 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 41 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 42 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 43 import org.apache.derby.iapi.sql.dictionary.SPSDescriptor; 44 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor; 45 46 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 47 import org.apache.derby.iapi.sql.execute.ExecRow; 48 import org.apache.derby.iapi.sql.execute.ExecPreparedStatement; 49 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 50 51 import org.apache.derby.iapi.error.StandardException; 52 53 import org.apache.derby.iapi.services.monitor.Monitor; 54 import org.apache.derby.catalog.UUID; 55 import org.apache.derby.iapi.services.uuid.UUIDFactory; 56 import org.apache.derby.iapi.types.*; 57 58 import org.apache.derby.iapi.services.sanity.SanityManager; 59 60 import java.sql.Timestamp ; 61 import java.util.Properties ; 62 63 70 71 public class SYSSTATEMENTSRowFactory extends CatalogRowFactory 72 { 73 static final String TABLENAME_STRING = "SYSSTATEMENTS"; 74 75 76 public static final int SYSSTATEMENTS_STMTID = 1; 77 public static final int SYSSTATEMENTS_STMTNAME = 2; 78 public static final int SYSSTATEMENTS_SCHEMAID = 3; 79 public static final int SYSSTATEMENTS_TYPE = 4; 80 public static final int SYSSTATEMENTS_VALID = 5; 81 public static final int SYSSTATEMENTS_TEXT = 6; 82 public static final int SYSSTATEMENTS_LASTCOMPILED = 7; 83 public static final int SYSSTATEMENTS_COMPILATION_SCHEMAID = 8; 84 public static final int SYSSTATEMENTS_USINGTEXT = 9; 85 public static final int SYSSTATEMENTS_CONSTANTSTATE = 10; 86 public static final int SYSSTATEMENTS_INITIALLY_COMPILABLE = 11; 87 88 public static final int SYSSTATEMENTS_COLUMN_COUNT = SYSSTATEMENTS_INITIALLY_COMPILABLE; 89 90 public static final int SYSSTATEMENTS_HIDDEN_COLUMN_COUNT = 2; 91 92 protected static final int SYSSTATEMENTS_INDEX1_ID = 0; 93 protected static final int SYSSTATEMENTS_INDEX2_ID = 1; 94 95 96 private static final int[][] indexColumnPositions = 97 { 98 {SYSSTATEMENTS_STMTID}, 99 {SYSSTATEMENTS_STMTNAME, SYSSTATEMENTS_SCHEMAID} 100 }; 101 102 private static final boolean[] uniqueness = null; 103 104 private static final String [] uuids = 105 { 106 "80000000-00d1-15f7-ab70-000a0a0b1500" ,"80000000-00d1-15fc-60b9-000a0a0b1500" ,"80000000-00d1-15fc-eda1-000a0a0b1500" ,"80000000-00d1-15fe-bdf8-000a0a0b1500" }; 111 112 118 public SYSSTATEMENTSRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf, 119 boolean convertIdToLower) 120 { 121 super(uuidf,ef,dvf,convertIdToLower); 122 initInfo(SYSSTATEMENTS_COLUMN_COUNT, TABLENAME_STRING, 123 indexColumnPositions, uniqueness, uuids); 124 } 125 126 132 151 152 public ExecRow makeSYSSTATEMENTSrow( 153 boolean compileMe, 154 SPSDescriptor spsDescriptor 155 ) throws StandardException 156 { 157 DataTypeDescriptor dtd; 158 ExecRow row; 159 DataValueDescriptor col; 160 String name = null; 161 UUID uuid = null; 162 String uuidStr = null; 163 String suuidStr = null; String compUuidStr = null; String text = null; 166 String usingText = null; 167 ExecPreparedStatement preparedStatement = null; 168 String typeStr = null; 169 boolean valid = true; 170 Timestamp time = null; 171 boolean initiallyCompilable = true; 172 173 if (spsDescriptor != null) 174 { 175 name = spsDescriptor.getName(); 176 uuid = spsDescriptor.getUUID(); 177 if ( uuid == null ) 178 { 179 uuid = getUUIDFactory().createUUID(); 180 spsDescriptor.setUUID(uuid); 181 } 182 suuidStr = spsDescriptor.getSchemaDescriptor().getUUID().toString(); 183 uuidStr = uuid.toString(); 184 text = spsDescriptor.getText(); 185 valid = spsDescriptor.isValid(); 186 time = spsDescriptor.getCompileTime(); 187 typeStr = spsDescriptor.getTypeAsString(); 188 initiallyCompilable = spsDescriptor.initiallyCompilable(); 189 preparedStatement = spsDescriptor.getPreparedStatement(compileMe); 190 compUuidStr = spsDescriptor.getCompSchemaId().toString(); 191 usingText = spsDescriptor.getUsingText(); 192 } 193 194 195 row = getExecutionFactory().getValueRow(SYSSTATEMENTS_COLUMN_COUNT); 196 197 198 row.setColumn(1, dvf.getCharDataValue(uuidStr)); 199 200 201 row.setColumn(2, dvf.getVarcharDataValue(name)); 202 203 204 row.setColumn(3, dvf.getCharDataValue(suuidStr)); 205 206 207 row.setColumn(4, dvf.getCharDataValue(typeStr)); 208 209 210 row.setColumn(5, dvf.getDataValue(valid)); 211 212 213 row.setColumn(6, dvf.getLongvarcharDataValue(text)); 214 215 216 row.setColumn(7, new SQLTimestamp(time)); 217 218 219 row.setColumn(8, dvf.getCharDataValue(compUuidStr)); 220 221 222 row.setColumn(9, dvf.getLongvarcharDataValue(usingText)); 223 224 229 row.setColumn(10, dvf.getDataValue(preparedStatement)); 230 231 232 row.setColumn(11, dvf.getDataValue(initiallyCompilable)); 233 234 return row; 235 } 236 237 243 254 public TupleDescriptor buildDescriptor( 255 ExecRow row, 256 TupleDescriptor parentTupleDescriptor, 257 DataDictionary dd ) 258 throws StandardException 259 { 260 DataValueDescriptor col; 261 SPSDescriptor descriptor; 262 String name; 263 String text; 264 String usingText; 265 UUID uuid; 266 UUID compUuid; 267 String uuidStr; 268 UUID suuid; String suuidStr; String typeStr; 271 char type; 272 boolean valid; 273 Timestamp time = null; 274 ExecPreparedStatement preparedStatement = null; 275 boolean initiallyCompilable; 276 DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator(); 277 278 if (SanityManager.DEBUG) 279 { 280 SanityManager.ASSERT(row.nColumns() == SYSSTATEMENTS_COLUMN_COUNT, 281 "Wrong number of columns for a SYSSTATEMENTS row"); 282 } 283 284 col = row.getColumn(1); 286 uuidStr = col.getString(); 287 uuid = getUUIDFactory().recreateUUID(uuidStr); 288 289 col = row.getColumn(2); 291 name = col.getString(); 292 293 col = row.getColumn(3); 295 suuidStr = col.getString(); 296 suuid = getUUIDFactory().recreateUUID(suuidStr); 297 298 col = row.getColumn(4); 300 type = col.getString().charAt(0); 301 302 if (SanityManager.DEBUG) 303 { 304 if (!SPSDescriptor.validType(type)) 305 { 306 SanityManager.THROWASSERT("Bad type value ("+type+") for statement "+name); 307 } 308 } 309 310 if (((DataDictionaryImpl) dd).readOnlyUpgrade) { 313 valid = false; 314 } else { 315 col = row.getColumn(5); 317 valid = col.getBoolean(); 318 } 319 320 col = row.getColumn(6); 322 text = col.getString(); 323 324 325 col = row.getColumn(7); 326 time = col.getTimestamp(new java.util.GregorianCalendar ()); 327 328 col = row.getColumn(8); 330 uuidStr = col.getString(); 331 compUuid = getUUIDFactory().recreateUUID(uuidStr); 332 333 col = row.getColumn(9); 335 usingText = col.getString(); 336 337 339 if (valid) { 341 col = row.getColumn(10); 342 preparedStatement = (ExecPreparedStatement) col.getObject(); 343 } 344 345 col = row.getColumn(11); 347 if ( col.isNull() ) { initiallyCompilable = true; } 348 else { initiallyCompilable = col.getBoolean(); } 349 350 descriptor = new SPSDescriptor(dd, name, 351 uuid, 352 suuid, 353 compUuid, 354 type, 355 valid, 356 text, 357 usingText, 358 time, 359 preparedStatement, 360 initiallyCompilable 361 ); 362 363 return descriptor; 364 } 365 366 public ExecRow makeEmptyRow() 367 throws StandardException 368 { 369 return makeSYSSTATEMENTSrow(false, 370 (SPSDescriptor) null); 371 } 372 373 383 public SystemColumn[] buildColumnList() 384 { 385 389 SystemColumn[] columnList = new SystemColumn[SYSSTATEMENTS_COLUMN_COUNT - SYSSTATEMENTS_HIDDEN_COLUMN_COUNT]; 390 391 392 columnList[0] = new SystemColumnImpl( 394 convertIdCase( "STMTID"), SYSSTATEMENTS_STMTID, 0, 0, false, "CHAR", true, 36 ); 403 404 columnList[1] = 405 new SystemColumnImpl( convertIdCase( "STMTNAME"), SYSSTATEMENTS_STMTNAME, false ); 410 411 columnList[2] = new SystemColumnImpl( 412 convertIdCase( "SCHEMAID"), SYSSTATEMENTS_SCHEMAID, 0, 0, false, "CHAR", true, 36 ); 421 422 columnList[3] = 423 new SystemColumnImpl( 424 convertIdCase( "TYPE"), SYSSTATEMENTS_TYPE, 0, 0, false, "CHAR", true, 1 ); 433 434 columnList[4] = 435 new SystemColumnImpl( 436 convertIdCase( "VALID"), SYSSTATEMENTS_VALID, 0, 0, false, "BOOLEAN", true, 1 ); 445 446 columnList[5] = 447 new SystemColumnImpl( 448 convertIdCase( "TEXT"), SYSSTATEMENTS_TEXT, 0, 0, false, "LONG VARCHAR", true, TypeId.LONGVARCHAR_MAXWIDTH ); 457 458 columnList[6] = 459 new SystemColumnImpl( 460 convertIdCase( "LASTCOMPILED"), SYSSTATEMENTS_LASTCOMPILED, 0, 0, true, "TIMESTAMP", true, TypeId.TIMESTAMP_MAXWIDTH ); 469 470 columnList[7] = new SystemColumnImpl( 471 convertIdCase( "COMPILATIONSCHEMAID"), SYSSTATEMENTS_COMPILATION_SCHEMAID, 0, 0, false, "CHAR", true, 36 ); 480 481 columnList[8] = 482 new SystemColumnImpl( 483 convertIdCase( "USINGTEXT"), SYSSTATEMENTS_USINGTEXT, 0, 0, true, "LONG VARCHAR", true, TypeId.LONGVARCHAR_MAXWIDTH ); 492 498 510 516 528 529 return columnList; 530 } 531 532 537 public Properties getCreateHeapProperties() 538 { 539 Properties properties = new Properties (); 540 541 properties.put(Property.PAGE_SIZE_PARAMETER,"2048"); 544 545 properties.put(RawStoreFactory.PAGE_RESERVED_SPACE_PARAMETER,"0"); 547 properties.put(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER,"1"); 548 return properties; 549 } 550 551 } 552 | Popular Tags |