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

📄 indexchanger.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.execute.IndexChanger   Copyright 1997, 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.execute;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;import org.apache.derby.iapi.sql.ResultDescription;import org.apache.derby.iapi.sql.execute.CursorResultSet;import org.apache.derby.iapi.sql.execute.ExecRow;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.reference.SQLState;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.ScanController;import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.catalog.UUID;import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.services.i18n.MessageService;import java.util.Properties;/**  Perform Index maintenace associated with DML operations for a single index.  */public class IndexChanger{	private IndexRowGenerator irg;	//Index Conglomerate ID	private long indexCID;	private DynamicCompiledOpenConglomInfo indexDCOCI;	private StaticCompiledOpenConglomInfo indexSCOCI;	private String indexName;	private ConglomerateController baseCC;	private TransactionController tc;	private int lockMode;	private FormatableBitSet baseRowReadMap;	private ConglomerateController indexCC = null;	private ScanController indexSC = null;	private LanguageConnectionContext lcc;	//	//Index rows used by this module to perform DML.	private ExecIndexRow ourIndexRow = null;	private ExecIndexRow ourUpdatedIndexRow = null;	private TemporaryRowHolderImpl	rowHolder = null;	private boolean					rowHolderPassedIn;	private int						isolationLevel;	private Activation				activation;	private boolean					ownIndexSC = true;	/**	  Create an IndexChanger	  @param irg the IndexRowGenerator for the index.	  @param indexCID the conglomerate id for the index.	  @param indexSCOCI the SCOCI for the idexes. 	  @param indexDCOCI the DCOCI for the idexes. 	  @param baseCC the ConglomerateController for the base table.	  @param tc			The TransactionController	  @param lockMode	The lock mode (granularity) to use	  @param baseRowReadMap Map of columns read in.  1 based.	  @param isolationLevel	Isolation level to use.	  @param activation	Current activation	  @exception StandardException		Thrown on error	  */	public IndexChanger	(		IndexRowGenerator 		irg,		long 					indexCID,	    StaticCompiledOpenConglomInfo indexSCOCI,		DynamicCompiledOpenConglomInfo indexDCOCI,		String					indexName,		ConglomerateController	baseCC,		TransactionController 	tc,		int 					lockMode,		FormatableBitSet					baseRowReadMap,		int						isolationLevel,		Activation				activation	)		 throws StandardException	{		this.irg = irg;		this.indexCID = indexCID;		this.indexSCOCI = indexSCOCI;		this.indexDCOCI = indexDCOCI;		this.baseCC = baseCC;		this.tc = tc;		this.lockMode = lockMode;		this.baseRowReadMap = baseRowReadMap;		this.rowHolderPassedIn = false;		this.isolationLevel = isolationLevel;		this.activation = activation;		this.indexName = indexName;		// activation will be null when called from DataDictionary		if (activation != null && activation.getIndexConglomerateNumber() == indexCID)		{			ownIndexSC = false;		}			if (SanityManager.DEBUG)		{			SanityManager.ASSERT(tc != null, 				"TransactionController argument to constructor is null");			SanityManager.ASSERT(irg != null, 				"IndexRowGenerator argument to constructor is null");		}	}	/**	 * Set the row holder for this changer to use.	 * If the row holder is set, it wont bother 	 * saving copies of rows needed for deferred	 * processing.  Also, it will never close the	 * passed in rowHolder.	 *	 * @param rowHolder	the row holder	 */	public void setRowHolder(TemporaryRowHolderImpl rowHolder)	{		this.rowHolder = rowHolder;		rowHolderPassedIn = (rowHolder != null);	}	/**	 * Propagate the heap's ConglomerateController to	 * this index changer.	 *	 * @param baseCC	The heap's ConglomerateController.	 *	 * @return Nothing.	 */	public void setBaseCC(ConglomerateController baseCC)	{		this.baseCC = baseCC;	}	/**	  Set the column values for 'ourIndexRow' to refer to 	  a base table row and location provided by the caller.	  The idea here is to 	  @param baseRow a base table row.	  @param baseRowLoc baseRowLoc baseRow's location	  @exception StandardException		Thrown on error	  */	private void setOurIndexRow(ExecRow baseRow,								RowLocation baseRowLoc)		 throws StandardException	{			if (ourIndexRow == null)				ourIndexRow = irg.getIndexRowTemplate();					irg.getIndexRow(baseRow, baseRowLoc, ourIndexRow, baseRowReadMap);	}	/**	  Set the column values for 'ourUpdatedIndexRow' to refer to 	  a base table row and location provided by the caller.	  The idea here is to 	  @param baseRow a base table row.	  @param baseRowLoc baseRowLoc baseRow's location	  @exception StandardException		Thrown on error	  */	private void setOurUpdatedIndexRow(ExecRow baseRow,								RowLocation baseRowLoc)		 throws StandardException	{			if (ourUpdatedIndexRow == null)				ourUpdatedIndexRow = irg.getIndexRowTemplate();					irg.getIndexRow(baseRow, baseRowLoc, ourUpdatedIndexRow, baseRowReadMap);	}	/**	 * Determine whether or not any columns in the current index	 * row are being changed by the update.  No need to update the	 * index if no columns changed.	 *	 * @return Nothing.	 *	 * @exception StandardException		Thrown on error	 */	private boolean indexRowChanged()		throws StandardException	{		int numColumns = ourIndexRow.nColumns();		for (int index = 1; index <= numColumns; index++)		{			DataValueDescriptor oldOrderable = ourIndexRow.getColumn(index);			DataValueDescriptor newOrderable = ourUpdatedIndexRow.getColumn(index);			if (! (oldOrderable.compare(DataValueDescriptor.ORDER_OP_EQUALS, newOrderable, true, true)))			{				return true;			}		}		return false;	}	private ExecIndexRow getDeferredIndexRowTemplate(ExecRow baseRow,													RowLocation baseRowLoc)		 throws StandardException	{		ExecIndexRow	template;		template = irg.getIndexRowTemplate();		irg.getIndexRow(baseRow, baseRowLoc, template, baseRowReadMap);		return template;	}	/**	  Position our index scan to 'ourIndexRow'.	  <P>This creates the scan the first time it is called.	  @exception StandardException		Thrown on error	  */	private void setScan()		 throws StandardException	{		/* Get the SC from the activation if re-using */		if (! ownIndexSC)		{			indexSC = activation.getIndexScanController();		}		else if (indexSC == null)		{			RowLocation templateBaseRowLocation = baseCC.newRowLocationTemplate();			/* DataDictionary doesn't have compiled info */			if (indexSCOCI == null)			{				indexSC = 		            tc.openScan(			              indexCID,				          false,                       /* hold */					      TransactionController.OPENMODE_FORUPDATE, /* forUpdate */						  lockMode,	                      isolationLevel,		                  (FormatableBitSet)null,					/* all fields */			              ourIndexRow.getRowArray(),    /* startKeyValue */				          ScanController.GE,            /* startSearchOp */					      null,                         /* qualifier */						  ourIndexRow.getRowArray(),    /* stopKeyValue */						ScanController.GT             /* stopSearchOp */	                      );			}			else			{				indexSC = 		            tc.openCompiledScan(				          false,                       /* hold */					      TransactionController.OPENMODE_FORUPDATE, /* forUpdate */						  lockMode,	                      isolationLevel,		                  (FormatableBitSet)null,					/* all fields */			              ourIndexRow.getRowArray(),    /* startKeyValue */				          ScanController.GE,            /* startSearchOp */					      null,                         /* qualifier */						  ourIndexRow.getRowArray(),    /* stopKeyValue */						  ScanController.GT,             /* stopSearchOp */						  indexSCOCI,						  indexDCOCI	                      );            }		}		else		{			indexSC.reopenScan(							   ourIndexRow.getRowArray(),			/* startKeyValue */							   ScanController.GE, 	/* startSearchOperator */							   null,	            /* qualifier */							   ourIndexRow.getRowArray(),			/* stopKeyValue */							   ScanController.GT	/* stopSearchOperator */							   );		}	}	/**	  Close our index Conglomerate Controller	  */	private void closeIndexCC()        throws StandardException	{		if (indexCC != null)			indexCC.close();		indexCC = null;	}	/**	  Close our index ScanController.	  */	private void closeIndexSC()        throws StandardException	{		/* Only consider closing index SC if we own it. */		if (ownIndexSC && indexSC != null)		{			indexSC.close();			indexSC = null;		}	}	/**	  Delete a row from our index. This assumes our index ScanController	  is positioned before the row by setScan if we own the SC, otherwise	  it is positioned on the row by the underlying index scan.	  	  <P>This verifies the row exists and is unique.	  	  @exception StandardException		Thrown on error	  */	private void doDelete()		 throws StandardException	{		if (ownIndexSC)

⌨️ 快捷键说明

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