1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.reference.JDBC30Translation; 25 import org.apache.derby.iapi.reference.Property; 26 import org.apache.derby.iapi.reference.SQLState; 27 import org.apache.derby.iapi.reference.Limits; 28 import org.apache.derby.iapi.sql.conn.Authorizer; 29 30 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor; 31 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory; 32 33 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor; 34 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList; 35 import org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor; 36 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 37 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor; 38 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList; 39 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList; 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.DataDictionaryContext; 43 import org.apache.derby.iapi.sql.dictionary.DefaultDescriptor; 44 import org.apache.derby.iapi.sql.dictionary.DependencyDescriptor; 45 import org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor; 46 import org.apache.derby.iapi.sql.dictionary.GenericDescriptorList; 47 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor; 48 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator; 49 import org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor; 50 import org.apache.derby.iapi.sql.dictionary.TablePermsDescriptor; 51 import org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor; 52 import org.apache.derby.iapi.sql.dictionary.RoutinePermsDescriptor; 53 import org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor; 54 import org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor; 55 import org.apache.derby.iapi.sql.dictionary.SPSDescriptor; 56 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 57 import org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor; 58 import org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor; 59 import org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor; 60 import org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor; 61 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 62 import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor; 63 import org.apache.derby.iapi.sql.dictionary.ViewDescriptor; 64 import org.apache.derby.iapi.sql.dictionary.SystemColumn; 65 66 import org.apache.derby.iapi.sql.depend.DependencyManager; 67 68 import org.apache.derby.impl.sql.depend.BasicDependencyManager; 69 70 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 71 import org.apache.derby.iapi.sql.execute.ExecutionContext; 72 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 73 import org.apache.derby.iapi.sql.execute.ScanQualifier; 74 75 import org.apache.derby.iapi.types.DataValueFactory; 76 import org.apache.derby.iapi.types.NumberDataValue; 77 78 import org.apache.derby.iapi.types.StringDataValue; 79 import org.apache.derby.iapi.types.TypeId; 80 import org.apache.derby.iapi.types.DataTypeDescriptor; 81 import org.apache.derby.iapi.types.DataValueDescriptor; 82 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 83 import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory; 84 85 import org.apache.derby.iapi.store.access.AccessFactory; 86 import org.apache.derby.iapi.store.access.ConglomerateController; 87 import org.apache.derby.iapi.types.Orderable; 88 import org.apache.derby.iapi.types.RowLocation; 89 import org.apache.derby.iapi.store.access.RowUtil; 90 import org.apache.derby.iapi.store.access.ScanController; 91 import org.apache.derby.iapi.store.access.TransactionController; 92 import org.apache.derby.iapi.store.access.Qualifier; 93 94 import org.apache.derby.iapi.services.monitor.Monitor; 95 import org.apache.derby.iapi.services.monitor.ModuleControl; 96 import org.apache.derby.iapi.services.monitor.ModuleSupportable; 97 98 import org.apache.derby.iapi.services.context.ContextManager; 99 import org.apache.derby.iapi.services.context.ContextService; 100 101 import org.apache.derby.iapi.error.StandardException; 102 103 import org.apache.derby.iapi.services.sanity.AssertFailure; 105 106 import org.apache.derby.iapi.sql.execute.ExecRow; 107 import org.apache.derby.iapi.sql.execute.TupleFilter; 108 109 import org.apache.derby.iapi.services.sanity.SanityManager; 110 111 import org.apache.derby.iapi.services.cache.CacheFactory; 112 import org.apache.derby.iapi.services.cache.CacheManager; 113 import org.apache.derby.iapi.services.cache.Cacheable; 114 import org.apache.derby.iapi.services.cache.CacheableFactory; 115 116 import org.apache.derby.iapi.services.locks.LockFactory; 117 import org.apache.derby.iapi.services.locks.C_LockFactory; 118 119 import org.apache.derby.iapi.services.property.PropertyUtil; 120 121 import org.apache.derby.impl.services.locks.Timeout; 122 123 import org.apache.derby.iapi.services.uuid.UUIDFactory; 124 import org.apache.derby.catalog.AliasInfo; 125 import org.apache.derby.catalog.DefaultInfo; 126 import org.apache.derby.catalog.TypeDescriptor; 127 import org.apache.derby.catalog.UUID; 128 import org.apache.derby.catalog.types.RoutineAliasInfo; 129 130 import org.apache.derby.iapi.services.io.FormatableBitSet; 131 import org.apache.derby.iapi.services.locks.ShExLockable; 132 import org.apache.derby.iapi.services.locks.ShExQual; 133 import org.apache.derby.iapi.util.StringUtil; 134 import org.apache.derby.iapi.util.IdUtil; 135 136 import java.util.Calendar ; 137 import java.util.Date ; 138 import java.util.GregorianCalendar ; 139 import java.util.Hashtable ; 140 import java.util.Properties ; 141 import java.util.Vector ; 142 143 import java.util.List ; 144 import java.util.Iterator ; 145 146 import java.util.Enumeration ; 147 import java.io.InputStream ; 148 import java.io.IOException ; 149 150 import java.sql.Types ; 151 152 166 167 public final class DataDictionaryImpl 168 implements DataDictionary, CacheableFactory, ModuleControl, ModuleSupportable,java.security.PrivilegedAction 169 { 170 171 private static final String CFG_SYSTABLES_ID = "SystablesIdentifier"; 172 private static final String CFG_SYSTABLES_INDEX1_ID = "SystablesIndex1Identifier"; 173 private static final String CFG_SYSTABLES_INDEX2_ID = "SystablesIndex2Identifier"; 174 private static final String CFG_SYSCOLUMNS_ID = "SyscolumnsIdentifier"; 175 private static final String CFG_SYSCOLUMNS_INDEX1_ID = "SyscolumnsIndex1Identifier"; 176 private static final String CFG_SYSCOLUMNS_INDEX2_ID = "SyscolumnsIndex2Identifier"; 177 private static final String CFG_SYSCONGLOMERATES_ID = "SysconglomeratesIdentifier"; 178 private static final String CFG_SYSCONGLOMERATES_INDEX1_ID = "SysconglomeratesIndex1Identifier"; 179 private static final String CFG_SYSCONGLOMERATES_INDEX2_ID = "SysconglomeratesIndex2Identifier"; 180 private static final String CFG_SYSCONGLOMERATES_INDEX3_ID = "SysconglomeratesIndex3Identifier"; 181 private static final String CFG_SYSSCHEMAS_ID = "SysschemasIdentifier"; 182 private static final String CFG_SYSSCHEMAS_INDEX1_ID = "SysschemasIndex1Identifier"; 183 private static final String CFG_SYSSCHEMAS_INDEX2_ID = "SysschemasIndex2Identifier"; 184 185 private static final int SYSCONGLOMERATES_CORE_NUM = 0; 186 private static final int SYSTABLES_CORE_NUM = 1; 187 private static final int SYSCOLUMNS_CORE_NUM = 2; 188 private static final int SYSSCHEMAS_CORE_NUM = 3; 189 private static final int NUM_CORE = 4; 190 191 221 private static final String [][] SYSFUN_FUNCTIONS = { 222 {"ACOS", "DOUBLE", "java.lang.StrictMath", "acos(double)", "DOUBLE"}, 223 {"ASIN", "DOUBLE", "java.lang.StrictMath", "asin(double)", "DOUBLE"}, 224 {"ATAN", "DOUBLE", "java.lang.StrictMath", "atan(double)", "DOUBLE"}, 225 {"COS", "DOUBLE", "java.lang.StrictMath", "cos(double)", "DOUBLE"}, 226 {"SIN", "DOUBLE", "java.lang.StrictMath", "sin(double)", "DOUBLE"}, 227 {"TAN", "DOUBLE", "java.lang.StrictMath", "tan(double)", "DOUBLE"}, 228 {"PI", "DOUBLE", "org.apache.derby.catalog.SystemProcedures", "PI()", null}, 229 {"DEGREES", "DOUBLE", "java.lang.StrictMath", "toDegrees(double)", "DOUBLE"}, 230 {"RADIANS", "DOUBLE", "java.lang.StrictMath", "toRadians(double)", "DOUBLE"}, 231 {"LN", "DOUBLE", "java.lang.StrictMath", "log(double)", "DOUBLE"}, 232 {"LOG", "DOUBLE", "java.lang.StrictMath", "log(double)", "DOUBLE"}, {"LOG10", "DOUBLE", "org.apache.derby.catalog.SystemProcedures", "LOG10(double)", "DOUBLE"}, 234 {"EXP", "DOUBLE", "java.lang.StrictMath", "exp(double)", "DOUBLE"}, 235 {"CEIL", "DOUBLE", "java.lang.StrictMath", "ceil(double)", "DOUBLE"}, 236 {"CEILING", "DOUBLE", "java.lang.StrictMath", "ceil(double)", "DOUBLE"}, {"FLOOR", "DOUBLE", "java.lang.StrictMath", "floor(double)", "DOUBLE"}, 238 }; 239 240 244 private static final AliasDescriptor[] SYSFUN_AD = 245 new AliasDescriptor[SYSFUN_FUNCTIONS.length]; 246 247 250 private static final String [] SYSFUN_PNAME = {"P1"}; 251 252 255 private static final int[] SYSFUN_PMODE = {JDBC30Translation.PARAMETER_MODE_IN}; 256 257 private TabInfoImpl[] coreInfo; 259 260 264 protected SchemaDescriptor systemSchemaDesc; 265 protected SchemaDescriptor sysIBMSchemaDesc; 266 protected SchemaDescriptor declaredGlobalTemporaryTablesSchemaDesc; 267 protected SchemaDescriptor systemDiagSchemaDesc; 268 protected SchemaDescriptor systemUtilSchemaDesc; 269 270 private String systemSchemaName; 271 private String systemDiagSchemaName; 272 private String systemUtilSchemaName; 273 private String sysIBMSchemaName; 274 private String declaredGlobalTemporaryTablesSchemaName; 275 boolean builtinSchemasAreFromLCC; 276 277 protected boolean convertIdToLower; 278 280 private static final String [] nonCoreNames = { 283 "SYSCONSTRAINTS", 284 "SYSKEYS", 285 "SYSDEPENDS", 286 "SYSALIASES", 287 "SYSVIEWS", 288 "SYSCHECKS", 289 "SYSFOREIGNKEYS", 290 "SYSSTATEMENTS", 291 "SYSFILES", 292 "SYSTRIGGERS", 293 "SYSSTATISTICS", 294 "SYSDUMMY1", 295 "SYSTABLEPERMS", 296 "SYSCOLPERMS", 297 "SYSROUTINEPERMS" 298 }; 299 300 private static final int NUM_NONCORE = nonCoreNames.length; 301 302 311 private static final String [] systemSchemaNames = { 312 SchemaDescriptor.IBM_SYSTEM_CAT_SCHEMA_NAME, 313 SchemaDescriptor.IBM_SYSTEM_FUN_SCHEMA_NAME, 314 SchemaDescriptor.IBM_SYSTEM_PROC_SCHEMA_NAME, 315 SchemaDescriptor.IBM_SYSTEM_STAT_SCHEMA_NAME, 316 SchemaDescriptor.IBM_SYSTEM_NULLID_SCHEMA_NAME, 317 SchemaDescriptor.STD_SYSTEM_DIAG_SCHEMA_NAME, 318 SchemaDescriptor.STD_SYSTEM_UTIL_SCHEMA_NAME, 319 SchemaDescriptor.IBM_SYSTEM_SCHEMA_NAME, 320 SchemaDescriptor.STD_SQLJ_SCHEMA_NAME, 321 SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME 322 }; 323 324 325 326 private DD_Version dictionaryVersion; 327 328 private DD_Version softwareVersion; 329 330 private String authorizationDatabaseOwner; 331 private boolean usesSqlAuthorization; 332 333 338 339 private TabInfoImpl[] noncoreInfo; 341 342 344 public DataDescriptorGenerator dataDescriptorGenerator; 345 protected DataValueFactory dvf; 346 protected AccessFactory af; 347 349 private ExecutionFactory exFactory; 350 protected UUIDFactory uuidFactory; 351 352 Properties startupParameters; 353 int engineType; 354 355 356 protected boolean booting; 357 private TransactionController bootingTC; 358 protected DependencyManager dmgr; 359 360 361 CacheManager OIDTdCache; 362 CacheManager nameTdCache; 363 private CacheManager spsNameCache; 364 private Hashtable spsIdHash; 365 int tdCacheSize; 367 int stmtCacheSize; 368 369 370 CacheManager permissionsCache; 371 int permissionsCacheSize; 372 373 376 ShExLockable cacheCoordinator; 377 public LockFactory lockFactory; 378 379 volatile int cacheMode = DataDictionary.COMPILE_ONLY_MODE; 380 381 382 volatile int ddlUsers; 383 384 volatile int readersInDDLMode; 385 386 387 403 public boolean readOnlyUpgrade; 404 405 private int systemSQLNameNumber; 409 private GregorianCalendar calendarForLastSystemSQLName = new GregorianCalendar (); 410 private long timeForLastSystemSQLName; 411 412 415 private static final String [] sysUtilProceduresWithPublicAccess = { 416 "SYSCS_SET_RUNTIMESTATISTICS", 417 "SYSCS_SET_STATISTICS_TIMING", 418 "SYSCS_INPLACE_COMPRESS_TABLE", 419 "SYSCS_COMPRESS_TABLE", 420 }; 421 422 425 private static final String [] sysUtilFunctionsWithPublicAccess = { 426 "SYSCS_GET_RUNTIMESTATISTICS", 427 }; 428 429 432 433 public DataDictionaryImpl() { 434 435 } 436 437 438 447 448 public boolean canSupport(Properties startParams) 449 { 450 return Monitor.isDesiredType( startParams, org.apache.derby.iapi.reference.EngineType.NONE ); 451 } 452 453 460 public void boot(boolean create, Properties startParams) 461 throws StandardException 462 { 463 softwareVersion = new DD_Version(this, DataDictionary.DD_VERSION_DERBY_10_2); 464 465 473 convertIdToLower = false; 474 475 startupParameters = startParams; 476 477 uuidFactory = Monitor.getMonitor().getUUIDFactory(); 478 479 engineType = Monitor.getEngineType( startParams ); 480 481 LanguageConnectionFactory langConnFactory = (LanguageConnectionFactory) Monitor.bootServiceModule( 485 create, this, LanguageConnectionFactory.MODULE, startParams); 486 487 dvf = langConnFactory.getDataValueFactory(); 488 exFactory = (ExecutionFactory) Monitor.bootServiceModule( 489 create, this, 490 ExecutionFactory.MODULE, 491 startParams); 492 493 initializeCatalogInfo(); 495 496 booting = true; 498 499 if ( dataDescriptorGenerator == null ) 501 { dataDescriptorGenerator = new DataDescriptorGenerator( this ); } 502 503 if (!create) { 504 505 506 508 coreInfo[SYSTABLES_CORE_NUM].setHeapConglomerate( 509 getBootParameter(startParams, CFG_SYSTABLES_ID, true)); 510 511 coreInfo[SYSTABLES_CORE_NUM].setIndexConglomerate(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, 512 getBootParameter(startParams, CFG_SYSTABLES_INDEX1_ID, true)); 513 514 515 coreInfo[SYSTABLES_CORE_NUM].setIndexConglomerate( 516 SYSTABLESRowFactory.SYSTABLES_INDEX2_ID, 517 getBootParameter(startParams, CFG_SYSTABLES_INDEX2_ID, true)); 518 519 521 coreInfo[SYSCOLUMNS_CORE_NUM].setHeapConglomerate( 522 getBootParameter(startParams, CFG_SYSCOLUMNS_ID, true)); 523 524 525 coreInfo[SYSCOLUMNS_CORE_NUM].setIndexConglomerate( 526 SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID, 527 getBootParameter(startParams, CFG_SYSCOLUMNS_INDEX1_ID, true)); 528 coreInfo[SYSCOLUMNS_CORE_NUM].setIndexConglomerate( 530 SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX2_ID, 531 getBootParameter(startParams, CFG_SYSCOLUMNS_INDEX2_ID, false)); 532 533 535 coreInfo[SYSCONGLOMERATES_CORE_NUM].setHeapConglomerate( 536 getBootParameter(startParams, CFG_SYSCONGLOMERATES_ID, true)); 537 538 539 coreInfo[SYSCONGLOMERATES_CORE_NUM].setIndexConglomerate( 540 SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX1_ID, 541 getBootParameter(startParams, CFG_SYSCONGLOMERATES_INDEX1_ID, true)); 542 543 544 coreInfo[SYSCONGLOMERATES_CORE_NUM].setIndexConglomerate( 545 SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX2_ID, 546 getBootParameter(startParams, CFG_SYSCONGLOMERATES_INDEX2_ID, true)); 547 548 coreInfo[SYSCONGLOMERATES_CORE_NUM].setIndexConglomerate( 549 SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX3_ID, 550 getBootParameter(startParams, CFG_SYSCONGLOMERATES_INDEX3_ID, true)); 551 552 553 coreInfo[SYSSCHEMAS_CORE_NUM].setHeapConglomerate( 555 getBootParameter(startParams, CFG_SYSSCHEMAS_ID, true)); 556 557 558 coreInfo[SYSSCHEMAS_CORE_NUM].setIndexConglomerate( 559 SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID, 560 getBootParameter(startParams, CFG_SYSSCHEMAS_INDEX1_ID, true)); 561 562 coreInfo[SYSSCHEMAS_CORE_NUM].setIndexConglomerate( 563 SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX2_ID, 564 getBootParameter(startParams, CFG_SYSSCHEMAS_INDEX2_ID, true)); 565 566 } 567 568 569 570 String value = startParams.getProperty(Property.LANG_TD_CACHE_SIZE); 571 tdCacheSize = PropertyUtil.intPropertyValue(Property.LANG_TD_CACHE_SIZE, value, 572 0, Integer.MAX_VALUE, Property.LANG_TD_CACHE_SIZE_DEFAULT); 573 574 575 value = startParams.getProperty(Property.LANG_SPS_CACHE_SIZE); 576 stmtCacheSize = PropertyUtil.intPropertyValue(Property.LANG_SPS_CACHE_SIZE, value, 577 0, Integer.MAX_VALUE, Property.LANG_SPS_CACHE_SIZE_DEFAULT); 578 579 value = startParams.getProperty(Property.LANG_PERMISSIONS_CACHE_SIZE); 580 permissionsCacheSize = PropertyUtil.intPropertyValue(Property.LANG_PERMISSIONS_CACHE_SIZE, value, 581 0, Integer.MAX_VALUE, Property.LANG_PERMISSIONS_CACHE_SIZE_DEFAULT); 582 583 584 589 590 593 CacheFactory cf = 594 (CacheFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory); 595 OIDTdCache = 596 cf.newCacheManager(this, 597 "TableDescriptorOIDCache", 598 tdCacheSize, 599 tdCacheSize); 600 nameTdCache = 601 cf.newCacheManager(this, 602 "TableDescriptorNameCache", 603 tdCacheSize, 604 tdCacheSize); 605 606 if (stmtCacheSize > 0) 607 { 608 spsNameCache = 609 cf.newCacheManager(this, 610 "SPSNameDescriptorCache", 611 stmtCacheSize, 612 stmtCacheSize); 613 spsIdHash = new Hashtable (stmtCacheSize); 614 } 616 617 618 619 cacheCoordinator = new ShExLockable(); 620 621 622 af = (AccessFactory) Monitor.findServiceModule(this, AccessFactory.MODULE); 623 624 625 lockFactory = af.getLockFactory(); 626 627 632 ContextService csf = ContextService.getFactory(); 633 634 ContextManager cm = csf.getCurrentContextManager(); 635 if (SanityManager.DEBUG) 636 SanityManager.ASSERT((cm != null), "Failed to get current ContextManager"); 637 638 639 pushDataDictionaryContext(cm); 640 641 bootingTC = null; 643 try 644 { 645 bootingTC = af.getTransaction(cm); 648 649 653 exFactory.newExecutionContext(cm); 654 655 DataDescriptorGenerator ddg = getDataDescriptorGenerator(); 656 657 if (create) { 658 String userName = IdUtil.getUserNameFromURLProps(startParams); 659 authorizationDatabaseOwner = IdUtil.getUserAuthorizationId(userName); 660 661 createDictionaryTables(startParams, bootingTC, ddg); 663 create_SYSIBM_procedures(bootingTC); 665 createSystemSps(bootingTC); 667 create_SYSCS_procedures(bootingTC); 669 dictionaryVersion = softwareVersion; 671 672 675 bootingTC.setProperty( 676 DataDictionary.CORE_DATA_DICTIONARY_VERSION, 677 dictionaryVersion, true); 678 679 bootingTC.setProperty( 680 DataDictionary.CREATE_DATA_DICTIONARY_VERSION, 681 dictionaryVersion, true); 682 683 if (PropertyUtil.getSystemBoolean(Property.SQL_AUTHORIZATION_PROPERTY)) 686 { 687 bootingTC.setProperty(Property.SQL_AUTHORIZATION_PROPERTY,"true",true); 688 usesSqlAuthorization=true; 689 } 690 691 } else { 692 loadDictionaryTables(bootingTC, ddg, startParams); 694 SchemaDescriptor sd = locateSchemaRow(SchemaDescriptor.IBM_SYSTEM_SCHEMA_NAME, 695 bootingTC); 696 authorizationDatabaseOwner = sd.getAuthorizationId(); 697 String sqlAuth = PropertyUtil.getDatabaseProperty(bootingTC, 698 Property.SQL_AUTHORIZATION_PROPERTY); 699 if (Boolean.valueOf(sqlAuth).booleanValue()) 700 { 701 checkVersion(DataDictionary.DD_VERSION_DERBY_10_2, "sqlAuthorization"); 703 usesSqlAuthorization=true; 704 } 705 } 706 707 if (SanityManager.DEBUG) 708 SanityManager.ASSERT((authorizationDatabaseOwner != null), "Failed to get Database Owner authorization"); 709 710 711 bootingTC.commit(); 712 cm.getContext(ExecutionContext.CONTEXT_ID).popMe(); } finally { 714 715 if (bootingTC != null) { 716 bootingTC.destroy(); bootingTC = null; 718 } 719 cm.popContext(); } 721 722 setDependencyManager(); 723 booting = false; 724 } 725 726 private CacheManager getPermissionsCache() throws StandardException 727 { 728 if( permissionsCache == null) 729 { 730 CacheFactory cf = 731 (CacheFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory); 732 LanguageConnectionContext lcc = getLCC(); 733 TransactionController tc = lcc.getTransactionExecute(); 734 permissionsCacheSize = PropertyUtil.getServiceInt( tc, 735 Property.LANG_PERMISSIONS_CACHE_SIZE, 736 40, 737 Integer.MAX_VALUE, 738 permissionsCacheSize ); 739 permissionsCache = cf.newCacheManager( this, 740 "PermissionsCache", 741 permissionsCacheSize, 742 permissionsCacheSize); 743 } 744 return permissionsCache; 745 } 747 751 protected void setDependencyManager() 752 { 753 dmgr = new BasicDependencyManager(); 754 } 755 756 760 public DependencyManager getDependencyManager() 761 { 762 return dmgr; 763 } 764 765 768 769 public void stop() 770 { 771 } 772 773 776 public Cacheable newCacheable(CacheManager cm) { 777 778 if (cm == OIDTdCache) 779 return new OIDTDCacheable(this); 780 else if (cm == nameTdCache) 781 return new NameTDCacheable(this); 782 else if( cm == permissionsCache) 783 return new PermissionsCacheable(this); 784 else { 785 return new SPSNameCacheable(this); 786 } 787 } 788 789 792 793 798 public int startReading(LanguageConnectionContext lcc) 799 throws StandardException 800 { 801 int bindCount = lcc.incrementBindCount(); 802 int localCacheMode; 803 804 boolean needRetry = false; 805 806 do 807 { 808 if (needRetry) 809 { 810 817 try 818 { 819 lockFactory.zeroDurationlockObject( 820 lcc.getTransactionExecute().getLockObject(), 821 cacheCoordinator, 822 ShExQual.SH, 823 C_LockFactory.WAIT_FOREVER); 824 } 825 catch (StandardException e) 826 { 827 829 lcc.decrementBindCount(); 830 throw e; 831 } 832 needRetry = false; 833 } 834 835 838 synchronized(this) 839 { 840 localCacheMode = getCacheMode(); 841 842 852 if (bindCount == 1) 853 { 854 if (localCacheMode == DataDictionary.COMPILE_ONLY_MODE) 855 { 856 if (SanityManager.DEBUG) 857 { 858 SanityManager.ASSERT(ddlUsers == 0, 859 "Cache mode is COMPILE_ONLY and there are DDL users."); 860 } 861 862 867 boolean lockGranted = false; 868 869 try 870 { 871 882 lockGranted = 883 lockFactory.lockObject( 884 lcc.getTransactionExecute().getLockObject(), 885 lcc.getTransactionExecute().getLockObject(), 886 cacheCoordinator, 887 ShExQual.SH, 888 C_LockFactory.NO_WAIT); 889 } 890 catch (StandardException e) 891 { 892 895 lcc.decrementBindCount(); 896 throw e; 897 } 898 899 if (!lockGranted) 900 needRetry = true; 901 } 902 else 903 { 904 readersInDDLMode++; 905 } 906 } 907 } 909 } while (needRetry); 910 911 return localCacheMode; 912 } 913 914 915 public void doneReading(int mode, LanguageConnectionContext lcc) 916 throws StandardException 917 { 918 int bindCount = lcc.decrementBindCount(); 919 920 921 synchronized(this) 922 { 923 933 if (bindCount == 0) 934 { 935 if (mode == DataDictionary.COMPILE_ONLY_MODE) 936 { 937 945 if ((lcc.getStatementContext() != null) && lcc.getStatementContext().inUse()) 946 { 947 int unlockCount = lockFactory.unlock(lcc.getTransactionExecute().getLockObject(), 948 lcc.getTransactionExecute().getLockObject(), 949 cacheCoordinator, 950 ShExQual.SH); 951 if (SanityManager.DEBUG) 952 { 953 if (unlockCount != 1) 954 { 955 SanityManager.THROWASSERT("unlockCount not "+ 956 "1 as expected, it is "+unlockCount); 957 } 958 } 959 } 960 } 961 else 962 { 963 readersInDDLMode--; 964 965 976 if (ddlUsers == 0 && readersInDDLMode == 0) 977 { 978 clearCaches(); 979 setCacheMode(DataDictionary.COMPILE_ONLY_MODE); 980 } 981 982 if (SanityManager.DEBUG) 983 { 984 SanityManager.ASSERT(readersInDDLMode >= 0, 985 "readersInDDLMode is invalid -- should never be < 0"); 986 } 987 } 988 } 989 } 990 } 991 992 997 public void startWriting(LanguageConnectionContext lcc) 998 throws StandardException 999 { 1000 1001 boolean blocked = true; 1002 1003 1006 if (lcc.getBindCount() != 0) 1007 { 1008 throw StandardException.newException(SQLState.LANG_DDL_IN_BIND); 1009 } 1010 1011 1016 if ( ! lcc.dataDictionaryInWriteMode()) 1017 { 1018 for (int i = 0; blocked; i++) 1019 { 1020 1027 if (i > 4 && 1028 getCacheMode() == DataDictionary.COMPILE_ONLY_MODE) 1029 { 1030 1035 lockFactory.zeroDurationlockObject( 1036 lcc.getTransactionExecute().getLockObject(), 1037 cacheCoordinator, 1038 ShExQual.EX, 1039 C_LockFactory.TIMED_WAIT); 1040 1041 1042 i = 1; 1043 } 1044 1045 if (i > 0) 1046 { 1047 try 1048 { 1049 Thread.sleep( 1050 (long)((java.lang.Math.random() * 1131) % 20)); 1051 } 1052 catch (InterruptedException ie) 1053 { 1054 throw StandardException.interrupt(ie); 1055 } 1056 } 1057 1058 synchronized(this) 1059 { 1060 if (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE) 1061 { 1062 1069 1072 boolean lockGranted = 1073 lockFactory.zeroDurationlockObject( 1074 lcc.getTransactionExecute().getLockObject(), 1075 cacheCoordinator, 1076 ShExQual.EX, 1077 C_LockFactory.NO_WAIT); 1078 1079 if (!lockGranted) 1080 continue; 1081 1082 1083 setCacheMode(DataDictionary.DDL_MODE); 1084 1085 1086 clearCaches(); 1087 } 1088 1089 1090 ddlUsers++; 1091 } 1093 1097 lcc.setDataDictionaryWriteMode(); 1098 blocked = false; 1099 } 1100 1101 } 1102 else if (SanityManager.DEBUG) 1103 { 1104 SanityManager.ASSERT(getCacheMode() == DataDictionary.DDL_MODE, 1105 "lcc.getDictionaryInWriteMode() but DataDictionary is COMPILE_MODE"); 1106 } 1107 } 1108 1109 1110 1111 public void transactionFinished() throws StandardException 1112 { 1113 1114 synchronized(this) 1115 { 1116 if (SanityManager.DEBUG) 1117 { 1118 SanityManager.ASSERT(ddlUsers > 0, 1119 "Number of DDL Users is <= 0 when finishing a transaction"); 1120 1121 SanityManager.ASSERT(getCacheMode() == DataDictionary.DDL_MODE, 1122 "transactionFinished called when not in DDL_MODE"); 1123 } 1124 1125 ddlUsers--; 1126 1127 1138 if (ddlUsers == 0 && readersInDDLMode == 0) 1139 { 1140 clearCaches(); 1141 setCacheMode(DataDictionary.COMPILE_ONLY_MODE); 1142 } 1143 1144 } 1145 } 1146 1147 1152 public int getCacheMode() 1153 { 1154 return cacheMode; 1155 } 1156 1157 1162 private void setCacheMode(int newMode) 1163 { 1164 cacheMode = newMode; 1165 } 1166 1167 1173 1174 public DataDescriptorGenerator getDataDescriptorGenerator() 1175 { 1176 return dataDescriptorGenerator; 1177 } 1178 1179 1184 public String getAuthorizationDatabaseOwner() 1185 { 1186 return authorizationDatabaseOwner; 1187 } 1188 1189 1192 public boolean usesSqlAuthorization() 1193 { 1194 return usesSqlAuthorization; 1195 } 1196 1197 1203 public DataValueFactory getDataValueFactory() 1204 { 1205 return dvf; 1206 } 1207 1208 1213 public ExecutionFactory getExecutionFactory() 1214 { 1215 return exFactory; 1216 } 1217 1218 1221 public DataDictionaryContext pushDataDictionaryContext(ContextManager contextManager) 1222 { 1223 DataDictionaryContextImpl dataDictionaryContextImpl = 1224 new DataDictionaryContextImpl(contextManager, this); 1225 1226 return dataDictionaryContextImpl; 1227 } 1228 1229 1230 1233 private void getBuiltinSchemaNames() throws StandardException 1234 { 1235 if( builtinSchemasAreFromLCC) 1236 return; 1237 1238 LanguageConnectionContext lcc = getLCC(); 1239 if( null == lcc) 1240 { 1241 systemSchemaName = SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME; 1242 sysIBMSchemaName = SchemaDescriptor.IBM_SYSTEM_SCHEMA_NAME; 1243 1244 systemDiagSchemaName = 1245 SchemaDescriptor.STD_SYSTEM_DIAG_SCHEMA_NAME; 1246 systemUtilSchemaName = 1247 SchemaDescriptor.STD_SYSTEM_UTIL_SCHEMA_NAME; 1248 declaredGlobalTemporaryTablesSchemaName = 1249 SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME; 1250 } 1251 else 1252 { 1253 systemSchemaName = lcc.getSystemSchemaName(); 1254 sysIBMSchemaName = lcc.getSysIBMSchemaName(); 1255 systemDiagSchemaName = lcc.getSystemDiagSchemaName(); 1256 systemUtilSchemaName = lcc.getSystemUtilSchemaName(); 1257 declaredGlobalTemporaryTablesSchemaName = 1258 lcc.getDeclaredGlobalTemporaryTablesSchemaName(); 1259 1260 builtinSchemasAreFromLCC = true; 1261 } 1262 } 1263 1264 private void getBuiltinSchemas() throws StandardException 1265 { 1266 if( builtinSchemasAreFromLCC 1267 && null != systemSchemaDesc 1268 && null != sysIBMSchemaDesc 1269 && null != systemDiagSchemaDesc 1270 && null != systemUtilSchemaDesc 1271 && null != declaredGlobalTemporaryTablesSchemaDesc) 1272 return; 1273 1274 getBuiltinSchemaNames(); 1275 1276 systemSchemaDesc = 1277 newSystemSchemaDesc( 1278 systemSchemaName, SchemaDescriptor.SYSTEM_SCHEMA_UUID); 1279 sysIBMSchemaDesc = 1280 newSystemSchemaDesc( 1281 sysIBMSchemaName, SchemaDescriptor.SYSIBM_SCHEMA_UUID); 1282 systemDiagSchemaDesc = 1283 newSystemSchemaDesc( 1284 systemDiagSchemaName, SchemaDescriptor.SYSCS_DIAG_SCHEMA_UUID); 1285 systemUtilSchemaDesc = 1286 newSystemSchemaDesc( 1287 systemUtilSchemaName, SchemaDescriptor.SYSCS_UTIL_SCHEMA_UUID); 1288 1289 declaredGlobalTemporaryTablesSchemaDesc = 1290 newDeclaredGlobalTemporaryTablesSchemaDesc( 1291 declaredGlobalTemporaryTablesSchemaName); 1292 } 1293 1294 1305 public SchemaDescriptor getSystemSchemaDescriptor() 1306 throws StandardException 1307 { 1308 getBuiltinSchemas(); 1309 return systemSchemaDesc; 1310 } 1311 1312 1313 1324 public SchemaDescriptor getSystemUtilSchemaDescriptor() 1325 throws StandardException 1326 { 1327 getBuiltinSchemas(); 1328 return(systemUtilSchemaDesc); 1329 } 1330 1331 1342 public SchemaDescriptor getSystemDiagSchemaDescriptor() 1343 throws StandardException 1344 { 1345 getBuiltinSchemas(); 1346 return(systemDiagSchemaDesc); 1347 } 1348 1349 1360 public SchemaDescriptor getSysIBMSchemaDescriptor() 1361 throws StandardException 1362 { 1363 getBuiltinSchemas(); 1364 return sysIBMSchemaDesc; 1365 } 1366 1367 1375 public SchemaDescriptor getDeclaredGlobalTemporaryTablesSchemaDescriptor() 1376 throws StandardException 1377 { 1378 getBuiltinSchemas(); 1379 return declaredGlobalTemporaryTablesSchemaDesc; 1380 } 1381 1382 1390 public boolean isSystemSchemaName( String name) 1391 throws StandardException 1392 { 1393 getBuiltinSchemaNames(); 1394 1395 boolean ret_val = false; 1396 1397 for (int i = systemSchemaNames.length - 1; i >= 0;) 1398 { 1399 if ((ret_val = systemSchemaNames[i--].equals(name))) 1400 break; 1401 } 1402 1403 return(ret_val); 1404 } 1405 1406 1422 public SchemaDescriptor getSchemaDescriptor(String schemaName, 1423 TransactionController tc, 1424 boolean raiseError) 1425 throws StandardException 1426 { 1427 1431 1432 if ( tc == null ) 1433 { 1434 tc = getTransactionCompile(); 1435 } 1436 1437 if (getSystemSchemaDescriptor().getSchemaName().equals(schemaName)) 1438 { 1439 return getSystemSchemaDescriptor(); 1440 } 1441 else if (getSysIBMSchemaDescriptor().getSchemaName().equals(schemaName)) 1442 { 1443 if (dictionaryVersion.checkVersion( 1448 DataDictionary.DD_VERSION_CS_5_2, null)) 1449 { 1450 return getSysIBMSchemaDescriptor(); 1451 } 1452 } 1453 1454 1457 SchemaDescriptor sd = locateSchemaRow(schemaName, tc); 1458 1459 if (sd == null && 1462 getDeclaredGlobalTemporaryTablesSchemaDescriptor().getSchemaName().equals(schemaName)) 1463 { 1464 return getDeclaredGlobalTemporaryTablesSchemaDescriptor(); 1465 } 1466 1467 if (sd == null && raiseError) 1468 { 1469 throw StandardException.newException( 1470 SQLState.LANG_SCHEMA_DOES_NOT_EXIST, schemaName); 1471 } 1472 else 1473 { 1474 return sd; 1475 } 1476 } 1477 1478 1492 private SchemaDescriptor locateSchemaRow(UUID schemaId, 1493 TransactionController tc) 1494 throws StandardException 1495 { 1496 DataValueDescriptor UUIDStringOrderable; 1497 TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM]; 1498 1499 1500 UUIDStringOrderable = dvf.getCharDataValue(schemaId.toString()); 1501 1502 1503 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 1504 keyRow.setColumn(1, UUIDStringOrderable); 1505 1506 return (SchemaDescriptor) 1507 getDescriptorViaIndex( 1508 SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX2_ID, 1509 keyRow, 1510 (ScanQualifier [][]) null, 1511 ti, 1512 (TupleDescriptor) null, 1513 (List) null, 1514 false); 1515 } 1516 1517 1531 private SchemaDescriptor locateSchemaRow(String schemaName, 1532 TransactionController tc) 1533 throws StandardException 1534 { 1535 DataValueDescriptor schemaNameOrderable; 1536 TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM]; 1537 1538 1541 schemaNameOrderable = dvf.getVarcharDataValue(schemaName); 1542 1543 1544 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 1545 keyRow.setColumn(1, schemaNameOrderable); 1546 1547 return (SchemaDescriptor) 1548 getDescriptorViaIndex( 1549 SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID, 1550 keyRow, 1551 (ScanQualifier [][]) null, 1552 ti, 1553 (TupleDescriptor) null, 1554 (List) null, 1555 false); 1556 } 1557 1558 1578 public SchemaDescriptor getSchemaDescriptor(UUID schemaId, 1579 TransactionController tc) 1580 throws StandardException 1581 { 1582 SchemaDescriptor sd = null; 1583 1584 if ( tc == null ) 1585 { 1586 tc = getTransactionCompile(); 1587 } 1588 1589 1593 if (schemaId != null) 1594 { 1595 if (getSystemSchemaDescriptor().getUUID().equals(schemaId)) 1596 { 1597 return getSystemSchemaDescriptor(); 1598 } 1599 else if (getSysIBMSchemaDescriptor().getUUID().equals(schemaId)) 1600 { 1601 return getSysIBMSchemaDescriptor(); 1602 } 1603 } 1604 1605 1610 if (!booting) 1611 { 1612 1613 LanguageConnectionContext lcc = getLCC(); 1614 1615 if (lcc != null) 1616 { 1617 sd = lcc.getDefaultSchema(); 1618 1619 if ((sd != null) && 1620 ((schemaId == null) || 1621 schemaId.equals(sd.getUUID()))) 1622 { 1623 return sd; 1624 } 1625 } 1626 } 1627 1628 return locateSchemaRow(schemaId, tc); 1629 } 1630 1631 1634 public void addDescriptor(TupleDescriptor td, TupleDescriptor parent, 1635 int catalogNumber, boolean duplicatesAllowed, 1636 TransactionController tc) 1637 throws StandardException 1638 { 1639 addDescriptor(td, parent, catalogNumber, duplicatesAllowed, tc, true); 1640 } 1641 1642 1645 public void addDescriptor(TupleDescriptor td, TupleDescriptor parent, 1646 int catalogNumber, boolean duplicatesAllowed, 1647 TransactionController tc, boolean wait) 1648 throws StandardException 1649 { 1650 TabInfoImpl ti = (catalogNumber < NUM_CORE) ? coreInfo[catalogNumber] : 1651 getNonCoreTI(catalogNumber); 1652 1653 ExecRow row = ti.getCatalogRowFactory().makeRow(td, parent); 1654 1655 int insertRetCode = ti.insertRow(row, tc, wait); 1656 1657 if (!duplicatesAllowed) 1658 { 1659 if (insertRetCode != TabInfoImpl.ROWNOTDUPLICATE) 1660 throw duplicateDescriptorException(td, parent); 1661 } 1662 } 1663 1664 private StandardException 1665 duplicateDescriptorException(TupleDescriptor tuple, 1666 TupleDescriptor parent) 1667 { 1668 if (parent != null) 1669 return 1670 StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT, 1671 tuple.getDescriptorType(), 1672 tuple.getDescriptorName(), 1673 parent.getDescriptorType(), 1674 parent.getDescriptorName()); 1675 1676 else return 1677 StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS, 1678 tuple.getDescriptorType(), 1679 tuple.getDescriptorName()); 1680 } 1681 1682 1685 public void addDescriptorArray(TupleDescriptor[] td, 1686 TupleDescriptor parent, 1687 int catalogNumber, 1688 boolean allowDuplicates, 1689 TransactionController tc) 1690 throws StandardException 1691 { 1692 TabInfoImpl ti = (catalogNumber < NUM_CORE) ? coreInfo[catalogNumber] : 1693 getNonCoreTI(catalogNumber); 1694 CatalogRowFactory crf = ti.getCatalogRowFactory(); 1695 1696 ExecRow[] rl = new ExecRow[td.length]; 1697 1698 for (int index = 0; index < td.length; index++) 1699 { 1700 ExecRow row = crf.makeRow(td[index], parent); 1701 rl[index] = row; 1702 } 1703 1704 int insertRetCode = ti.insertRowList( rl, tc ); 1705 if (!allowDuplicates && insertRetCode != TabInfoImpl.ROWNOTDUPLICATE) 1706 { 1707 throw duplicateDescriptorException(td[insertRetCode], parent); 1708 } 1709 } 1710 1711 1719 public void dropSchemaDescriptor(String schemaName, 1720 TransactionController tc) 1721 throws StandardException 1722 { 1723 ExecIndexRow keyRow1 = null; 1724 DataValueDescriptor schemaNameOrderable; 1725 TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM]; 1726 1727 if (SanityManager.DEBUG) 1728 { 1729 SchemaDescriptor sd = getSchemaDescriptor(schemaName, getTransactionCompile(), true); 1730 if (!isSchemaEmpty(sd)) 1731 { 1732 SanityManager.THROWASSERT("Attempt to drop schema "+schemaName+" that is not empty"); 1733 } 1734 } 1735 1736 1739 schemaNameOrderable = dvf.getVarcharDataValue(schemaName); 1740 1741 1742 keyRow1 = exFactory.getIndexableRow(1); 1743 keyRow1.setColumn(1, schemaNameOrderable); 1744 1745 ti.deleteRow( tc, keyRow1, SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID ); 1746 } 1747 1748 1763 public TableDescriptor getTableDescriptor(String tableName, 1764 SchemaDescriptor schema) 1765 throws StandardException 1766 { 1767 TableDescriptor retval = null; 1768 1769 1773 if (SanityManager.DEBUG) 1774 { 1775 if ((schema == null) && !tableName.startsWith("SYS")) 1776 { 1777 SanityManager.THROWASSERT("null schema for non system table "+tableName); 1778 } 1779 } 1780 1781 SchemaDescriptor sd = (schema == null) ? 1782 getSystemSchemaDescriptor() 1783 : schema; 1784 1785 UUID schemaUUID = sd.getUUID(); 1786 1787 if (SchemaDescriptor.STD_SYSTEM_DIAG_SCHEMA_NAME.equals( 1788 sd.getSchemaName())) 1789 { 1790 TableDescriptor td = 1791 new TableDescriptor(this, tableName, sd, 1792 TableDescriptor.VTI_TYPE, 1793 TableDescriptor.DEFAULT_LOCK_GRANULARITY); 1794 1795 if (getVTIClass(td) != null) 1797 return td; 1798 1799 } 1801 1802 TableKey tableKey = new TableKey(schemaUUID, tableName); 1803 1804 1805 if (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE) 1806 { 1807 NameTDCacheable cacheEntry = (NameTDCacheable) nameTdCache.find(tableKey); 1808 if (cacheEntry != null) 1809 { 1810 retval = cacheEntry.getTableDescriptor(); 1811 retval.setReferencedColumnMap(null); 1813 nameTdCache.release(cacheEntry); 1814 } 1815 return retval; 1816 } 1817 1818 return getTableDescriptorIndex1Scan(tableName, schemaUUID.toString()); 1819 1820 } 1821 1822 1829 private TableDescriptor getTableDescriptorIndex1Scan( 1830 String tableName, 1831 String schemaUUID) 1832 throws StandardException 1833 { 1834 DataValueDescriptor schemaIDOrderable; 1835 DataValueDescriptor tableNameOrderable; 1836 TableDescriptor td; 1837 TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM]; 1838 1839 1842 tableNameOrderable = dvf.getVarcharDataValue(tableName); 1843 schemaIDOrderable = dvf.getCharDataValue(schemaUUID); 1844 1845 1846 ExecIndexRow keyRow = exFactory.getIndexableRow(2); 1847 keyRow.setColumn(1, tableNameOrderable); 1848 keyRow.setColumn(2, schemaIDOrderable); 1849 1850 td = (TableDescriptor) 1851 getDescriptorViaIndex( 1852 SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, 1853 keyRow, 1854 (ScanQualifier [][]) null, 1855 ti, 1856 (TupleDescriptor) null, 1857 (List) null, 1858 false); 1859 1860 return finishTableDescriptor(td); 1861 } 1862 1863 1873 TableDescriptor getUncachedTableDescriptor(TableKey tableKey) 1874 throws StandardException 1875 { 1876 return getTableDescriptorIndex1Scan(tableKey.getTableName(), 1877 tableKey.getSchemaId().toString()); 1878 } 1879 1880 1896 public TableDescriptor getTableDescriptor(UUID tableID) 1897 throws StandardException 1898 { 1899 OIDTDCacheable cacheEntry; 1900 TableDescriptor retval = null; 1901 1902 1903 if (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE) 1904 { 1905 cacheEntry = (OIDTDCacheable) OIDTdCache.find(tableID); 1906 if (cacheEntry != null) 1907 { 1908 retval = cacheEntry.getTableDescriptor(); 1909 retval.setReferencedColumnMap(null); 1911 OIDTdCache.release(cacheEntry); 1912 } 1913 1914 return retval; 1915 1916 } 1917 1918 return getTableDescriptorIndex2Scan(tableID.toString()); 1919 } 1920 1921 1931 protected TableDescriptor getUncachedTableDescriptor(UUID tableID) 1932 throws StandardException 1933 { 1934 return getTableDescriptorIndex2Scan(tableID.toString()); 1935 } 1936 1937 1944 private TableDescriptor getTableDescriptorIndex2Scan( 1945 String tableUUID) 1946 throws StandardException 1947 { 1948 DataValueDescriptor tableIDOrderable; 1949 TableDescriptor td; 1950 TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM]; 1951 1952 1955 tableIDOrderable = dvf.getCharDataValue(tableUUID); 1956 1957 1958 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 1959 keyRow.setColumn(1, tableIDOrderable); 1960 1961 td = (TableDescriptor) 1962 getDescriptorViaIndex( 1963 SYSTABLESRowFactory.SYSTABLES_INDEX2_ID, 1964 keyRow, 1965 (ScanQualifier [][]) null, 1966 ti, 1967 (TupleDescriptor) null, 1968 (List) null, 1969 false); 1970 1971 return finishTableDescriptor(td); 1972 } 1973 1974 1984 private TableDescriptor finishTableDescriptor(TableDescriptor td) 1985 throws StandardException 1986 { 1987 1988 if (td != null) 1989 { 1990 synchronized(td) 1991 { 1992 getColumnDescriptorsScan(td); 1993 getConglomerateDescriptorsScan(td); 1994 } 1995 } 1996 1997 return td; 1998 } 1999 2000 2012 public boolean isSchemaEmpty(SchemaDescriptor sd) 2013 throws StandardException 2014 { 2015 DataValueDescriptor schemaIdOrderable; 2016 TransactionController tc = getTransactionCompile(); 2017 2018 schemaIdOrderable = getValueAsDVD(sd.getUUID()); 2019 2020 if (isSchemaReferenced(tc, coreInfo[SYSTABLES_CORE_NUM], 2021 SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, 2022 SYSTABLESRowFactory.SYSTABLES_INDEX1_SCHEMAID, 2023 schemaIdOrderable)) 2024 { 2025 return false; 2026 } 2027 2028 if (isSchemaReferenced(tc, getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM), 2029 SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX2_ID, 2030 2, 2031 schemaIdOrderable)) 2032 { 2033 return false; 2034 } 2035 2036 if (isSchemaReferenced(tc, getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM), 2037 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INDEX2_ID, 2038 2, 2039 schemaIdOrderable)) 2040 { 2041 return false; 2042 } 2043 2044 if (isSchemaReferenced(tc, getNonCoreTI(SYSTRIGGERS_CATALOG_NUM), 2045 SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX2_ID, 2046 2, 2047 schemaIdOrderable)) 2048 { 2049 return false; 2050 } 2051 2052 return true; 2053 } 2054 2055 2071 protected boolean isSchemaReferenced(TransactionController tc, 2072 TabInfoImpl ti, 2073 int indexId, 2074 int indexCol, 2075 DataValueDescriptor schemaIdOrderable ) 2076 throws StandardException 2077 { 2078 ConglomerateController heapCC = null; 2079 ExecIndexRow indexRow1; 2080 ExecIndexRow indexTemplateRow; 2081 ExecRow outRow; 2082 ScanController scanController = null; 2083 boolean foundRow; 2084 FormatableBitSet colToCheck = new FormatableBitSet(indexCol); 2085 CatalogRowFactory rf = ti.getCatalogRowFactory(); 2086 2087 if (SanityManager.DEBUG) 2088 { 2089 SanityManager.ASSERT(indexId >= 0, "code needs to be enhanced"+ 2090 " to support a table scan to find the index id"); 2091 } 2092 2093 colToCheck.set(indexCol - 1); 2094 2095 ScanQualifier[][] qualifier = exFactory.getScanQualifier(1); 2096 qualifier[0][0].setQualifier 2097 (indexCol - 1, 2098 schemaIdOrderable, 2099 Orderable.ORDER_OP_EQUALS, 2100 false, 2101 false, 2102 false); 2103 2104 outRow = rf.makeEmptyRow(); 2105 2106 try 2107 { 2108 heapCC = 2109 tc.openConglomerate( 2110 ti.getHeapConglomerate(), false, 0, 2111 TransactionController.MODE_RECORD, 2112 TransactionController.ISOLATION_REPEATABLE_READ); 2113 2114 scanController = tc.openScan( 2115 ti.getIndexConglomerate(indexId), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, 2120 colToCheck, null, ScanController.GE, qualifier, null, ScanController.GT); 2127 foundRow = (scanController.next()); 2128 } 2129 finally 2130 { 2131 if (scanController != null) 2132 { 2133 scanController.close(); 2134 } 2135 if (heapCC != null) 2136 { 2137 heapCC.close(); 2138 } 2139 } 2140 2141 return foundRow; 2142 } 2143 2144 2156 public void dropTableDescriptor(TableDescriptor td, SchemaDescriptor schema, 2157 TransactionController tc) 2158 throws StandardException 2159 { 2160 ConglomerateController heapCC; 2161 ExecIndexRow keyRow1 = null; 2162 DataValueDescriptor schemaIDOrderable; 2163 DataValueDescriptor tableNameOrderable; 2164 TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM]; 2165 2166 2169 tableNameOrderable = dvf.getVarcharDataValue(td.getName()); 2170 schemaIDOrderable = getValueAsDVD(schema.getUUID()); 2171 2172 2173 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(2); 2174 keyRow1.setColumn(1, tableNameOrderable); 2175 keyRow1.setColumn(2, schemaIDOrderable); 2176 2177 ti.deleteRow( tc, keyRow1, SYSTABLESRowFactory.SYSTABLES_INDEX1_ID ); 2178 } 2179 2180 2190 public void updateLockGranularity(TableDescriptor td, SchemaDescriptor schema, 2191 char lockGranularity, TransactionController tc) 2192 throws StandardException 2193 { 2194 ConglomerateController heapCC; 2195 ExecIndexRow keyRow1 = null; 2196 ExecRow row; 2197 DataValueDescriptor schemaIDOrderable; 2198 DataValueDescriptor tableNameOrderable; 2199 TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM]; 2200 SYSTABLESRowFactory rf = (SYSTABLESRowFactory) ti.getCatalogRowFactory(); 2201 2202 2205 tableNameOrderable = dvf.getVarcharDataValue(td.getName()); 2206 schemaIDOrderable = getValueAsDVD(schema.getUUID()); 2207 2208 2209 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(2); 2210 keyRow1.setColumn(1, tableNameOrderable); 2211 keyRow1.setColumn(2, schemaIDOrderable); 2212 2213 row = rf.makeRow(td, schema); 2215 boolean[] bArray = new boolean[2]; 2217 for (int index = 0; index < 2; index++) 2218 { 2219 bArray[index] = false; 2220 } 2221 ti.updateRow(keyRow1, row, 2222 SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, 2223 bArray, 2224 (int[])null, 2225 tc); 2226 } 2227 2228 2238 2245 2246 2255 public ColumnDescriptor getColumnDescriptorByDefaultId(UUID uuid) 2256 throws StandardException 2257 { 2258 DataValueDescriptor UUIDStringOrderable; 2259 TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM]; 2260 2261 2262 UUIDStringOrderable = dvf.getCharDataValue(uuid.toString()); 2263 2264 2265 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 2266 keyRow.setColumn(1, UUIDStringOrderable); 2267 2268 return (ColumnDescriptor) 2269 getDescriptorViaIndex( 2270 SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX2_ID, 2271 keyRow, 2272 (ScanQualifier [][]) null, 2273 ti, 2274 (DefaultDescriptor) null, 2275 (List) null, 2276 false); 2277 } 2278 2279 2280 2290 private void getColumnDescriptorsScan(TableDescriptor td) 2291 throws StandardException 2292 { 2293 getColumnDescriptorsScan( 2294 td.getUUID(), 2295 td.getColumnDescriptorList(), 2296 td); 2297 } 2298 2299 2311 private void getColumnDescriptorsScan( 2312 UUID uuid, 2313 ColumnDescriptorList cdl, 2314 TupleDescriptor td) 2315 throws StandardException 2316 { 2317 ColumnDescriptor cd; 2318 ColumnDescriptorList cdlCopy = new ColumnDescriptorList(); 2319 DataValueDescriptor refIDOrderable = null; 2320 TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM]; 2321 2322 2323 refIDOrderable = getValueAsDVD(uuid); 2324 2325 2326 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 2327 keyRow.setColumn(1, refIDOrderable); 2328 2329 getDescriptorViaIndex( 2330 SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID, 2331 keyRow, 2332 (ScanQualifier [][]) null, 2333 ti, 2334 td, 2335 (ColumnDescriptorList) cdl, 2336 false); 2337 2338 2345 int cdlSize = cdl.size(); 2346 for (int index = 0; index < cdlSize; index++) 2347 { 2348 cdlCopy.add( cdl.get(index)); 2349 } 2350 for (int index = 0; index < cdlSize; index++) 2351 { 2352 cd = (ColumnDescriptor) cdlCopy.elementAt(index); 2353 cdl.set(cd.getPosition() - 1, cd); 2354 } 2355 } 2356 2357 2367 public void dropColumnDescriptor(UUID tableID, 2368 String columnName, TransactionController tc) 2369 throws StandardException 2370 { 2371 DataValueDescriptor columnNameOrderable; 2372 DataValueDescriptor tableIdOrderable; 2373 2374 2377 tableIdOrderable = getValueAsDVD(tableID); 2378 columnNameOrderable = dvf.getVarcharDataValue(columnName); 2379 2380 2381 ExecIndexRow keyRow = exFactory.getIndexableRow(2); 2382 keyRow.setColumn(1, tableIdOrderable); 2383 keyRow.setColumn(2, columnNameOrderable); 2384 2385 dropColumnDescriptorCore( tc, keyRow); 2386 } 2387 2388 2398 public void dropAllColumnDescriptors(UUID tableID, TransactionController tc) 2399 throws StandardException 2400 { 2401 DataValueDescriptor tableIdOrderable; 2402 2403 2404 tableIdOrderable = getValueAsDVD(tableID); 2405 2406 2407 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 2408 keyRow.setColumn(1, tableIdOrderable); 2409 2410 dropColumnDescriptorCore(tc, keyRow); 2411 } 2412 2413 2422 public void dropAllTableAndColPermDescriptors(UUID tableID, TransactionController tc) 2423 throws StandardException 2424 { 2425 DataValueDescriptor tableIdOrderable; 2426 2427 if (!usesSqlAuthorization) 2429 return; 2430 2431 2432 tableIdOrderable = getValueAsDVD(tableID); 2433 2434 2435 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 2436 keyRow.setColumn(1, tableIdOrderable); 2437 2438 dropTablePermDescriptor(tc, keyRow); 2439 dropColumnPermDescriptor(tc, keyRow); 2440 } 2441 2442 2457 public void updateSYSCOLPERMSforAddColumnToUserTable(UUID tableID, TransactionController tc) 2458 throws StandardException 2459 { 2460 if (!usesSqlAuthorization) 2462 return; 2463 2464 2471 2472 List permissionDescriptorsList; DataValueDescriptor tableIDOrderable = getValueAsDVD(tableID); 2476 TabInfoImpl ti = getNonCoreTI(SYSCOLPERMS_CATALOG_NUM); 2477 SYSCOLPERMSRowFactory rf = (SYSCOLPERMSRowFactory) ti.getCatalogRowFactory(); 2478 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 2479 keyRow.setColumn(1, tableIDOrderable); 2480 permissionDescriptorsList = newSList(); 2481 getDescriptorViaIndex( 2482 SYSCOLPERMSRowFactory.TABLEID_INDEX_NUM, 2483 keyRow, 2484 (ScanQualifier [][]) null, 2485 ti, 2486 (TupleDescriptor) null, 2487 permissionDescriptorsList, 2488 false); 2489 2490 2493 ColPermsDescriptor colPermsDescriptor; 2494 ExecRow curRow; 2495 ExecIndexRow uuidKey; 2496 boolean[] bArray = new boolean[SYSCOLPERMSRowFactory.TOTAL_NUM_OF_INDEXES]; 2498 int[] colsToUpdate = {SYSCOLPERMSRowFactory.COLUMNS_COL_NUM}; 2499 for (Iterator iterator = permissionDescriptorsList.iterator(); iterator.hasNext(); ) 2500 { 2501 colPermsDescriptor = (ColPermsDescriptor) iterator.next(); 2502 removePermEntryInCache(colPermsDescriptor); 2503 uuidKey = rf.buildIndexKeyRow(rf.COLPERMSID_INDEX_NUM, colPermsDescriptor); 2504 curRow=ti.getRow(tc, uuidKey, rf.COLPERMSID_INDEX_NUM); 2505 FormatableBitSet columns = (FormatableBitSet) curRow.getColumn( 2506 SYSCOLPERMSRowFactory.COLUMNS_COL_NUM).getObject(); 2507 int currentLength = columns.getLength(); 2508 columns.grow(currentLength+1); 2509 curRow.setColumn(SYSCOLPERMSRowFactory.COLUMNS_COL_NUM, 2510 dvf.getDataValue((Object ) columns)); 2511 ti.updateRow(keyRow, curRow, 2512 SYSCOLPERMSRowFactory.TABLEID_INDEX_NUM, 2513 bArray, 2514 colsToUpdate, 2515 tc); 2516 } 2517 } 2518 2519 2520 2523 private void removePermEntryInCache(PermissionsDescriptor perm) 2524 throws StandardException 2525 { 2526 Cacheable cacheEntry = getPermissionsCache().findCached( perm); 2528 if (cacheEntry != null) 2529 getPermissionsCache().remove(cacheEntry); 2530 } 2531 2532 2541 public void dropAllRoutinePermDescriptors(UUID routineID, TransactionController tc) 2542 throws StandardException 2543 { 2544 TabInfoImpl ti = getNonCoreTI(SYSROUTINEPERMS_CATALOG_NUM); 2545 SYSROUTINEPERMSRowFactory rf = (SYSROUTINEPERMSRowFactory) ti.getCatalogRowFactory(); 2546 DataValueDescriptor routineIdOrderable; 2547 ExecRow curRow; 2548 PermissionsDescriptor perm; 2549 2550 if (!usesSqlAuthorization) 2552 return; 2553 2554 2555 routineIdOrderable = getValueAsDVD(routineID); 2556 2557 2558 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 2559 keyRow.setColumn(1, routineIdOrderable); 2560 2561 while ((curRow=ti.getRow(tc, keyRow, rf.ALIASID_INDEX_NUM)) != null) 2562 { 2563 perm = (PermissionsDescriptor)rf.buildDescriptor(curRow, (TupleDescriptor) null, this); 2564 removePermEntryInCache(perm); 2565 2566 ExecIndexRow uuidKey; 2569 uuidKey = rf.buildIndexKeyRow(rf.ROUTINEPERMSID_INDEX_NUM, perm); 2570 ti.deleteRow(tc, uuidKey, rf.ROUTINEPERMSID_INDEX_NUM); 2571 } 2572 } 2573 2574 2583 private void dropColumnDescriptorCore( 2584 TransactionController tc, 2585 ExecIndexRow keyRow) 2586 throws StandardException 2587 { 2588 TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM]; 2589 2590 ti.deleteRow( tc, keyRow, SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID ); 2591 } 2592 2593 2602 private void dropTablePermDescriptor( 2603 TransactionController tc, 2604 ExecIndexRow keyRow) 2605 throws StandardException 2606 { 2607 ExecRow curRow; 2608 PermissionsDescriptor perm; 2609 TabInfoImpl ti = getNonCoreTI(SYSTABLEPERMS_CATALOG_NUM); 2610 SYSTABLEPERMSRowFactory rf = (SYSTABLEPERMSRowFactory) ti.getCatalogRowFactory(); 2611 2612 while ((curRow=ti.getRow(tc, keyRow, rf.TABLEID_INDEX_NUM)) != null) 2613 { 2614 perm = (PermissionsDescriptor)rf.buildDescriptor(curRow, (TupleDescriptor) null, this); 2615 removePermEntryInCache(perm); 2616 2617 ExecIndexRow uuidKey; 2619 uuidKey = rf.buildIndexKeyRow(rf.TABLEPERMSID_INDEX_NUM, perm); 2620 ti.deleteRow(tc, uuidKey, rf.TABLEPERMSID_INDEX_NUM); 2621 } 2622 } 2623 2624 2633 private void dropColumnPermDescriptor( 2634 TransactionController tc, 2635 ExecIndexRow keyRow) 2636 throws StandardException 2637 { 2638 ExecRow curRow; 2639 PermissionsDescriptor perm; 2640 TabInfoImpl ti = getNonCoreTI(SYSCOLPERMS_CATALOG_NUM); 2641 SYSCOLPERMSRowFactory rf = (SYSCOLPERMSRowFactory) ti.getCatalogRowFactory(); 2642 2643 while ((curRow=ti.getRow(tc, keyRow, rf.TABLEID_INDEX_NUM)) != null) 2644 { 2645 perm = (PermissionsDescriptor)rf.buildDescriptor(curRow, (TupleDescriptor) null, this); 2646 removePermEntryInCache(perm); 2647 2648 ExecIndexRow uuidKey; 2650 uuidKey = rf.buildIndexKeyRow(rf.COLPERMSID_INDEX_NUM, perm); 2651 ti.deleteRow(tc, uuidKey, rf.COLPERMSID_INDEX_NUM); 2652 } 2653 } 2654 2655 2675 private void updateColumnDescriptor(ColumnDescriptor cd, 2676 UUID formerUUID, 2677 String formerName, 2678 int[] colsToSet, 2679 TransactionController tc, 2680 boolean wait) 2681 throws StandardException 2682 { 2683 ExecIndexRow keyRow1 = null; 2684 ExecRow row; 2685 DataValueDescriptor refIDOrderable; 2686 DataValueDescriptor columnNameOrderable; 2687 TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM]; 2688 SYSCOLUMNSRowFactory rf = (SYSCOLUMNSRowFactory) ti.getCatalogRowFactory(); 2689 2690 2693 refIDOrderable = getValueAsDVD(formerUUID); 2694 columnNameOrderable = dvf.getVarcharDataValue(formerName); 2695 2696 2697 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(2); 2698 keyRow1.setColumn(1, refIDOrderable); 2699 keyRow1.setColumn(2, columnNameOrderable); 2700 2701 row = rf.makeRow(cd, null); 2703 2704 2708 if (SanityManager.DEBUG) 2709 { 2710 SanityManager.ASSERT(rf.getNumIndexes() == 2, 2711 "There are more indexes on syscolumns than expected, the code herein needs to change"); 2712 } 2713 2714 boolean[] bArray = new boolean[rf.getNumIndexes()]; 2715 2716 2719 if (colsToSet == null) 2720 { 2721 bArray[0] = true; 2722 bArray[1] = true; 2723 } 2724 else 2725 { 2726 2730 for (int i = 0; i < colsToSet.length; i++) 2731 { 2732 if ((colsToSet[i] == rf.SYSCOLUMNS_COLUMNNAME) || 2733 (colsToSet[i] == rf.SYSCOLUMNS_REFERENCEID)) 2734 { 2735 bArray[0] = true; 2736 break; 2737 } 2738 else if (colsToSet[i] == rf.SYSCOLUMNS_COLUMNDEFAULTID) 2739 { 2740 bArray[1] = true; 2741 break; 2742 } 2743 } 2744 } 2745 2746 ti.updateRow(keyRow1, row, 2747 SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID, 2748 bArray, 2749 colsToSet, 2750 tc, 2751 wait); 2752 } 2753 2754 2763 public ViewDescriptor getViewDescriptor(UUID uuid) 2764 throws StandardException 2765 { 2766 return getViewDescriptor(getTableDescriptor(uuid)); 2767 } 2768 2769 2778 public ViewDescriptor getViewDescriptor(TableDescriptor td) 2779 throws StandardException 2780 { 2781 TableDescriptor tdi = (TableDescriptor) td; 2782 2783 2784 if (tdi.getViewDescriptor() != null) 2785 { 2786 return tdi.getViewDescriptor(); 2787 } 2788 2789 synchronized(tdi) 2790 { 2791 2792 if (tdi.getViewDescriptor() != null) 2793 { 2794 return tdi.getViewDescriptor(); 2795 } 2796 2797 tdi.setViewDescriptor((ViewDescriptor) getViewDescriptorScan(tdi)); 2798 } 2799 return tdi.getViewDescriptor(); 2800 } 2801 2802 2811 private ViewDescriptor getViewDescriptorScan(TableDescriptor tdi) 2812 throws StandardException 2813 { 2814 ViewDescriptor vd; 2815 DataValueDescriptor viewIdOrderable; 2816 TabInfoImpl ti = getNonCoreTI(SYSVIEWS_CATALOG_NUM); 2817 UUID viewID = tdi.getUUID(); 2818 2819 2822 viewIdOrderable = dvf.getCharDataValue(viewID.toString()); 2823 2824 2825 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 2826 keyRow.setColumn(1, viewIdOrderable); 2827 2828 vd = (ViewDescriptor) 2829 getDescriptorViaIndex( 2830 SYSVIEWSRowFactory.SYSVIEWS_INDEX1_ID, 2831 keyRow, 2832 (ScanQualifier [][]) null, 2833 ti, 2834 (TupleDescriptor) null, 2835 (List) null, 2836 false); 2837 2838 if (vd != null) 2839 { 2840 vd.setViewName(tdi.getName()); 2841 } 2842 return vd; 2843 } 2844 2845 2853 public void dropViewDescriptor(ViewDescriptor vd, 2854 TransactionController tc) 2855 throws StandardException 2856 { 2857 DataValueDescriptor viewIdOrderable; 2858 TabInfoImpl ti = getNonCoreTI(SYSVIEWS_CATALOG_NUM); 2859 2860 2863 viewIdOrderable = getValueAsDVD(vd.getUUID()); 2864 2865 2866 ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 2867 keyRow.setColumn(1, viewIdOrderable); 2868 2869 ti.deleteRow( tc, keyRow, SYSVIEWSRowFactory.SYSVIEWS_INDEX1_ID ); 2870 2871 } 2872 2873 2878 private FileInfoDescriptor 2879 getFileInfoDescriptorIndex2Scan(UUID id) 2880 throws StandardException 2881 { 2882 DataValueDescriptor idOrderable; 2883 TabInfoImpl ti = getNonCoreTI(SYSFILES_CATALOG_NUM); 2884 idOrderable = dvf.getCharDataValue(id.toString()); 2885 2886 2887 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 2888 keyRow.setColumn(1, idOrderable); 2889 2890 return (FileInfoDescriptor) 2891 getDescriptorViaIndex( 2892 SYSFILESRowFactory.SYSFILES_INDEX2_ID, 2893 keyRow, 2894 (ScanQualifier [][]) null, 2895 ti, 2896 (TupleDescriptor) null, 2897 (List) null, 2898 false); 2899 } 2900 2901 2905 public FileInfoDescriptor getFileInfoDescriptor(UUID id) 2906 throws StandardException 2907 { 2908 return getFileInfoDescriptorIndex2Scan(id); 2909 } 2910 2911 2912 2917 private FileInfoDescriptor getFileInfoDescriptorIndex1Scan( 2918 UUID schemaId, 2919 String name) 2920 throws StandardException 2921 { 2922 DataValueDescriptor schemaIDOrderable; 2923 DataValueDescriptor nameOrderable; 2924 TabInfoImpl ti = getNonCoreTI(SYSFILES_CATALOG_NUM); 2925 2926 nameOrderable = dvf.getVarcharDataValue(name); 2927 schemaIDOrderable = dvf.getCharDataValue(schemaId.toString()); 2928 2929 2930 ExecIndexRow keyRow = exFactory.getIndexableRow(2); 2931 keyRow.setColumn(1, nameOrderable); 2932 keyRow.setColumn(2, schemaIDOrderable); 2933 FileInfoDescriptor r = (FileInfoDescriptor) 2934 getDescriptorViaIndex( 2935 SYSFILESRowFactory.SYSFILES_INDEX1_ID, 2936 keyRow, 2937 (ScanQualifier [][]) null, 2938 ti, 2939 (TupleDescriptor) null, 2940 (List) null, 2941 false); 2942 return r; 2943 } 2944 2945 2949 public FileInfoDescriptor getFileInfoDescriptor(SchemaDescriptor sd, String name) 2950 throws StandardException 2951 { 2952 return getFileInfoDescriptorIndex1Scan(sd.getUUID(),name); 2953 } 2954 2955 2959 public void dropFileInfoDescriptor(FileInfoDescriptor fid) 2960 throws StandardException 2961 { 2962 ConglomerateController heapCC; 2963 ExecIndexRow keyRow1 = null; 2964 DataValueDescriptor idOrderable; 2965 TabInfoImpl ti = getNonCoreTI(SYSFILES_CATALOG_NUM); 2966 TransactionController tc = getTransactionExecute(); 2967 2968 2971 idOrderable = getValueAsDVD(fid.getUUID()); 2972 2973 2974 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1); 2975 keyRow1.setColumn(1, idOrderable); 2976 ti.deleteRow( tc, keyRow1, SYSFILESRowFactory.SYSFILES_INDEX2_ID ); 2977 } 2978 2979 2988 public SPSDescriptor getSPSDescriptor(UUID uuid) 2989 throws StandardException 2990 { 2991 SPSDescriptor sps; 2992 2993 2994 getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM); 2995 2996 2997 if ((spsNameCache != null) && 2998 (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE)) 2999 { 3000 sps = (SPSDescriptor)spsIdHash.get(uuid); 3001 if (sps != null) 3002 { 3003 3006 return sps; 3007 } 3008 3009 sps = getSPSDescriptorIndex2Scan(uuid.toString()); 3010 TableKey stmtKey = new TableKey(sps.getSchemaDescriptor().getUUID(), sps.getName()); 3011 try 3012 { 3013 SPSNameCacheable cacheEntry = (SPSNameCacheable)spsNameCache.create(stmtKey, sps); 3014 spsNameCache.release(cacheEntry); 3015 } catch (StandardException se) 3016 { 3017 3021 if (SQLState.OBJECT_EXISTS_IN_CACHE.equals(se.getMessageId())) 3022 { 3023 return sps; 3024 } 3025 else 3026 { 3027 throw se; 3028 } 3029 } 3030 3031 } 3032 else 3033 { 3034 sps = getSPSDescriptorIndex2Scan(uuid.toString()); 3035 } 3036 3037 return sps; 3038 } 3039 3040 3043 void spsCacheEntryAdded(SPSDescriptor spsd) 3044 { 3045 spsIdHash.put(spsd.getUUID(), spsd); 3046 } 3048 3049 void spsCacheEntryRemoved(SPSDescriptor spsd) { 3050 spsIdHash.remove(spsd.getUUID()); 3051 } 3053 3054 3056 3059 3069 public SPSDescriptor getUncachedSPSDescriptor(TableKey stmtKey) 3070 throws StandardException 3071 { 3072 return getSPSDescriptorIndex1Scan(stmtKey.getTableName(), 3073 stmtKey.getSchemaId().toString()); 3074 } 3075 3076 3086 protected SPSDescriptor getUncachedSPSDescriptor(UUID stmtId) 3087 throws StandardException 3088 { 3089 return getSPSDescriptorIndex2Scan(stmtId.toString()); 3090 } 3091 3092 3100 private SPSDescriptor getSPSDescriptorIndex2Scan( 3101 String stmtUUID) 3102 throws StandardException 3103 { 3104 DataValueDescriptor stmtIDOrderable; 3105 TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM); 3106 3107 3110 stmtIDOrderable = dvf.getCharDataValue(stmtUUID); 3111 3112 3113 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 3114 keyRow.setColumn(1, stmtIDOrderable); 3115 3116 SPSDescriptor spsd = (SPSDescriptor) 3117 getDescriptorViaIndex( 3118 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INDEX1_ID, 3119 keyRow, 3120 (ScanQualifier [][]) null, 3121 ti, 3122 (TupleDescriptor) null, 3123 (List) null, 3124 false); 3125 3126 return spsd; 3127 } 3128 3129 3143 public SPSDescriptor getSPSDescriptor(String stmtName, SchemaDescriptor sd) 3144 throws StandardException 3145 { 3146 SPSDescriptor sps = null; 3147 TableKey stmtKey; 3148 UUID schemaUUID; 3149 3150 3154 if (SanityManager.DEBUG) 3155 { 3156 if (sd == null) 3157 { 3158 SanityManager.THROWASSERT("null schema for statement "+stmtName); 3159 } 3160 } 3161 3162 schemaUUID = sd.getUUID(); 3163 stmtKey = new TableKey(schemaUUID, stmtName); 3164 3165 3166 if ((spsNameCache != null) && 3167 (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE)) 3168 { 3169 SPSNameCacheable cacheEntry = (SPSNameCacheable) spsNameCache.find(stmtKey); 3170 if (cacheEntry != null) 3171 { 3172 sps = cacheEntry.getSPSDescriptor(); 3173 spsNameCache.release(cacheEntry); 3174 } 3175 return sps; 3178 } 3179 3180 return getSPSDescriptorIndex1Scan(stmtName, schemaUUID.toString()); 3181 } 3182 3183 3190 private SPSDescriptor getSPSDescriptorIndex1Scan( 3191 String stmtName, 3192 String schemaUUID) 3193 throws StandardException 3194 { 3195 DataValueDescriptor schemaIDOrderable; 3196 DataValueDescriptor stmtNameOrderable; 3197 TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM); 3198 3199 3202 stmtNameOrderable = dvf.getVarcharDataValue(stmtName); 3203 schemaIDOrderable = dvf.getCharDataValue(schemaUUID); 3204 3205 3206 ExecIndexRow keyRow = exFactory.getIndexableRow(2); 3207 keyRow.setColumn(1, stmtNameOrderable); 3208 keyRow.setColumn(2, schemaIDOrderable); 3209 3210 SPSDescriptor spsd = (SPSDescriptor) 3211 getDescriptorViaIndex( 3212 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INDEX2_ID, 3213 keyRow, 3214 (ScanQualifier [][]) null, 3215 ti, 3216 (TupleDescriptor) null, 3217 (List) null, 3218 false); 3219 3220 3227 if (spsd != null) 3228 { 3229 Vector v = new Vector (); 3230 spsd.setParams(getSPSParams(spsd, v)); 3231 Object [] defaults = new Object [v.size()]; 3232 v.copyInto(defaults); 3233 spsd.setParameterDefaults(defaults); 3234 } 3235 3236 return spsd; 3237 } 3238 3239 3248 public void addSPSDescriptor 3249 ( 3250 SPSDescriptor descriptor, 3251 TransactionController tc, 3252 boolean wait 3253 ) throws StandardException 3254 { 3255 ExecRow row; 3256 TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM); 3257 SYSSTATEMENTSRowFactory rf = (SYSSTATEMENTSRowFactory) ti.getCatalogRowFactory(); 3258 int insertRetCode; 3259 3260 3266 synchronized(descriptor) 3267 { 3268 boolean compileMe = descriptor.initiallyCompilable(); 3271 row = rf.makeSYSSTATEMENTSrow(compileMe, descriptor); 3272 3273 insertRetCode = ti.insertRow(row, tc, wait); 3275 } 3276 3277 if (insertRetCode != TabInfoImpl.ROWNOTDUPLICATE) 3279 { 3280 throw StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT, 3281 descriptor.getDescriptorType(), 3282 descriptor.getDescriptorName(), 3283 descriptor.getSchemaDescriptor().getDescriptorType(), 3284 descriptor.getSchemaDescriptor().getSchemaName()); 3285 } 3286 3287 addSPSParams(descriptor, tc, wait); 3288 } 3289 3290 3294 private void addSPSParams(SPSDescriptor spsd, TransactionController tc, boolean wait) 3295 throws StandardException 3296 { 3297 UUID uuid = spsd.getUUID(); 3298 DataTypeDescriptor[] params = spsd.getParams(); 3299 Object [] parameterDefaults = spsd.getParameterDefaults(); 3300 3301 if (params == null) 3302 return; 3303 3304 3305 int pdlSize = params.length; 3306 for (int index = 0; index < pdlSize; index++) 3307 { 3308 int parameterId = index + 1; 3309 3310 ColumnDescriptor cd = 3312 new ColumnDescriptor( 3313 "PARAM" + parameterId, 3314 parameterId, params[index], 3316 ((parameterDefaults == null) || (index >= parameterDefaults.length)) ? 3318 (DataValueDescriptor)null : 3319 (DataValueDescriptor)parameterDefaults[index], 3320 (DefaultInfo) null, 3321 uuid, 3322 (UUID) null, 0, 0); 3323 3324 addDescriptor(cd, null, SYSCOLUMNS_CATALOG_NUM, 3325 false, tc, wait); 3327 } 3328 } 3329 3330 3342 public DataTypeDescriptor[] getSPSParams(SPSDescriptor spsd, Vector defaults) 3343 throws StandardException 3344 { 3345 ColumnDescriptorList cdl = new ColumnDescriptorList(); 3346 getColumnDescriptorsScan(spsd.getUUID(), cdl, spsd); 3347 3348 int cdlSize = cdl.size(); 3349 DataTypeDescriptor[] params = new DataTypeDescriptor[cdlSize]; 3350 for (int index = 0; index < cdlSize; index++) 3351 { 3352 ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index); 3353 params[index] = cd.getType(); 3354 if (defaults != null) 3355 { 3356 defaults.addElement(cd.getDefaultValue()); 3357 } 3358 } 3359 3360 return params; 3361 } 3362 3363 3380 public void updateSPS( 3381 SPSDescriptor spsd, 3382 TransactionController tc, 3383 boolean recompile, 3384 boolean updateParamDescriptors, 3385 boolean wait, 3386 boolean firstCompilation) 3387 throws StandardException 3388 { 3389 ExecIndexRow keyRow1 = null; 3390 ExecRow row; 3391 DataValueDescriptor idOrderable; 3392 DataValueDescriptor columnNameOrderable; 3393 TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM); 3394 SYSSTATEMENTSRowFactory rf = (SYSSTATEMENTSRowFactory) ti.getCatalogRowFactory(); 3395 int[] updCols; 3396 if (recompile) 3397 { 3398 if(firstCompilation) 3399 { 3400 updCols = new int[] {SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID, 3401 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_LASTCOMPILED, 3402 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_USINGTEXT, 3403 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_CONSTANTSTATE, 3404 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INITIALLY_COMPILABLE}; 3405 }else 3406 { 3407 3408 updCols = new int[] {SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID, 3409 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_LASTCOMPILED, 3410 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_USINGTEXT, 3411 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_CONSTANTSTATE }; 3412 } 3413 } 3414 else 3415 { 3416 updCols = new int[] {SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID} ; 3417 } 3418 3419 idOrderable = getValueAsDVD(spsd.getUUID()); 3420 3421 3422 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1); 3423 keyRow1.setColumn(1, idOrderable); 3424 3425 row = rf.makeSYSSTATEMENTSrow(false, spsd); 3427 3428 3431 boolean[] bArray = new boolean[2]; 3432 3433 3436 ti.updateRow(keyRow1, row, 3437 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INDEX1_ID, 3438 bArray, 3439 updCols, 3440 tc, 3441 wait); 3442 3443 3444 3448 if (!updateParamDescriptors) 3449 { 3450 return; 3451 } 3452 3453 3457 DataTypeDescriptor[] params = spsd.getParams(); 3458 if (params == null) 3459 { 3460 return; 3461 } 3462 3463 if(firstCompilation) 3464 { 3465 3472 addSPSParams(spsd, tc, wait); 3473 } 3474 else 3475 { 3476 Object [] parameterDefaults = spsd.getParameterDefaults(); 3477 3478 3485 int[] columnsToSet = new int[2]; 3486 columnsToSet[0] = SYSCOLUMNSRowFactory.SYSCOLUMNS_COLUMNDATATYPE; 3487 columnsToSet[1] = SYSCOLUMNSRowFactory.SYSCOLUMNS_COLUMNDEFAULT; 3488 3489 UUID uuid = spsd.getUUID(); 3490 3491 for (int index = 0; index < params.length; index++) 3492 { 3493 int parameterId = index + 1; 3494 3495 ColumnDescriptor cd = new ColumnDescriptor("PARAM" + parameterId, 3497 parameterId, params[index], 3499 ((parameterDefaults == null) || (index >= parameterDefaults.length)) ? 3501 (DataValueDescriptor)null : 3502 (DataValueDescriptor)parameterDefaults[index], 3503 (DefaultInfo) null, 3504 uuid, 3505 (UUID) null, 3506 0, 0); 3507 3508 updateColumnDescriptor(cd, 3509 cd.getReferencingUUID(), 3510 cd.getColumnName(), 3511 columnsToSet, 3512 tc, 3513 wait); 3514 } 3515 } 3516 } 3517 3518 3522 public void invalidateAllSPSPlans() throws StandardException 3523 { 3524 LanguageConnectionContext lcc = (LanguageConnectionContext) 3525 ContextService.getContext(LanguageConnectionContext.CONTEXT_ID); 3526 startWriting(lcc); 3527 3528 for (java.util.Iterator li = getAllSPSDescriptors().iterator(); li.hasNext(); ) 3529 { 3530 SPSDescriptor spsd = (SPSDescriptor) li.next(); 3531 spsd.makeInvalid(DependencyManager.USER_RECOMPILE_REQUEST, lcc); 3532 } 3533 } 3534 3535 3536 3542 void clearSPSPlans() throws StandardException 3543 { 3544 TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM); 3545 faultInTabInfo(ti); 3546 3547 TransactionController tc = getTransactionExecute(); 3548 3549 FormatableBitSet columnToReadSet = new FormatableBitSet(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_COLUMN_COUNT); 3550 FormatableBitSet columnToUpdateSet = new FormatableBitSet(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_COLUMN_COUNT); 3551 columnToUpdateSet.set(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID -1); 3552 columnToUpdateSet.set(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_CONSTANTSTATE -1); 3553 3554 DataValueDescriptor[] replaceRow = 3555 new DataValueDescriptor[SYSSTATEMENTSRowFactory.SYSSTATEMENTS_COLUMN_COUNT]; 3556 3557 3558 3559 replaceRow[SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID - 1] = 3560 dvf.getDataValue(false); 3561 replaceRow[SYSSTATEMENTSRowFactory.SYSSTATEMENTS_CONSTANTSTATE - 1] = 3562 dvf.getDataValue((Object ) null); 3563 3564 3565 ScanController sc = 3566 tc.openScan( 3567 ti.getHeapConglomerate(), 3568 false, 3569 TransactionController.OPENMODE_FORUPDATE, 3570 TransactionController.MODE_TABLE, 3571 TransactionController.ISOLATION_REPEATABLE_READ, 3572 columnToReadSet, 3573 (DataValueDescriptor[]) null, 3574 ScanController.NA, 3575 (Qualifier[][]) null, 3576 (DataValueDescriptor[]) null, 3577 ScanController.NA); 3578 3579 while (sc.fetchNext((DataValueDescriptor[]) null)) 3580 { 3581 3582 sc.replace(replaceRow, columnToUpdateSet); 3583 } 3584 3585 sc.close(); 3586 } 3587 3588 3596 public void dropSPSDescriptor(SPSDescriptor descriptor, 3597 TransactionController tc) 3598 throws StandardException 3599 { 3600 dropSPSDescriptor(descriptor.getUUID(), tc); 3601 } 3602 3603 3611 public void dropSPSDescriptor 3612 ( 3613 UUID uuid, 3614 TransactionController tc 3615 ) throws StandardException 3616 { 3617 DataValueDescriptor stmtIdOrderable; 3618 TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM); 3619 3620 stmtIdOrderable = getValueAsDVD(uuid); 3621 3622 3623 ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 3624 keyRow.setColumn(1, stmtIdOrderable); 3625 3626 ti.deleteRow( tc, keyRow, SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INDEX1_ID ); 3627 3628 3629 dropAllColumnDescriptors(uuid, tc); 3630 } 3631 3632 3640 public List getAllSPSDescriptors() 3641 throws StandardException 3642 { 3643 TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM); 3644 3645 List list = newSList(); 3646 3647 getDescriptorViaHeap( 3648 (ScanQualifier[][]) null, 3649 ti, 3650 (TupleDescriptor) null, 3651 list); 3652 3653 return list; 3654 3655 } 3656 3657 3668 private ConstraintDescriptorList getAllConstraintDescriptors() 3669 throws StandardException 3670 { 3671 TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM); 3672 3673 ConstraintDescriptorList list = new ConstraintDescriptorList(); 3674 3675 getConstraintDescriptorViaHeap( 3676 (ScanQualifier[][]) null, 3677 ti, 3678 (TupleDescriptor) null, 3679 list); 3680 return list; 3681 } 3682 3683 3694 private GenericDescriptorList getAllTriggerDescriptors() 3695 throws StandardException 3696 { 3697 TabInfoImpl ti = getNonCoreTI(SYSTRIGGERS_CATALOG_NUM); 3698 3699 GenericDescriptorList list = new GenericDescriptorList(); 3700 3701 getDescriptorViaHeap( 3702 (ScanQualifier[][]) null, 3703 ti, 3704 (TupleDescriptor) null, 3705 list); 3706 return list; 3707 } 3708 3709 3718 public TriggerDescriptor getTriggerDescriptor(UUID uuid) 3719 throws StandardException 3720 { 3721 TabInfoImpl ti = getNonCoreTI(SYSTRIGGERS_CATALOG_NUM); 3722 DataValueDescriptor triggerIdOrderable = dvf.getCharDataValue(uuid.toString()); 3723 3724 3725 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 3726 keyRow.setColumn(1, triggerIdOrderable); 3727 3728 return (TriggerDescriptor) 3729 getDescriptorViaIndex( 3730 SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX1_ID, 3731 keyRow, 3732 (ScanQualifier [][]) null, 3733 ti, 3734 (TupleDescriptor) null, 3735 (List) null, 3736 false); 3737 } 3738 3739 3750 public TriggerDescriptor getTriggerDescriptor(String name, SchemaDescriptor sd) 3751 throws StandardException 3752 { 3753 DataValueDescriptor schemaIDOrderable; 3754 DataValueDescriptor triggerNameOrderable; 3755 TabInfoImpl ti = getNonCoreTI(SYSTRIGGERS_CATALOG_NUM); 3756 3757 3760 triggerNameOrderable = dvf.getVarcharDataValue(name); 3761 schemaIDOrderable = dvf.getCharDataValue(sd.getUUID().toString()); 3762 3763 3764 ExecIndexRow keyRow = exFactory.getIndexableRow(2); 3765 keyRow.setColumn(1, triggerNameOrderable); 3766 keyRow.setColumn(2, schemaIDOrderable); 3767 3768 return (TriggerDescriptor) 3769 getDescriptorViaIndex( 3770 SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX2_ID, 3771 keyRow, 3772 (ScanQualifier [][]) null, 3773 ti, 3774 (TupleDescriptor) null, 3775 (List) null, 3776 false); 3777 } 3778 3779 3791 public GenericDescriptorList getTriggerDescriptors(TableDescriptor td) 3792 throws StandardException 3793 { 3794 GenericDescriptorList gdl; 3795 3796 if (td == null) 3797 { 3798 return getAllTriggerDescriptors(); 3799 } 3800 3801 3802 gdl = td.getTriggerDescriptorList(); 3803 3804 3809 synchronized(gdl) 3810 { 3811 if (!gdl.getScanned()) 3812 { 3813 getTriggerDescriptorsScan(td, false); 3814 } 3815 } 3816 3817 return gdl; 3818 } 3819 3820 3831 private void getTriggerDescriptorsScan(TableDescriptor td, boolean forUpdate) 3832 throws StandardException 3833 { 3834 GenericDescriptorList gdl = (td).getTriggerDescriptorList(); 3835 DataValueDescriptor tableIDOrderable = null; 3836 TabInfoImpl ti = getNonCoreTI(SYSTRIGGERS_CATALOG_NUM); 3837 3838 3839 tableIDOrderable = getValueAsDVD(td.getUUID()); 3840 3841 3842 ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 3843 3844 keyRow.setColumn(1, tableIDOrderable); 3845 3846 getDescriptorViaIndex( 3847 SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX3_ID, 3848 keyRow, 3849 (ScanQualifier [][]) null, 3850 ti, 3851 (TupleDescriptor) null, 3852 gdl, 3853 forUpdate); 3854 gdl.setScanned(true); 3855 } 3856 3857 3866 public void dropTriggerDescriptor 3867 ( 3868 TriggerDescriptor descriptor, 3869 TransactionController tc 3870 ) throws StandardException 3871 { 3872 DataValueDescriptor idOrderable; 3873 TabInfoImpl ti = getNonCoreTI(SYSTRIGGERS_CATALOG_NUM); 3874 3875 idOrderable = getValueAsDVD(descriptor.getUUID()); 3876 3877 3878 ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 3879 keyRow.setColumn(1, idOrderable); 3880 3881 ti.deleteRow(tc, keyRow, SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX1_ID); 3882 } 3883 3884 3898 public void updateTriggerDescriptor 3899 ( 3900 TriggerDescriptor triggerd, 3901 UUID formerUUID, 3902 int[] colsToSet, 3903 TransactionController tc 3904 ) throws StandardException 3905 { 3906 ExecIndexRow keyRow1 = null; 3907 ExecRow row; 3908 DataValueDescriptor IDOrderable; 3909 DataValueDescriptor columnNameOrderable; 3910 TabInfoImpl ti = getNonCoreTI(SYSTRIGGERS_CATALOG_NUM); 3911 SYSTRIGGERSRowFactory rf = (SYSTRIGGERSRowFactory) ti.getCatalogRowFactory(); 3912 3913 3916 IDOrderable = getValueAsDVD(formerUUID); 3917 3918 3919 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1); 3920 keyRow1.setColumn(1, IDOrderable); 3921 3922 row = rf.makeRow(triggerd, null); 3924 3925 3929 if (SanityManager.DEBUG) 3930 { 3931 SanityManager.ASSERT(rf.getNumIndexes() == 3, 3932 "There are more indexes on systriggers than expected, the code herein needs to change"); 3933 } 3934 3935 boolean[] bArray = new boolean[3]; 3936 3937 3940 if (colsToSet == null) 3941 { 3942 bArray[0] = true; 3943 bArray[1] = true; 3944 bArray[2] = true; 3945 } 3946 else 3947 { 3948 3952 for (int i = 0; i < colsToSet.length; i++) 3953 { 3954 switch (colsToSet[i]) 3955 { 3956 case SYSTRIGGERSRowFactory.SYSTRIGGERS_TRIGGERID: 3957 bArray[0] = true; 3958 break; 3959 3960 case SYSTRIGGERSRowFactory.SYSTRIGGERS_TRIGGERNAME: 3961 case SYSTRIGGERSRowFactory.SYSTRIGGERS_SCHEMAID: 3962 bArray[1] = true; 3963 break; 3964 3965 case SYSTRIGGERSRowFactory.SYSTRIGGERS_TABLEID: 3966 bArray[2] = true; 3967 break; 3968 } 3969 } 3970 } 3971 3972 ti.updateRow(keyRow1, row, 3973 SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX1_ID, 3974 bArray, 3975 colsToSet, 3976 tc); 3977 } 3978 3979 3980 3992 public ConstraintDescriptor getConstraintDescriptor(UUID uuid) 3993 throws StandardException 3994 { 3995 DataValueDescriptor UUIDStringOrderable; 3996 TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM); 3997 3998 3999 UUIDStringOrderable = dvf.getCharDataValue(uuid.toString()); 4000 4001 4002 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 4003 keyRow.setColumn(1, UUIDStringOrderable); 4004 4005 return getConstraintDescriptorViaIndex( 4006 SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX1_ID, 4007 keyRow, 4008 ti, 4009 (TableDescriptor) null, 4010 (ConstraintDescriptorList) null, 4011 false); 4012 } 4013 4014 4026 public ConstraintDescriptor getConstraintDescriptor 4027 ( 4028 String constraintName, 4029 UUID schemaID 4030 ) 4031 throws StandardException 4032 { 4033 DataValueDescriptor UUIDStringOrderable; 4034 DataValueDescriptor constraintNameOrderable; 4035 TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM); 4036 4037 4038 constraintNameOrderable = dvf.getVarcharDataValue(constraintName); 4039 UUIDStringOrderable = dvf.getCharDataValue(schemaID.toString()); 4040 4041 4042 ExecIndexRow keyRow = exFactory.getIndexableRow(2); 4043 keyRow.setColumn(1, constraintNameOrderable); 4044 keyRow.setColumn(2, UUIDStringOrderable); 4045 4046 return getConstraintDescriptorViaIndex( 4047 SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX2_ID, 4048 keyRow, 4049 ti, 4050 (TableDescriptor) null, 4051 (ConstraintDescriptorList) null, 4052 false); 4053 } 4054 4055 4058 public List getStatisticsDescriptors(TableDescriptor td) 4059 throws StandardException 4060 { 4061 TabInfoImpl ti = getNonCoreTI(SYSSTATISTICS_CATALOG_NUM); 4062 List statDescriptorList = newSList(); 4063 DataValueDescriptor UUIDStringOrderable; 4064 4065 4066 UUIDStringOrderable = dvf.getCharDataValue(td.getUUID().toString()); 4067 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 4068 keyRow.setColumn(1, UUIDStringOrderable); 4069 4070 getDescriptorViaIndex(SYSSTATISTICSRowFactory.SYSSTATISTICS_INDEX1_ID, 4071 keyRow, 4072 (ScanQualifier [][])null, 4073 ti, 4074 (TupleDescriptor)null, 4075 statDescriptorList, false); 4076 4077 return statDescriptorList; 4078 } 4079 4080 4098 public ConstraintDescriptorList getConstraintDescriptors(TableDescriptor td) 4099 throws StandardException 4100 { 4101 ConstraintDescriptorList cdl; 4102 4103 if (td == null) 4104 { 4105 return getAllConstraintDescriptors(); 4106 } 4107 4108 4111 4112 4113 cdl = td.getConstraintDescriptorList(); 4114 4115 4120 synchronized(cdl) 4121 { 4122 if (! cdl.getScanned()) 4123 { 4124 getConstraintDescriptorsScan(td, false); 4125 } 4126 } 4127 4128 return cdl; 4129 } 4130 4131 4148 public ConstraintDescriptorList getActiveConstraintDescriptors(ConstraintDescriptorList cdl) 4149 throws StandardException 4150 { return cdl; } 4151 4152 4168 public boolean activeConstraint( ConstraintDescriptor constraint ) 4169 throws StandardException 4170 { return true; } 4171 4172 4183 public ConstraintDescriptor getConstraintDescriptor(TableDescriptor td, 4184 UUID uuid) 4185 throws StandardException 4186 { 4187 return getConstraintDescriptors(td).getConstraintDescriptor(uuid); 4188 } 4189 4190 4191 4202 public ConstraintDescriptor getConstraintDescriptorById 4203 ( 4204 TableDescriptor td, 4205 UUID uuid 4206 ) 4207 throws StandardException 4208 { 4209 return getConstraintDescriptors(td).getConstraintDescriptorById(uuid); 4210 } 4211 4212 4224 public ConstraintDescriptor getConstraintDescriptorByName(TableDescriptor td, 4225 SchemaDescriptor sd, 4226 String constraintName, 4227 boolean forUpdate) 4228 throws StandardException 4229 { 4230 4231 if (forUpdate) 4232 { 4233 td.emptyConstraintDescriptorList(); 4234 getConstraintDescriptorsScan(td, true); 4235 } 4236 return getConstraintDescriptors(td).getConstraintDescriptorByName(sd, constraintName); 4237 } 4238 4239 4250 private void getConstraintDescriptorsScan(TableDescriptor td, boolean forUpdate) 4251 throws StandardException 4252 { 4253 ConstraintDescriptorList cdl = td.getConstraintDescriptorList(); 4254 DataValueDescriptor tableIDOrderable = null; 4255 TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM); 4256 4257 4258 tableIDOrderable = getValueAsDVD(td.getUUID()); 4259 4260 4261 ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 4262 4263 keyRow.setColumn(1, tableIDOrderable); 4264 4265 getConstraintDescriptorViaIndex( 4266 SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX3_ID, 4267 keyRow, 4268 ti, 4269 td, 4270 cdl, 4271 forUpdate); 4272 cdl.setScanned(true); 4273 } 4274 4275 4291 protected ConstraintDescriptor getConstraintDescriptorViaIndex( 4292 int indexId, 4293 ExecIndexRow keyRow, 4294 TabInfoImpl ti, 4295 TableDescriptor td, 4296 ConstraintDescriptorList dList, 4297 boolean forUpdate) 4298 throws StandardException 4299 { 4300 SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory(); 4301 ConglomerateController heapCC; 4302 ConstraintDescriptor cd = null; 4303 ExecIndexRow indexRow1; 4304 ExecIndexRow indexTemplateRow; 4305 ExecRow outRow; 4306 RowLocation baseRowLocation; 4307 ScanController scanController; 4308 TransactionController tc; 4309 4310 tc = getTransactionCompile(); 4312 4313 outRow = rf.makeEmptyRow(); 4314 4315 heapCC = 4316 tc.openConglomerate( 4317 ti.getHeapConglomerate(), false, 0, 4318 TransactionController.MODE_RECORD, 4319 TransactionController.ISOLATION_REPEATABLE_READ); 4320 4321 4322 4325 scanController = tc.openScan( 4326 ti.getIndexConglomerate(indexId), false, (forUpdate) ? TransactionController.OPENMODE_FORUPDATE : 0, 4329 TransactionController.MODE_RECORD, 4330 TransactionController.ISOLATION_REPEATABLE_READ, 4331 (FormatableBitSet) null, keyRow.getRowArray(), ScanController.GE, null, keyRow.getRowArray(), ScanController.GT); 4338 while (scanController.next()) 4339 { 4340 SubConstraintDescriptor subCD = null; 4341 4342 indexRow1 = getIndexRowFromHeapRow( 4344 ti.getIndexRowGenerator(indexId), 4345 heapCC.newRowLocationTemplate(), 4346 outRow); 4347 4348 scanController.fetch(indexRow1.getRowArray()); 4349 4350 baseRowLocation = (RowLocation) indexRow1.getColumn( 4351 indexRow1.nColumns()); 4352 4353 boolean base_row_exists = 4354 heapCC.fetch( 4355 baseRowLocation, outRow.getRowArray(), (FormatableBitSet) null); 4356 4357 if (SanityManager.DEBUG) 4358 { 4359 SanityManager.ASSERT(base_row_exists, "base row doesn't exist"); 4362 } 4363 4364 switch (rf.getConstraintType(outRow)) 4365 { 4366 case DataDictionary.PRIMARYKEY_CONSTRAINT: 4367 case DataDictionary.FOREIGNKEY_CONSTRAINT: 4368 case DataDictionary.UNIQUE_CONSTRAINT: 4369 subCD = getSubKeyConstraint( 4370 rf.getConstraintId(outRow), rf.getConstraintType(outRow)); 4371 break; 4372 4373 case DataDictionary.CHECK_CONSTRAINT: 4374 subCD = getSubCheckConstraint( 4375 rf.getConstraintId(outRow)); 4376 break; 4377 4378 default: 4379 if (SanityManager.DEBUG) 4380 { 4381 SanityManager.THROWASSERT("unexpected value "+ 4382 "from rf.getConstraintType(outRow)" + 4383 rf.getConstraintType(outRow)); 4384 } 4385 } 4386 4387 if (SanityManager.DEBUG) 4388 { 4389 SanityManager.ASSERT(subCD != null, 4390 "subCD is expected to be non-null"); 4391 } 4392 4393 4397 subCD.setTableDescriptor(td); 4398 4399 cd = (ConstraintDescriptor) rf.buildDescriptor( 4400 outRow, 4401 subCD, 4402 this); 4403 4404 4407 if (dList == null) 4408 { 4409 break; 4410 } 4411 else 4412 { 4413 dList.add(cd); 4414 } 4415 } 4416 scanController.close(); 4417 heapCC.close(); 4418 return cd; 4419 } 4420 4421 4435 protected TupleDescriptor getConstraintDescriptorViaHeap( 4436 ScanQualifier [][] scanQualifiers, 4437 TabInfoImpl ti, 4438 TupleDescriptor parentTupleDescriptor, 4439 List list) 4440 throws StandardException 4441 { 4442 SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory(); 4443 ConglomerateController heapCC; 4444 ExecRow outRow; 4445 ExecRow templateRow; 4446 ScanController scanController; 4447 TransactionController tc; 4448 ConstraintDescriptor cd = null; 4449 4450 tc = getTransactionCompile(); 4452 4453 outRow = rf.makeEmptyRow(); 4454 4455 4458 scanController = tc.openScan( 4459 ti.getHeapConglomerate(), false, 0, TransactionController.MODE_TABLE, 4463 TransactionController.ISOLATION_REPEATABLE_READ, 4464 (FormatableBitSet) null, (DataValueDescriptor[]) null, 0, scanQualifiers, (DataValueDescriptor[]) null, 0); 4471 try 4472 { 4473 while (scanController.fetchNext(outRow.getRowArray())) 4474 { 4475 SubConstraintDescriptor subCD = null; 4476 4477 switch (rf.getConstraintType(outRow)) 4478 { 4479 case DataDictionary.PRIMARYKEY_CONSTRAINT: 4480 case DataDictionary.FOREIGNKEY_CONSTRAINT: 4481 case DataDictionary.UNIQUE_CONSTRAINT: 4482 subCD = getSubKeyConstraint( 4483 rf.getConstraintId(outRow), rf.getConstraintType(outRow)); 4484 break; 4485 4486 case DataDictionary.CHECK_CONSTRAINT: 4487 subCD = getSubCheckConstraint( 4488 rf.getConstraintId(outRow)); 4489 break; 4490 4491 default: 4492 if (SanityManager.DEBUG) 4493 { 4494 SanityManager.THROWASSERT("unexpected value from "+ 4495 " rf.getConstraintType(outRow) " 4496 + rf.getConstraintType(outRow)); 4497 } 4498 } 4499 4500 if (SanityManager.DEBUG) 4501 { 4502 SanityManager.ASSERT(subCD != null, 4503 "subCD is expected to be non-null"); 4504 } 4505 cd = (ConstraintDescriptor) rf.buildDescriptor( 4506 outRow, 4507 subCD, 4508 this); 4509 4510 4513 if (list == null) 4514 { 4515 break; 4516 } 4517 else 4518 { 4519 list.add(cd); 4520 } 4521 } 4522 } 4523 finally 4524 { 4525 scanController.close(); 4526 } 4527 return cd; 4528 } 4529 4530 4541 public TableDescriptor getConstraintTableDescriptor(UUID constraintId) 4542 throws StandardException 4543 { 4544 List slist = getConstraints(constraintId, 4545 SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX1_ID, 4546 SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_TABLEID); 4547 4548 if (slist.size() == 0) 4549 { 4550 return null; 4551 } 4552 4553 return getTableDescriptor((UUID)slist.get(0)); 4555 } 4556 4557 4568 public ConstraintDescriptorList getForeignKeys(UUID constraintId) 4569 throws StandardException 4570 { 4571 TabInfoImpl ti = getNonCoreTI(SYSFOREIGNKEYS_CATALOG_NUM); 4572 List fkList = newSList(); 4573 4574 DataValueDescriptor constraintIDOrderable = getValueAsDVD(constraintId); 4576 4577 4578 ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 4579 keyRow.setColumn(1, constraintIDOrderable); 4580 4581 getDescriptorViaIndex( 4582 SYSFOREIGNKEYSRowFactory.SYSFOREIGNKEYS_INDEX2_ID, 4583 keyRow, 4584 (ScanQualifier [][]) null, 4585 ti, 4586 (TupleDescriptor) null, 4587 fkList, 4588 false); 4589 4590 SubKeyConstraintDescriptor cd; 4591 TableDescriptor td; 4592 ConstraintDescriptorList cdl = new ConstraintDescriptorList(); 4593 ConstraintDescriptorList tmpCdl; 4594 4595 for (Iterator iterator = fkList.iterator(); iterator.hasNext(); ) 4596 { 4597 cd = (SubKeyConstraintDescriptor) iterator.next(); 4598 td = getConstraintTableDescriptor(cd.getUUID()); 4599 cdl.add(getConstraintDescriptors(td).getConstraintDescriptorById(cd.getUUID())); 4600 } 4601 4602 return cdl; 4603 } 4604 4605 4618 public List getConstraints(UUID uuid, int indexId, int columnNum) 4619 throws StandardException 4620 { 4621 ExecIndexRow indexRow1; 4622 ExecIndexRow indexTemplateRow; 4623 ExecRow outRow; 4624 RowLocation baseRowLocation; 4625 ConglomerateController heapCC = null; 4626 ScanController scanController = null; 4627 TransactionController tc; 4628 TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM); 4629 SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory(); 4630 TableDescriptor td = null; 4631 List slist = newSList(); 4632 4633 if (SanityManager.DEBUG) 4634 { 4635 SanityManager.ASSERT(indexId == SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX1_ID || 4636 indexId == SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX3_ID, 4637 "bad index id, must be one of the indexes on a uuid"); 4638 SanityManager.ASSERT(columnNum > 0 && 4639 columnNum <= SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT, 4640 "invalid column number for column to be retrieved"); 4641 } 4642 4643 try 4644 { 4645 4646 DataValueDescriptor orderable = getValueAsDVD(uuid); 4647 4648 4649 ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 4650 keyRow.setColumn(1, orderable); 4651 4652 tc = getTransactionCompile(); 4654 4655 outRow = rf.makeEmptyRow(); 4656 4657 heapCC = 4658 tc.openConglomerate( 4659 ti.getHeapConglomerate(), false, 0, 4660 TransactionController.MODE_RECORD, 4661 TransactionController.ISOLATION_REPEATABLE_READ); 4662 4663 indexRow1 = getIndexRowFromHeapRow( 4665 ti.getIndexRowGenerator(indexId), 4666 heapCC.newRowLocationTemplate(), 4667 outRow); 4668 4669 DataValueDescriptor[] rowTemplate = 4671 new DataValueDescriptor[SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT]; 4672 FormatableBitSet columnToGetSet = 4673 new FormatableBitSet(SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT); 4674 columnToGetSet.set(columnNum - 1); 4675 4676 rowTemplate[columnNum - 1] = 4677 dvf.getNullChar((StringDataValue) null); 4678 4679 scanController = tc.openScan( 4681 ti.getIndexConglomerate(indexId), false, 0, TransactionController.MODE_RECORD, 4685 TransactionController.ISOLATION_REPEATABLE_READ, (FormatableBitSet) null, keyRow.getRowArray(), ScanController.GE, null, keyRow.getRowArray(), ScanController.GT); 4693 while (scanController.fetchNext(indexRow1.getRowArray())) 4694 { 4695 baseRowLocation = (RowLocation) 4696 indexRow1.getColumn(indexRow1.nColumns()); 4697 4698 boolean base_row_exists = 4700 heapCC.fetch( 4701 baseRowLocation, rowTemplate, columnToGetSet); 4702 4703 if (SanityManager.DEBUG) 4704 { 4705 SanityManager.ASSERT(base_row_exists, "base row not found"); 4708 } 4709 4710 slist.add(uuidFactory.recreateUUID( 4711 (String )((DataValueDescriptor)rowTemplate[columnNum - 1]).getObject())); 4712 } 4713 } 4714 finally 4715 { 4716 if (heapCC != null) 4717 { 4718 heapCC.close(); 4719 } 4720 if (scanController != null) 4721 { 4722 scanController.close(); 4723 } 4724 } 4725 return slist; 4726 } 4727 4728 4737 public void addConstraintDescriptor( 4738 ConstraintDescriptor descriptor, 4739 TransactionController tc) 4740 throws StandardException 4741 { 4742 ExecRow row = null; 4743 int type = descriptor.getConstraintType(); 4744 TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM); 4745 SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory(); 4746 int insertRetCode; 4747 4748 if (SanityManager.DEBUG) 4749 { 4750 if (!(type == DataDictionary.PRIMARYKEY_CONSTRAINT || 4751 type == DataDictionary.FOREIGNKEY_CONSTRAINT || 4752 type == DataDictionary.UNIQUE_CONSTRAINT || 4753 type == DataDictionary.CHECK_CONSTRAINT)) 4754 { 4755 SanityManager.THROWASSERT("constraint type (" + type + 4756 ") is unexpected value"); 4757 } 4758 } 4759 4760 addDescriptor(descriptor, descriptor.getSchemaDescriptor(), 4761 SYSCONSTRAINTS_CATALOG_NUM, false, 4762 tc); 4763 4764 switch (type) 4765 { 4766 case DataDictionary.PRIMARYKEY_CONSTRAINT: 4767 case DataDictionary.FOREIGNKEY_CONSTRAINT: 4768 case DataDictionary.UNIQUE_CONSTRAINT: 4769 if (SanityManager.DEBUG) 4770 { 4771 if (!(descriptor instanceof KeyConstraintDescriptor)) 4772 { 4773 SanityManager.THROWASSERT( 4774 "descriptor expected to be instanceof KeyConstraintDescriptor, " + 4775 "not, " + descriptor.getClass().getName()); 4776 } 4777 } 4778 4779 addSubKeyConstraint((KeyConstraintDescriptor) descriptor, tc); 4780 break; 4781 4782 case DataDictionary.CHECK_CONSTRAINT: 4783 if (SanityManager.DEBUG) 4784 { 4785 if (!(descriptor instanceof CheckConstraintDescriptor)) 4786 { 4787 SanityManager.THROWASSERT("descriptor expected "+ 4788 "to be instanceof CheckConstraintDescriptorImpl, " + 4789 "not, " + descriptor.getClass().getName()); 4790 } 4791 } 4792 4793 addDescriptor(descriptor, null, SYSCHECKS_CATALOG_NUM, true, tc); 4794 break; 4795 } 4796 } 4797 4798 4812 public void updateConstraintDescriptor(ConstraintDescriptor cd, 4813 UUID formerUUID, 4814 int[] colsToSet, 4815 TransactionController tc) 4816 throws StandardException 4817 { 4818 ExecIndexRow keyRow1 = null; 4819 ExecRow row; 4820 DataValueDescriptor IDOrderable; 4821 DataValueDescriptor columnNameOrderable; 4822 TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM); 4823 SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory(); 4824 4825 4828 IDOrderable = getValueAsDVD(formerUUID); 4829 4830 4831 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1); 4832 keyRow1.setColumn(1, IDOrderable); 4833 4834 row = rf.makeRow(cd, null); 4836 4837 4841 if (SanityManager.DEBUG) 4842 { 4843 SanityManager.ASSERT(rf.getNumIndexes() == 3, 4844 "There are more indexes on sysconstraints than expected, the code herein needs to change"); 4845 } 4846 4847 boolean[] bArray = new boolean[3]; 4848 4849 4852 if (colsToSet == null) 4853 { 4854 bArray[0] = true; 4855 bArray[1] = true; 4856 bArray[2] = true; 4857 } 4858 else 4859 { 4860 4864 for (int i = 0; i < colsToSet.length; i++) 4865 { 4866 switch (colsToSet[i]) 4867 { 4868 case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_CONSTRAINTID: 4869 bArray[0] = true; 4870 break; 4871 4872 case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_CONSTRAINTNAME: 4873 case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_SCHEMAID: 4874 bArray[1] = true; 4875 break; 4876 4877 case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_TABLEID: 4878 bArray[2] = true; 4879 break; 4880 } 4881 } 4882 } 4883 4884 ti.updateRow(keyRow1, row, 4885 SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX1_ID, 4886 bArray, 4887 colsToSet, 4888 tc); 4889 } 4890 4891 4902 public void dropConstraintDescriptor(TableDescriptor table, 4903 ConstraintDescriptor descriptor, 4904 TransactionController tc) 4905 throws StandardException 4906 { 4907 ExecIndexRow keyRow = null; 4908 DataValueDescriptor schemaIDOrderable; 4909 DataValueDescriptor constraintNameOrderable; 4910 TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM); 4911 4912 switch (descriptor.getConstraintType()) 4913 { 4914 case DataDictionary.PRIMARYKEY_CONSTRAINT: 4915 case DataDictionary.FOREIGNKEY_CONSTRAINT: 4916 case DataDictionary.UNIQUE_CONSTRAINT: 4917 dropSubKeyConstraint( 4918 descriptor, 4919 tc); 4920 break; 4921 4922 case DataDictionary.CHECK_CONSTRAINT: 4923 dropSubCheckConstraint( 4924 descriptor.getUUID(), 4925 tc); 4926 break; 4927 } 4928 4929 4932 constraintNameOrderable = dvf.getVarcharDataValue(descriptor.getConstraintName()); 4933 schemaIDOrderable = getValueAsDVD(descriptor.getSchemaDescriptor().getUUID()); 4934 4935 4936 keyRow = (ExecIndexRow) exFactory.getIndexableRow(2); 4937 keyRow.setColumn(1, constraintNameOrderable); 4938 keyRow.setColumn(2, schemaIDOrderable); 4939 4940 ti.deleteRow( tc, keyRow, SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX2_ID ); 4941 } 4942 4943 4953 public void dropAllConstraintDescriptors(TableDescriptor table, 4954 TransactionController tc) 4955 throws StandardException 4956 { 4957 ConstraintDescriptorList cdl = getConstraintDescriptors(table); 4958 4959 for (Iterator iterator = cdl.iterator(); iterator.hasNext(); ) 4961 { 4962 ConstraintDescriptor cd = (ConstraintDescriptor) iterator.next(); 4963 dropConstraintDescriptor(table, cd, tc); 4964 } 4965 4966 4972 table.setConstraintDescriptorList(null); 4973 } 4974 4975 4988 public SubKeyConstraintDescriptor getSubKeyConstraint(UUID constraintId, int type) 4989 throws StandardException 4990 { 4991 DataValueDescriptor constraintIDOrderable = null; 4992 TabInfoImpl ti; 4993 int indexNum; 4994 int baseNum; 4995 4996 if (type == DataDictionary.FOREIGNKEY_CONSTRAINT) 4997 { 4998 baseNum = SYSFOREIGNKEYS_CATALOG_NUM; 4999 indexNum = SYSFOREIGNKEYSRowFactory.SYSFOREIGNKEYS_INDEX1_ID; 5000 } 5001 else 5002 { 5003 baseNum = SYSKEYS_CATALOG_NUM; 5004 indexNum = SYSKEYSRowFactory.SYSKEYS_INDEX1_ID; 5005 } 5006 ti = getNonCoreTI(baseNum); 5007 5008 5009 constraintIDOrderable = getValueAsDVD(constraintId); 5010 5011 5012 ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 5013 keyRow.setColumn(1, constraintIDOrderable); 5014 5015 return (SubKeyConstraintDescriptor) 5016 getDescriptorViaIndex( 5017 indexNum, 5018 keyRow, 5019 (ScanQualifier [][]) null, 5020 ti, 5021 (TupleDescriptor) null, 5022 (List) null, 5023 false); 5024 } 5025 5026 5034 private void addSubKeyConstraint(KeyConstraintDescriptor descriptor, 5035 TransactionController tc) 5036 throws StandardException 5037 { 5038 ExecRow row; 5039 TabInfoImpl ti; 5040 5041 5045 if (descriptor.getConstraintType() 5046 == DataDictionary.FOREIGNKEY_CONSTRAINT) 5047 { 5048 ForeignKeyConstraintDescriptor fkDescriptor = 5049 (ForeignKeyConstraintDescriptor)descriptor; 5050 5051 if (SanityManager.DEBUG) 5052 { 5053 if (!(descriptor instanceof ForeignKeyConstraintDescriptor)) 5054 { 5055 SanityManager.THROWASSERT("descriptor not an fk descriptor, is "+ 5056 descriptor.getClass().getName()); 5057 } 5058 } 5059 5060 ti = getNonCoreTI(SYSFOREIGNKEYS_CATALOG_NUM); 5061 SYSFOREIGNKEYSRowFactory fkkeysRF = (SYSFOREIGNKEYSRowFactory)ti.getCatalogRowFactory(); 5062 5063 row = fkkeysRF.makeRow(fkDescriptor, null); 5064 5065 5069 ReferencedKeyConstraintDescriptor refDescriptor = 5070 fkDescriptor.getReferencedConstraint(); 5071 5072 refDescriptor.incrementReferenceCount(); 5073 5074 int[] colsToSet = new int[1]; 5075 colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_REFERENCECOUNT; 5076 5077 updateConstraintDescriptor(refDescriptor, 5078 refDescriptor.getUUID(), 5079 colsToSet, 5080 tc); 5081 } 5082 else 5083 { 5084 ti = getNonCoreTI(SYSKEYS_CATALOG_NUM); 5085 SYSKEYSRowFactory keysRF = (SYSKEYSRowFactory) ti.getCatalogRowFactory(); 5086 5087 row = keysRF.makeRow(descriptor, null); 5089 } 5090 5091 ti.insertRow(row, tc, true); 5093 } 5094 5095 5104 private void dropSubKeyConstraint(ConstraintDescriptor constraint, TransactionController tc) 5105 throws StandardException 5106 { 5107 ExecIndexRow keyRow1 = null; 5108 DataValueDescriptor constraintIdOrderable; 5109 TabInfoImpl ti; 5110 int baseNum; 5111 int indexNum; 5112 5113 if (constraint.getConstraintType() 5114 == DataDictionary.FOREIGNKEY_CONSTRAINT) 5115 { 5116 baseNum = SYSFOREIGNKEYS_CATALOG_NUM; 5117 indexNum = SYSFOREIGNKEYSRowFactory.SYSFOREIGNKEYS_INDEX1_ID; 5118 5119 5125 if (constraint.getConstraintType() 5126 == DataDictionary.FOREIGNKEY_CONSTRAINT) 5127 { 5128 ReferencedKeyConstraintDescriptor refDescriptor = 5129 (ReferencedKeyConstraintDescriptor) 5130 getConstraintDescriptor( 5131 ((ForeignKeyConstraintDescriptor)constraint). 5132 getReferencedConstraintId()); 5133 5134 if (refDescriptor != null) 5135 { 5136 refDescriptor.decrementReferenceCount(); 5137 5138 int[] colsToSet = new int[1]; 5139 colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_REFERENCECOUNT; 5140 5141 updateConstraintDescriptor(refDescriptor, 5142 refDescriptor.getUUID(), 5143 colsToSet, 5144 tc); 5145 } 5146 } 5147 } 5148 else 5149 { 5150 baseNum = SYSKEYS_CATALOG_NUM; 5151 indexNum = SYSKEYSRowFactory.SYSKEYS_INDEX1_ID; 5152 } 5153 5154 ti = getNonCoreTI(baseNum); 5155 5156 5159 constraintIdOrderable = getValueAsDVD(constraint.getUUID()); 5160 5161 5162 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1); 5163 keyRow1.setColumn(1, constraintIdOrderable); 5164 5165 ti.deleteRow( tc, keyRow1, indexNum); 5166 } 5167 5168 5178 private SubCheckConstraintDescriptor getSubCheckConstraint(UUID constraintId) 5179 throws StandardException 5180 { 5181 DataValueDescriptor constraintIDOrderable = null; 5182 TabInfoImpl ti = getNonCoreTI(SYSCHECKS_CATALOG_NUM); 5183 SYSCHECKSRowFactory rf = (SYSCHECKSRowFactory) ti.getCatalogRowFactory(); 5184 5185 5186 constraintIDOrderable = getValueAsDVD(constraintId); 5187 5188 5189 ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 5190 keyRow.setColumn(1, constraintIDOrderable); 5191 5192 return (SubCheckConstraintDescriptor) 5193 getDescriptorViaIndex( 5194 SYSCHECKSRowFactory.SYSCHECKS_INDEX1_ID, 5195 keyRow, 5196 (ScanQualifier [][]) null, 5197 ti, 5198 (TupleDescriptor) null, 5199 (List) null, 5200 false); 5201 } 5202 5203 5211 private void dropSubCheckConstraint(UUID constraintId, TransactionController tc) 5212 throws StandardException 5213 { 5214 ExecIndexRow checkRow1 = null; 5215 DataValueDescriptor constraintIdOrderable; 5216 TabInfoImpl ti = getNonCoreTI(SYSCHECKS_CATALOG_NUM); 5217 5218 5221 constraintIdOrderable = getValueAsDVD(constraintId); 5222 5223 5224 checkRow1 = (ExecIndexRow) exFactory.getIndexableRow(1); 5225 checkRow1.setColumn(1, constraintIdOrderable); 5226 5227 ti.deleteRow( tc, checkRow1, SYSCHECKSRowFactory.SYSCHECKS_INDEX1_ID ); 5228 } 5229 5230 5243 public Hashtable hashAllConglomerateDescriptorsByNumber(TransactionController tc) 5244 throws StandardException 5245 { 5246 Hashtable ht = new Hashtable (); 5247 ConglomerateDescriptor cd = null; 5248 ScanController scanController; 5249 ExecRow outRow; 5250 TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM]; 5252 SYSCONGLOMERATESRowFactory rf = (SYSCONGLOMERATESRowFactory) ti.getCatalogRowFactory(); 5253 5254 outRow = rf.makeEmptyRow(); 5255 scanController = tc.openScan( 5256 ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED, 5261 (FormatableBitSet) null, (DataValueDescriptor[]) null, ScanController.GE, (ScanQualifier [][]) null, 5265 (DataValueDescriptor[]) null, ScanController.GT); 5268 while (scanController.fetchNext(outRow.getRowArray())) 5273 { 5274 cd = (ConglomerateDescriptor) rf.buildDescriptor( 5275 outRow, 5276 (TupleDescriptor) null, 5277 this ); 5278 Long hashKey = new Long (cd.getConglomerateNumber()); 5279 ht.put(hashKey, cd); 5280 } 5281 5282 scanController.close(); 5283 5284 return ht; 5285 } 5286 5287 5300 public Hashtable hashAllTableDescriptorsByTableId(TransactionController tc) 5301 throws StandardException 5302 { 5303 Hashtable ht = new Hashtable (); 5304 ScanController scanController; 5305 ExecRow outRow; 5306 TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM]; 5307 SYSTABLESRowFactory 5308 rf = (SYSTABLESRowFactory) ti.getCatalogRowFactory(); 5309 5310 outRow = rf.makeEmptyRow(); 5311 5312 scanController = tc.openScan( 5313 ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED, 5318 (FormatableBitSet) null, (DataValueDescriptor[])null, ScanController.GE, (ScanQualifier[][])null, (DataValueDescriptor[])null, ScanController.GT); 5325 while(scanController.fetchNext(outRow.getRowArray())) 5330 { 5331 TableDescriptor td = (TableDescriptor) 5332 rf.buildDescriptor(outRow, (TupleDescriptor)null, 5333 this); 5334 ht.put(td.getUUID(), td); 5335 } 5336 scanController.close(); 5337 return ht; 5338 } 5339 5340 5352 public ConglomerateDescriptor getConglomerateDescriptor(UUID uuid) 5353 throws StandardException 5354 { 5355 ConglomerateDescriptor[] cds = getConglomerateDescriptors(uuid); 5356 if (cds.length == 0) 5357 return null; 5358 return cds[0]; 5359 } 5360 5361 5374 public ConglomerateDescriptor[] getConglomerateDescriptors(UUID uuid) 5375 throws StandardException 5376 { 5377 DataValueDescriptor UUIDStringOrderable; 5378 SYSCONGLOMERATESRowFactory rf; 5379 TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM]; 5380 5381 5382 UUIDStringOrderable = dvf.getCharDataValue(uuid.toString()); 5383 5384 5385 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 5386 keyRow.setColumn(1, UUIDStringOrderable); 5387 5388 List cdl = newSList(); 5389 5390 getDescriptorViaIndex( 5391 SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX1_ID, 5392 keyRow, 5393 (ScanQualifier [][]) null, 5394 ti, 5395 (TupleDescriptor) null, 5396 cdl, 5397 false); 5398 5399 ConglomerateDescriptor[] cda = new ConglomerateDescriptor[cdl.size()]; 5400 cdl.toArray(cda); 5401 return cda; 5402 5403 } 5404 5405 5418 public ConglomerateDescriptor getConglomerateDescriptor( 5419 long conglomerateNumber) 5420 throws StandardException 5421 { 5422 ConglomerateDescriptor[] cds = getConglomerateDescriptors(conglomerateNumber); 5423 if (cds.length == 0) 5424 return null; 5425 return cds[0]; 5426 } 5427 5428 5441 public ConglomerateDescriptor[] getConglomerateDescriptors( 5442 long conglomerateNumber) 5443 throws StandardException 5444 { 5445 ScanController scanController; 5446 TransactionController tc; 5447 ExecRow outRow; 5448 DataValueDescriptor conglomNumberOrderable = null; 5449 TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM]; 5450 SYSCONGLOMERATESRowFactory rf = (SYSCONGLOMERATESRowFactory) ti.getCatalogRowFactory(); 5451 5452 conglomNumberOrderable = 5453 dvf.getDataValue(conglomerateNumber); 5454 5455 ScanQualifier[][] scanQualifier = exFactory.getScanQualifier(1); 5456 scanQualifier[0][0].setQualifier( 5457 rf.SYSCONGLOMERATES_CONGLOMERATENUMBER - 1, 5458 conglomNumberOrderable, 5459 Orderable.ORDER_OP_EQUALS, 5460 false, 5461 false, 5462 false); 5463 5464 ConglomerateDescriptorList cdl = new ConglomerateDescriptorList(); 5465 getDescriptorViaHeap(scanQualifier, 5466 ti, 5467 null, 5468 cdl); 5469 5470 int size = cdl.size(); 5471 ConglomerateDescriptor[] cda = new ConglomerateDescriptor[size]; 5472 for (int index = 0; index < size; index++) 5473 cda[index] = (ConglomerateDescriptor) cdl.get(index); 5474 5475 return cda; 5476 } 5477 5478 5479 5490 private void getConglomerateDescriptorsScan(TableDescriptor td) 5491 throws StandardException 5492 { 5493 ConglomerateDescriptorList cdl = td.getConglomerateDescriptorList(); 5494 5495 ExecIndexRow keyRow3 = null; 5496 DataValueDescriptor tableIDOrderable; 5497 TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM]; 5498 5499 5500 tableIDOrderable = getValueAsDVD(td.getUUID()); 5501 5502 5503 keyRow3 = (ExecIndexRow) exFactory.getIndexableRow(1); 5504 keyRow3.setColumn(1, tableIDOrderable); 5505 5506 getDescriptorViaIndex( 5507 SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX3_ID, 5508 keyRow3, 5509 (ScanQualifier [][]) null, 5510 ti, 5511 (TupleDescriptor) null, 5512 cdl, 5513 false); 5514 } 5515 5516 5531 public ConglomerateDescriptor getConglomerateDescriptor( 5532 String indexName, 5533 SchemaDescriptor sd, 5534 boolean forUpdate) 5535 throws StandardException 5536 { 5537 ExecIndexRow keyRow2 = null; 5538 DataValueDescriptor nameOrderable; 5539 DataValueDescriptor schemaIDOrderable = null; 5540 TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM]; 5541 5542 nameOrderable = dvf.getVarcharDataValue(indexName); 5543 schemaIDOrderable = getValueAsDVD(sd.getUUID()); 5544 5545 5546 keyRow2 = exFactory.getIndexableRow(2); 5547 keyRow2.setColumn(1, nameOrderable); 5548 keyRow2.setColumn(2, schemaIDOrderable); 5549 5550 return (ConglomerateDescriptor) 5551 getDescriptorViaIndex( 5552 SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX2_ID, 5553 keyRow2, 5554 (ScanQualifier [][]) null, 5555 ti, 5556 (TupleDescriptor) null, 5557 (List) null, 5558 forUpdate); 5559 } 5560 5561 5569 public void dropConglomerateDescriptor( 5570 ConglomerateDescriptor conglomerate, 5571 TransactionController tc) 5572 throws StandardException 5573 { 5574 ExecIndexRow keyRow2 = null; 5575 DataValueDescriptor nameOrderable; 5576 DataValueDescriptor schemaIDOrderable = null; 5577 TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM]; 5578 5579 nameOrderable = dvf.getVarcharDataValue(conglomerate.getConglomerateName()); 5580 schemaIDOrderable = getValueAsDVD(conglomerate.getSchemaID()); 5581 5582 5583 keyRow2 = (ExecIndexRow) exFactory.getIndexableRow(2); 5584 keyRow2.setColumn(1, nameOrderable); 5585 keyRow2.setColumn(2, schemaIDOrderable); 5586 5587 ti.deleteRow( tc, keyRow2, SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX2_ID ); 5588 5589 } 5590 5591 5599 5600 public void dropAllConglomerateDescriptors( 5601 TableDescriptor td, 5602 TransactionController tc) 5603 throws StandardException 5604 { 5605 ExecIndexRow keyRow3 = null; 5606 DataValueDescriptor tableIDOrderable; 5607 TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM]; 5608 5609 5612 tableIDOrderable = getValueAsDVD(td.getUUID()); 5613 5614 5615 keyRow3 = (ExecIndexRow) exFactory.getIndexableRow(1); 5616 keyRow3.setColumn(1, tableIDOrderable); 5617 5618 5619 ti.deleteRow( tc, keyRow3, SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX3_ID ); 5620 } 5621 5622 5634 public void updateConglomerateDescriptor(ConglomerateDescriptor cd, 5635 long conglomerateNumber, 5636 TransactionController tc) 5637 throws StandardException 5638 { 5639 ConglomerateDescriptor[] cds = new ConglomerateDescriptor[1]; 5640 cds[0] = cd; 5641 updateConglomerateDescriptor(cds, conglomerateNumber, tc); 5642 } 5643 5644 5654 public void updateSystemSchemaAuthorization(String aid, 5655 TransactionController tc) 5656 throws StandardException 5657 { 5658 updateSchemaAuth(SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME, aid, tc); 5659 updateSchemaAuth(SchemaDescriptor.IBM_SYSTEM_SCHEMA_NAME, aid, tc); 5660 5661 updateSchemaAuth(SchemaDescriptor.IBM_SYSTEM_CAT_SCHEMA_NAME, aid, tc); 5662 updateSchemaAuth(SchemaDescriptor.IBM_SYSTEM_FUN_SCHEMA_NAME, aid, tc); 5663 updateSchemaAuth(SchemaDescriptor.IBM_SYSTEM_PROC_SCHEMA_NAME, aid, tc); 5664 updateSchemaAuth(SchemaDescriptor.IBM_SYSTEM_STAT_SCHEMA_NAME, aid, tc); 5665 updateSchemaAuth(SchemaDescriptor.IBM_SYSTEM_NULLID_SCHEMA_NAME, aid, tc); 5666 5667 updateSchemaAuth(SchemaDescriptor.STD_SQLJ_SCHEMA_NAME, aid, tc); 5668 updateSchemaAuth(SchemaDescriptor.STD_SYSTEM_DIAG_SCHEMA_NAME, aid, tc); 5669 updateSchemaAuth(SchemaDescriptor.STD_SYSTEM_UTIL_SCHEMA_NAME, aid, tc); 5670 } 5671 5672 5681 public void updateSchemaAuth(String schemaName, 5682 String authorizationId, 5683 TransactionController tc) 5684 throws StandardException 5685 { 5686 ExecIndexRow keyRow; 5687 DataValueDescriptor schemaNameOrderable; 5688 TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM]; 5689 5690 5693 schemaNameOrderable = dvf.getVarcharDataValue(schemaName); 5694 5695 5696 keyRow = (ExecIndexRow) exFactory.getIndexableRow(1); 5697 keyRow.setColumn(1, schemaNameOrderable); 5698 5699 SYSSCHEMASRowFactory rf = (SYSSCHEMASRowFactory) ti.getCatalogRowFactory(); 5700 ExecRow row = rf.makeEmptyRow(); 5701 5702 row.setColumn(SYSSCHEMASRowFactory.SYSSCHEMAS_SCHEMAAID, 5703 dvf.getVarcharDataValue(authorizationId)); 5704 5705 boolean[] bArray = {false, false}; 5706 5707 int[] colsToUpdate = {SYSSCHEMASRowFactory.SYSSCHEMAS_SCHEMAAID}; 5708 5709 ti.updateRow(keyRow, row, 5710 SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID, 5711 bArray, 5712 colsToUpdate, 5713 tc); 5714 } 5715 5716 5733 public void updateConglomerateDescriptor(ConglomerateDescriptor[] cds, 5734 long conglomerateNumber, 5735 TransactionController tc) 5736 throws StandardException 5737 { 5738 ExecIndexRow keyRow1 = null; 5739 ExecRow row; 5740 DataValueDescriptor conglomIDOrderable; 5741 TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM]; 5742 SYSCONGLOMERATESRowFactory rf = (SYSCONGLOMERATESRowFactory) ti.getCatalogRowFactory(); 5743 boolean[] bArray = {false, false, false}; 5744 5745 for (int i = 0; i < cds.length; i++) 5746 { 5747 5750 conglomIDOrderable = getValueAsDVD(cds[i].getUUID()); 5751 5752 5753 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1); 5754 keyRow1.setColumn(1, conglomIDOrderable); 5755 5756 cds[i].setConglomerateNumber(conglomerateNumber); 5757 row = rf.makeRow(cds[i], null); 5759 5760 ti.updateRow(keyRow1, row, 5762 SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX1_ID, 5763 bArray, 5764 (int[])null, 5765 tc); 5766 } 5767 5768 } 5769 5770 5771 5782 public List getDependentsDescriptorList(String dependentID) 5783 throws StandardException 5784 { 5785 List ddlList = newSList(); 5786 DataValueDescriptor dependentIDOrderable; 5787 TabInfoImpl ti = getNonCoreTI(SYSDEPENDS_CATALOG_NUM); 5788 5789 5790 dependentIDOrderable = dvf.getCharDataValue(dependentID); 5791 5792 5793 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 5794 keyRow.setColumn(1, dependentIDOrderable); 5795 5796 getDescriptorViaIndex( 5797 SYSDEPENDSRowFactory.SYSDEPENDS_INDEX1_ID, 5798 keyRow, 5799 (ScanQualifier [][]) null, 5800 ti, 5801 (TupleDescriptor) null, 5802 ddlList, 5803 false); 5804 5805 return ddlList; 5806 } 5807 5808 5819 public List getProvidersDescriptorList(String providerID) 5820 throws StandardException 5821 { 5822 List ddlList = newSList(); 5823 DataValueDescriptor providerIDOrderable; 5824 TabInfoImpl ti = getNonCoreTI(SYSDEPENDS_CATALOG_NUM); 5825 5826 5827 providerIDOrderable = dvf.getCharDataValue(providerID); 5828 5829 5830 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 5831 keyRow.setColumn(1, providerIDOrderable); 5832 5833 getDescriptorViaIndex( 5834 SYSDEPENDSRowFactory.SYSDEPENDS_INDEX2_ID, 5835 keyRow, 5836 (ScanQualifier [][]) null, 5837 ti, 5838 (TupleDescriptor) null, 5839 ddlList, 5840 false); 5841 5842 5843 5844 return ddlList; 5845 } 5846 5847 5856 public List getAllDependencyDescriptorsList() 5857 throws StandardException 5858 { 5859 ScanController scanController; 5860 TransactionController tc; 5861 ExecRow outRow; 5862 ExecRow templateRow; 5863 List ddl = newSList(); 5864 TabInfoImpl ti = getNonCoreTI(SYSDEPENDS_CATALOG_NUM); 5865 SYSDEPENDSRowFactory rf = (SYSDEPENDSRowFactory) ti.getCatalogRowFactory(); 5866 5867 5868 tc = getTransactionCompile(); 5870 5871 outRow = rf.makeEmptyRow(); 5872 5873 scanController = tc.openScan( 5874 ti.getHeapConglomerate(), false, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_REPEATABLE_READ, 5879 (FormatableBitSet) null, null, ScanController.GE, null, 5883 null, ScanController.GT); 5886 while (scanController.fetchNext(outRow.getRowArray())) 5887 { 5888 DependencyDescriptor dependencyDescriptor; 5889 5890 dependencyDescriptor = (DependencyDescriptor) 5891 rf.buildDescriptor(outRow, 5892 (TupleDescriptor) null, 5893 this); 5894 5895 ddl.add(dependencyDescriptor); 5896 } 5897 5898 scanController.close(); 5899 5900 return ddl; 5901 } 5902 5903 5911 public void dropStoredDependency(DependencyDescriptor dd, 5912 TransactionController tc ) 5913 throws StandardException 5914 { 5915 ExecIndexRow keyRow1 = null; 5916 UUID dependentID = dd.getUUID(); 5917 UUID providerID = dd.getProviderID(); 5918 DataValueDescriptor dependentIDOrderable = getValueAsDVD(dependentID); 5919 TabInfoImpl ti = getNonCoreTI(SYSDEPENDS_CATALOG_NUM); 5920 5921 5924 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1); 5925 keyRow1.setColumn(1, dependentIDOrderable); 5926 5927 TupleFilter filter = new DropDependencyFilter( providerID ); 5929 5930 ti.deleteRows( tc, 5931 keyRow1, ScanController.GE, 5933 null, filter, keyRow1, ScanController.GT, 5937 SYSDEPENDSRowFactory.SYSDEPENDS_INDEX1_ID ); 5938 5939 } 5940 5941 5942 5951 public void dropDependentsStoredDependencies(UUID dependentsUUID, 5952 TransactionController tc) 5953 throws StandardException 5954 { 5955 dropDependentsStoredDependencies(dependentsUUID, tc, true); 5956 } 5957 5958 5961 public void dropDependentsStoredDependencies(UUID dependentsUUID, 5962 TransactionController tc, 5963 boolean wait) 5964 throws StandardException 5965 { 5966 ExecIndexRow keyRow1 = null; 5967 DataValueDescriptor dependentIDOrderable; 5968 TabInfoImpl ti = getNonCoreTI(SYSDEPENDS_CATALOG_NUM); 5969 5970 5973 dependentIDOrderable = getValueAsDVD(dependentsUUID); 5974 5975 5976 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1); 5977 keyRow1.setColumn(1, dependentIDOrderable); 5978 5979 ti.deleteRow( tc, keyRow1, SYSDEPENDSRowFactory.SYSDEPENDS_INDEX1_ID, 5980 wait ); 5981 5982 } 5983 5984 5989 public UUIDFactory getUUIDFactory() 5990 { 5991 return uuidFactory; 5992 } 5993 5994 6004 public AliasDescriptor getAliasDescriptor(UUID uuid) 6005 throws StandardException 6006 { 6007 DataValueDescriptor UUIDStringOrderable; 6008 SYSALIASESRowFactory rf; 6009 TabInfoImpl ti = getNonCoreTI(SYSALIASES_CATALOG_NUM); 6010 6011 rf = (SYSALIASESRowFactory) ti.getCatalogRowFactory(); 6012 6013 6014 UUIDStringOrderable = dvf.getCharDataValue(uuid.toString()); 6015 6016 6017 ExecIndexRow keyRow = exFactory.getIndexableRow(1); 6018 keyRow.setColumn(1, UUIDStringOrderable); 6019 6020 return (AliasDescriptor) 6021 getDescriptorViaIndex( 6022 SYSALIASESRowFactory.SYSALIASES_INDEX2_ID, 6023 keyRow, 6024 (ScanQualifier [][]) null, 6025 ti, 6026 (TupleDescriptor) null, 6027 (List) null, 6028 false); 6029 } 6030 6031 6043 public AliasDescriptor getAliasDescriptor(String schemaId, String aliasName, char nameSpace) 6044 throws StandardException 6045 { 6046 DataValueDescriptor aliasNameOrderable; 6047 DataValueDescriptor nameSpaceOrderable; 6048 TabInfoImpl ti = getNonCoreTI(SYSALIASES_CATALOG_NUM); 6049 SYSALIASESRowFactory rf = (SYSALIASESRowFactory) ti.getCatalogRowFactory(); 6050 6051 6054 aliasNameOrderable = dvf.getVarcharDataValue(aliasName); 6055 char[] charArray = new char[1]; 6056 charArray[0] = nameSpace; 6057 nameSpaceOrderable = dvf.getCharDataValue(new String (charArray)); 6058 6059 6060 ExecIndexRow keyRow = exFactory.getIndexableRow(3); 6061 keyRow.setColumn(1, dvf.getCharDataValue(schemaId)); 6062 keyRow.setColumn(2, aliasNameOrderable); 6063 keyRow.setColumn(3, nameSpaceOrderable); 6064 6065 return (AliasDescriptor) 6066 getDescriptorViaIndex( 6067 SYSALIASESRowFactory.SYSALIASES_INDEX1_ID, 6068 keyRow, 6069 (ScanQualifier [][]) null, 6070 ti, 6071 (TupleDescriptor) null, 6072 (List) null, 6073 false); 6074 } 6075 6076 6084 public java.util.List getRoutineList(String schemaID, String routineName, char nameSpace) 6085 throws StandardException { 6086 6087 java.util.List list = new java.util.ArrayList (); 6088 6089 if (schemaID.equals(SchemaDescriptor.SYSFUN_SCHEMA_UUID) 6091 && nameSpace == AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR) 6092 { 6093 for (int f = 0; f < DataDictionaryImpl.SYSFUN_FUNCTIONS.length; f++) 6094 { 6095 String [] details = DataDictionaryImpl.SYSFUN_FUNCTIONS[f]; 6096 String name = details[0]; 6097 if (!name.equals(routineName)) 6098 continue; 6099 6100 AliasDescriptor ad = DataDictionaryImpl.SYSFUN_AD[f]; 6101 if (ad == null) 6102 { 6103 TypeDescriptor rt = 6105 DataTypeDescriptor.getBuiltInDataTypeDescriptor(details[1]); 6106 6107 String paramType = details[4]; 6109 TypeDescriptor[] pt; 6110 String [] paramNames; 6111 int[] paramModes; 6112 int paramCount; 6113 if (paramType != null) 6114 { 6115 paramNames = DataDictionaryImpl.SYSFUN_PNAME; 6116 paramCount = 1; 6117 paramModes = DataDictionaryImpl.SYSFUN_PMODE; 6118 pt = new TypeDescriptor[1]; 6119 pt[0] = 6120 DataTypeDescriptor.getBuiltInDataTypeDescriptor(paramType); 6121 } 6122 else 6123 { 6124 paramNames = null; 6126 pt = null; 6127 paramCount = 0; 6128 paramModes = null; 6129 } 6130 6131 RoutineAliasInfo ai = new RoutineAliasInfo(details[3], 6133 paramCount, paramNames, 6134 pt, paramModes, 0, 6135 RoutineAliasInfo.PS_JAVA, RoutineAliasInfo.NO_SQL, 6136 false, rt); 6137 6138 ad = new AliasDescriptor(this, uuidFactory.createUUID(), name, 6140 uuidFactory.recreateUUID(schemaID), 6141 details[2], AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR, 6142 AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR, 6143 true, ai, null); 6144 6145 DataDictionaryImpl.SYSFUN_AD[f] = ad; 6146 } 6147 list.add(ad); 6148 } 6149 return list; 6150 } 6151 6152 AliasDescriptor ad = getAliasDescriptor(schemaID, routineName, nameSpace); 6153 if (ad != null) { 6154 list.add(ad); 6155 } 6156 return list; 6157 } 6158 6159 6167 6168 public void dropAliasDescriptor(AliasDescriptor ad, 6169 TransactionController tc) 6170 throws StandardException 6171 { 6172 ExecIndexRow keyRow1 = null; 6173 DataValueDescriptor aliasNameOrderable; 6174 DataValueDescriptor nameSpaceOrderable; 6175 TabInfoImpl ti = getNonCoreTI(SYSALIASES_CATALOG_NUM); 6176 6177 6180 aliasNameOrderable = dvf.getVarcharDataValue(ad.getDescriptorName()); 6181 char[] charArray = new char[1]; 6182 charArray[0] = ad.getNameSpace(); 6183 nameSpaceOrderable = dvf.getCharDataValue(new String (charArray)); 6184 6185 6186 keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(3); 6187 keyRow1.setColumn(1, dvf.getCharDataValue(ad.getSchemaUUID().toString())); 6188 keyRow1.setColumn(2, aliasNameOrderable); 6189 keyRow1.setColumn(3, nameSpaceOrderable); 6190 6191 ti.deleteRow( tc, keyRow1, SYSALIASESRowFactory.SYSALIASES_INDEX1_ID ); 6192 6193 } 6194 6195 6199 6213 protected void loadDictionaryTables(TransactionController tc, 6214 DataDescriptorGenerator ddg, 6215 Properties startParams) 6216 throws StandardException 6217 { 6218 loadCatalogs(ddg, coreInfo); 6220 6221 dictionaryVersion = (DD_Version)tc.getProperty( 6222 DataDictionary.CORE_DATA_DICTIONARY_VERSION); 6223 6224 softwareVersion.upgradeIfNeeded(dictionaryVersion, tc, startParams); 6225 } 6226 6227 6235 public void loadCatalogs(DataDescriptorGenerator ddg, TabInfoImpl[] catalogArray) 6236 throws StandardException 6237 { 6238 int ictr; 6239 int numIndexes; 6240 int indexCtr; 6241 TabInfoImpl catalog; 6242 int catalogCount = catalogArray.length; 6243 6244 6245 for (ictr = 0; ictr < catalogCount; ictr++) 6246 { 6247 catalog = catalogArray[ictr]; 6250 6251 numIndexes = catalog.getNumberOfIndexes(); 6252 6253 if (numIndexes > 0) 6254 { 6255 for (indexCtr = 0; indexCtr < numIndexes; indexCtr++) 6256 { 6257 initSystemIndexVariables(ddg, catalog, indexCtr); 6258 } 6259 } 6260 } 6261 6262 } 6263 6264 6267 6268 6285 protected void createDictionaryTables(Properties params, TransactionController tc, 6286 DataDescriptorGenerator ddg) 6287 throws StandardException 6288 { 6289 6294 systemSchemaDesc = 6295 newSystemSchemaDesc( 6296 convertIdToLower ? 6297 StringUtil.SQLToLowerCase(SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME) : 6298 SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME, 6299 SchemaDescriptor.SYSTEM_SCHEMA_UUID); 6300 6301 6306 for (int coreCtr = 0; coreCtr < NUM_CORE; coreCtr++) 6307 { 6308 TabInfoImpl ti = coreInfo[coreCtr]; 6309 6310 Properties heapProperties = ti.getCreateHeapProperties(); 6311 6312 ti.setHeapConglomerate( 6313 createConglomerate( 6314 ti.getTableName(), 6315 tc, 6316 ti.getCatalogRowFactory().makeEmptyRow(), 6317 heapProperties 6318 ) 6319 ); 6320 6321 if (coreInfo[coreCtr].getNumberOfIndexes() > 0) 6323 { 6324 bootStrapSystemIndexes(systemSchemaDesc, tc, ddg, ti); 6325 } 6326 } 6327 6328 for ( int ictr = 0; ictr < NUM_CORE; ictr++ ) 6330 { 6331 6332 TabInfoImpl ti = coreInfo[ictr]; 6333 6334 addSystemTableToDictionary(ti, systemSchemaDesc, tc, ddg); 6335 } 6336 6337 params.put(CFG_SYSTABLES_ID, 6339 Long.toString( 6340 coreInfo[SYSTABLES_CORE_NUM].getHeapConglomerate())); 6341 params.put(CFG_SYSTABLES_INDEX1_ID, 6342 Long.toString( 6343 coreInfo[SYSTABLES_CORE_NUM].getIndexConglomerate( 6344 ((SYSTABLESRowFactory) coreInfo[SYSTABLES_CORE_NUM]. 6345 getCatalogRowFactory()).SYSTABLES_INDEX1_ID))); 6346 params.put(CFG_SYSTABLES_INDEX2_ID, 6347 Long.toString( 6348 coreInfo[SYSTABLES_CORE_NUM].getIndexConglomerate( 6349 ((SYSTABLESRowFactory) coreInfo[SYSTABLES_CORE_NUM]. 6350 getCatalogRowFactory()).SYSTABLES_INDEX2_ID))); 6351 6352 params.put(CFG_SYSCOLUMNS_ID, 6353 Long.toString( 6354 coreInfo[SYSCOLUMNS_CORE_NUM].getHeapConglomerate())); 6355 params.put(CFG_SYSCOLUMNS_INDEX1_ID, 6356 Long.toString( 6357 coreInfo[SYSCOLUMNS_CORE_NUM].getIndexConglomerate( 6358 ((SYSCOLUMNSRowFactory) coreInfo[SYSCOLUMNS_CORE_NUM]. 6359 getCatalogRowFactory()).SYSCOLUMNS_INDEX1_ID))); 6360 params.put(CFG_SYSCOLUMNS_INDEX2_ID, 6361 Long.toString( 6362 coreInfo[SYSCOLUMNS_CORE_NUM].getIndexConglomerate( 6363 ((SYSCOLUMNSRowFactory) coreInfo[SYSCOLUMNS_CORE_NUM]. 6364 getCatalogRowFactory()).SYSCOLUMNS_INDEX2_ID))); 6365 6366 params.put(CFG_SYSCONGLOMERATES_ID, 6367 Long.toString( 6368 coreInfo[SYSCONGLOMERATES_CORE_NUM].getHeapConglomerate())); 6369 params.put(CFG_SYSCONGLOMERATES_INDEX1_ID, 6370 Long.toString( 6371 coreInfo[SYSCONGLOMERATES_CORE_NUM].getIndexConglomerate( 6372 ((SYSCONGLOMERATESRowFactory) coreInfo[SYSCONGLOMERATES_CORE_NUM]. 6373 getCatalogRowFactory()).SYSCONGLOMERATES_INDEX1_ID))); 6374 params.put(CFG_SYSCONGLOMERATES_INDEX2_ID, 6375 Long.toString( 6376 coreInfo[SYSCONGLOMERATES_CORE_NUM].getIndexConglomerate( 6377 ((SYSCONGLOMERATESRowFactory) coreInfo[SYSCONGLOMERATES_CORE_NUM]. 6378 getCatalogRowFactory()).SYSCONGLOMERATES_INDEX2_ID))); 6379 params.put(CFG_SYSCONGLOMERATES_INDEX3_ID, 6380 Long.toString( 6381 coreInfo[SYSCONGLOMERATES_CORE_NUM].getIndexConglomerate( 6382 ((SYSCONGLOMERATESRowFactory) coreInfo[SYSCONGLOMERATES_CORE_NUM]. 6383 getCatalogRowFactory()).SYSCONGLOMERATES_INDEX3_ID))); 6384 6385 params.put(CFG_SYSSCHEMAS_ID, 6386 Long.toString( 6387 coreInfo[SYSSCHEMAS_CORE_NUM].getHeapConglomerate())); 6388 params.put(CFG_SYSSCHEMAS_INDEX1_ID, 6389 Long.toString( 6390 coreInfo[SYSSCHEMAS_CORE_NUM].getIndexConglomerate( 6391 ((SYSSCHEMASRowFactory) coreInfo[SYSSCHEMAS_CORE_NUM]. 6392 getCatalogRowFactory()).SYSSCHEMAS_INDEX1_ID))); 6393 params.put(CFG_SYSSCHEMAS_INDEX2_ID, 6394 Long.toString( 6395 coreInfo[SYSSCHEMAS_CORE_NUM].getIndexConglomerate( 6396 ((SYSSCHEMASRowFactory) coreInfo[SYSSCHEMAS_CORE_NUM]. 6397 getCatalogRowFactory()).SYSSCHEMAS_INDEX2_ID))); 6398 6399 sysIBMSchemaDesc = 6401 addSystemSchema( 6402 SchemaDescriptor.IBM_SYSTEM_SCHEMA_NAME, 6403 SchemaDescriptor.SYSIBM_SCHEMA_UUID, tc); 6404 6405 6410 for (int noncoreCtr = 0; noncoreCtr < NUM_NONCORE; noncoreCtr++) 6411 { 6412 int catalogNumber = noncoreCtr + NUM_CORE; 6413 boolean isDummy = (catalogNumber == SYSDUMMY1_CATALOG_NUM); 6414 6415 TabInfoImpl ti = getNonCoreTIByNumber(catalogNumber); 6416 6417 makeCatalog(ti, isDummy ? sysIBMSchemaDesc : systemSchemaDesc, tc ); 6418 6419 if (isDummy) 6420 populateSYSDUMMY1(tc); 6421 6422 clearNoncoreTable(noncoreCtr); 6427 } 6428 6429 addDescriptor( 6431 systemSchemaDesc, null, SYSSCHEMAS_CATALOG_NUM, false, tc); 6432 6433 6434 6444 addSystemSchema( 6446 SchemaDescriptor.IBM_SYSTEM_CAT_SCHEMA_NAME, 6447 SchemaDescriptor.SYSCAT_SCHEMA_UUID, tc); 6448 6449 addSystemSchema( 6451 SchemaDescriptor.IBM_SYSTEM_FUN_SCHEMA_NAME, 6452 SchemaDescriptor.SYSFUN_SCHEMA_UUID, tc); 6453 6454 addSystemSchema( 6456 SchemaDescriptor.IBM_SYSTEM_PROC_SCHEMA_NAME, 6457 SchemaDescriptor.SYSPROC_SCHEMA_UUID, tc); 6458 6459 addSystemSchema( 6461 SchemaDescriptor.IBM_SYSTEM_STAT_SCHEMA_NAME, 6462 SchemaDescriptor.SYSSTAT_SCHEMA_UUID, tc); 6463 6464 addSystemSchema( 6466 SchemaDescriptor.IBM_SYSTEM_NULLID_SCHEMA_NAME, 6467 SchemaDescriptor.NULLID_SCHEMA_UUID, tc); 6468 6469 addSystemSchema( 6471 SchemaDescriptor.STD_SQLJ_SCHEMA_NAME, 6472 SchemaDescriptor.SQLJ_SCHEMA_UUID, tc); 6473 6474 addSystemSchema( 6476 SchemaDescriptor.STD_SYSTEM_DIAG_SCHEMA_NAME, 6477 SchemaDescriptor.SYSCS_DIAG_SCHEMA_UUID, tc); 6478 6479 addSystemSchema( 6481 SchemaDescriptor.STD_SYSTEM_UTIL_SCHEMA_NAME, 6482 SchemaDescriptor.SYSCS_UTIL_SCHEMA_UUID, tc); 6483 6484 SchemaDescriptor appSchemaDesc = new SchemaDescriptor(this, 6486 SchemaDescriptor.STD_DEFAULT_SCHEMA_NAME, 6487 SchemaDescriptor.DEFAULT_USER_NAME, 6488 uuidFactory.recreateUUID( SchemaDescriptor.DEFAULT_SCHEMA_UUID), 6489 false); 6490 6491 addDescriptor(appSchemaDesc, null, SYSSCHEMAS_CATALOG_NUM, false, tc); 6492 } 6493 6494 6502 private SchemaDescriptor addSystemSchema( 6503 String schema_name, 6504 String schema_uuid, 6505 TransactionController tc) 6506 throws StandardException 6507 { 6508 SchemaDescriptor schema_desc = 6510 new SchemaDescriptor( 6511 this, 6512 convertIdToLower ? schema_name.toLowerCase() : schema_name, 6513 authorizationDatabaseOwner, 6514 uuidFactory.recreateUUID(schema_uuid), 6515 true); 6516 6517 addDescriptor(schema_desc, null, SYSSCHEMAS_CATALOG_NUM, false, tc); 6519 6520 return(schema_desc); 6521 } 6522 6523 6528 protected void upgradeMakeCatalog(TransactionController tc, int catalogNumber) 6529 throws StandardException 6530 { 6531 TabInfoImpl ti; 6532 if (catalogNumber >= NUM_CORE) 6533 ti = getNonCoreTIByNumber(catalogNumber); 6534 else 6535 ti = coreInfo[catalogNumber]; 6536 6537 makeCatalog(ti, (catalogNumber == SYSDUMMY1_CATALOG_NUM) ? getSysIBMSchemaDescriptor() : 6538 getSystemSchemaDescriptor(), tc); 6539 } 6540 6541 6550 public void makeCatalog( TabInfoImpl ti, 6551 SchemaDescriptor sd, 6552 TransactionController tc ) 6553 throws StandardException 6554 { 6555 DataDescriptorGenerator ddg = getDataDescriptorGenerator(); 6556 6557 Properties heapProperties = ti.getCreateHeapProperties(); 6558 ti.setHeapConglomerate( 6559 createConglomerate( 6560 ti.getTableName(), 6561 tc, 6562 ti.getCatalogRowFactory().makeEmptyRow(), 6563 heapProperties 6564 ) 6565 ); 6566 6567 if (ti.getNumberOfIndexes() > 0) 6569 { 6570 bootStrapSystemIndexes(sd, tc, ddg, ti); 6571 } 6572 6573 addSystemTableToDictionary(ti, sd, tc, ddg); 6574 } 6575 6584 public void upgrade_setNullability(CatalogRowFactory rowFactory, 6585 int columnNumber, 6586 boolean nullability, 6587 TransactionController tc) 6588 throws StandardException 6589 { 6590 SystemColumn theColumn; 6591 SystemColumn[] columns = rowFactory.buildColumnList(); 6592 SchemaDescriptor sd = getSystemSchemaDescriptor(); 6593 String columnName; 6594 6595 TableDescriptor td = getTableDescriptor(rowFactory.getCatalogName(), sd); 6596 6597 theColumn = columns[columnNumber - 1]; ColumnDescriptor cd = makeColumnDescriptor(theColumn, columnNumber, td ); 6599 columnName = cd.getColumnName(); 6600 cd.getType().setNullability(nullability); 6601 int[] columnNameColArray = new int[1]; 6602 columnNameColArray[0] = SYSCOLUMNSRowFactory.SYSCOLUMNS_COLUMNDATATYPE ; 6603 updateColumnDescriptor(cd, 6604 td.getUUID(), 6605 columnName, 6606 columnNameColArray, 6607 tc, 6608 true); 6609 6610 } 6611 6612 6613 6622 public void upgrade_addColumns( CatalogRowFactory rowFactory, 6623 int[] newColumnIDs, 6624 TransactionController tc ) 6625 throws StandardException 6626 { 6627 int columnID; 6628 SystemColumn currentColumn; 6629 ColumnDescriptor cd; 6630 6631 SystemColumn[] columns = rowFactory.buildColumnList(); 6632 ExecRow templateRow = rowFactory.makeEmptyRow(); 6633 int columnCount = newColumnIDs.length; 6634 SchemaDescriptor sd = getSystemSchemaDescriptor(); 6635 TableDescriptor td; 6636 long conglomID; 6637 6638 if (rowFactory instanceof SYSTABLESRowFactory) 6642 { 6643 td = dataDescriptorGenerator.newTableDescriptor( 6644 "SYSTABLES", 6645 sd, 6646 TableDescriptor.BASE_TABLE_TYPE, 6647 TableDescriptor.ROW_LOCK_GRANULARITY); 6648 td.setUUID(getUUIDForCoreTable("SYSTABLES", sd.getUUID().toString(), tc)); 6649 conglomID = coreInfo[SYSTABLES_CORE_NUM].getHeapConglomerate(); 6650 } 6651 else if (rowFactory instanceof SYSCOLUMNSRowFactory) 6652 { 6653 td = dataDescriptorGenerator.newTableDescriptor( 6654 "SYSCOLUMNS", 6655 sd, 6656 TableDescriptor.BASE_TABLE_TYPE, 6657 TableDescriptor.ROW_LOCK_GRANULARITY); 6658 td.setUUID(getUUIDForCoreTable("SYSCOLUMNS", sd.getUUID().toString(), tc)); 6659 conglomID = coreInfo[SYSCOLUMNS_CORE_NUM].getHeapConglomerate(); 6660 } 6661 else 6662 { 6663 td = getTableDescriptor( rowFactory.getCatalogName(), sd ); 6664 conglomID = td.getHeapConglomerateId(); 6665 } 6666 6667 widenConglomerate( templateRow, newColumnIDs, conglomID, tc ); 6668 6669 6670 ColumnDescriptor[] cdArray = new ColumnDescriptor[columnCount]; 6671 for ( int ix = 0; ix < columnCount; ix++ ) 6672 { 6673 columnID = newColumnIDs[ix]; 6674 currentColumn = columns[ columnID - 1 ]; 6676 cdArray[ix] = makeColumnDescriptor( currentColumn, ix + 1, td ); 6677 } 6678 addDescriptorArray(cdArray, td, SYSCOLUMNS_CATALOG_NUM, false, tc); 6679 6680 } 6681 6682 6691 public void upgrade_addInvisibleColumns 6692 ( 6693 CatalogRowFactory rowFactory, 6694 int[] newColumnIDs, 6695 TransactionController tc 6696 ) 6697 throws StandardException 6698 { 6699 ExecRow templateRow = rowFactory.makeEmptyRow(); 6700 SchemaDescriptor sd = getSystemSchemaDescriptor( ); 6701 long conglomID = getTableDescriptor( rowFactory.getCatalogName(), sd ).getHeapConglomerateId(); 6702 6703 widenConglomerate( templateRow, newColumnIDs, conglomID, tc ); 6704 } 6705 6706 6707 6717 private void widenConglomerate 6718 ( 6719 ExecRow templateRow, 6720 int[] newColumnIDs, 6721 long conglomID, 6722 TransactionController tc 6723 ) 6724 throws StandardException 6725 { 6726 int columnCount = newColumnIDs.length; 6727 6728 for ( int ix = 0; ix < columnCount; ix++ ) 6729 { 6730 int columnID = newColumnIDs[ix]; 6731 int storablePosition = columnID - 1; 6733 tc.addColumnToConglomerate( conglomID, 6734 storablePosition, 6735 templateRow.getColumn( columnID) ); 6736 } 6737 6738 } 6739 6740 6741 6753 public long upgrade_makeOneIndex 6754 ( 6755 TransactionController tc, 6756 TabInfoImpl ti, 6757 int indexNumber, 6758 long heapConglomerateNumber 6759 ) 6760 throws StandardException 6761 { 6762 SchemaDescriptor sd = getSystemSchemaDescriptor( ); 6763 DataDescriptorGenerator ddg = getDataDescriptorGenerator(); 6764 long indexConglomerateNumber; 6765 6766 ConglomerateDescriptor conglomerateDescriptor = bootstrapOneIndex 6767 ( sd, tc, ddg, ti, indexNumber, heapConglomerateNumber ); 6768 6769 indexConglomerateNumber = conglomerateDescriptor.getConglomerateNumber(); 6770 6771 addDescriptor(conglomerateDescriptor, sd, 6772 SYSCONGLOMERATES_CATALOG_NUM, false, tc); 6773 6774 return indexConglomerateNumber; 6775 } 6776 6777 6778 6792 private UUID getUUIDForCoreTable(String tableName, 6793 String schemaUUID, 6794 TransactionController tc) 6795 throws StandardException 6796 { 6797 ConglomerateController heapCC; 6798 ExecIndexRow indexRow1; 6799 ExecRow row; 6800 DataValueDescriptor schemaIDOrderable; 6801 DataValueDescriptor tableNameOrderable; 6802 ScanController scanController; 6803 TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM]; 6804 SYSTABLESRowFactory rf = (SYSTABLESRowFactory) ti.getCatalogRowFactory(); 6805 6806 row = exFactory.getValueRow(1); 6808 6809 6812 tableNameOrderable = dvf.getVarcharDataValue(tableName); 6813 schemaIDOrderable = dvf.getCharDataValue(schemaUUID); 6814 6815 6816 ExecIndexRow keyRow = exFactory.getIndexableRow(2); 6817 keyRow.setColumn(1, tableNameOrderable); 6818 keyRow.setColumn(2, schemaIDOrderable); 6819 6820 heapCC = tc.openConglomerate( 6821 ti.getHeapConglomerate(), false, 0, 6822 TransactionController.MODE_RECORD, 6823 TransactionController.ISOLATION_REPEATABLE_READ); 6824 6825 ExecRow indexTemplateRow = rf.buildEmptyIndexRow( SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, heapCC.newRowLocationTemplate() ); 6826 6827 6830 scanController = tc.openScan( 6831 ti.getIndexConglomerate(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID), false, 0, 6834 TransactionController.MODE_RECORD, 6835 TransactionController.ISOLATION_REPEATABLE_READ, 6836 (FormatableBitSet) null, keyRow.getRowArray(), ScanController.GE, (ScanQualifier[][]) null, keyRow.getRowArray(), ScanController.GT); 6843 6846 if (scanController.fetchNext(indexTemplateRow.getRowArray())) 6847 { 6848 RowLocation baseRowLocation; 6849 6850 6851 baseRowLocation = (RowLocation) indexTemplateRow.getColumn( 6852 indexTemplateRow.nColumns()); 6853 6854 6855 row.setColumn(SYSTABLESRowFactory.SYSTABLES_TABLEID, dvf.getCharDataValue((String ) null)); 6856 FormatableBitSet bi = new FormatableBitSet(1); 6857 bi.set(0); 6858 boolean base_row_exists = 6859 heapCC.fetch( 6860 baseRowLocation, row.getRowArray(), (FormatableBitSet) null); 6861 6862 if (SanityManager.DEBUG) 6863 { 6864 SanityManager.ASSERT(base_row_exists, "base row not found"); 6867 } 6868 } 6869 6870 scanController.close(); 6871 heapCC.close(); 6872 6873 return uuidFactory.recreateUUID(row.getColumn(1).toString()); 6874 } 6875 6876 6877 6889 void upgrade_initSystemTableCols( 6890 TransactionController tc, 6891 boolean isCoreTable, 6892 int tableNum, 6893 FormatableBitSet columnsToUpdateSet, 6894 DataValueDescriptor[] replaceRow 6895 ) 6896 throws StandardException 6897 { 6898 6899 TabInfoImpl ti = (isCoreTable) ? coreInfo[tableNum] : 6900 getNonCoreTIByNumber(tableNum); 6901 6902 if (!isCoreTable) 6903 faultInTabInfo(ti); 6904 6905 6906 ScanController sc = 6907 tc.openScan( 6908 ti.getHeapConglomerate(), 6909 false, 6910 TransactionController.OPENMODE_FORUPDATE, 6911 TransactionController.MODE_TABLE, 6912 TransactionController.ISOLATION_REPEATABLE_READ, 6913 RowUtil.EMPTY_ROW_BITSET, 6914 (DataValueDescriptor[]) null, 6915 ScanController.NA, 6916 (Qualifier[][]) null, 6917 (DataValueDescriptor[]) null, 6918 ScanController.NA); 6919 6920 while (sc.next()) 6921 { 6922 6923 sc.replace(replaceRow, columnsToUpdateSet); 6924 } 6925 6926 sc.close(); 6927 } 6928 6929 6930 6931 6946 6947 6948 6954 private void bootStrapSystemIndexes( 6955 SchemaDescriptor sd, 6956 TransactionController tc, 6957 DataDescriptorGenerator ddg, 6958 TabInfoImpl ti) 6959 throws StandardException 6960 { 6961 ConglomerateDescriptor[] cgd = new ConglomerateDescriptor[ti.getNumberOfIndexes()]; 6962 6963 6969 for (int indexCtr = 0; indexCtr < ti.getNumberOfIndexes(); indexCtr++) 6970 { 6971 cgd[indexCtr] = bootstrapOneIndex( sd, tc, ddg, ti, indexCtr, ti.getHeapConglomerate() ); 6972 } 6973 6974 for (int indexCtr = 0; indexCtr < ti.getNumberOfIndexes(); indexCtr++) 6975 { 6976 addDescriptor(cgd[indexCtr], sd, 6977 SYSCONGLOMERATES_CATALOG_NUM, false, tc); 6978 } 6979 } 6980 6981 6984 public RowLocation[] computeAutoincRowLocations(TransactionController tc, 6985 TableDescriptor td) 6986 throws StandardException 6987 { 6988 int size; 6989 if (!(td.tableHasAutoincrement())) 6990 return null; 6991 6992 size = td.getNumberOfColumns(); 6993 RowLocation[] rla = new RowLocation[size]; 6994 6995 for (int i = 0; i < size; i++) 6996 { 6997 ColumnDescriptor cd = td.getColumnDescriptor(i + 1); 6998 if (cd.isAutoincrement()) 6999 rla[i] = computeRowLocation(tc, td, cd.getColumnName()); 7000 } 7001 return rla; 7002 } 7003 7004 7005 7008 public NumberDataValue getSetAutoincrementValue( 7009 RowLocation rl, 7010 TransactionController tc, 7011 boolean doUpdate, 7012 NumberDataValue newValue, 7013 boolean wait) 7014 throws StandardException 7015 { 7016 7017 FormatableBitSet columnToUpdate = new 7018 FormatableBitSet(SYSCOLUMNSRowFactory.SYSCOLUMNS_COLUMN_COUNT); 7019 int columnNum = SYSCOLUMNSRowFactory.SYSCOLUMNS_AUTOINCREMENTVALUE; 7020 TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM]; 7021 ConglomerateController heapCC = null; 7022 SYSCOLUMNSRowFactory rf = (SYSCOLUMNSRowFactory) ti.getCatalogRowFactory(); 7023 ExecRow row = rf.makeEmptyRow(); 7024 7025 FormatableBitSet columnToRead = new 7026 FormatableBitSet(SYSCOLUMNSRowFactory.SYSCOLUMNS_COLUMN_COUNT); 7027 7028 columnToRead.set(columnNum - 1); columnToRead.set(columnNum); columnToRead.set(columnNum + 1); 7033 try 7034 { 7035 7039 heapCC = 7040 tc.openConglomerate( 7041 ti.getHeapConglomerate(), 7042 false, 7043 (TransactionController.OPENMODE_FORUPDATE | 7044 ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)), 7045 TransactionController.MODE_RECORD, 7046 TransactionController.ISOLATION_REPEATABLE_READ); 7047 7048 boolean baseRowExists = 7049 heapCC.fetch(rl, row.getRowArray(), columnToRead, wait); 7050 7051 columnToUpdate.set(columnNum - 1); 7053 NumberDataValue currentAI = (NumberDataValue)row.getColumn(columnNum); 7055 long currentAIValue = currentAI.getLong(); 7056 NumberDataValue increment = (NumberDataValue)row.getColumn(columnNum + 2); 7057 7058 if (doUpdate) 7059 { 7060 currentAI = currentAI.plus(currentAI, increment, currentAI); 7062 row.setColumn(columnNum, currentAI); 7063 heapCC.replace(rl, row.getRowArray(), columnToUpdate); 7064 } 7065 7066 if (newValue != null) 7069 { 7070 newValue.setValue(currentAIValue); 7073 return newValue; 7074 } 7075 7076 else 7077 { 7078 currentAI.setValue(currentAIValue); 7080 return currentAI; 7081 } 7082 } 7083 finally 7084 { 7085 if (heapCC != null) 7086 heapCC.close(); 7087 } 7088 } 7089 7090 private ConglomerateDescriptor bootstrapOneIndex 7091 ( 7092 SchemaDescriptor sd, 7093 TransactionController tc, 7094 DataDescriptorGenerator ddg, 7095 TabInfoImpl ti, 7096 int indexNumber, 7097 long heapConglomerateNumber 7098 ) 7099 throws StandardException 7100 { 7101 boolean isUnique; 7102 ConglomerateController cc; 7103 ExecRow baseRow; 7104 ExecIndexRow indexableRow; 7105 int numColumns; 7106 long conglomId; 7107 RowLocation rl; 7108 CatalogRowFactory rf = ti.getCatalogRowFactory(); 7109 IndexRowGenerator irg; 7110 ConglomerateDescriptor conglomerateDescriptor; 7111 7112 initSystemIndexVariables(ddg, ti, indexNumber); 7113 7114 irg = ti.getIndexRowGenerator(indexNumber); 7115 7116 numColumns = ti.getIndexColumnCount(indexNumber); 7117 7118 7119 isUnique = ti.isIndexUnique(indexNumber); 7120 7121 indexableRow = irg.getIndexRowTemplate(); 7123 7124 baseRow = rf.makeEmptyRow(); 7125 7126 cc = tc.openConglomerate( 7128 heapConglomerateNumber, false, 0, 7129 TransactionController.MODE_RECORD, 7130 TransactionController.ISOLATION_REPEATABLE_READ); 7131 7132 rl = cc.newRowLocationTemplate(); 7133 cc.close(); 7134 7135 irg.getIndexRow(baseRow, rl, indexableRow, (FormatableBitSet) null); 7137 7138 Properties indexProperties = ti.getCreateIndexProperties(indexNumber); 7141 7142 indexProperties.put( 7144 "baseConglomerateId", 7145 Long.toString( heapConglomerateNumber ) ); 7146 7147 indexProperties.put("nUniqueColumns", 7151 Integer.toString( 7152 isUnique ? numColumns : numColumns + 1)); 7153 7154 indexProperties.put("rowLocationColumn", 7156 Integer.toString(numColumns)); 7157 7158 indexProperties.put("nKeyFields", 7160 Integer.toString(numColumns + 1)); 7161 7162 7163 conglomId = tc.createConglomerate( 7164 "BTREE", indexableRow.getRowArray(), 7166 null, indexProperties, TransactionController.IS_DEFAULT); 7170 conglomerateDescriptor = 7171 ddg.newConglomerateDescriptor(conglomId, 7172 rf.getIndexName(indexNumber), 7173 true, 7174 irg, 7175 false, 7176 rf.getCanonicalIndexUUID(indexNumber), 7177 rf.getCanonicalTableUUID(), 7178 sd.getUUID()); 7179 ti.setIndexConglomerate( conglomerateDescriptor ); 7180 7181 return conglomerateDescriptor; 7182 } 7183 7184 public void initSystemIndexVariables(DataDescriptorGenerator ddg, 7185 TabInfoImpl ti, 7186 int indexNumber) 7187 throws StandardException 7188 { 7189 int numCols = ti.getIndexColumnCount(indexNumber); 7190 int[] baseColumnPositions = new int[numCols]; 7191 CatalogRowFactory rf = ti.getCatalogRowFactory(); 7192 7193 for (int colCtr = 0; colCtr < numCols; colCtr++) 7194 { 7195 baseColumnPositions[colCtr] = 7196 ti.getBaseColumnPosition(indexNumber, colCtr); 7197 } 7198 7199 boolean[] isAscending = new boolean[baseColumnPositions.length]; 7200 for (int i = 0; i < baseColumnPositions.length; i++) 7201 isAscending[i] = true; 7202 7203 ti.setIndexRowGenerator(indexNumber, 7205 new IndexRowGenerator( 7206 "BTREE", ti.isIndexUnique(indexNumber), 7207 baseColumnPositions, 7208 isAscending, 7209 baseColumnPositions.length)); 7210 } 7211 7212 7217 protected void populateSYSDUMMY1( 7218 TransactionController tc) 7219 throws StandardException 7220 { 7221 TabInfoImpl ti = getNonCoreTI(SYSDUMMY1_CATALOG_NUM); 7222 ExecRow row = ti.getCatalogRowFactory().makeRow(null, null); 7223 7224 int insertRetCode = ti.insertRow(row, tc, true); 7225 } 7226 7227 7232 public void clearCaches() throws StandardException 7233 { 7234 nameTdCache.cleanAll(); 7235 nameTdCache.ageOut(); 7236 OIDTdCache.cleanAll(); 7237 OIDTdCache.ageOut(); 7238 if (spsNameCache != null) 7239 { 7240 spsNameCache.cleanAll(); 7242 spsNameCache.ageOut(); 7243 spsIdHash.clear(); 7244 } 7246 } 7247 7248 7251 7252 private void addSystemTableToDictionary(TabInfoImpl ti, 7253 SchemaDescriptor sd, 7254 TransactionController tc, 7255 DataDescriptorGenerator ddg) 7256 throws StandardException 7257 { 7258 CatalogRowFactory crf = ti.getCatalogRowFactory(); 7259 7260 String name = ti.getTableName(); 7261 long conglomId = ti.getHeapConglomerate(); 7262 SystemColumn[] columnList = crf.buildColumnList(); 7263 UUID heapUUID = crf.getCanonicalHeapUUID(); 7264 String heapName = crf.getCanonicalHeapName(); 7265 TableDescriptor td; 7266 UUID toid; 7267 ColumnDescriptor cd; 7268 int columnCount; 7269 SystemColumn column; 7270 7271 7273 columnCount = columnList.length; 7274 td = ddg.newTableDescriptor(name, sd, TableDescriptor.SYSTEM_TABLE_TYPE, 7275 TableDescriptor.ROW_LOCK_GRANULARITY); 7276 td.setUUID(crf.getCanonicalTableUUID()); 7277 addDescriptor(td, sd, SYSTABLES_CATALOG_NUM, 7278 false, tc); 7279 toid = td.getUUID(); 7280 7281 7282 ConglomerateDescriptor cgd = ddg.newConglomerateDescriptor(conglomId, 7283 heapName, 7284 false, 7285 null, 7286 false, 7287 heapUUID, 7288 toid, 7289 sd.getUUID()); 7290 7291 addDescriptor(cgd, sd, SYSCONGLOMERATES_CATALOG_NUM, false, tc); 7292 7293 7294 ColumnDescriptor[] cdlArray = new ColumnDescriptor[columnCount]; 7295 7296 for (int columnNumber = 0; columnNumber < columnCount; columnNumber++) 7297 { 7298 column = columnList[columnNumber]; 7299 7300 if (SanityManager.DEBUG) 7301 { 7302 if (column == null) 7303 { 7304 SanityManager.THROWASSERT("column "+columnNumber+" for table "+ti.getTableName()+" is null"); 7305 } 7306 } 7307 cdlArray[columnNumber] = makeColumnDescriptor( column, 7308 columnNumber + 1, td ); 7309 } 7310 addDescriptorArray(cdlArray, td, SYSCOLUMNS_CATALOG_NUM, false, tc); 7311 7312 ColumnDescriptorList cdl = td.getColumnDescriptorList(); 7314 for (int i = 0; i < columnCount; i++) 7315 cdl.add(cdlArray[i]); 7316 } 7317 7318 7329 private ColumnDescriptor makeColumnDescriptor( SystemColumn column, 7330 int columnPosition, 7331 TableDescriptor td ) 7332 throws StandardException 7333 { 7334 return new ColumnDescriptor 7336 (column.getName(), columnPosition, column.getType(), null, null, td, 7337 (UUID) null, 0, 0 7339 ); 7340 } 7341 7342 7343 7355 private long createConglomerate(String name, TransactionController tc, 7356 ExecRow rowTemplate, 7357 Properties properties) 7358 throws StandardException 7359 { 7360 long conglomId; 7361 7362 conglomId = tc.createConglomerate( 7363 "heap", rowTemplate.getRowArray(), null, properties, TransactionController.IS_DEFAULT); 7369 return conglomId; 7370 } 7371 7372 7379 public DataValueDescriptor getValueAsDVD( UUID uuid ) throws StandardException 7380 { 7381 String uuidString = uuid.toString(); 7382 return dvf.getCharDataValue(uuidString); 7383 } 7384 7385 7389 public void initializeCatalogInfo() 7390 throws StandardException 7391 { 7392 initializeCoreInfo(); 7393 initializeNoncoreInfo(); 7394 } 7395 7396 7399 private void initializeCoreInfo() 7400 throws StandardException 7401 { 7402 TabInfoImpl[] lcoreInfo = coreInfo = new TabInfoImpl[NUM_CORE]; 7403 7404 UUIDFactory luuidFactory = uuidFactory; 7405 7406 lcoreInfo[SYSTABLES_CORE_NUM] = 7407 new TabInfoImpl(new SYSTABLESRowFactory(luuidFactory, exFactory, dvf, convertIdToLower)); 7408 lcoreInfo[SYSCOLUMNS_CORE_NUM] = 7409 new TabInfoImpl(new SYSCOLUMNSRowFactory(luuidFactory, exFactory, dvf, convertIdToLower)); 7410 lcoreInfo[SYSCONGLOMERATES_CORE_NUM] = 7411 new TabInfoImpl(new SYSCONGLOMERATESRowFactory(luuidFactory, exFactory, dvf, convertIdToLower)); 7412 lcoreInfo[SYSSCHEMAS_CORE_NUM] = 7413 new TabInfoImpl(new SYSSCHEMASRowFactory(luuidFactory, exFactory, dvf, convertIdToLower)); 7414 } 7415 7416 7419 private void initializeNoncoreInfo() 7420 throws StandardException 7421 { 7422 noncoreInfo = new TabInfoImpl[NUM_NONCORE]; 7423 } 7424 7425 7436 public TransactionController getTransactionCompile() 7437 throws StandardException 7438 { 7439 if (bootingTC != null) 7440 { 7441 if (SanityManager.DEBUG) 7442 { 7443 SanityManager.ASSERT(booting, "booting is expected to be true"); 7444 } 7445 return bootingTC; 7446 } 7447 else 7448 { 7449 if (SanityManager.DEBUG) 7450 { 7451 SanityManager.ASSERT(! booting, "booting is expected to be false"); 7452 } 7453 { 7454 LanguageConnectionContext lcc = getLCC(); 7455 return lcc.getTransactionCompile(); 7456 } 7457 } 7458 } 7459 7460 7461 7472 public TransactionController getTransactionExecute() 7473 throws StandardException 7474 { 7475 if (bootingTC != null) 7476 { 7477 if (SanityManager.DEBUG) 7478 { 7479 SanityManager.ASSERT(booting, "booting is expected to be true"); 7480 } 7481 return bootingTC; 7482 } 7483 else 7484 { 7485 if (SanityManager.DEBUG) 7486 { 7487 SanityManager.ASSERT(! booting, "booting is expected to be false"); 7488 } 7489 { 7490 LanguageConnectionContext lcc = getLCC(); 7491 return lcc.getTransactionExecute(); 7492 } 7493 } 7494 } 7495 7496 7512 private final TupleDescriptor getDescriptorViaIndex( 7513 int indexId, 7514 ExecIndexRow keyRow, 7515 ScanQualifier [][] scanQualifiers, 7516 TabInfoImpl ti, 7517 TupleDescriptor parentTupleDescriptor, 7518 List list, 7519 boolean forUpdate) 7520 throws StandardException 7521 { 7522 CatalogRowFactory rf = ti.getCatalogRowFactory(); 7523 ConglomerateController heapCC; 7524 ExecIndexRow indexRow1; 7525 ExecIndexRow indexTemplateRow; 7526 ExecRow outRow; 7527 RowLocation baseRowLocation; 7528 ScanController scanController; 7529 TransactionController tc; 7530 TupleDescriptor td = null; 7531 7532 tc = getTransactionCompile(); 7534 7535 outRow = rf.makeEmptyRow(); 7536 7537 heapCC = tc.openConglomerate( 7538 ti.getHeapConglomerate(), false, 0, 7539 TransactionController.MODE_RECORD, 7540 TransactionController.ISOLATION_REPEATABLE_READ); 7541 7542 7545 scanController = tc.openScan( 7546 ti.getIndexConglomerate(indexId), false, (forUpdate) ? TransactionController.OPENMODE_FORUPDATE : 0, 7549 TransactionController.MODE_RECORD, 7550 TransactionController.ISOLATION_REPEATABLE_READ, 7551 (FormatableBitSet) null, keyRow.getRowArray(), ScanController.GE, scanQualifiers, keyRow.getRowArray(), ScanController.GT); 7558 while (scanController.next()) 7559 { 7560 indexRow1 = getIndexRowFromHeapRow( 7562 ti.getIndexRowGenerator(indexId), 7563 heapCC.newRowLocationTemplate(), 7564 outRow); 7565 7566 scanController.fetch(indexRow1.getRowArray()); 7567 7568 baseRowLocation = (RowLocation) indexRow1.getColumn( 7569 indexRow1.nColumns()); 7570 7571 7575 boolean base_row_exists = false; 7576 try 7577 { 7578 base_row_exists = 7579 heapCC.fetch( 7580 baseRowLocation, outRow.getRowArray(), (FormatableBitSet) null); 7581 } 7582 catch (RuntimeException re) 7583 { 7584 if (SanityManager.DEBUG) 7585 { 7586 if (re instanceof AssertFailure) 7587 { 7588 StringBuffer strbuf = new StringBuffer ("Error retrieving base row in table "+ti.getTableName()); 7589 strbuf.append(": An ASSERT was thrown when trying to locate a row matching index row "+indexRow1+" from index "+ti.getIndexName(indexId)+", conglom number "+ti.getIndexConglomerate(indexId)); 7590 debugGenerateInfo(strbuf,tc,heapCC,ti,indexId); 7591 } 7592 } 7593 throw re; 7594 } 7595 catch (StandardException se) 7596 { 7597 if (SanityManager.DEBUG) 7598 { 7599 if (se.getSQLState().equals("XSRS9")) 7603 { 7604 StringBuffer strbuf = new StringBuffer ("Error retrieving base row in table "+ti.getTableName()); 7605 strbuf.append(": A StandardException was thrown when trying to locate a row matching index row "+indexRow1+" from index "+ti.getIndexName(indexId)+", conglom number "+ti.getIndexConglomerate(indexId)); 7606 debugGenerateInfo(strbuf,tc,heapCC,ti,indexId); 7607 } 7608 } 7609 throw se; 7610 } 7611 7612 if (SanityManager.DEBUG) 7613 { 7614 if (! base_row_exists) 7617 { 7618 StringBuffer strbuf = new StringBuffer ("Error retrieving base row in table "+ti.getTableName()); 7619 strbuf.append(": could not locate a row matching index row "+indexRow1+" from index "+ti.getIndexName(indexId)+", conglom number "+ti.getIndexConglomerate(indexId)); 7620 debugGenerateInfo(strbuf,tc,heapCC,ti,indexId); 7621 System.exit(1); 7624 7625 } 7628 } 7629 7630 td = rf.buildDescriptor(outRow, parentTupleDescriptor, this); 7631 7632 7635 if (list == null) 7636 { 7637 break; 7638 } 7639 else 7640 { 7641 list.add(td); 7642 } 7643 } 7644 scanController.close(); 7645 heapCC.close(); 7646 return td; 7647 } 7648 7649 7650 private void debugGenerateInfo(StringBuffer strbuf, 7651 TransactionController tc, ConglomerateController heapCC, TabInfoImpl ti, 7652 int indexId) 7653 { 7654 if (SanityManager.DEBUG) { 7655 try 7656 { 7657 strbuf.append("\nadditional information: "); 7658 7659 LanguageConnectionContext lcc = (LanguageConnectionContext) 7662 ContextService.getContext(LanguageConnectionContext.CONTEXT_ID); 7663 if (lcc != null) 7664 { 7665 long currentTime = System.currentTimeMillis(); 7666 Enumeration lockTable = lockFactory.makeVirtualLockTable(); 7668 String lockTableString = Timeout.buildString(lockTable,currentTime); 7669 strbuf.append("lock table at time of failure\n\n"); 7670 strbuf.append(lockTableString); 7671 } 7673 7674 ConglomerateController btreeCC = 7676 tc.openConglomerate( 7677 ti.getIndexConglomerate(indexId), 7678 false, 7679 0, TransactionController.MODE_RECORD, 7680 TransactionController.ISOLATION_REPEATABLE_READ); 7681 7682 btreeCC.debugConglomerate(); 7683 heapCC.debugConglomerate(); 7684 heapCC.checkConsistency(); 7685 strbuf.append("\nheapCC.checkConsistency() = true"); 7686 ConglomerateController indexCC = tc.openConglomerate( 7687 ti.getIndexConglomerate(indexId), 7688 false, 7689 0, 7690 TransactionController.MODE_TABLE, 7691 TransactionController.ISOLATION_REPEATABLE_READ); 7692 indexCC.checkConsistency(); 7693 strbuf.append("\nindexCC.checkConsistency() = true"); 7694 7695 System.err.println("ASSERT FAILURE: "+strbuf.toString()); 7696 System.out.println("ASSERT FAILURE: "+strbuf.toString()); 7697 SanityManager.DEBUG_PRINT("ASSERT FAILURE", strbuf.toString()); 7698 } 7699 catch (StandardException se) 7700 { 7701 strbuf.append("\ngot the following error when doing extra consistency checks:\n"+se.toString()); 7702 } 7703 } 7704 } 7705 7706 7707 7708 7722 protected TupleDescriptor getDescriptorViaHeap( 7723 ScanQualifier [][] scanQualifiers, 7724 TabInfoImpl ti, 7725 TupleDescriptor parentTupleDescriptor, 7726 List list) 7727 throws StandardException 7728 { 7729 CatalogRowFactory rf = ti.getCatalogRowFactory(); 7730 ConglomerateController heapCC; 7731 ExecRow outRow; 7732 ScanController scanController; 7733 TransactionController tc; 7734 TupleDescriptor td = null; 7735 7736 tc = getTransactionCompile(); 7738 7739 outRow = rf.makeEmptyRow(); 7740 7741 7744 scanController = tc.openScan( 7745 ti.getHeapConglomerate(), false, 0, TransactionController.MODE_TABLE, 7749 TransactionController.ISOLATION_REPEATABLE_READ, 7750 (FormatableBitSet) null, (DataValueDescriptor[]) null, 0, scanQualifiers, (DataValueDescriptor[]) null, 0); 7757 while (scanController.fetchNext(outRow.getRowArray())) 7758 { 7759 td = rf.buildDescriptor(outRow, parentTupleDescriptor, this); 7760 7761 7764 if (list == null) 7765 { 7766 break; 7767 } 7768 else 7769 { 7770 list.add(td); 7771 } 7772 } 7773 scanController.close(); 7774 return td; 7775 } 7776 7777 7785 private TabInfoImpl getNonCoreTI(int catalogNumber) 7786 throws StandardException 7787 { 7788 TabInfoImpl ti = getNonCoreTIByNumber(catalogNumber); 7789 7790 faultInTabInfo( ti ); 7791 7792 return ti; 7793 } 7794 7795 7798 protected TabInfoImpl getNonCoreTIByNumber(int catalogNumber) 7799 throws StandardException 7800 { 7801 int nonCoreNum = catalogNumber - NUM_CORE; 7802 7803 7806 TabInfoImpl retval = noncoreInfo[nonCoreNum]; 7807 7808 if (retval == null) 7809 { 7810 UUIDFactory luuidFactory = uuidFactory; 7817 7818 switch (catalogNumber) 7819 { 7820 case SYSCONSTRAINTS_CATALOG_NUM: 7821 retval = new TabInfoImpl(new SYSCONSTRAINTSRowFactory( 7822 luuidFactory, exFactory, dvf, convertIdToLower)); 7823 break; 7824 7825 case SYSKEYS_CATALOG_NUM: 7826 retval = new TabInfoImpl(new SYSKEYSRowFactory( 7827 luuidFactory, exFactory, dvf, convertIdToLower)); 7828 break; 7829 7830 case SYSDEPENDS_CATALOG_NUM: 7831 retval = new TabInfoImpl(new SYSDEPENDSRowFactory( 7832 luuidFactory, exFactory, dvf, convertIdToLower)); 7833 break; 7834 7835 case SYSVIEWS_CATALOG_NUM: 7836 retval = new TabInfoImpl(new SYSVIEWSRowFactory( 7837 luuidFactory, exFactory, dvf, convertIdToLower)); 7838 break; 7839 7840 case SYSCHECKS_CATALOG_NUM: 7841 retval = new TabInfoImpl(new SYSCHECKSRowFactory( 7842 luuidFactory, exFactory, dvf, convertIdToLower)); 7843 break; 7844 7845 case SYSFOREIGNKEYS_CATALOG_NUM: 7846 retval = new TabInfoImpl(new SYSFOREIGNKEYSRowFactory( 7847 luuidFactory, exFactory, dvf, convertIdToLower)); 7848 break; 7849 7850 case SYSSTATEMENTS_CATALOG_NUM: 7851 retval = new TabInfoImpl(new SYSSTATEMENTSRowFactory( 7852 luuidFactory, exFactory, dvf, convertIdToLower)); 7853 break; 7854 7855 case SYSFILES_CATALOG_NUM: 7856 retval = new TabInfoImpl(new SYSFILESRowFactory( 7857 luuidFactory, exFactory, dvf, convertIdToLower)); 7858 break; 7859 7860 case SYSALIASES_CATALOG_NUM: 7861 retval = new TabInfoImpl(new SYSALIASESRowFactory( 7862 luuidFactory, exFactory, dvf, convertIdToLower)); 7863 break; 7864 7865 case SYSTRIGGERS_CATALOG_NUM: 7866 retval = new TabInfoImpl(new SYSTRIGGERSRowFactory( 7867 luuidFactory, exFactory, dvf, convertIdToLower)); 7868 break; 7869 7870 case SYSSTATISTICS_CATALOG_NUM: 7871 retval = new TabInfoImpl(new SYSSTATISTICSRowFactory( 7872 luuidFactory, exFactory, dvf, convertIdToLower)); 7873 break; 7874 7875 case SYSDUMMY1_CATALOG_NUM: 7876 retval = new TabInfoImpl(new SYSDUMMY1RowFactory( 7877 luuidFactory, exFactory, dvf, convertIdToLower)); 7878 break; 7879 7880 case SYSTABLEPERMS_CATALOG_NUM: 7881 retval = new TabInfoImpl(new SYSTABLEPERMSRowFactory( 7882 luuidFactory, exFactory, dvf, convertIdToLower)); 7883 break; 7884 7885 case SYSCOLPERMS_CATALOG_NUM: 7886 retval = new TabInfoImpl(new SYSCOLPERMSRowFactory( 7887 luuidFactory, exFactory, dvf, convertIdToLower)); 7888 break; 7889 7890 case SYSROUTINEPERMS_CATALOG_NUM: 7891 retval = new TabInfoImpl(new SYSROUTINEPERMSRowFactory( 7892 luuidFactory, exFactory, dvf, convertIdToLower)); 7893 break; 7894 } 7895 7896 initSystemIndexVariables(retval); 7897 7898 noncoreInfo[nonCoreNum] = retval; 7899 } 7900 7901 return retval; 7902 } 7903 7904 protected void initSystemIndexVariables(TabInfoImpl ti) 7905 throws StandardException 7906 { 7907 int numIndexes = ti.getNumberOfIndexes(); 7908 7909 if (numIndexes > 0) 7910 { 7911 DataDescriptorGenerator ddg = getDataDescriptorGenerator(); 7912 7913 for (int indexCtr = 0; indexCtr < numIndexes; indexCtr++) 7914 { 7915 initSystemIndexVariables(ddg, ti, indexCtr); 7916 } 7917 } 7918 } 7919 7920 private void clearNoncoreTable(int nonCoreNum) 7922 { 7923 noncoreInfo[nonCoreNum] = null; 7924 } 7925 7926 7934 public void faultInTabInfo( TabInfoImpl ti ) 7935 throws StandardException 7936 { 7937 int numIndexes; 7938 7939 7947 if (ti.isComplete()) 7948 { 7949 return; 7950 } 7951 7952 7957 synchronized(ti) 7958 { 7959 7964 if (ti.isComplete()) 7965 { 7966 return; 7967 } 7968 7969 TableDescriptor td = getTableDescriptor(ti.getTableName(), 7970 getSystemSchemaDescriptor()); 7971 7972 if (td == null) 7979 { 7980 return; 7981 } 7982 7983 ConglomerateDescriptor cd = null; 7984 ConglomerateDescriptor[] cds = td.getConglomerateDescriptors(); 7985 7986 7987 for (int index = 0; index < cds.length; index++) 7988 { 7989 cd = cds[index]; 7990 7991 if (! cd.isIndex()) 7992 { 7993 ti.setHeapConglomerate(cd.getConglomerateNumber()); 7994 break; 7995 } 7996 } 7997 7998 if (SanityManager.DEBUG) 7999 { 8000 if (cd == null) 8001 { 8002 SanityManager.THROWASSERT("No heap conglomerate found for " 8003 + ti.getTableName()); 8004 } 8005 } 8006 8007 8008 numIndexes = ti.getCatalogRowFactory().getNumIndexes(); 8009 if (numIndexes == 0) 8010 { 8011 return; 8012 } 8013 8014 8015 ConglomerateDescriptor icd = null; 8016 int indexCount = 0; 8017 8018 for (int index = 0; index < cds.length; index++) 8019 { 8020 icd = cds[index]; 8021 8022 if (icd.isIndex()) 8023 { 8024 ti.setIndexConglomerate(icd); 8025 indexCount++; 8026 } 8027 continue; 8028 } 8029 8030 if (SanityManager.DEBUG) 8031 { 8032 if (indexCount != ti.getCatalogRowFactory().getNumIndexes()) 8033 { 8034 SanityManager.THROWASSERT("Number of indexes found (" + indexCount + 8035 ") does not match the number expected (" + 8036 ti.getCatalogRowFactory().getNumIndexes() + ")"); 8037 } 8038 } 8039 } 8040 } 8041 8042 8043 8054 public static ExecIndexRow getIndexRowFromHeapRow(IndexRowGenerator irg, 8055 RowLocation rl, 8056 ExecRow heapRow) 8057 throws StandardException 8058 { 8059 ExecIndexRow indexRow; 8060 8061 indexRow = irg.getIndexRowTemplate(); 8062 irg.getIndexRow(heapRow, rl, indexRow, (FormatableBitSet) null); 8064 8065 return indexRow; 8066 } 8067 8068 public int getEngineType() 8069 { 8070 return engineType; 8071 } 8072 8073 8074 8080 public long getSYSCOLUMNSHeapConglomerateNumber() 8081 { 8082 return coreInfo[SYSCOLUMNS_CORE_NUM].getHeapConglomerate(); 8083 } 8084 8085 void addSYSCOLUMNSIndex2Property(TransactionController tc, long index2ConglomerateNumber) 8086 { 8087 startupParameters.put(CFG_SYSCOLUMNS_INDEX2_ID, 8088 Long.toString(index2ConglomerateNumber)); 8089 } 8090 8091 8093 private long getBootParameter(Properties startParams, String key, boolean required) 8094 throws StandardException { 8095 8096 String value = startParams.getProperty(key); 8097 if (value == null) 8098 { 8099 if (! required) 8100 { 8101 return -1; 8102 } 8103 throw StandardException.newException(SQLState.PROPERTY_MISSING, key); 8104 } 8105 8106 try { 8107 return Long.parseLong(value); 8108 } catch (NumberFormatException nfe) { 8109 throw StandardException.newException(SQLState.PROPERTY_INVALID_VALUE, key, value); 8110 } 8111 } 8112 8113 8150 public String getSystemSQLName() 8151 { 8152 StringBuffer generatedSystemSQLName = new StringBuffer ("SQL"); 8157 synchronized (this) { 8158 long timeNow = (System.currentTimeMillis()/10L)*10L; 8160 8161 if (timeNow > timeForLastSystemSQLName) { 8164 systemSQLNameNumber = 0; 8165 calendarForLastSystemSQLName.setTime(new Date (timeNow)); 8166 timeForLastSystemSQLName = timeNow; 8167 } else { 8168 8172 systemSQLNameNumber++; 8174 if (systemSQLNameNumber == 10) { systemSQLNameNumber = 0; 8177 timeForLastSystemSQLName = timeForLastSystemSQLName + 10L; 8178 calendarForLastSystemSQLName.setTime(new Date (timeForLastSystemSQLName)); 8180 } 8181 } 8182 8183 generatedSystemSQLName.append(twoDigits(calendarForLastSystemSQLName.get(Calendar.YEAR))); 8184 generatedSystemSQLName.append(twoDigits(calendarForLastSystemSQLName.get(Calendar.MONTH)+1)); 8186 generatedSystemSQLName.append(twoDigits(calendarForLastSystemSQLName.get(Calendar.DAY_OF_MONTH))); 8187 generatedSystemSQLName.append(twoDigits(calendarForLastSystemSQLName.get(Calendar.HOUR))); 8188 generatedSystemSQLName.append(twoDigits(calendarForLastSystemSQLName.get(Calendar.MINUTE))); 8189 generatedSystemSQLName.append(twoDigits(calendarForLastSystemSQLName.get(Calendar.SECOND))); 8190 generatedSystemSQLName.append(twoDigits((int) (calendarForLastSystemSQLName.get(Calendar.MILLISECOND)/10))); 8192 generatedSystemSQLName.append(systemSQLNameNumber); 8193 } 8194 return generatedSystemSQLName.toString(); 8195 } 8196 8197 private static String twoDigits(int val) { 8198 String retval; 8199 8200 if (val < 10) { 8201 retval = "0" + val; 8202 } else { 8203 int retvalLength = Integer.toString(val).length(); 8204 retval = Integer.toString(val).substring(retvalLength-2); 8205 } 8206 8207 return retval; 8208 } 8209 8210 8220 public void setAutoincrementValue(TransactionController tc, 8221 UUID tableUUID, 8222 String columnName, 8223 long aiValue, boolean incrementNeeded) 8224 throws StandardException 8225 { 8226 TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM]; 8227 ExecIndexRow keyRow = null; 8228 8229 keyRow = (ExecIndexRow)exFactory.getIndexableRow(2); 8230 keyRow.setColumn(1, dvf.getCharDataValue(tableUUID.toString())); 8231 keyRow.setColumn(2, dvf.getCharDataValue(columnName)); 8232 8233 SYSCOLUMNSRowFactory rf = (SYSCOLUMNSRowFactory) ti.getCatalogRowFactory(); 8234 ExecRow row = rf.makeEmptyRow(); 8235 8236 boolean[] bArray = new boolean[2]; 8237 for (int index = 0; index < 2; index++) 8238 { 8239 bArray[index] = false; 8240 } 8241 8242 int[] colsToUpdate = new int[1]; 8243 8244 colsToUpdate[0] = SYSCOLUMNSRowFactory.SYSCOLUMNS_AUTOINCREMENTVALUE; 8245 8246 if (incrementNeeded) 8247 { 8248 ExecRow readRow = ti.getRow(tc, keyRow, 8249 SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID); 8250 NumberDataValue increment = 8251 (NumberDataValue)readRow.getColumn(SYSCOLUMNSRowFactory.SYSCOLUMNS_AUTOINCREMENTINC); 8252 aiValue += increment.getLong(); 8253 } 8254 row.setColumn(SYSCOLUMNSRowFactory.SYSCOLUMNS_AUTOINCREMENTVALUE, 8255 dvf.getDataValue(aiValue)); 8256 8257 ti.updateRow(keyRow, row, 8258 SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID, 8259 bArray, 8260 colsToUpdate, 8261 tc); 8262 return; 8263 } 8264 8265 8275 private RowLocation computeRowLocation(TransactionController tc, 8276 TableDescriptor td, 8277 String columnName) 8278 throws StandardException 8279 { 8280 TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM]; 8281 ExecIndexRow keyRow = null; 8282 ExecRow row; 8283 UUID tableUUID = td.getUUID(); 8284 8285 keyRow = (ExecIndexRow)exFactory.getIndexableRow(2); 8286 keyRow.setColumn(1, dvf.getCharDataValue(tableUUID.toString())); 8287 keyRow.setColumn(2, dvf.getCharDataValue(columnName)); 8288 return ti.getRowLocation(tc, keyRow, 8289 SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID); 8290 } 8291 8292 public RowLocation getRowLocationTemplate(LanguageConnectionContext lcc, 8293 TableDescriptor td) 8294 throws StandardException 8295 { 8296 RowLocation rl; 8297 ConglomerateController heapCC = null; 8298 8299 TransactionController tc = 8300 lcc.getTransactionCompile(); 8301 8302 long tableId = td.getHeapConglomerateId(); 8303 heapCC = 8304 tc.openConglomerate( 8305 tableId, false, 0, tc.MODE_RECORD, tc.ISOLATION_READ_COMMITTED); 8306 try 8307 { 8308 rl = heapCC.newRowLocationTemplate(); 8309 } 8310 finally 8311 { 8312 heapCC.close(); 8313 } 8314 8315 return rl; 8316 } 8317 8318 8328 public void addTableDescriptorToOtherCache(TableDescriptor td, 8329 Cacheable c) 8330 throws StandardException 8331 { 8332 CacheManager otherCache = 8335 (c instanceof OIDTDCacheable) ? nameTdCache : OIDTdCache; 8336 Object key; 8337 TDCacheable otherCacheEntry = null; 8338 8339 if (otherCache == nameTdCache) 8340 key = new TableKey(td.getSchemaDescriptor().getUUID(), td.getName()); 8341 else 8342 key = td.getUUID(); 8343 8344 try 8345 { 8346 otherCacheEntry = (TDCacheable)otherCache.create(key, td); 8348 } 8349 catch (StandardException se) 8350 { 8351 if (!(se.getMessageId().equals(SQLState.OBJECT_EXISTS_IN_CACHE))) 8354 throw se; 8355 } 8356 finally 8357 { 8358 if (otherCacheEntry != null) 8359 otherCache.release(otherCacheEntry); 8360 } 8361 } 8362 8363 8364 8365 public void dropStatisticsDescriptors(UUID tableUUID, UUID referenceUUID, 8366 TransactionController tc) 8367 throws StandardException 8368 { 8369 TabInfoImpl ti = getNonCoreTI(SYSSTATISTICS_CATALOG_NUM); 8370 DataValueDescriptor first, second; 8371 first = dvf.getCharDataValue(tableUUID.toString()); 8372 8373 ExecIndexRow keyRow; 8374 if (referenceUUID != null) 8375 { 8376 keyRow = exFactory.getIndexableRow(2); 8377 second = dvf.getCharDataValue(referenceUUID.toString()); 8378 keyRow.setColumn(2, second); 8379 } 8380 else 8381 { 8382 keyRow = exFactory.getIndexableRow(1); 8383 } 8384 8385 keyRow.setColumn(1, first); 8386 8387 ti.deleteRow(tc, keyRow, 8388 SYSSTATISTICSRowFactory.SYSSTATISTICS_INDEX1_ID); 8389 8390 } 8391 8392 private static LanguageConnectionContext getLCC() { 8393 return (LanguageConnectionContext) 8394 ContextService.getContextOrNull(LanguageConnectionContext.CONTEXT_ID); 8395 } 8396 8397 private SchemaDescriptor newSystemSchemaDesc( 8398 String name, 8399 String uuid) 8400 { 8401 return new SchemaDescriptor( 8402 this, 8403 name, 8404 authorizationDatabaseOwner, 8405 uuidFactory.recreateUUID(uuid), 8406 true); 8407 } 8408 8409 private SchemaDescriptor newDeclaredGlobalTemporaryTablesSchemaDesc( String name) 8410 { 8411 return new SchemaDescriptor(this, 8412 name, 8413 authorizationDatabaseOwner, 8414 (UUID) null, 8415 false); 8416 } 8417 8426 public boolean checkVersion(int requiredMajorVersion, String feature) throws StandardException { 8427 8428 if (requiredMajorVersion == DataDictionary.DD_VERSION_CURRENT) { 8429 requiredMajorVersion = softwareVersion.majorVersionNumber; 8430 } 8431 8432 return dictionaryVersion.checkVersion(requiredMajorVersion, feature); 8433 } 8434 8435 8438 void createSystemSps(TransactionController tc) 8439 throws StandardException 8440 { 8441 createSPSSet(tc, false, getSystemSchemaDescriptor().getUUID()); 8443 8444 createSPSSet(tc, true, getSysIBMSchemaDescriptor().getUUID()); 8446 } 8447 8448 8452 protected void createSPSSet(TransactionController tc, boolean net, UUID schemaID) 8453 throws StandardException 8454 { 8455 Properties p = getQueryDescriptions(net); 8456 Enumeration e = p.keys(); 8457 boolean nocompile = true; 8460 8461 while (e.hasMoreElements()) 8462 { 8463 String spsName = (String )e.nextElement(); 8464 String spsText = p.getProperty(spsName); 8465 SPSDescriptor spsd = new SPSDescriptor(this, spsName, 8466 getUUIDFactory().createUUID(), 8467 schemaID, 8468 schemaID, 8469 SPSDescriptor.SPS_TYPE_REGULAR, 8470 !nocompile, spsText, !nocompile ); 8473 8474 addSPSDescriptor(spsd, tc, true); 8475 } 8476 } 8477 8478 8479 8508 private final UUID createSystemProcedureOrFunction( 8509 String routine_name, 8510 UUID schema_uuid, 8511 String [] arg_names, 8512 TypeDescriptor[] arg_types, 8513 int num_out_param, 8514 int num_result_sets, 8515 short routine_sql_control, 8516 TypeDescriptor return_type, 8517 TransactionController tc) 8518 throws StandardException 8519 { 8520 int num_args = 0; 8521 if (arg_names != null) 8522 num_args = arg_names.length; 8523 8524 if (SanityManager.DEBUG) 8525 { 8526 if (num_args != 0) 8527 { 8528 SanityManager.ASSERT(arg_names != null); 8529 SanityManager.ASSERT(arg_types != null); 8530 SanityManager.ASSERT(arg_names.length == arg_types.length); 8531 } 8532 } 8533 8534 String procClass = "org.apache.derby.catalog.SystemProcedures"; 8536 8537 int[] arg_modes = null; 8539 if (num_args != 0) 8540 { 8541 arg_modes = new int[num_args]; 8542 int num_in_param = num_args - num_out_param; 8543 for (int i = 0; i < num_in_param; i++) 8544 arg_modes[i] = JDBC30Translation.PARAMETER_MODE_IN; 8545 for (int i = 0; i < num_out_param; i++) 8546 arg_modes[num_in_param + i] = JDBC30Translation.PARAMETER_MODE_OUT; 8547 } 8548 8549 RoutineAliasInfo routine_alias_info = 8550 new RoutineAliasInfo( 8551 routine_name, num_args, arg_names, arg_types, arg_modes, num_result_sets, RoutineAliasInfo.PS_JAVA, routine_sql_control, true, return_type); 8565 8566 UUID routine_uuid = getUUIDFactory().createUUID(); 8567 AliasDescriptor ads = 8568 new AliasDescriptor( 8569 this, 8570 routine_uuid, 8571 routine_name, 8572 schema_uuid, 8573 procClass, 8574 (return_type == null) ? 8575 AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR : 8576 AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR, 8577 (return_type == null) ? 8578 AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR : 8579 AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR, 8580 false, 8581 routine_alias_info, null); 8582 8583 addDescriptor( 8584 ads, null, DataDictionary.SYSALIASES_CATALOG_NUM, false, tc); 8585 8586 return routine_uuid; 8587 } 8588 8589 8602 private final void create_SYSCS_procedures( 8603 TransactionController tc) 8604 throws StandardException 8605 { 8606 8609 8610 UUID routine_uuid = null; 8611 UUID sysUtilUUID = getSystemUtilSchemaDescriptor().getUUID(); 8613 8614 8615 { 8618 8619 String [] arg_names = { 8621 "KEY", 8622 "VALUE"}; 8623 8624 TypeDescriptor[] arg_types = { 8626 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8627 Types.VARCHAR, 128), 8628 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8629 Types.VARCHAR, Limits.DB2_VARCHAR_MAXWIDTH) 8630 }; 8631 8632 createSystemProcedureOrFunction( 8633 "SYSCS_SET_DATABASE_PROPERTY", 8634 sysUtilUUID, 8635 arg_names, 8636 arg_types, 8637 0, 8638 0, 8639 RoutineAliasInfo.MODIFIES_SQL_DATA, 8640 (TypeDescriptor) null, 8641 tc); 8642 } 8643 8644 8645 { 8647 String [] arg_names = {"SCHEMANAME", "TABLENAME", "SEQUENTIAL"}; 8649 8650 TypeDescriptor[] arg_types = { 8652 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8653 Types.VARCHAR, 128), 8654 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8655 Types.VARCHAR, 128), 8656 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8657 Types.SMALLINT) 8658 8659 }; 8660 8661 routine_uuid = createSystemProcedureOrFunction( 8662 "SYSCS_COMPRESS_TABLE", 8663 sysUtilUUID, 8664 arg_names, 8665 arg_types, 8666 0, 8667 0, 8668 RoutineAliasInfo.MODIFIES_SQL_DATA, 8669 (TypeDescriptor) null, 8670 tc); 8671 8672 createRoutinePermPublicDescriptor(routine_uuid, tc); 8673 } 8674 8675 { 8677 createSystemProcedureOrFunction( 8678 "SYSCS_CHECKPOINT_DATABASE", 8679 sysUtilUUID, 8680 null, 8681 null, 8682 0, 8683 0, 8684 RoutineAliasInfo.CONTAINS_SQL, 8685 (TypeDescriptor) null, 8686 tc); 8687 } 8688 8689 { 8691 createSystemProcedureOrFunction( 8692 "SYSCS_FREEZE_DATABASE", 8693 sysUtilUUID, 8694 null, 8695 null, 8696 0, 8697 0, 8698 RoutineAliasInfo.CONTAINS_SQL, 8699 (TypeDescriptor) null, 8700 tc); 8701 } 8702 8703 { 8705 createSystemProcedureOrFunction( 8706 "SYSCS_UNFREEZE_DATABASE", 8707 sysUtilUUID, 8708 null, 8709 null, 8710 0, 8711 0, 8712 RoutineAliasInfo.CONTAINS_SQL, 8713 (TypeDescriptor) null, 8714 tc); 8715 } 8716 8717 { 8719 String [] arg_names = {"BACKUPDIR"}; 8721 8722 TypeDescriptor[] arg_types = { 8724 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8725 Types.VARCHAR, Limits.DB2_VARCHAR_MAXWIDTH) 8726 }; 8727 8728 createSystemProcedureOrFunction( 8729 "SYSCS_BACKUP_DATABASE", 8730 sysUtilUUID, 8731 arg_names, 8732 arg_types, 8733 0, 8734 0, 8735 RoutineAliasInfo.MODIFIES_SQL_DATA, 8736 (TypeDescriptor) null, 8737 tc); 8738 } 8739 8740 { 8743 String [] arg_names = {"BACKUPDIR", "DELETE_ARCHIVED_LOG_FILES"}; 8745 8746 TypeDescriptor[] arg_types = { 8748 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8749 Types.VARCHAR, Limits.DB2_VARCHAR_MAXWIDTH), 8750 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8751 Types.SMALLINT) 8752 }; 8753 8754 createSystemProcedureOrFunction( 8755 "SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE", 8756 sysUtilUUID, 8757 arg_names, 8758 arg_types, 8759 0, 8760 0, 8761 RoutineAliasInfo.MODIFIES_SQL_DATA, 8762 (TypeDescriptor) null, 8763 tc); 8764 } 8765 8766 { 8768 String [] arg_names = {"DELETE_ARCHIVED_LOG_FILES"}; 8770 8771 TypeDescriptor[] arg_types = { 8773 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8774 Types.SMALLINT) 8775 }; 8776 8777 createSystemProcedureOrFunction( 8778 "SYSCS_DISABLE_LOG_ARCHIVE_MODE", 8779 sysUtilUUID, 8780 arg_names, 8781 arg_types, 8782 0, 8783 0, 8784 RoutineAliasInfo.MODIFIES_SQL_DATA, 8785 (TypeDescriptor) null, 8786 tc); 8787 } 8788 8789 { 8791 String [] arg_names = {"ENABLE"}; 8793 8794 TypeDescriptor[] arg_types = { 8796 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8797 Types.SMALLINT) 8798 }; 8799 8800 routine_uuid = createSystemProcedureOrFunction( 8801 "SYSCS_SET_RUNTIMESTATISTICS", 8802 sysUtilUUID, 8803 arg_names, 8804 arg_types, 8805 0, 8806 0, 8807 RoutineAliasInfo.CONTAINS_SQL, 8808 (TypeDescriptor) null, 8809 tc); 8810 8811 createRoutinePermPublicDescriptor(routine_uuid, tc); 8812 } 8813 8814 { 8816 String [] arg_names = {"ENABLE"}; 8818 8819 TypeDescriptor[] arg_types = { 8821 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8822 Types.SMALLINT) 8823 }; 8824 8825 routine_uuid = createSystemProcedureOrFunction( 8826 "SYSCS_SET_STATISTICS_TIMING", 8827 sysUtilUUID, 8828 arg_names, 8829 arg_types, 8830 0, 8831 0, 8832 RoutineAliasInfo.CONTAINS_SQL, 8833 (TypeDescriptor) null, 8834 tc); 8835 8836 createRoutinePermPublicDescriptor(routine_uuid, tc); 8837 } 8838 8839 8840 8846 8849 { 8850 String [] arg_names = {"KEY"}; 8852 8853 TypeDescriptor[] arg_types = { 8855 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8856 Types.VARCHAR, 128) 8857 }; 8858 8859 createSystemProcedureOrFunction( 8860 "SYSCS_GET_DATABASE_PROPERTY", 8861 sysUtilUUID, 8862 arg_names, 8863 arg_types, 8864 0, 8865 0, 8866 RoutineAliasInfo.READS_SQL_DATA, 8867 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8868 Types.VARCHAR, Limits.DB2_VARCHAR_MAXWIDTH), 8869 tc); 8870 } 8871 8872 { 8874 String [] arg_names = {"SCHEMANAME", "TABLENAME"}; 8876 8877 TypeDescriptor[] arg_types = { 8879 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8880 Types.VARCHAR, 128), 8881 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8882 Types.VARCHAR, 128) 8883 }; 8884 8885 createSystemProcedureOrFunction( 8886 "SYSCS_CHECK_TABLE", 8887 sysUtilUUID, 8888 arg_names, 8889 arg_types, 8890 0, 8891 0, 8892 RoutineAliasInfo.READS_SQL_DATA, 8893 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8894 Types.INTEGER), 8895 tc); 8896 } 8897 8898 { 8900 8901 routine_uuid = createSystemProcedureOrFunction( 8902 "SYSCS_GET_RUNTIMESTATISTICS", 8903 sysUtilUUID, 8904 null, 8905 null, 8906 0, 8907 0, 8908 RoutineAliasInfo.CONTAINS_SQL, 8909 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8910 Types.VARCHAR, Limits.DB2_VARCHAR_MAXWIDTH), 8911 8912 8918 tc); 8919 8920 createRoutinePermPublicDescriptor(routine_uuid, tc); 8921 } 8922 8923 8924 8927 8928 UUID sqlJUUID = 8929 getSchemaDescriptor( 8930 SchemaDescriptor.STD_SQLJ_SCHEMA_NAME, tc, true).getUUID(); 8931 8932 { 8934 String [] arg_names = {"URL", "JAR", "DEPLOY"}; 8935 8936 TypeDescriptor[] arg_types = { 8937 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8938 Types.VARCHAR, 256), 8939 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8940 Types.VARCHAR, 128), 8941 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8942 Types.INTEGER) 8943 }; 8944 8945 createSystemProcedureOrFunction( 8946 "INSTALL_JAR", 8947 sqlJUUID, 8948 arg_names, 8949 arg_types, 8950 0, 8951 0, 8952 RoutineAliasInfo.MODIFIES_SQL_DATA, 8953 (TypeDescriptor) null, 8954 tc); 8955 } 8956 8957 { 8959 String [] arg_names = {"URL", "JAR"}; 8960 8961 TypeDescriptor[] arg_types = { 8962 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8963 Types.VARCHAR, 256), 8964 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8965 Types.VARCHAR, 128) 8966 }; 8967 8968 createSystemProcedureOrFunction( 8969 "REPLACE_JAR", 8970 sqlJUUID, 8971 arg_names, 8972 arg_types, 8973 0, 8974 0, 8975 RoutineAliasInfo.MODIFIES_SQL_DATA, 8976 (TypeDescriptor) null, 8977 tc); 8978 } 8979 8980 { 8982 String [] arg_names = {"JAR", "UNDEPLOY"}; 8983 8984 TypeDescriptor[] arg_types = { 8985 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8986 Types.VARCHAR, 128), 8987 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 8988 Types.INTEGER) 8989 }; 8990 8991 createSystemProcedureOrFunction( 8992 "REMOVE_JAR", 8993 sqlJUUID, 8994 arg_names, 8995 arg_types, 8996 0, 8997 0, 8998 RoutineAliasInfo.MODIFIES_SQL_DATA, 8999 (TypeDescriptor) null, 9000 tc); 9001 } 9002 9003 9008 9009 9010 { 9011 String [] arg_names = {"schemaName", "tableName" , 9013 "fileName"," columnDelimiter", 9014 "characterDelimiter", "codeset"}; 9015 9016 TypeDescriptor[] arg_types = { 9018 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9019 Types.VARCHAR, 128), 9020 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9021 Types.VARCHAR, 128), 9022 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9023 Types.VARCHAR, 32672), 9024 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9025 Types.CHAR, 1), 9026 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9027 Types.CHAR, 1), 9028 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9029 Types.VARCHAR, 128) 9030 }; 9031 9032 createSystemProcedureOrFunction( 9033 "SYSCS_EXPORT_TABLE", 9034 sysUtilUUID, 9035 arg_names, 9036 arg_types, 9037 0, 9038 0, 9039 RoutineAliasInfo.READS_SQL_DATA, 9040 (TypeDescriptor) null, 9041 tc); 9042 } 9043 9044 9045 9050 { 9051 String [] arg_names = {"selectStatement", "fileName", 9053 " columnDelimiter", "characterDelimiter", 9054 "codeset"}; 9055 9056 TypeDescriptor[] arg_types = { 9058 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9059 Types.VARCHAR, 32672), 9060 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9061 Types.VARCHAR, 32672), 9062 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9063 Types.CHAR, 1), 9064 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9065 Types.CHAR, 1), 9066 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9067 Types.VARCHAR, 128) 9068 }; 9069 9070 createSystemProcedureOrFunction( 9071 "SYSCS_EXPORT_QUERY", 9072 sysUtilUUID, 9073 arg_names, 9074 arg_types, 9075 0, 9076 0, 9077 RoutineAliasInfo.READS_SQL_DATA, 9078 (TypeDescriptor) null, 9079 tc); 9080 } 9081 9082 9083 9088 { 9089 String [] arg_names = {"schemaName", "tableName", "fileName", 9091 " columnDelimiter", "characterDelimiter", 9092 "codeset", "replace"}; 9093 9094 9096 TypeDescriptor[] arg_types = { 9098 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9099 Types.VARCHAR, 128), 9100 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9101 Types.VARCHAR, 128), 9102 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9103 Types.VARCHAR, 32672), 9104 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9105 Types.CHAR, 1), 9106 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9107 Types.CHAR, 1), 9108 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9109 Types.VARCHAR, 128), 9110 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9111 Types.SMALLINT), 9112 }; 9113 9114 9115 createSystemProcedureOrFunction( 9116 "SYSCS_IMPORT_TABLE", 9117 sysUtilUUID, 9118 arg_names, 9119 arg_types, 9120 0, 9121 0, 9122 RoutineAliasInfo.MODIFIES_SQL_DATA, 9123 (TypeDescriptor) null, 9124 tc); 9125 } 9126 9127 9128 9134 { 9135 String [] arg_names = {"schemaName", "tableName", "insertColumnList","columnIndexes", 9137 "fileName", " columnDelimiter", "characterDelimiter", 9138 "codeset", "replace"}; 9139 9140 9142 TypeDescriptor[] arg_types = { 9144 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9145 Types.VARCHAR, 128), 9146 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9147 Types.VARCHAR, 128), 9148 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9149 Types.VARCHAR, 32672), 9150 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9151 Types.VARCHAR, 32672), 9152 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9153 Types.VARCHAR, 32672), 9154 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9155 Types.CHAR, 1), 9156 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9157 Types.CHAR, 1), 9158 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9159 Types.VARCHAR, 128), 9160 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9161 Types.SMALLINT), 9162 }; 9163 9164 9165 createSystemProcedureOrFunction( 9166 "SYSCS_IMPORT_DATA", 9167 sysUtilUUID, 9168 arg_names, 9169 arg_types, 9170 0, 9171 0, 9172 RoutineAliasInfo.MODIFIES_SQL_DATA, 9173 (TypeDescriptor) null, 9174 tc); 9175 } 9176 9177 9178 9185 { 9186 String [] arg_names = {"schemaName", "tableName", "vtiName","vtiArg"}; 9188 9189 9190 TypeDescriptor[] arg_types = { 9192 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9193 Types.VARCHAR, 128), 9194 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9195 Types.VARCHAR, 128), 9196 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9197 Types.VARCHAR, 32672), 9198 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9199 Types.VARCHAR, 32672), 9200 }; 9201 9202 9203 createSystemProcedureOrFunction( 9204 "SYSCS_BULK_INSERT", 9205 sysUtilUUID, 9206 arg_names, 9207 arg_types, 9208 0, 9209 0, 9210 RoutineAliasInfo.MODIFIES_SQL_DATA, 9211 (TypeDescriptor) null, 9212 tc); 9213 } 9214 9215 create_10_1_system_procedures(tc, sysUtilUUID); 9217 create_10_2_system_procedures(tc, sysUtilUUID); 9219 } 9220 9221 9234 protected final void create_SYSIBM_procedures( 9235 TransactionController tc) 9236 throws StandardException 9237 { 9238 9241 9242 UUID sysIBMUUID = getSysIBMSchemaDescriptor().getUUID(); 9244 9245 9246 { 9248 9249 String [] arg_names = { 9251 "SQLCODE", 9252 "SQLERRML", 9253 "SQLERRMC", 9254 "SQLERRP", 9255 "SQLERRD0", 9256 "SQLERRD1", 9257 "SQLERRD2", 9258 "SQLERRD3", 9259 "SQLERRD4", 9260 "SQLERRD5", 9261 "SQLWARN", 9262 "SQLSTATE", 9263 "FILE", 9264 "LOCALE", 9265 "MESSAGE", 9266 "RETURNCODE"}; 9267 9268 TypeDescriptor[] arg_types = { 9270 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER), 9271 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.SMALLINT), 9272 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9273 Types.VARCHAR, Limits.DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH), 9274 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 8), 9275 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER), 9276 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER), 9277 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER), 9278 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER), 9279 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER), 9280 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER), 9281 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 11), 9282 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 5), 9283 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 50), 9284 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 5), 9285 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 2400), 9286 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER) 9287 }; 9288 9289 createSystemProcedureOrFunction( 9290 "SQLCAMESSAGE", 9291 sysIBMUUID, 9292 arg_names, 9293 arg_types, 9294 2, 9295 0, 9296 RoutineAliasInfo.READS_SQL_DATA, 9297 (TypeDescriptor) null, 9298 tc); 9299 } 9300 9301 { 9303 9304 String [] arg_names = { 9306 "CATALOGNAME", 9307 "SCHEMANAME", 9308 "PROCNAME", 9309 "OPTIONS"}; 9310 9311 TypeDescriptor[] arg_types = { 9313 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9314 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9315 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9316 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9317 9318 createSystemProcedureOrFunction( 9319 "SQLPROCEDURES", 9320 sysIBMUUID, 9321 arg_names, 9322 arg_types, 9323 0, 9324 1, 9325 RoutineAliasInfo.READS_SQL_DATA, 9326 (TypeDescriptor) null, 9327 tc); 9328 } 9329 9330 { 9332 9333 String [] arg_names = { 9335 "CATALOGNAME", 9336 "SCHEMANAME", 9337 "TABLENAME", 9338 "OPTIONS"}; 9339 9340 TypeDescriptor[] arg_types = { 9342 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9343 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9344 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9345 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9346 9347 createSystemProcedureOrFunction( 9348 "SQLTABLEPRIVILEGES", 9349 sysIBMUUID, 9350 arg_names, 9351 arg_types, 9352 0, 9353 1, 9354 RoutineAliasInfo.READS_SQL_DATA, 9355 (TypeDescriptor) null, 9356 tc); 9357 } 9358 9359 { 9361 9362 String [] arg_names = { 9364 "CATALOGNAME", 9365 "SCHEMANAME", 9366 "TABLENAME", 9367 "OPTIONS"}; 9368 9369 TypeDescriptor[] arg_types = { 9371 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9372 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9373 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9374 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9375 9376 createSystemProcedureOrFunction( 9377 "SQLPRIMARYKEYS", 9378 sysIBMUUID, 9379 arg_names, 9380 arg_types, 9381 0, 9382 1, 9383 RoutineAliasInfo.READS_SQL_DATA, 9384 (TypeDescriptor) null, 9385 tc); 9386 } 9387 9388 { 9390 9391 String [] arg_names = { 9393 "CATALOGNAME", 9394 "SCHEMANAME", 9395 "TABLENAME", 9396 "TABLETYPE", 9397 "OPTIONS"}; 9398 9399 TypeDescriptor[] arg_types = { 9401 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9402 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9403 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9404 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000), 9405 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9406 9407 createSystemProcedureOrFunction( 9408 "SQLTABLES", 9409 sysIBMUUID, 9410 arg_names, 9411 arg_types, 9412 0, 9413 1, 9414 RoutineAliasInfo.READS_SQL_DATA, 9415 (TypeDescriptor) null, 9416 tc); 9417 } 9418 9419 9420 { 9422 9423 String [] arg_names = { 9425 "CATALOGNAME", 9426 "SCHEMANAME", 9427 "PROCNAME", 9428 "PARAMNAME", 9429 "OPTIONS"}; 9430 9431 TypeDescriptor[] arg_types = { 9433 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9434 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9435 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9436 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9437 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9438 9439 createSystemProcedureOrFunction( 9440 "SQLPROCEDURECOLS", 9441 sysIBMUUID, 9442 arg_names, 9443 arg_types, 9444 0, 9445 1, 9446 RoutineAliasInfo.READS_SQL_DATA, 9447 (TypeDescriptor) null, 9448 tc); 9449 } 9450 9451 { 9453 9454 String [] arg_names = { 9456 "CATALOGNAME", 9457 "SCHEMANAME", 9458 "TABLENAME", 9459 "COLUMNNAME", 9460 "OPTIONS"}; 9461 9462 TypeDescriptor[] arg_types = { 9464 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9465 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9466 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9467 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9468 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9469 9470 createSystemProcedureOrFunction( 9471 "SQLCOLUMNS", 9472 sysIBMUUID, 9473 arg_names, 9474 arg_types, 9475 0, 9476 1, 9477 RoutineAliasInfo.READS_SQL_DATA, 9478 (TypeDescriptor) null, 9479 tc); 9480 } 9481 9482 { 9484 9485 String [] arg_names = { 9487 "CATALOGNAME", 9488 "SCHEMANAME", 9489 "TABLENAME", 9490 "COLUMNNAME", 9491 "OPTIONS"}; 9492 9493 TypeDescriptor[] arg_types = { 9495 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9496 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9497 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9498 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9499 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9500 9501 createSystemProcedureOrFunction( 9502 "SQLCOLPRIVILEGES", 9503 sysIBMUUID, 9504 arg_names, 9505 arg_types, 9506 0, 9507 1, 9508 RoutineAliasInfo.READS_SQL_DATA, 9509 (TypeDescriptor) null, 9510 tc); 9511 } 9512 9513 { 9515 9516 String [] arg_names = { 9518 "CATALOGNAME", 9519 "SCHEMAPATTERN", 9520 "TYPENAMEPATTERN", 9521 "UDTTYPES", 9522 "OPTIONS"}; 9523 9524 TypeDescriptor[] arg_types = { 9526 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9527 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9528 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9529 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9530 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9531 9532 createSystemProcedureOrFunction( 9533 "SQLUDTS", 9534 sysIBMUUID, 9535 arg_names, 9536 arg_types, 9537 0, 9538 1, 9539 RoutineAliasInfo.READS_SQL_DATA, 9540 (TypeDescriptor) null, 9541 tc); 9542 } 9543 9544 { 9547 9548 String [] arg_names = { 9550 "PKCATALOGNAME", 9551 "PKSCHEMANAME", 9552 "PKTABLENAME", 9553 "FKCATALOGNAME", 9554 "FKSCHEMANAME", 9555 "FKTABLENAME", 9556 "OPTIONS"}; 9557 9558 TypeDescriptor[] arg_types = { 9560 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9561 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9562 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9563 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9564 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9565 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9566 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9567 9568 createSystemProcedureOrFunction( 9569 "SQLFOREIGNKEYS", 9570 sysIBMUUID, 9571 arg_names, 9572 arg_types, 9573 0, 9574 1, 9575 RoutineAliasInfo.READS_SQL_DATA, 9576 (TypeDescriptor) null, 9577 tc); 9578 } 9579 9580 { 9583 9584 String [] arg_names = { 9586 "COLTYPE", 9587 "CATALOGNAME", 9588 "SCHEMANAME", 9589 "TABLENAME", 9590 "SCOPE", 9591 "NULLABLE", 9592 "OPTIONS"}; 9593 9594 TypeDescriptor[] arg_types = { 9596 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.SMALLINT), 9597 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9598 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9599 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9600 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.SMALLINT), 9601 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.SMALLINT), 9602 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9603 9604 createSystemProcedureOrFunction( 9605 "SQLSPECIALCOLUMNS", 9606 sysIBMUUID, 9607 arg_names, 9608 arg_types, 9609 0, 9610 1, 9611 RoutineAliasInfo.READS_SQL_DATA, 9612 (TypeDescriptor) null, 9613 tc); 9614 } 9615 9616 { 9618 9619 String [] arg_names = { 9621 "DATATYPE", 9622 "OPTIONS"}; 9623 9624 TypeDescriptor[] arg_types = { 9626 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.SMALLINT), 9627 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9628 9629 createSystemProcedureOrFunction( 9630 "SQLGETTYPEINFO", 9631 sysIBMUUID, 9632 arg_names, 9633 arg_types, 9634 0, 9635 1, 9636 RoutineAliasInfo.READS_SQL_DATA, 9637 (TypeDescriptor) null, 9638 tc); 9639 } 9640 9641 { 9644 9645 String [] arg_names = { 9647 "CATALOGNAME", 9648 "SCHEMANAME", 9649 "TABLENAME", 9650 "UNIQUE", 9651 "RESERVED", 9652 "OPTIONS"}; 9653 9654 TypeDescriptor[] arg_types = { 9656 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9657 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9658 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9659 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.SMALLINT), 9660 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.SMALLINT), 9661 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9662 9663 createSystemProcedureOrFunction( 9664 "SQLSTATISTICS", 9665 sysIBMUUID, 9666 arg_names, 9667 arg_types, 9668 0, 9669 1, 9670 RoutineAliasInfo.READS_SQL_DATA, 9671 (TypeDescriptor) null, 9672 tc); 9673 } 9674 9675 { 9677 createSystemProcedureOrFunction( 9678 "METADATA", 9679 sysIBMUUID, 9680 null, 9681 null, 9682 0, 9683 1, 9684 RoutineAliasInfo.READS_SQL_DATA, 9685 (TypeDescriptor) null, 9686 tc); 9687 } 9688 9689 } 9690 9691 9699 public void grantPublicAccessToSystemRoutines(TransactionController tc, 9700 String authorizationID) throws StandardException { 9701 9702 String schemaID = getSystemUtilSchemaDescriptor().getUUID().toString(); 9704 9705 for(int i=0; i < sysUtilProceduresWithPublicAccess.length; i++) { 9706 grantPublicAccessToSystemRoutine(schemaID, 9707 sysUtilProceduresWithPublicAccess[i], 9708 AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR, 9709 tc, authorizationID); 9710 } 9711 9712 for(int i=0; i < sysUtilFunctionsWithPublicAccess.length; i++) { 9713 grantPublicAccessToSystemRoutine(schemaID, 9714 sysUtilFunctionsWithPublicAccess[i], 9715 AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR, 9716 tc, authorizationID); 9717 } 9718 } 9719 9720 9721 9733 private void grantPublicAccessToSystemRoutine(String schemaID, 9734 String routineName, 9735 char nameSpace, 9736 TransactionController tc, 9737 String authorizationID) 9738 throws StandardException { 9739 AliasDescriptor ad = getAliasDescriptor(schemaID, routineName, 9741 nameSpace); 9742 9743 if (SanityManager.DEBUG) { 9744 SanityManager.ASSERT((ad != null), "Failed to get AliasDescriptor" 9745 + " of the routine"); 9746 } 9747 9748 UUID routineUUID = ad.getUUID(); 9749 createRoutinePermPublicDescriptor(routineUUID, tc, authorizationID); 9750 } 9751 9752 9753 9763 void createRoutinePermPublicDescriptor( 9764 UUID routineUUID, 9765 TransactionController tc) throws StandardException 9766 { 9767 createRoutinePermPublicDescriptor(routineUUID, tc, authorizationDatabaseOwner); 9768 } 9769 9770 9779 void createRoutinePermPublicDescriptor( 9780 UUID routineUUID, 9781 TransactionController tc, 9782 String authorizationID) throws StandardException 9783 { 9784 RoutinePermsDescriptor routinePermDesc = 9785 new RoutinePermsDescriptor( 9786 this, 9787 "PUBLIC", 9788 authorizationID, 9789 routineUUID); 9790 9791 addDescriptor( 9792 routinePermDesc, null, DataDictionary.SYSROUTINEPERMS_CATALOG_NUM, false, tc); 9793 } 9794 9795 9806 void create_10_1_system_procedures( 9807 TransactionController tc, 9808 UUID sysUtilUUID) 9809 throws StandardException 9810 { 9811 9812 UUID routine_uuid = null; 9813 9814 { 9822 String [] arg_names = { 9824 "SCHEMANAME", 9825 "TABLENAME", 9826 "PURGE_ROWS", 9827 "DEFRAGMENT_ROWS", 9828 "TRUNCATE_END"}; 9829 9830 TypeDescriptor[] arg_types = { 9832 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9833 Types.VARCHAR, 128), 9834 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9835 Types.VARCHAR, 128), 9836 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9837 Types.SMALLINT), 9838 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9839 Types.SMALLINT), 9840 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9841 Types.SMALLINT) 9842 }; 9843 9844 routine_uuid = createSystemProcedureOrFunction( 9845 "SYSCS_INPLACE_COMPRESS_TABLE", 9846 sysUtilUUID, 9847 arg_names, 9848 arg_types, 9849 0, 9850 0, 9851 RoutineAliasInfo.MODIFIES_SQL_DATA, 9852 (TypeDescriptor) null, 9853 tc); 9854 9855 createRoutinePermPublicDescriptor(routine_uuid, tc); 9856 } 9857 } 9858 9859 9860 9871 void create_10_2_system_procedures( 9872 TransactionController tc, 9873 UUID sysUtilUUID) 9874 throws StandardException 9875 { 9876 9877 9881 { 9882 String [] arg_names = {"BACKUPDIR"}; 9884 9885 TypeDescriptor[] arg_types = { 9887 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9888 Types.VARCHAR, Limits.DB2_VARCHAR_MAXWIDTH) 9889 }; 9890 9891 createSystemProcedureOrFunction( 9892 "SYSCS_BACKUP_DATABASE_NOWAIT", 9893 sysUtilUUID, 9894 arg_names, 9895 arg_types, 9896 0, 9897 0, 9898 RoutineAliasInfo.MODIFIES_SQL_DATA, 9899 (TypeDescriptor) null, 9900 tc); 9901 } 9902 9903 { 9909 String [] arg_names = 9911 {"BACKUPDIR", "DELETE_ARCHIVED_LOG_FILES"}; 9912 9913 TypeDescriptor[] arg_types = { 9915 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9916 Types.VARCHAR, Limits.DB2_VARCHAR_MAXWIDTH), 9917 DataTypeDescriptor.getBuiltInDataTypeDescriptor( 9918 Types.SMALLINT) 9919 }; 9920 9921 createSystemProcedureOrFunction( 9922 "SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT", 9923 sysUtilUUID, 9924 arg_names, 9925 arg_types, 9926 0, 9927 0, 9928 RoutineAliasInfo.MODIFIES_SQL_DATA, 9929 (TypeDescriptor) null, 9930 tc); 9931 } 9932 9933 { 9936 9937 String [] arg_names = { 9939 "CATALOGNAME", 9940 "SCHEMANAME", 9941 "FUNCNAME", 9942 "OPTIONS"}; 9943 9944 TypeDescriptor[] arg_types = { 9946 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9947 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9948 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9949 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9950 9951 createSystemProcedureOrFunction( 9952 "SQLFUNCTIONS", 9953 getSysIBMSchemaDescriptor().getUUID(), 9954 arg_names, 9955 arg_types, 9956 0, 9957 1, 9958 RoutineAliasInfo.READS_SQL_DATA, 9959 (TypeDescriptor) null, 9960 tc); 9961 } 9962 9963 { 9966 9967 String [] arg_names = { 9969 "CATALOGNAME", 9970 "SCHEMANAME", 9971 "FUNCNAME", 9972 "PARAMNAME", 9973 "OPTIONS"}; 9974 9975 TypeDescriptor[] arg_types = { 9977 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9978 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9979 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9980 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 128), 9981 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 4000)}; 9982 9983 createSystemProcedureOrFunction( 9984 "SQLFUNCTIONPARAMS", 9985 getSysIBMSchemaDescriptor().getUUID(), 9986 arg_names, 9987 arg_types, 9988 0, 9989 1, 9990 RoutineAliasInfo.READS_SQL_DATA, 9991 (TypeDescriptor) null, 9992 tc); 9993 } 9994 } 9995 9996 9997 0000 0001 private String spsSet; 0002 private final synchronized Properties getQueryDescriptions(boolean net) { 0003 spsSet = net ? "metadata_net.properties" : "/org/apache/derby/impl/jdbc/metadata.properties"; 0004 return (Properties ) java.security.AccessController.doPrivileged(this); 0005 } 0006 0007 public final Object run() { 0008 Properties p = new Properties (); 0010 try { 0011 0012 InputStream is = getClass().getResourceAsStream(spsSet); 0014 p.load(is); 0015 is.close(); 0016 } catch (IOException ioe) {} 0017 return p; 0018 } 0019 0020 0021 private static List newSList() { 0022 return java.util.Collections.synchronizedList(new java.util.LinkedList ()); 0023 } 0024 0025 0035 public TablePermsDescriptor getTablePermissions( UUID tableUUID, String authorizationId) 0036 throws StandardException 0037 { 0038 TablePermsDescriptor key = new TablePermsDescriptor( this, authorizationId, (String ) null, tableUUID); 0039 return (TablePermsDescriptor) getPermissions( key); 0040 } 0042 0043 public TablePermsDescriptor getTablePermissions( UUID tablePermsUUID) 0044 throws StandardException 0045 { 0046 TablePermsDescriptor key = new TablePermsDescriptor( this, tablePermsUUID); 0047 return getUncachedTablePermsDescriptor( key ); 0048 } 0049 0050 private Object getPermissions( PermissionsDescriptor key) throws StandardException 0051 { 0052 Cacheable entry = getPermissionsCache().find( key); 0054 if( entry == null) 0055 return null; 0056 Object perms = entry.getIdentity(); 0057 getPermissionsCache().release( entry); 0058 return perms; 0059 } 0060 0061 0062 public ColPermsDescriptor getColumnPermissions( UUID colPermsUUID) 0063 throws StandardException 0064 { 0065 ColPermsDescriptor key = new ColPermsDescriptor( this, colPermsUUID); 0066 return getUncachedColPermsDescriptor( key ); 0067 } 0068 0069 0085 public ColPermsDescriptor getColumnPermissions( UUID tableUUID, 0086 int privType, 0087 boolean forGrant, 0088 String authorizationId) 0089 throws StandardException 0090 { 0091 String privTypeStr = forGrant ? colPrivTypeMapForGrant[privType] : colPrivTypeMap[privType]; 0092 if( SanityManager.DEBUG) 0093 SanityManager.ASSERT( privTypeStr != null, 0094 "Invalid column privilege type: " + privType); 0095 ColPermsDescriptor key = new ColPermsDescriptor( this, 0096 authorizationId, 0097 (String ) null, 0098 tableUUID, 0099 privTypeStr); 0100 return (ColPermsDescriptor) getPermissions( key); 0101 } 0103 0120 public ColPermsDescriptor getColumnPermissions( UUID tableUUID, 0121 String privTypeStr, 0122 boolean forGrant, 0123 String authorizationId) 0124 throws StandardException 0125 { 0126 ColPermsDescriptor key = new ColPermsDescriptor( this, 0127 authorizationId, 0128 (String ) null, 0129 tableUUID, 0130 privTypeStr); 0131 return (ColPermsDescriptor) getPermissions( key); 0132 0133 } 0134 0135 private static final String [] colPrivTypeMap; 0136 private static final String [] colPrivTypeMapForGrant; 0137 static { 0138 colPrivTypeMap = new String [ Authorizer.PRIV_TYPE_COUNT]; 0139 colPrivTypeMapForGrant = new String [ Authorizer.PRIV_TYPE_COUNT]; 0140 colPrivTypeMap[ Authorizer.SELECT_PRIV] = "s"; 0141 colPrivTypeMapForGrant[ Authorizer.SELECT_PRIV] = "S"; 0142 colPrivTypeMap[ Authorizer.UPDATE_PRIV] = "u"; 0143 colPrivTypeMapForGrant[ Authorizer.UPDATE_PRIV] = "U"; 0144 colPrivTypeMap[ Authorizer.REFERENCES_PRIV] = "r"; 0145 colPrivTypeMapForGrant[ Authorizer.REFERENCES_PRIV] = "R"; 0146 } 0147 0148 0158 public RoutinePermsDescriptor getRoutinePermissions( UUID routineUUID, String authorizationId) 0159 throws StandardException 0160 { 0161 RoutinePermsDescriptor key = new RoutinePermsDescriptor( this, authorizationId, (String ) null, routineUUID); 0162 0163 return (RoutinePermsDescriptor) getPermissions( key); 0164 } 0166 0167 public RoutinePermsDescriptor getRoutinePermissions( UUID routinePermsUUID) 0168 throws StandardException 0169 { 0170 RoutinePermsDescriptor key = new RoutinePermsDescriptor( this, routinePermsUUID); 0171 return getUncachedRoutinePermsDescriptor( key ); 0172 } 0173 0174 0186 public boolean addRemovePermissionsDescriptor( boolean add, 0187 PermissionsDescriptor perm, 0188 String grantee, 0189 TransactionController tc) 0190 throws StandardException 0191 { 0192 int catalogNumber = perm.getCatalogNumber(); 0193 0194 perm.setUUID(null); 0213 perm.setGrantee( grantee); 0214 TabInfoImpl ti = getNonCoreTI( catalogNumber); 0215 PermissionsCatalogRowFactory rf = (PermissionsCatalogRowFactory) ti.getCatalogRowFactory(); 0216 int primaryIndexNumber = rf.getPrimaryKeyIndexNumber(); 0217 ConglomerateController heapCC = tc.openConglomerate( ti.getHeapConglomerate(), 0218 false, 0, 0220 TransactionController.MODE_RECORD, 0221 TransactionController.ISOLATION_REPEATABLE_READ); 0222 RowLocation rl = null; 0223 try 0224 { 0225 rl = heapCC.newRowLocationTemplate(); 0226 } 0227 finally 0228 { 0229 heapCC.close(); 0230 heapCC = null; 0231 } 0232 ExecIndexRow key = rf.buildIndexKeyRow( primaryIndexNumber, perm); 0233 ExecRow existingRow = ti.getRow( tc, key, primaryIndexNumber); 0234 if( existingRow == null) 0235 { 0236 if( ! add) 0237 return false; 0243 ExecRow row = ti.getCatalogRowFactory().makeRow( perm, (TupleDescriptor) null); 0247 int insertRetCode = ti.insertRow(row, tc, true ); 0248 if( SanityManager.DEBUG) 0249 SanityManager.ASSERT( insertRetCode == TabInfoImpl.ROWNOTDUPLICATE, 0250 "Race condition in inserting table privilege."); 0251 } 0252 else 0253 { 0254 boolean[] colsChanged = new boolean[ existingRow.nColumns()]; 0256 boolean[] indicesToUpdate = new boolean[ rf.getNumIndexes()]; 0257 int changedColCount = 0; 0258 if( add) 0259 changedColCount = rf.orPermissions( existingRow, perm, colsChanged); 0260 else 0261 changedColCount = rf.removePermissions( existingRow, perm, colsChanged); 0262 if( changedColCount == 0) 0263 { 0264 return false; 0267 } 0268 if (!add) 0269 { 0270 rf.setUUIDOfThePassedDescriptor(existingRow, perm); 0276 } 0277 if( changedColCount < 0) 0278 { 0279 ti.deleteRow( tc, key, primaryIndexNumber); 0281 } 0282 else if( changedColCount > 0) 0283 { 0284 int[] colsToUpdate = new int[changedColCount]; 0285 changedColCount = 0; 0286 for( int i = 0; i < colsChanged.length; i++) 0287 { 0288 if( colsChanged[i]) 0289 colsToUpdate[ changedColCount++] = i + 1; 0290 } 0291 if( SanityManager.DEBUG) 0292 SanityManager.ASSERT( 0293 changedColCount == colsToUpdate.length, 0294 "return value of " + rf.getClass().getName() + 0295 ".orPermissions does not match the number of booleans it set in colsChanged."); 0296 ti.updateRow( key, existingRow, primaryIndexNumber, indicesToUpdate, colsToUpdate, tc, true ); 0297 } 0298 } 0299 removePermEntryInCache(perm); 0303 0304 if (add) 0307 return false; 0308 return true; 0309 } 0311 0320 TablePermsDescriptor getUncachedTablePermsDescriptor( TablePermsDescriptor key) 0321 throws StandardException 0322 { 0323 if (key.getObjectID() == null) 0324 { 0325 return (TablePermsDescriptor) 0328 getUncachedPermissionsDescriptor( SYSTABLEPERMS_CATALOG_NUM, 0329 SYSTABLEPERMSRowFactory.GRANTEE_TABLE_GRANTOR_INDEX_NUM, 0330 key); 0331 } else 0332 { 0333 return (TablePermsDescriptor) 0336 getUncachedPermissionsDescriptor(SYSTABLEPERMS_CATALOG_NUM, 0337 SYSTABLEPERMSRowFactory.TABLEPERMSID_INDEX_NUM,key); 0338 } 0339 } 0341 0342 0352 ColPermsDescriptor getUncachedColPermsDescriptor( ColPermsDescriptor key) 0353 throws StandardException 0354 { 0355 if (key.getObjectID() == null) 0356 { 0357 return (ColPermsDescriptor) 0360 getUncachedPermissionsDescriptor( SYSCOLPERMS_CATALOG_NUM, 0361 SYSCOLPERMSRowFactory.GRANTEE_TABLE_TYPE_GRANTOR_INDEX_NUM, 0362 key); 0363 }else 0364 { 0365 return (ColPermsDescriptor) 0368 getUncachedPermissionsDescriptor( SYSCOLPERMS_CATALOG_NUM, 0369 SYSCOLPERMSRowFactory.COLPERMSID_INDEX_NUM, 0370 key); 0371 } 0372 } 0374 private TupleDescriptor getUncachedPermissionsDescriptor( int catalogNumber, 0375 int indexNumber, 0376 PermissionsDescriptor key) 0377 throws StandardException 0378 { 0379 TabInfoImpl ti = getNonCoreTI( catalogNumber); 0380 PermissionsCatalogRowFactory rowFactory = (PermissionsCatalogRowFactory) ti.getCatalogRowFactory(); 0381 ExecIndexRow keyRow = rowFactory.buildIndexKeyRow( indexNumber, key); 0382 return 0383 getDescriptorViaIndex( indexNumber, 0384 keyRow, 0385 (ScanQualifier [][]) null, 0386 ti, 0387 (TupleDescriptor) null, 0388 (List) null, 0389 false); 0390 } 0392 0401 RoutinePermsDescriptor getUncachedRoutinePermsDescriptor( RoutinePermsDescriptor key) 0402 throws StandardException 0403 { 0404 if (key.getObjectID() == null) 0405 { 0406 return (RoutinePermsDescriptor) 0409 getUncachedPermissionsDescriptor( SYSROUTINEPERMS_CATALOG_NUM, 0410 SYSROUTINEPERMSRowFactory.GRANTEE_ALIAS_GRANTOR_INDEX_NUM, 0411 key); 0412 } else 0413 { 0414 return (RoutinePermsDescriptor) 0417 getUncachedPermissionsDescriptor(SYSROUTINEPERMS_CATALOG_NUM, 0418 SYSROUTINEPERMSRowFactory.ROUTINEPERMSID_INDEX_NUM,key); 0419 0420 } 0421 } 0423 private String [][] DIAG_VTI_CLASSES = 0424 { 0425 {"LOCK_TABLE", "org.apache.derby.diag.LockTable"}, 0426 {"STATEMENT_CACHE", "org.apache.derby.diag.StatementCache"}, 0427 {"TRANSACTION_TABLE", "org.apache.derby.diag.TransactionTable"}, 0428 {"ERROR_MESSAGES", "org.apache.derby.diag.ErrorMessages"}, 0429 0430 0431 }; 0432 0433 0436 public String getVTIClass(TableDescriptor td) throws StandardException { 0437 0438 if (SanityManager.DEBUG) 0439 { 0440 if (td.getTableType() != TableDescriptor.VTI_TYPE) 0441 SanityManager.THROWASSERT("getVTIClass: Invalid table type " + td); 0442 } 0443 0444 for (int i = 0; i < DIAG_VTI_CLASSES.length; i++) 0445 { 0446 String [] entry = DIAG_VTI_CLASSES[i]; 0447 if (entry[0].equals(td.getDescriptorName())) 0448 return entry[1]; 0449 } 0450 0451 return null; 0452 } 0453} 0454 0455 0456 0457 0458 0459 0460 0461 0462 0463 | Popular Tags |