⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dd_version.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.catalog.DD_Version   Copyright 1998, 2004 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.services.monitor.Monitor;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.io.Formatable;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.SPSDescriptor;import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;import org.apache.derby.iapi.sql.dictionary.TabInfo;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;import org.apache.derby.iapi.types.DataValueFactory;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;import org.apache.derby.iapi.store.access.ScanController;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.ExecIndexRow;import org.apache.derby.iapi.services.io.StoredFormatIds;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.services.info.ProductGenusNames;import org.apache.derby.iapi.services.info.ProductVersionHolder;import org.apache.derby.iapi.reference.JDBC30Translation;import org.apache.derby.iapi.reference.Limits;import org.apache.derby.iapi.services.uuid.UUIDFactory;import org.apache.derby.catalog.UUID;import org.apache.derby.catalog.types.RoutineAliasInfo;import org.apache.derby.catalog.AliasInfo;import org.apache.derby.catalog.TypeDescriptor;import org.apache.derby.iapi.types.DataTypeDescriptor;import java.io.IOException;import java.io.ObjectInput;import java.io.ObjectOutput;import java.sql.Types;import java.util.Enumeration;import java.util.Properties;/** * Generic code for upgrading data dictionaries. * Currently has all minor version upgrade logic. * <p> * A word about minor vs. major upgraded.  Minor * upgrades must be backwards/forwards compatible. * So they cannot version classes or introduce new * classes.  Major releases are only backwards compatible; * they will run against an old database, but not the * other way around.  So they can introduce new classes, * etc. * * @author Rick */public	class DD_Version implements	Formatable{	////////////////////////////////////////////////////////////////////////	//	//	STATE	//	////////////////////////////////////////////////////////////////////////	private		transient	DataDictionaryImpl	bootingDictionary;	int majorVersionNumber;	private int minorVersionNumber;	////////////////////////////////////////////////////////////////////////	//	//	CONSTRUCTORS	//	////////////////////////////////////////////////////////////////////////	/**	  *	Public niladic constructor needed for Formatable interface.	  */	public	DD_Version() {}	/**	 * Construct a Version for the currently booting data dictionary.	 * The minor version is set by the subclass.	 *	 * @param	bootingDictionary	The booting dictionary that needs to be upgraded.	 */	DD_Version( DataDictionaryImpl bootingDictionary, int majorVersionNumber)	{		this.majorVersionNumber = majorVersionNumber;		this.minorVersionNumber = getJBMSMinorVersionNumber();		this.bootingDictionary = bootingDictionary;	}	////////////////////////////////////////////////////////////////////////	//	//	OVERRIDE OBJECT METHODS	//	////////////////////////////////////////////////////////////////////////	/**	  *	Stringify this Version.	  *	  *	@return	String representation of this Version.	  */	public	String	toString()	{		return DD_Version.majorToString(majorVersionNumber);	}	private static String majorToString(int majorVersionNumber) {		switch (majorVersionNumber) {		case DataDictionary.DD_VERSION_CS_5_0:			return "5.0";		case DataDictionary.DD_VERSION_CS_5_1:			return "5.1";		case DataDictionary.DD_VERSION_CS_5_2:			return "5.2";		case DataDictionary.DD_VERSION_CS_8_1:			return "8.1";		case DataDictionary.DD_VERSION_CS_10_0:			return "10.0";		case DataDictionary.DD_VERSION_DERBY_10_1:			return "10.1";		default:			return null;		}	}	////////////////////////////////////////////////////////////////////////	//	//	DataDictionary SPECIFIC	//	////////////////////////////////////////////////////////////////////////	/**	 * Upgrade the data dictionary catalogs to the version represented by this	 * DD_Version.	 *	 * @param dictionaryVersion the version of the data dictionary tables.	 * @exception StandardException Ooops	 */	void upgradeIfNeeded(DD_Version dictionaryVersion,								TransactionController tc, Properties startParams)		 throws StandardException	{		// database has been upgrade with a later engine version than this?		if (dictionaryVersion.majorVersionNumber > majorVersionNumber) {			throw StandardException.newException(SQLState.LANG_CANT_UPGRADE_CATALOGS,  				dictionaryVersion, this);		}		boolean minorOnly = false;		boolean performMajorUpgrade = false;		boolean softUpgradeRun = false;		if (dictionaryVersion.majorVersionNumber == majorVersionNumber) {			// exact match of engine to database, do nothing.			if (dictionaryVersion.minorVersionNumber == minorVersionNumber)				return;			// database and engine at same major level			minorOnly = true;		} else {           			if (Monitor.isFullUpgrade(startParams, dictionaryVersion.toString())) {				performMajorUpgrade = true;			} else {				softUpgradeRun = true;			}		}		// make sure we have a clean transaction for the upgrade		tc.commit();		if (performMajorUpgrade) {			// real upgrade changes.			doFullUpgrade( tc, dictionaryVersion.majorVersionNumber );		}		if (!minorOnly) {			// apply changes that can be made and will continue to work			// against previous version.			// See if we have already applied these changes.			DD_Version softUpgradeVersion = (DD_Version) tc.getProperty(											DataDictionary.SOFT_DATA_DICTIONARY_VERSION);			// need to apply them if we have never performed a soft upgrade			// or only a soft upgrade using a previous version.			int softUpgradeMajorVersion = 0;			if (softUpgradeVersion != null)				softUpgradeMajorVersion = softUpgradeVersion.majorVersionNumber;			if (softUpgradeMajorVersion < majorVersionNumber) {				applySafeChanges( tc, dictionaryVersion.majorVersionNumber, softUpgradeMajorVersion);			}		}		// changes such as invalidating SPS so they will recompile against		// the new internal classes.		// this method also changes the on-disk format version on the disk and in-memory as well.		handleMinorRevisionChange(tc, dictionaryVersion, softUpgradeRun);		// commit any upgrade		tc.commit();	}	/**		Apply changes that can safely be made in soft upgrade.		Any changes must not prevent the database from being re-booted		by the a Derby engine at the older version fromMajorVersionNumber.		<BR>		Examples are fixes to catalog meta data, e.g. fix nullability of		a system column.		<BR>		<B>Upgrade items for 10.1</B>		<UL>		<LI> None.		</UL>	  *	  * @param	tc	transaction controller	  * @param	fromMajorVersionNumber	version of the on-disk database	    @param  lastSoftUpgradeVersion last engine to perform a soft upgrade that made changes.	  *	  *	@exception StandardException  Standard Cloudscape error policy.	  */	private	void	applySafeChanges(TransactionController tc, int fromMajorVersionNumber, int lastSoftUpgradeVersion)		throws StandardException	{		/*		 * OLD Cloudscape 5.1 upgrade code, Derby does not support		 * upgrade from Cloudscape 5.x databases. If it ever is changed		 * to do so, this code would be useful.		 * 		 * 		if (lastSoftUpgradeVersion <= DataDictionary.DD_VERSION_CS_5_1)		{			// All these soft upgrade actions are new in 5.2 (first ever soft upgrade)			if (fromMajorVersionNumber <= DataDictionary.DD_VERSION_CS_5_0)				modifySysTableNullability(tc,					DataDictionaryImpl.SYSALIASES_CATALOG_NUM);			if (fromMajorVersionNumber <= DataDictionary.DD_VERSION_CS_5_1)				modifySysTableNullability(tc,					DataDictionaryImpl.SYSSTATEMENTS_CATALOG_NUM);		}		*/		tc.setProperty(DataDictionary.SOFT_DATA_DICTIONARY_VERSION, this, true);	}	/**		Do full upgrade.  Apply changes that can NOT be safely made in soft upgrade.				<BR>		<B>Upgrade items for 10.1</B>		<UL>		<LI> None.		</UL>	  *	  * @param	tc	transaction controller	  * @param	fromMajorVersionNumber	version of the on-disk database	  *	  *	@exception StandardException  Standard Cloudscape error policy.	  */	private	void	doFullUpgrade(TransactionController tc, int fromMajorVersionNumber)		throws StandardException	{		// Only supports upgrade from Derby 10.0 releases onwards		if (fromMajorVersionNumber < DataDictionary.DD_VERSION_CS_10_0)		{			throw StandardException.newException(SQLState.UPGRADE_UNSUPPORTED,					DD_Version.majorToString(fromMajorVersionNumber), this);					}		/*		 * OLD Cloudscape 5.1 upgrade code, Derby does not support		 * upgrade from Cloudscape 5.x databases. If it ever is changed		 * to do so, this code would be useful.			if (fromMajorVersionNumber <= DataDictionary.DD_VERSION_CS_5_1)		{			// drop sps in SYSIBM, SYSIBM, recreate SYSIBM, SYSDUMMY1, populate SYSDUMMY1, create procs			dropJDBCMetadataSPSes(tc, true);			SchemaDescriptor sd = bootingDictionary.getSchemaDescriptor("SYSIBM", null, false);			if (sd != null)				bootingDictionary.dropSchemaDescriptor("SYSIBM", tc);			sd = bootingDictionary.getSysIBMSchemaDescriptor();			bootingDictionary.addDescriptor(sd, null, DataDictionary.SYSSCHEMAS_CATALOG_NUM, false, tc);			bootingDictionary.upgradeMakeCatalog(tc, DataDictionary.SYSDUMMY1_CATALOG_NUM);			bootingDictionary.populateSYSDUMMY1(tc);			bootingDictionary.create_SYSIBM_procedures(tc);			bootingDictionary.createSystemSps(tc);		}				*/        if (fromMajorVersionNumber == DataDictionary.DD_VERSION_CS_10_0)        {            // This upgrade depends on the SYSUTIL schema, which only exists            // since 10.0.  Will not work to upgrade any db previous to 10.0,            // thus only checks for 10.0 rather than <= 10.0.            bootingDictionary.create_10_1_system_procedures(                tc,                 bootingDictionary.getSystemUtilSchemaDescriptor().getUUID());        }	}	/**	 * Do any work needed for a minor revision change.	 * For the data dictionary this is always invalidating	 * stored prepared statements.  When we are done 	 * with the upgrade, we always recompile all SPSes	 * so the customer doesn't have to (and isn't going	 * to get deadlocks because of the recomp).	 *	 * @param tc the xact	 *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -