1 21 22 package org.apache.derby.iapi.sql.dictionary; 23 24 import org.apache.derby.iapi.reference.Property; 25 import org.apache.derby.iapi.util.StringUtil; 26 27 import org.apache.derby.iapi.services.context.ContextService; 28 import org.apache.derby.iapi.services.monitor.Monitor; 29 import org.apache.derby.iapi.services.sanity.SanityManager; 30 import org.apache.derby.iapi.error.StandardException; 31 import org.apache.derby.iapi.types.DataValueFactory; 32 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 33 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 34 import org.apache.derby.iapi.sql.execute.ExecRow; 35 import org.apache.derby.iapi.sql.execute.ExecutionContext; 36 import org.apache.derby.iapi.types.DataTypeDescriptor; 37 import org.apache.derby.iapi.types.DataValueFactory; 38 import org.apache.derby.iapi.types.RowLocation; 39 import org.apache.derby.iapi.store.raw.RawStoreFactory; 40 import org.apache.derby.iapi.services.uuid.UUIDFactory; 41 import org.apache.derby.catalog.UUID; 42 import java.util.Properties ; 43 44 52 53 public abstract class CatalogRowFactory 54 { 55 61 62 protected String [] indexNames; 63 protected int[][] indexColumnPositions; 64 protected boolean[] indexUniqueness; 65 66 protected UUID tableUUID; 67 protected UUID heapUUID; 68 protected UUID[] indexUUID; 69 70 protected DataValueFactory dvf; 71 private final ExecutionFactory ef; 72 private UUIDFactory uuidf; 73 74 private boolean convertIdToLower; 75 private int indexCount; 76 private int columnCount; 77 private String catalogName; 78 79 85 public CatalogRowFactory(UUIDFactory uuidf, 86 ExecutionFactory ef, 87 DataValueFactory dvf, 88 boolean convertIdToLower) 89 90 { 91 this.uuidf = uuidf; 92 this.dvf = dvf; 93 this.ef = ef; 94 this.convertIdToLower = convertIdToLower; 95 } 96 97 102 public ExecutionFactory getExecutionFactory() {return ef;} 103 104 109 public UUIDFactory getUUIDFactory() { return uuidf; } 110 111 114 115 123 public UUID getCanonicalTableUUID() { return tableUUID; } 124 125 131 public UUID getCanonicalHeapUUID() { return heapUUID; } 132 133 141 public UUID getCanonicalIndexUUID( int indexNumber ) 142 { 143 return indexUUID[indexNumber]; 144 } 145 146 153 public int getIndexColumnCount(int indexNum) 154 { 155 return indexColumnPositions[indexNum].length; 156 } 157 158 164 public String getCanonicalHeapName() { return catalogName + convertIdCase( "_HEAP"); } 165 166 173 public String getIndexName(int indexNum) 174 { 175 return indexNames[indexNum]; 176 } 177 178 185 public boolean isIndexUnique(int indexNumber) 186 { 187 return (indexUniqueness != null ? indexUniqueness[indexNumber] : true); 188 } 189 190 195 public DataValueFactory getDataValueFactory() { return dvf; } 196 197 204 public String generateIndexName( int indexNumber ) 205 { 206 indexNumber++; 207 return catalogName + convertIdCase( "_INDEX") + indexNumber; 208 } 209 210 211 public int getNumIndexes() { return indexCount; } 212 213 214 public String getCatalogName() { return catalogName; }; 215 216 228 public void initInfo(int columnCount, 229 String catalogName, 230 int[][] indexColumnPositions, 231 boolean[] indexUniqueness, 232 String [] uuidStrings) 233 234 { 235 indexCount = (indexColumnPositions != null) ? 236 indexColumnPositions.length : 0; 237 238 this.catalogName = convertIdCase(catalogName); 239 this.columnCount = columnCount; 240 241 UUIDFactory uf = getUUIDFactory(); 242 this.tableUUID = uf.recreateUUID(uuidStrings[0] ); 243 this.heapUUID = uf.recreateUUID( uuidStrings[1] ); 244 245 if (indexCount > 0) 246 { 247 indexNames = new String [indexCount]; 248 indexUUID = new UUID[indexCount]; 249 for (int ictr = 0; ictr < indexCount; ictr++) 250 { 251 indexNames[ictr] = generateIndexName(ictr); 252 indexUUID[ictr] = uf.recreateUUID(uuidStrings[ictr + 2 ]); 253 } 254 this.indexColumnPositions = indexColumnPositions; 255 this.indexUniqueness = indexUniqueness; 256 257 } 258 } 259 260 265 public Properties getCreateHeapProperties() 266 { 267 Properties properties = new Properties (); 268 properties.put(Property.PAGE_SIZE_PARAMETER,"1024"); 270 properties.put(RawStoreFactory.PAGE_RESERVED_SPACE_PARAMETER,"0"); 271 properties.put(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER,"1"); 272 return properties; 273 } 274 275 282 public Properties getCreateIndexProperties(int indexNumber) 283 { 284 Properties properties = new Properties (); 285 properties.put(Property.PAGE_SIZE_PARAMETER,"1024"); 287 return properties; 288 } 289 290 296 public int getPrimaryKeyIndexNumber() 297 { 298 if (SanityManager.DEBUG) 299 SanityManager.NOTREACHED(); 300 return 0; 301 } 302 303 308 public final int getHeapColumnCount() 309 { 310 return columnCount; 311 } 312 313 protected String convertIdCase( String id) 314 { 315 if( convertIdToLower) 316 return StringUtil.SQLToLowerCase(id); 317 else 318 return id; 319 } 320 321 322 325 public ExecRow makeEmptyRow() throws StandardException 326 { 327 return this.makeRow(null, null); 328 } 329 330 335 public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException 336 { 337 if (SanityManager.DEBUG) { SanityManager.THROWASSERT( "Should not get here." ); } 338 return null; 339 } 340 341 343 344 public abstract TupleDescriptor 345 buildDescriptor(ExecRow row, 346 TupleDescriptor parentTuple, 347 DataDictionary dataDictionary) 348 throws StandardException; 349 350 351 public abstract SystemColumn[] buildColumnList(); 352 353 354 public int[] getIndexColumnPositions(int indexNumber) 355 { 356 return indexColumnPositions[indexNumber]; 357 } 358 } 359 | Popular Tags |