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

📄 indexrowtobaserowresultset.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.execute.IndexRowToBaseRowResultSet   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.services.stream.HeaderPrintWriter;import org.apache.derby.iapi.services.stream.InfoStreams;import org.apache.derby.iapi.sql.execute.CursorResultSet;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.NoPutResultSet;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.conn.StatementContext;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.services.loader.GeneratedMethod;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl;/** * Takes a result set with a RowLocation as the last column, and uses the * RowLocation to get and return a row from the given base conglomerate. * Normally, the input result set will be a TableScanResultSet scanning an * index conglomerate. * * @author jeff */public class IndexRowToBaseRowResultSet extends NoPutResultSetImpl	implements CursorResultSet {    // set in constructor and not altered during    // life of object.	private long conglomId;    public NoPutResultSet source;	private GeneratedMethod resultRowAllocator;	private GeneratedMethod restriction;    private long baseConglomId;    private GeneratedMethod closeCleanup;	public FormatableBitSet accessedHeapCols;	private FormatableBitSet accessedIndexCols;	//caching accessed columns (heap+index) beetle 3865	private FormatableBitSet accessedAllCols;	public String indexName;	private int[] indexCols;	private DynamicCompiledOpenConglomInfo dcoci;	private StaticCompiledOpenConglomInfo scoci;	// set in open() and not changed after that	private ConglomerateController	baseCC;	private boolean                 closeBaseCCHere;	private ExecRow					resultRow;	private ExecRow					compactRow;	private boolean					forUpdate;	private DataValueDescriptor[]	rowArray;	// changed a whole bunch	RowLocation	baseRowLocation;	/* Remember whether or not we have copied any	 * columns from the source row to our row yet.	 */	boolean copiedFromSource;	/* Run time statistics variables */	public long restrictionTime;	protected boolean currentRowPrescanned;	private boolean sourceIsForUpdateIndexScan;    //    // class interface    //    public IndexRowToBaseRowResultSet(					long conglomId,					int scociItem,					Activation a,					NoPutResultSet source,					GeneratedMethod resultRowAllocator,					int resultSetNumber,					String indexName,					int heapColRefItem,					int indexColRefItem,					int indexColMapItem,					GeneratedMethod restriction,					boolean forUpdate,					double optimizerEstimatedRowCount,					double optimizerEstimatedCost,					GeneratedMethod closeCleanup) 		throws StandardException	{		super(a, resultSetNumber, optimizerEstimatedRowCount, optimizerEstimatedCost);        scoci = (StaticCompiledOpenConglomInfo)(activation.getPreparedStatement().						getSavedObject(scociItem));		TransactionController tc = activation.getTransactionController();		dcoci = tc.getDynamicCompiledConglomInfo(conglomId);        this.source = source;		this.resultRowAllocator = resultRowAllocator;		this.indexName = indexName;		this.forUpdate = forUpdate;		this.restriction = restriction;		/* RESOLVE - once we push Qualifiers into the store we		 * need to clear their Orderable cache on each open/reopen.		 */        this.closeCleanup = closeCleanup;		// retrieve the valid column list from		// the saved objects, if it exists		this.accessedHeapCols = null;		if (heapColRefItem != -1)		{			this.accessedHeapCols = (FormatableBitSet)(a.getPreparedStatement().						getSavedObject(heapColRefItem));		}		if (indexColRefItem != -1)		{			this.accessedIndexCols = (FormatableBitSet)(a.getPreparedStatement().						getSavedObject(indexColRefItem));		}		if (accessedIndexCols == null)			accessedAllCols = accessedHeapCols;		else		{			accessedAllCols = new FormatableBitSet(accessedHeapCols);			accessedAllCols.or(accessedIndexCols);		}					// retrieve the array of columns coming from the index		indexCols = ((ReferencedColumnsDescriptorImpl) (a.getPreparedStatement().						getSavedObject(indexColMapItem))).getReferencedColumnPositions();		/* Get the result row template */		resultRow = (ExecRow) resultRowAllocator.invoke(activation);		compactRow =			getCompactRow(resultRow,							accessedHeapCols,							accessedIndexCols,							false);		/* If there's no partial row bit map, then we want the entire		 * row, otherwise we need to diddle with the row array so that		 * we only get the columns coming from the heap on the fetch.		 */		if (accessedHeapCols == null)		{			rowArray = resultRow.getRowArray();		}		else		{			// Figure out how many columns are coming from the heap			int arraySize = accessedHeapCols.getNumBitsSet();			int accessedHeapColsSize = accessedHeapCols.size();			rowArray = new DataValueDescriptor[accessedHeapColsSize];			// Now, fill in rowArray with the desired columns			int partialIndex = 0;			int numFromIndex = 0;			for (int index = 0; index < accessedHeapColsSize; index++)			{				if (accessedIndexCols != null && accessedIndexCols.get(index))				{					numFromIndex++;					continue;				}				if (accessedHeapCols.get(index))				{					rowArray[index] =						resultRow.getRowArray()[index];					partialIndex++;				}			}		}		constructorTime += getElapsedMillis(beginTime);    }	//	// ResultSet interface (leftover from NoPutResultSet)	//	/**     * open this ResultSet.	 *	 * @exception StandardException thrown if cursor finished.     */	public void	openCore() throws StandardException 	{		boolean						lockingRequired = false;		TransactionController		tc;		// REVISIT: through the direct DB API, this needs to be an		// error, not an ASSERT; users can open twice. Only through JDBC		// is access to open controlled and ensured valid.		if (SanityManager.DEBUG)		{	    	SanityManager.ASSERT( ! isOpen,								"IndexRowToBaseRowResultSet already open");		}		beginTime = getCurrentTimeMillis();		source.openCore();		if ((source instanceof TableScanResultSet) && 			((TableScanResultSet) source).indexCols != null)			sourceIsForUpdateIndexScan = true;		/* Get a ConglomerateController for the base conglomerate 		 * NOTE: We only need to acquire locks on the data pages when		 * going through the index when we are at READ COMMITTED and		 * the source is a BulkTableScan or HashScan.  (The underlying		 * row will not be guaranteed to be locked.)		 */		if (source.requiresRelocking())		{			lockingRequired = true;		}		tc = activation.getTransactionController();		int openMode;		int isolationLevel;				if (forUpdate)		{			openMode = TransactionController.OPENMODE_FORUPDATE;		}		else		{			openMode = 0;		}		isolationLevel = source.getScanIsolationLevel();		if (!lockingRequired)		{            // flag indicates that lock has already been acquired by access to            // the secondary index, and need not be gotten again in the base            // table.			openMode |= TransactionController.OPENMODE_SECONDARY_LOCKED;		}				/* Try to get the ConglomerateController from the activation		 * first, for the case that we are part of an update or delete.		 * If so, then the RowChangerImpl did the correct locking.		 * If not there, then we go off and open it ourself.		 */		if (forUpdate)		{			baseCC = activation.getHeapConglomerateController();		}		if (baseCC == null)		{			baseCC = 		        tc.openCompiledConglomerate(                    activation.getResultSetHoldability(),				    openMode,					// consistent with FromBaseTable's updateTargetLockMode					TransactionController.MODE_RECORD,	                isolationLevel,					scoci,					dcoci);			closeBaseCCHere = true;		}		isOpen = true;		numOpens++;		openTime += getElapsedMillis(beginTime);	}	/**	 * reopen this ResultSet.	 *	 * @exception StandardException thrown if cursor finished.	 */	public void	reopenCore() throws StandardException {		TransactionController		tc;		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(isOpen,					"IndexRowToBaseRowResultSet already open");		}		beginTime = getCurrentTimeMillis();		source.reopenCore();		numOpens++;		openTime += getElapsedMillis(beginTime);	}	/**     * Return the requested values computed     * from the next row (if any) for which     * the restriction evaluates to true.     * <p>     * restriction and projection parameters     * are evaluated for each row.	 *	 * @exception StandardException thrown on failure.	 * @exception StandardException ResultSetNotOpen thrown if not yet open.	 *	 * @return the next row in the result	 */	public ExecRow	getNextRowCore() throws StandardException {	    ExecRow sourceRow = null;		ExecRow retval = null;

⌨️ 快捷键说明

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