📄 datadictionaryimpl.java
字号:
/* Derby - Class org.apache.derby.impl.sql.catalog.DataDictionaryImpl Copyright 1997, 2005 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.sql.catalog;import org.apache.derby.iapi.reference.JDBC30Translation;import org.apache.derby.iapi.reference.Property;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.reference.Limits;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList;import org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor;import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList;import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList;import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;import org.apache.derby.iapi.sql.dictionary.DefaultDescriptor;import org.apache.derby.iapi.sql.dictionary.DependencyDescriptor;import org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.GenericDescriptorList;import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;import org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.SPSDescriptor;import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;import org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.TabInfo;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor;import org.apache.derby.iapi.sql.dictionary.ViewDescriptor;import org.apache.derby.iapi.sql.dictionary.SystemColumn;import org.apache.derby.iapi.sql.depend.DependencyManager;import org.apache.derby.impl.sql.depend.BasicDependencyManager;import org.apache.derby.iapi.sql.execute.ExecIndexRow;import org.apache.derby.iapi.sql.execute.ExecutionContext;import org.apache.derby.iapi.sql.execute.ExecutionFactory;import org.apache.derby.iapi.sql.execute.ScanQualifier;import org.apache.derby.iapi.types.DataValueFactory;import org.apache.derby.iapi.types.NumberDataValue;import org.apache.derby.iapi.types.StringDataValue;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory;import org.apache.derby.iapi.store.access.AccessFactory;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.types.Orderable;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.store.access.RowUtil;import org.apache.derby.iapi.store.access.ScanController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.monitor.ModuleControl;import org.apache.derby.iapi.services.monitor.ModuleSupportable;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.context.ContextService;import org.apache.derby.iapi.error.StandardException;// RESOLVE - paulat - remove this import when track 3677 is fixedimport org.apache.derby.iapi.services.sanity.AssertFailure;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.TupleFilter;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.cache.CacheFactory;import org.apache.derby.iapi.services.cache.CacheManager;import org.apache.derby.iapi.services.cache.Cacheable;import org.apache.derby.iapi.services.cache.CacheableFactory;import org.apache.derby.iapi.services.locks.LockFactory;import org.apache.derby.iapi.services.locks.C_LockFactory;import org.apache.derby.iapi.services.property.PropertyUtil;import org.apache.derby.impl.services.locks.Timeout;import org.apache.derby.iapi.services.uuid.UUIDFactory;import org.apache.derby.catalog.AliasInfo;import org.apache.derby.catalog.DefaultInfo;import org.apache.derby.catalog.TypeDescriptor;import org.apache.derby.catalog.UUID;import org.apache.derby.catalog.types.RoutineAliasInfo;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.services.locks.ShExLockable;import org.apache.derby.iapi.services.locks.ShExQual;import org.apache.derby.iapi.util.StringUtil;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.Hashtable;import java.util.Properties;import java.util.Vector;import java.util.List;import java.util.Iterator;import java.util.Enumeration;import java.io.InputStream;import java.io.IOException;import java.sql.Types;/** * This abstract class contains the common code for the "regular" and * limited data dictionaries. The limited configuration puts an upper * limit on the number of tables a user is allowed to create. * * This class provides the entire implementation of DataDictionary, * and ModuleControl, except for the stop() * method, which is to be provided by a non-abstract super-class. * The reason for putting the stop() method in the super-class is to * prevent someone from inadvertently changing this to a non-abstract * class. This class is shipped with both the limited and non-limited * configurations, and we don't want anyone to be able to cheat by * booting this class instead of booting the super-class. */public final class DataDictionaryImpl implements DataDictionary, CacheableFactory, ModuleControl, ModuleSupportable,java.security.PrivilegedAction{ private static final String CFG_SYSTABLES_ID = "SystablesIdentifier"; private static final String CFG_SYSTABLES_INDEX1_ID = "SystablesIndex1Identifier"; private static final String CFG_SYSTABLES_INDEX2_ID = "SystablesIndex2Identifier"; private static final String CFG_SYSCOLUMNS_ID = "SyscolumnsIdentifier"; private static final String CFG_SYSCOLUMNS_INDEX1_ID = "SyscolumnsIndex1Identifier"; private static final String CFG_SYSCOLUMNS_INDEX2_ID = "SyscolumnsIndex2Identifier"; private static final String CFG_SYSCONGLOMERATES_ID = "SysconglomeratesIdentifier"; private static final String CFG_SYSCONGLOMERATES_INDEX1_ID = "SysconglomeratesIndex1Identifier"; private static final String CFG_SYSCONGLOMERATES_INDEX2_ID = "SysconglomeratesIndex2Identifier"; private static final String CFG_SYSCONGLOMERATES_INDEX3_ID = "SysconglomeratesIndex3Identifier"; private static final String CFG_SYSSCHEMAS_ID = "SysschemasIdentifier"; private static final String CFG_SYSSCHEMAS_INDEX1_ID = "SysschemasIndex1Identifier"; private static final String CFG_SYSSCHEMAS_INDEX2_ID = "SysschemasIndex2Identifier"; private static final int SYSCONGLOMERATES_CORE_NUM = 0; private static final int SYSTABLES_CORE_NUM = 1; private static final int SYSCOLUMNS_CORE_NUM = 2; private static final int SYSSCHEMAS_CORE_NUM = 3; private static final int NUM_CORE = 4; // the structure that holds all the core table info private TabInfo[] coreInfo; /* ** SchemaDescriptors for system and app schemas. Both ** are canonical. We cache them for fast lookup. */ protected SchemaDescriptor systemSchemaDesc; protected SchemaDescriptor sysIBMSchemaDesc; protected SchemaDescriptor declaredGlobalTemporaryTablesSchemaDesc; protected SchemaDescriptor systemDiagSchemaDesc; protected SchemaDescriptor systemUtilSchemaDesc; private String systemSchemaName; private String systemDiagSchemaName; private String systemUtilSchemaName; private String sysIBMSchemaName; private String declaredGlobalTemporaryTablesSchemaName; boolean builtinSchemasAreFromLCC; protected boolean convertIdToLower; // Convert identifiers to lower case (as in Foundation) or not. private static final int NUM_NONCORE = 12; // This array of non-core table names *MUST* be in the same order // as the non-core table numbers, above. private static final String[] nonCoreNames = { "SYSCONSTRAINTS", "SYSKEYS", "SYSDEPENDS", "SYSALIASES", "SYSVIEWS", "SYSCHECKS", "SYSFOREIGNKEYS", "SYSSTATEMENTS", "SYSFILES", "SYSTRIGGERS", "SYSSTATISTICS", "SYSDUMMY1" }; /** * List of all "system" schemas * <p> * This list should contain all schema's used by the system and are * created when the database is created. Users should not be able to * create or drop these schema's and should not be able to create or * drop objects in these schema's. This list is used by code that * needs to check if a particular schema is a "system" schema. **/ private static final String[] systemSchemaNames = { SchemaDescriptor.IBM_SYSTEM_CAT_SCHEMA_NAME, SchemaDescriptor.IBM_SYSTEM_FUN_SCHEMA_NAME, SchemaDescriptor.IBM_SYSTEM_PROC_SCHEMA_NAME, SchemaDescriptor.IBM_SYSTEM_STAT_SCHEMA_NAME, SchemaDescriptor.IBM_SYSTEM_NULLID_SCHEMA_NAME, SchemaDescriptor.STD_SYSTEM_DIAG_SCHEMA_NAME, SchemaDescriptor.STD_SYSTEM_UTIL_SCHEMA_NAME, SchemaDescriptor.IBM_SYSTEM_SCHEMA_NAME, SchemaDescriptor.STD_SQLJ_SCHEMA_NAME, SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME }; /** Dictionary version of the on-disk database */ private DD_Version dictionaryVersion; /** Dictionary version of the currently running engine */ private DD_Version softwareVersion; /* ** This property and value are written into the database properties ** when the database is created, and are used to determine whether ** the system catalogs need to be upgraded. */ // the structure that holds all the noncore info private TabInfo[] noncoreInfo; // no other system tables have id's in the configuration. public DataDescriptorGenerator dataDescriptorGenerator; protected DataValueFactory dvf; protected AccessFactory af; //DataDictionaryContext ddc; private ExecutionFactory exFactory; protected UUIDFactory uuidFactory; Properties startupParameters; int engineType; /* Information about whether or not we are at boot time */ protected boolean booting; private TransactionController bootingTC; protected DependencyManager dmgr; /* Cache of table descriptors */ CacheManager OIDTdCache; CacheManager nameTdCache; private CacheManager spsNameCache; private Hashtable spsIdHash; // private Hashtable spsTextHash; int tdCacheSize; int stmtCacheSize; /* ** Lockable object for synchronizing transition from caching to non-caching */ ShExLockable cacheCoordinator; public LockFactory lockFactory; volatile int cacheMode = DataDictionary.COMPILE_ONLY_MODE; /* Number of DDL users */ volatile int ddlUsers; /* Number of readers that start in DDL_MODE */ volatile int readersInDDLMode; /** True if the database is read only and requires some form of upgrade, that makes the stored prepared statements invalid. With this case the engine is running at a different version to the underlying stored database. This can happen in 5.1 if the database is read only and a different point release (later than 5.1.25?) to the one that created it, has been booted. (Beetle 5170). <P> In 5.2 and newer this will be the case if the engine booting the database is newer than the engine that created it. */ public boolean readOnlyUpgrade; //systemSQLNameNumber is the number used as the last digit during the previous call to getSystemSQLName. //If it is 9 for a given calendarForLastSystemSQLName, we will restart the counter to 0 //and increment the calendarForLastSystemSQLName by 10ms. private int systemSQLNameNumber; private GregorianCalendar calendarForLastSystemSQLName = new GregorianCalendar(); private long timeForLastSystemSQLName; /* ** Constructor */ public DataDictionaryImpl() { } /** Currently, all this routine does is check to see if the Replication property has been turned on for this database. If so, then this is not the NodeFactory that's wanted--so we return false. The NodeFactory that is wanted is our child class "RepNodeFactory". @return true if this database does not want Replication false otherwise */ public boolean canSupport(Properties startParams) { return Monitor.isDesiredType( startParams, org.apache.derby.iapi.reference.EngineType.NONE ); } /** * Start-up method for this instance of the data dictionary. * * @param startParams The start-up parameters * * @return Nothing * * @exception StandardException Thrown if the module fails to start */ public void boot(boolean create, Properties startParams) throws StandardException { softwareVersion = new DD_Version(this, DataDictionary.DD_VERSION_DERBY_10_1); /* There is a bootstrapping problem here. We would like to use * a language connection context to find the name of the system and default * schemas. However a language connection context is not available when a * database is being created, as it is when this method is called. So, * this method must look at the params properties to discover the identifier * casing and convert the standard names as necessary, essentially duplicating * logic found in GenericLanguageConnectionContext. */ convertIdToLower = false; startupParameters = startParams; uuidFactory = Monitor.getMonitor().getUUIDFactory(); engineType = Monitor.getEngineType( startParams ); // REMIND: actually, we're supposed to get the DataValueFactory // out of the connection context...this is a bit of a shortcut. // We get the DataValueFactory early in order to help bootstrap the system catalogs. LanguageConnectionFactory langConnFactory = (LanguageConnectionFactory) Monitor.bootServiceModule( create, this, LanguageConnectionFactory.MODULE, startParams); dvf = langConnFactory.getDataValueFactory(); exFactory = (ExecutionFactory) Monitor.bootServiceModule( create, this, ExecutionFactory.MODULE, startParams); // initailze the arrays of core and noncore tables initializeCatalogInfo(); // indicate that we are in the process of booting booting = true; // set only if child class hasn't overriden this already if ( dataDescriptorGenerator == null ) { dataDescriptorGenerator = new DataDescriptorGenerator( this ); } if (!create) { // SYSTABLES coreInfo[SYSTABLES_CORE_NUM].setHeapConglomerate( getBootParameter(startParams, CFG_SYSTABLES_ID, true)); coreInfo[SYSTABLES_CORE_NUM].setIndexConglomerate(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, getBootParameter(startParams, CFG_SYSTABLES_INDEX1_ID, true));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -