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

📄 altertableconstantaction.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			DropConstraintConstantAction.dropConstraintAndIndex(dm, td, dd,							 cd, tc, activation, true);			activation.addWarning(StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED,				cd.getConstraintName(), td.getName()));		}		for (int i = tbr_size - 1; i >= 0; i--)		{			ConstraintDescriptor cd = toBeRemoved[i];			DropConstraintConstantAction.dropConstraintAndIndex(dm, td, dd, cd,						tc, activation, false);			activation.addWarning(StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED,					cd.getConstraintName(), td.getName()));			if (cascade)			{				ConstraintDescriptorList fkcdl = dd.getForeignKeys(cd.getUUID());				for (int j = 0; j < fkcdl.size(); j++)				{					ConstraintDescriptor fkcd = (ConstraintDescriptor) fkcdl.elementAt(j);					dm.invalidateFor(fkcd,									DependencyManager.DROP_CONSTRAINT,									lcc);					DropConstraintConstantAction.dropConstraintAndIndex(						dm, fkcd.getTableDescriptor(), dd, fkcd, tc, activation, true);					activation.addWarning(StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED,						fkcd.getConstraintName(), fkcd.getTableDescriptor().getName()));				}			}			dm.invalidateFor(cd, DependencyManager.DROP_CONSTRAINT, lcc);			dm.clearDependencies(lcc, cd);		}		compressTable(activation);		// drop the column from syscolumns 		dd.dropColumnDescriptor(td.getUUID(), columnInfo[ix].name, tc);		ColumnDescriptor[] cdlArray = new ColumnDescriptor[size - columnDescriptor.getPosition()];		for (int i = columnDescriptor.getPosition(), j = 0; i < size; i++, j++)		{			ColumnDescriptor cd = (ColumnDescriptor) tab_cdl.elementAt(i);			dd.dropColumnDescriptor(td.getUUID(), cd.getColumnName(), tc);			cd.setPosition(i);			cdlArray[j] = cd;		}		dd.addDescriptorArray(cdlArray, td,							  DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);		List deps = dd.getProvidersDescriptorList(td.getObjectID().toString());		for (Iterator depsIterator = deps.listIterator(); depsIterator.hasNext();)		{			DependencyDescriptor depDesc = (DependencyDescriptor) depsIterator.next();			DependableFinder finder = depDesc.getProviderFinder();			if (finder instanceof DDColumnDependableFinder)			{				DDColumnDependableFinder colFinder = (DDColumnDependableFinder) finder;				FormatableBitSet oldColumnBitMap = new FormatableBitSet(colFinder.getColumnBitMap());				FormatableBitSet newColumnBitMap = new FormatableBitSet(oldColumnBitMap);				newColumnBitMap.clear();				int bitLen = oldColumnBitMap.getLength();				for (int i = 0; i < bitLen; i++)				{					if (i < columnPosition && oldColumnBitMap.isSet(i))						newColumnBitMap.set(i);					if (i > columnPosition && oldColumnBitMap.isSet(i))						newColumnBitMap.set(i - 1);				}				if (newColumnBitMap.equals(oldColumnBitMap))					continue;				dd.dropStoredDependency(depDesc, tc);				colFinder.setColumnBitMap(newColumnBitMap.getByteArray());				dd.addDescriptor(depDesc, null,								 DataDictionary.SYSDEPENDS_CATALOG_NUM,								 true, tc);			}		}	}	private void modifyColumnType(Activation activation,								  int ix)		throws StandardException						  	{		LanguageConnectionContext lcc = activation.getLanguageConnectionContext();		DataDictionary dd = lcc.getDataDictionary();		TransactionController tc = lcc.getTransactionExecute();		ColumnDescriptor columnDescriptor = 			td.getColumnDescriptor(columnInfo[ix].name),			newColumnDescriptor = null;		newColumnDescriptor = 			new ColumnDescriptor(columnInfo[ix].name,									columnDescriptor.getPosition(),									columnInfo[ix].dataType,									columnDescriptor.getDefaultValue(),									columnDescriptor.getDefaultInfo(),									td,									columnDescriptor.getDefaultUUID(),								    columnInfo[ix].autoincStart,								    columnInfo[ix].autoincInc									);				// Update the ColumnDescriptor with new default info		dd.dropColumnDescriptor(td.getUUID(), columnInfo[ix].name, tc);		dd.addDescriptor(newColumnDescriptor, td,						 DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);	}		/**	 * Workhorse for modifying column level constraints. 	 * Right now it is restricted to modifying a null constraint to a not null	 * constraint.	 */	private void modifyColumnConstraint(Activation activation, 										String colName,										boolean nullability)		throws StandardException									{		LanguageConnectionContext lcc = activation.getLanguageConnectionContext();		DataDictionary dd = lcc.getDataDictionary();		TransactionController tc = lcc.getTransactionExecute();		ColumnDescriptor columnDescriptor = 			td.getColumnDescriptor(colName),			newColumnDescriptor = null;		DataTypeDescriptor dataType = columnDescriptor.getType();		// set nullability		dataType.setNullability(nullability);		newColumnDescriptor = 			 new ColumnDescriptor(colName,									columnDescriptor.getPosition(),									dataType,									columnDescriptor.getDefaultValue(),									columnDescriptor.getDefaultInfo(),									td,									columnDescriptor.getDefaultUUID(),									columnDescriptor.getAutoincStart(),									columnDescriptor.getAutoincInc());				// Update the ColumnDescriptor with new default info		dd.dropColumnDescriptor(td.getUUID(), colName, tc);		dd.addDescriptor(newColumnDescriptor, td,						 DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);			}	/**	 * Workhorse for modifying the default value of a column.	 * 	 * @param 		activation 		activation	 * @param       ix 		the index of the column specfication in the ALTER 	 *						statement-- currently we allow only one.	 * @exception	StandardException, thrown on error.	 */	private void modifyColumnDefault(Activation activation,									 int ix)			throws StandardException						 	{		LanguageConnectionContext lcc = activation.getLanguageConnectionContext();		DataDictionary dd = lcc.getDataDictionary();		DependencyManager dm = dd.getDependencyManager();		TransactionController tc = lcc.getTransactionExecute();		ColumnDescriptor columnDescriptor = 			td.getColumnDescriptor(columnInfo[ix].name);		DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();		int columnPosition = columnDescriptor.getPosition();		// Clean up after the old default, if non-null		if (columnDescriptor.hasNonNullDefault())		{			// Invalidate off of the old default			DefaultDescriptor defaultDescriptor = new DefaultDescriptor(dd, columnInfo[ix].oldDefaultUUID, 										 td.getUUID(), columnPosition);					dm.invalidateFor(defaultDescriptor, DependencyManager.MODIFY_COLUMN_DEFAULT, lcc);					// Drop any dependencies			dm.clearDependencies(lcc, defaultDescriptor);		}		UUID defaultUUID = columnInfo[ix].newDefaultUUID;		/* Generate a UUID for the default, if one exists		 * and there is no default id yet.		 */		if (columnInfo[ix].defaultInfo != null &&			defaultUUID == null)		{				defaultUUID = dd.getUUIDFactory().createUUID();		}		/* Get a ColumnDescriptor reflecting the new default */		columnDescriptor = new ColumnDescriptor(												   columnInfo[ix].name,												   columnPosition,												   columnInfo[ix].dataType,												   columnInfo[ix].defaultValue,												   columnInfo[ix].defaultInfo,												   td,												   defaultUUID,												   columnInfo[ix].autoincStart,												   columnInfo[ix].autoincInc												   );		// Update the ColumnDescriptor with new default info		dd.dropColumnDescriptor(td.getUUID(), columnInfo[ix].name, tc);		dd.addDescriptor(columnDescriptor, td,						 DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);			if (columnInfo[ix].autoincInc != 0)		{			// adding an autoincrement default-- calculate the maximum value 			// of the autoincrement column.			long maxValue = getColumnMax(activation, td, columnInfo[ix].name,										 columnInfo[ix].autoincInc,										 columnInfo[ix].autoincStart);			dd.setAutoincrementValue(tc, td.getUUID(), columnInfo[ix].name,									 maxValue, true);		}	}	/* NOTE: compressTable can also be called for 	 * ALTER TABLE <t> DROP COLUMN <c>;	 */	private void compressTable(Activation activation)		throws StandardException	{		ExecRow					emptyHeapRow;		long					newHeapConglom;		Properties				properties = new Properties();		RowLocation				rl;		this.lcc = activation.getLanguageConnectionContext();		this.dd = lcc.getDataDictionary();		this.dm = dd.getDependencyManager();		this.tc = lcc.getTransactionExecute();		this.activation = activation;		if (SanityManager.DEBUG)		{			if (lockGranularity != '\0')			{				SanityManager.THROWASSERT(					"lockGranularity expected to be '\0', not " + lockGranularity);			}			SanityManager.ASSERT(! compressTable || columnInfo == null,				"columnInfo expected to be null");			SanityManager.ASSERT(constraintActions == null,				"constraintActions expected to be null");		}		emptyHeapRow = td.getEmptyExecRow(lcc.getContextManager());		compressHeapCC = tc.openConglomerate(								td.getHeapConglomerateId(),                                false,                                TransactionController.OPENMODE_FORUPDATE,                                TransactionController.MODE_TABLE,                                TransactionController.ISOLATION_SERIALIZABLE);		// invalidate any prepared statements that		// depended on this table (including this one)		// bug 3653 has threads that start up and block on our lock, but do		// not see they have to recompile their plan.    We now invalidate earlier		// however they still might recompile using the old conglomerate id before we		// commit our DD changes.		//		dm.invalidateFor(td, DependencyManager.COMPRESS_TABLE, lcc);		rl = compressHeapCC.newRowLocationTemplate();		// Get the properties on the old heap		compressHeapCC.getInternalTablePropertySet(properties);		compressHeapCC.close();		compressHeapCC = null;		// Create an array to put base row template		baseRow = new ExecRow[bulkFetchSize];		baseRowArray = new DataValueDescriptor[bulkFetchSize][];		validRow = new boolean[bulkFetchSize];		/* Set up index info */		getAffectedIndexes(activation);		// Get an array of RowLocation template		compressRL = new RowLocation[bulkFetchSize];		indexRows = new ExecIndexRow[numIndexes];		if (! compressTable)		{			ExecRow newRow = activation.getExecutionFactory().getValueRow(emptyHeapRow.nColumns() - 1);			for (int i = 0; i < newRow.nColumns(); i++)			{				newRow.setColumn(i + 1, i < columnPosition - 1 ?										 emptyHeapRow.getColumn(i + 1) :										 emptyHeapRow.getColumn(i + 1 + 1));			}			emptyHeapRow = newRow;		}		setUpAllSorts(emptyHeapRow, rl);		// Start by opening a full scan on the base table.		openBulkFetchScan(td.getHeapConglomerateId());		// Get the estimated row count for the sorters		estimatedRowCount = compressHeapGSC.getEstimatedRowCount();		// Create the array of base row template		for (int i = 0; i < bulkFetchSize; i++)		{			// create a base row template			baseRow[i] = td.getEmptyExecRow(lcc.getContextManager());			baseRowArray[i] = baseRow[i].getRowArray();			compressRL[i] = compressHeapGSC.newRowLocationTemplate();		}		newHeapConglom = tc.createAndLoadConglomerate(									"heap",									emptyHeapRow.getRowArray(),									null, //column sort order - not required for heap									properties,									TransactionController.IS_DEFAULT,									this,									(long[]) null);		closeBulkFetchScan();		// Set the "estimated" row count		ScanController compressHeapSC = tc.openScan(							newHeapConglom,							false,							TransactionController.OPENMODE_FORUPDATE,							TransactionController.MODE_TABLE,                            TransactionController.ISOLATION_SERIALIZABLE,							(FormatableBitSet) null,							(DataValueDescriptor[]) null,							0,							(Qualifier[][]) null,							(DataValueDescriptor[]) null,							0);				compressHeapSC.setEstimatedRowCount(rowCount);		compressHeapSC.close();		compressHeapSC = null; // RESOLVE DJD CLEANUP		/*		** Inform the data dictionary that we are about to write to it.		** There are several calls to data dictionary "get" methods here		** that might be done in "read" mode in the data dictionary, but		** it seemed safer to do this whole operation in "write" mode.		**		** We tell the data dictionary we're done writing at the end of		** the transaction.		*/		dd.startWriting(lcc);		// Update all indexes		if (compressIRGs.length > 0)		{			updateAllIndexes(newHeapConglom, dd);		}		/* Update the DataDictionary		 * RESOLVE - this will change in 1.4 because we will get		 * back the same conglomerate number		 */		// Get the ConglomerateDescriptor for the heap		long oldHeapConglom = td.getHeapConglomerateId();		ConglomerateDescriptor cd = td.getConglomerateDescriptor(oldHeapConglom);		// Update sys.sysconglomerates with new conglomerate #		dd.updateConglomerateDescriptor(cd, newHeapConglom, tc);		// Drop the old conglomerate		tc.dropConglomerate(oldHeapConglom);		cleanUp();	}		/* 	 * TRUNCATE TABLE  TABLENAME; (quickly removes all the rows from table and	 * it's correctponding indexes).	 * Truncate is implemented by dropping the existing conglomerates(heap,indexes) and recreating a	 * new ones  with the properties of dropped conglomerates. Currently Store	 * does not have support to truncate existing conglomerated until store	 * supports it , this is the only way to do it.	 * Error Cases: Truncate error cases same as other DDL's statements except	 * 1)Truncate is not allowed when the table is references by another table.	 * 2)Truncate is not allowed when there are enabled delete triggers on the table.	 * Note: Because conglomerate number is changed during recreate process all the statements will be	 * marked as invalide and they will get recompiled internally on their next	 * execution. This is okay because truncate makes the number of rows to zero	 * it may be good idea to recompile them becuase plans are likely to be	 * incorrect. Recompile is done internally by cloudscape, user does not have	 * any effect.	 */	private void truncateTable(Activation activation)		throws StandardException	{		ExecRow					emptyHeapRow;		long					newHeapConglom;		Properties				properties = new Properties();		RowLocation				rl;		this.lcc = activation.getLanguageConnectionContext();

⌨️ 快捷键说明

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