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

📄 indexchanger.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		{			if (! indexSC.next())			{                // This means that the entry for the index does not exist, this                // is a serious problem with the index.  Past fixed problems                // like track 3703 can leave db's in the field with this problem                // even though the bug in the code which caused it has long                 // since been fixed.  Then the problem can surface months later                // when the customer attempts to upgrade.  By "ignoring" the                // missing row here the problem is automatically "fixed" and                // since the code is trying to delete the row anyway it doesn't                // seem like such a bad idea.  It also then gives a tool to                 // support to be able to fix some system catalog problems where                // they can delete the base rows by dropping the system objects                // like stored statements.				if (SanityManager.DEBUG)					SanityManager.THROWASSERT(                        "Index row "+RowUtil.toString(ourIndexRow)+                        " not found in conglomerateid " + indexCID +                        "Current scan = " + indexSC);                Object[] args = new Object[2];                args[0] = ourIndexRow.getRowArray()[ourIndexRow.getRowArray().length - 1];                args[1] = new Long(indexCID);                Monitor.getStream().println(MessageService.getCompleteMessage(                    SQLState.LANG_IGNORE_MISSING_INDEX_ROW_DURING_DELETE,                     args));                // just return indicating the row has been deleted.                return;			}		}        indexSC.delete();	}	/**	  Insert a row into our indes.	  	  <P>This opens our index ConglomeratController the first time it	  is called. 	  	  @exception StandardException		Thrown on error	  */	private void doInsert()		 throws StandardException	{		insertAndCheckDups(ourIndexRow);	}	/**	  Insert a row into the temporary conglomerate	  	  <P>This opens our deferred ConglomeratController the first time it	  is called.	  	  @exception StandardException		Thrown on error	  */	private void doDeferredInsert()		 throws StandardException	{		if (rowHolder == null)		{			Properties properties = new Properties();			// Get the properties on the index			openIndexCC().getInternalTablePropertySet(properties);			/*			** Create our row holder.  it is ok to skip passing			** in the result description because if we don't already			** have a row holder, then we are the only user of the			** row holder (the description is needed when the row			** holder is going to be handed to users for triggers).			*/			rowHolder = new TemporaryRowHolderImpl(tc, properties, (ResultDescription)null);		}		/*		** If the user of the IndexChanger already		** had a row holder, then we don't need to		** bother saving deferred inserts -- they		** have already done so.			*/		if (!rowHolderPassedIn)		{			rowHolder.insert(ourIndexRow);		}	}	/**	 * Insert the given row into the given conglomerate and check for duplicate	 * key error.	 *	 * @param row	The row to insert	 *	 * @exception StandardException		Thrown on duplicate key error	 */	private void insertAndCheckDups(ExecIndexRow row)				throws StandardException	{		openIndexCC();		int insertStatus = indexCC.insert(row.getRowArray());		if (insertStatus == ConglomerateController.ROWISDUPLICATE)		{			/*			** We have a duplicate key error. 			*/			String indexOrConstraintName = indexName;			// now get table name, and constraint name if needed			LanguageConnectionContext lcc =                			activation.getLanguageConnectionContext();			DataDictionary dd = lcc.getDataDictionary();			//get the descriptors			ConglomerateDescriptor cd = dd.getConglomerateDescriptor(indexCID);			UUID tableID = cd.getTableID();			TableDescriptor td = dd.getTableDescriptor(tableID);			String tableName = td.getName();						if (indexOrConstraintName == null) // no index name passed in			{				ConstraintDescriptor conDesc = dd.getConstraintDescriptor(td,                                                                      cd.getUUID());				indexOrConstraintName = conDesc.getConstraintName();			}					StandardException se = 				StandardException.newException(				SQLState.LANG_DUPLICATE_KEY_CONSTRAINT, indexOrConstraintName, tableName);			throw se;		}		if (SanityManager.DEBUG)		{			if (insertStatus != 0)			{				SanityManager.THROWASSERT("Unknown insert status " + insertStatus);			}		}	}	/**	 * Open the ConglomerateController for this index if it isn't open yet.	 *	 * @return The ConglomerateController for this index.	 *	 * @exception StandardException		Thrown on duplicate key error	 */	private ConglomerateController openIndexCC()		throws StandardException	{		if (indexCC == null)		{			/* DataDictionary doesn't have compiled info */			if (indexSCOCI == null)			{				indexCC = 		            tc.openConglomerate(						indexCID,                        false,			            (TransactionController.OPENMODE_FORUPDATE |				         TransactionController.OPENMODE_BASEROW_INSERT_LOCKED),					    lockMode,                        isolationLevel);			}			else			{				indexCC = 		            tc.openCompiledConglomerate(                        false,			            (TransactionController.OPENMODE_FORUPDATE |				         TransactionController.OPENMODE_BASEROW_INSERT_LOCKED),					    lockMode,                        isolationLevel,						indexSCOCI,						indexDCOCI);			}		}		return indexCC;	}	/**	  Open this IndexChanger.	  @exception StandardException		Thrown on error	  */	public void open()		 throws StandardException	{	}	/**	  Perform index maintenance to support a delete of a base table row.	  @param baseRow the base table row.	  @param baseRowLocation the base table row's location.	  @exception StandardException		Thrown on error	  */	public void delete(ExecRow baseRow,					   RowLocation baseRowLocation)		 throws StandardException	{		setOurIndexRow(baseRow, baseRowLocation);		setScan();		doDelete();	}	/**	  Perform index maintenance to support an update of a base table row.	  @param ef	                ExecutionFactory to use in case of cloning	  @param oldBaseRow         the old image of the base table row.	  @param newBaseRow         the new image of the base table row.	  @param baseRowLocation    the base table row's location.	  @exception StandardException		Thrown on error	  */	public void update(ExecRow oldBaseRow,					   ExecRow newBaseRow,					   RowLocation baseRowLocation					   )		 throws StandardException	{		setOurIndexRow(oldBaseRow, baseRowLocation);		setOurUpdatedIndexRow(newBaseRow, baseRowLocation);		/* We skip the update in the degenerate case		 * where none of the key columns changed.		 * (From an actual customer case.)		 */		if (indexRowChanged())		{			setScan();			doDelete();			insertForUpdate(newBaseRow, baseRowLocation);		}	}	/**	  Perform index maintenance to support an insert of a base table row.	  @param baseRow            the base table row.	  @param baseRowLocation    the base table row's location.	  @exception StandardException		Thrown on error	  */	public void insert(ExecRow newRow, RowLocation baseRowLocation)		 throws StandardException	{		setOurIndexRow(newRow, baseRowLocation);		doInsert();	}	/**	  If we're updating a unique index, the inserts have to be	  deferred.  This is to avoid uniqueness violations that are only	  temporary.  If we do all the deletes first, only "true" uniqueness	  violations can happen.  We do this here, rather than in open(),	  because this is the only operation that requires deferred inserts,	  and we only want to create the conglomerate if necessary.	  @param ef		            ExecutionFactory to use in case of cloning	  @param baseRow            the base table row.	  @param baseRowLocation    the base table row's location.	  @exception StandardException		Thrown on error	*/	void insertForUpdate(ExecRow newRow, RowLocation baseRowLocation)		 throws StandardException	{		setOurIndexRow(newRow, baseRowLocation);		if (irg.isUnique())		{			doDeferredInsert();		}		else		{			doInsert();		}	}	/**	  Finish doing the changes for this index.  This is intended for deferred	  inserts for unique indexes.  It has no effect unless we are doing an	  update of a unique index.	  @exception StandardException		Thrown on error	 */	public void finish()		throws StandardException	{		ExecRow			deferredRow;		ExecIndexRow	deferredIndexRow = new IndexRow();		/* Deferred processing only necessary for unique indexes */		if (rowHolder != null)		{			CursorResultSet rs = rowHolder.getResultSet();			try			{				rs.open();				while ((deferredRow = rs.getNextRow()) != null)				{					if (SanityManager.DEBUG)					{						if (!(deferredRow instanceof ExecIndexRow))						{							SanityManager.THROWASSERT("deferredRow isn't an instance "+								"of ExecIndexRow as expected. "+								"It is an "+deferredRow.getClass().getName());						}					}					insertAndCheckDups((ExecIndexRow)deferredRow);				}			}			finally			{				rs.close();				/*				** If row holder was passed in, let the				** client of this method clean it up.				*/				if (!rowHolderPassedIn)				{					rowHolder.close();				}			}		}	}	/**	  Close this IndexChanger.	  @exception StandardException		Thrown on error	  */	public void close()		throws StandardException	{		closeIndexCC();		closeIndexSC();		if (rowHolder != null && !rowHolderPassedIn)		{			rowHolder.close();		}		baseCC = null;	}}

⌨️ 快捷键说明

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