1 21 22 package org.apache.derby.iapi.sql.dictionary; 23 24 import org.apache.derby.iapi.services.monitor.Monitor; 25 import org.apache.derby.iapi.error.StandardException; 26 27 import org.apache.derby.iapi.sql.dictionary.*; 28 29 import org.apache.derby.iapi.types.TypeId; 30 import org.apache.derby.iapi.sql.depend.Dependent; 31 import org.apache.derby.iapi.sql.depend.Provider; 32 import org.apache.derby.iapi.reference.SQLState; 33 import org.apache.derby.iapi.sql.execute.ConstantAction; 34 import org.apache.derby.iapi.sql.execute.ExecPreparedStatement; 35 import org.apache.derby.iapi.services.uuid.UUIDFactory; 36 import org.apache.derby.iapi.services.io.FormatableBitSet; 37 38 import org.apache.derby.catalog.AliasInfo; 39 import org.apache.derby.catalog.DefaultInfo; 40 import org.apache.derby.catalog.Dependable; 41 import org.apache.derby.catalog.DependableFinder; 42 import org.apache.derby.catalog.ReferencedColumns; 43 import org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl; 44 import org.apache.derby.catalog.UUID; 45 import org.apache.derby.catalog.Statistics; 46 import java.sql.Timestamp ; 47 import java.io.InputStream ; 48 49 57 58 public class DataDescriptorGenerator 59 { 60 private UUIDFactory uuidf; 61 62 protected final DataDictionary dataDictionary; 64 69 public DataDescriptorGenerator( DataDictionary dataDictionary ) 70 { 71 this.dataDictionary = dataDictionary; 72 } 73 74 88 public SchemaDescriptor newSchemaDescriptor(String schemaName, 89 String aid, UUID oid) 90 throws StandardException 91 { 92 return new SchemaDescriptor( 93 dataDictionary, schemaName, aid, oid, 94 dataDictionary.isSystemSchemaName(schemaName)); 95 } 96 97 110 public TableDescriptor newTableDescriptor 111 ( 112 String tableName, 113 SchemaDescriptor schema, 114 int tableType, 115 char lockGranularity 116 ) 117 { 118 return new TableDescriptor 119 (dataDictionary, tableName, schema, tableType, lockGranularity); 120 } 121 122 133 public TableDescriptor newTableDescriptor 134 ( 135 String tableName, 136 SchemaDescriptor schema, 137 int tableType, 138 boolean onCommitDeleteRows, 139 boolean onRollbackDeleteRows 140 ) 141 { 142 return new TableDescriptor 143 (dataDictionary, tableName, schema, tableType, onCommitDeleteRows, onRollbackDeleteRows); 144 } 145 146 157 public ViewDescriptor newViewDescriptor(UUID viewID, 158 String viewName, String viewText, int checkOption, 159 UUID compSchemaId) 160 { 161 return new ViewDescriptor(dataDictionary, viewID, viewName, 162 viewText, checkOption, compSchemaId); 163 } 164 165 166 169 public ReferencedKeyConstraintDescriptor newUniqueConstraintDescriptor( 170 TableDescriptor table, 171 String constraintName, 172 boolean deferrable, 173 boolean initiallyDeferred, 174 int[] referencedColumns, 175 UUID constraintId, 176 UUID indexId, 177 SchemaDescriptor schemaDesc, 178 boolean isEnabled, 179 int referenceCount 180 ) 181 { 182 return new ReferencedKeyConstraintDescriptor(DataDictionary.UNIQUE_CONSTRAINT, 183 dataDictionary, table, constraintName, 184 deferrable, initiallyDeferred, 185 referencedColumns, constraintId, 186 indexId, schemaDesc, isEnabled, referenceCount); 187 } 188 189 192 public ReferencedKeyConstraintDescriptor newPrimaryKeyConstraintDescriptor( 193 TableDescriptor table, 194 String constraintName, 195 boolean deferrable, 196 boolean initiallyDeferred, 197 int[] referencedColumns, 198 UUID constraintId, 199 UUID indexId, 200 SchemaDescriptor schemaDesc, 201 boolean isEnabled, 202 int referenceCount 203 ) 204 { 205 return new ReferencedKeyConstraintDescriptor(DataDictionary.PRIMARYKEY_CONSTRAINT, 206 dataDictionary, table, constraintName, 207 deferrable, initiallyDeferred, 208 referencedColumns, constraintId, 209 indexId, schemaDesc, isEnabled, referenceCount); 210 } 211 212 215 public ForeignKeyConstraintDescriptor newForeignKeyConstraintDescriptor( 216 TableDescriptor table, 217 String constraintName, 218 boolean deferrable, 219 boolean initiallyDeferred, 220 int[] fkColumns, 221 UUID constraintId, 222 UUID indexId, 223 SchemaDescriptor schemaDesc, 224 ReferencedKeyConstraintDescriptor referencedConstraintDescriptor, 225 boolean isEnabled, 226 int raDeleteRule, 227 int raUpdateRule 228 ) 229 { 230 return new ForeignKeyConstraintDescriptor(dataDictionary, table, constraintName, 231 deferrable, initiallyDeferred, 232 fkColumns, constraintId, 233 indexId, schemaDesc, 234 referencedConstraintDescriptor, isEnabled, raDeleteRule, raUpdateRule); 235 } 236 237 238 241 public ForeignKeyConstraintDescriptor newForeignKeyConstraintDescriptor( 242 TableDescriptor table, 243 String constraintName, 244 boolean deferrable, 245 boolean initiallyDeferred, 246 int[] fkColumns, 247 UUID constraintId, 248 UUID indexId, 249 SchemaDescriptor schemaDesc, 250 UUID referencedConstraintId, 251 boolean isEnabled, 252 int raDeleteRule, 253 int raUpdateRule 254 ) 255 { 256 return new ForeignKeyConstraintDescriptor(dataDictionary, table, constraintName, 257 deferrable, initiallyDeferred, 258 fkColumns, constraintId, 259 indexId, schemaDesc, 260 referencedConstraintId, isEnabled, raDeleteRule, raUpdateRule); 261 } 262 263 266 public CheckConstraintDescriptor newCheckConstraintDescriptor( 267 TableDescriptor table, 268 String constraintName, 269 boolean deferrable, 270 boolean initiallyDeferred, 271 UUID constraintId, 272 String constraintText, 273 ReferencedColumns referencedColumns, 274 SchemaDescriptor schemaDesc, 275 boolean isEnabled 276 ) 277 { 278 return new CheckConstraintDescriptor(dataDictionary, table, constraintName, 279 deferrable, initiallyDeferred, 280 constraintId, 281 constraintText, referencedColumns, schemaDesc, isEnabled); 282 } 283 284 public CheckConstraintDescriptor newCheckConstraintDescriptor( 285 TableDescriptor table, 286 String constraintName, 287 boolean deferrable, 288 boolean initiallyDeferred, 289 UUID constraintId, 290 String constraintText, 291 int[] refCols, 292 SchemaDescriptor schemaDesc, 293 boolean isEnabled 294 ) 295 { 296 ReferencedColumns referencedColumns = new ReferencedColumnsDescriptorImpl(refCols); 297 return new CheckConstraintDescriptor(dataDictionary, table, constraintName, 298 deferrable, initiallyDeferred, 299 constraintId, 300 constraintText, referencedColumns, schemaDesc, isEnabled); 301 } 302 303 323 public ConglomerateDescriptor newConglomerateDescriptor( 324 long conglomerateId, 325 String name, 326 boolean indexable, 327 IndexRowGenerator indexRowGenerator, 328 boolean isConstraint, 329 UUID uuid, 330 UUID tableID, 331 UUID schemaID 332 ) 333 { 334 return (ConglomerateDescriptor) 335 new ConglomerateDescriptor(dataDictionary, conglomerateId, 336 name, 337 indexable, 338 indexRowGenerator, 339 isConstraint, 340 uuid, 341 tableID, 342 schemaID); 343 } 344 345 368 public TriggerDescriptor newTriggerDescriptor 369 ( 370 SchemaDescriptor sd, 371 UUID uuid, 372 String name, 373 int eventMask, 374 boolean isBefore, 375 boolean isRow, 376 boolean isEnabled, 377 TableDescriptor td, 378 UUID whenSPSId, 379 UUID actionSPSId, 380 Timestamp creationTimestamp, 381 int[] referencedCols, 382 String triggerDefinition, 383 boolean referencingOld, 384 boolean referencingNew, 385 String oldReferencingName, 386 String newReferencingName 387 ) throws StandardException 388 { 389 return new TriggerDescriptor( 390 dataDictionary, 391 sd, 392 uuid, 393 name, 394 eventMask, 395 isBefore, 396 isRow, 397 isEnabled, 398 td, 399 whenSPSId, 400 actionSPSId, 401 creationTimestamp, 402 referencedCols, 403 triggerDefinition, 404 referencingOld, 405 referencingNew, 406 oldReferencingName, 407 newReferencingName 408 ); 409 } 410 411 415 protected UUIDFactory getUUIDFactory() 416 { 417 if (uuidf == null) 418 uuidf = Monitor.getMonitor().getUUIDFactory(); 419 return uuidf; 420 } 421 422 425 public FileInfoDescriptor newFileInfoDescriptor( 426 UUID id, 427 SchemaDescriptor sd, 428 String SQLName, 429 long generationId 430 ) 431 { 432 if (id == null) id = getUUIDFactory().createUUID(); 433 return new FileInfoDescriptor(dataDictionary, id,sd,SQLName,generationId); 434 } 435 436 public TablePermsDescriptor newTablePermsDescriptor( TableDescriptor td, 437 String selectPerm, 438 String deletePerm, 439 String insertPerm, 440 String updatePerm, 441 String referencesPerm, 442 String triggerPerm, 443 String grantor) 444 throws StandardException 445 { 446 if( "N".equals( selectPerm) && "N".equals( deletePerm) && "N".equals( insertPerm) 447 && "N".equals( updatePerm) && "N".equals( referencesPerm) && "N".equals( triggerPerm)) 448 return null; 449 450 return new TablePermsDescriptor( dataDictionary, 451 (String ) null, 452 grantor, 453 td.getUUID(), 454 selectPerm, 455 deletePerm, 456 insertPerm, 457 updatePerm, 458 referencesPerm, 459 triggerPerm); 460 } 461 462 477 public ColPermsDescriptor newColPermsDescriptor( TableDescriptor td, 478 String type, 479 FormatableBitSet columns, 480 String grantor) throws StandardException 481 { 482 return new ColPermsDescriptor( dataDictionary, 483 (String ) null, 484 grantor, 485 td.getUUID(), 486 type, 487 columns); 488 } 489 490 496 public RoutinePermsDescriptor newRoutinePermsDescriptor( AliasDescriptor ad, String grantor) 497 throws StandardException 498 { 499 return new RoutinePermsDescriptor( dataDictionary, 500 (String ) null, 501 grantor, 502 ad.getUUID()); 503 } 504 } 505 | Popular Tags |