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

📄 sortresultset.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			/* The sorter is responsible for doing the cloning */			sorter.insert(inputRow.getRowArray());		}		source.close();		sortProperties = sorter.getSortInfo().getAllSortInfo(sortProperties);		sorter.close();		return tc.openSortScan(sortId, activation.getResultSetHoldability());	}	/**	 * Return the next 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 	{		if (!isOpen)		{			return null;		}		beginTime = getCurrentTimeMillis();		// In order distinct		if (isInSortedOrder && distinct)		{			// No rows, no work to do			if (currSortedRow == null)			{				nextTime += getElapsedMillis(beginTime);				return null;			}			/* If this is the 1st next, then simply return the 1st row			 * (which we got on the open()).			 */			if (! nextCalled)			{				nextCalled = true;				numColumns = currSortedRow.getRowArray().length;				nextTime += getElapsedMillis(beginTime);				rowsReturned++;				setCurrentRow(currSortedRow);				return currSortedRow;			}		    ExecRow sortResult = getNextRowFromRS();			/* Drain and throw away rows until we find a new distinct row. */			while (sortResult != null)			{				/* We found a new row.  Update the current row and return this one. */				if (! filterRow(currSortedRow, sortResult))				{					/* Save a clone of the new row so that it doesn't get overwritten */					currSortedRow = (ExecRow) sortResult.getClone();					setCurrentRow(currSortedRow);					nextTime += getElapsedMillis(beginTime);					rowsReturned++;					return currSortedRow;				}				// Get the next row				sortResult = getNextRowFromRS();			}			// We've drained the source, so no more rows to return			currSortedRow = null;			nextTime += getElapsedMillis(beginTime);			return null;		}		else		{		    ExecRow sortResult = getNextRowFromRS();			if (sortResult != null)			{				setCurrentRow(sortResult);				rowsReturned++;			}			nextTime += getElapsedMillis(beginTime);		    return sortResult;		}	}	/**	 * Filter out the new row if it has the same contents as	 * the current row.  (This allows us to process in-order	 * distincts without a sorter.)	 *	 * @param currRow	The current row.	 * @param newRow	The new row.	 *	 * @return	Whether or not to filter out the new row.	 *	 * @exception StandardException thrown on failure to get row location	 */	private boolean filterRow(ExecRow currRow, ExecRow newRow)		throws StandardException	{		for (int index = 1; index <= numColumns; index++)		{			DataValueDescriptor currOrderable = currRow.getColumn(index);			DataValueDescriptor newOrderable = newRow.getColumn(index);			if (! (currOrderable.compare(DataValueDescriptor.ORDER_OP_EQUALS, newOrderable, true, true)))			{				return false;			}		}		return true;	}	/**	 * If the result set has been opened,	 * close the open scan.	 *	 * @exception StandardException thrown on error	 */	public void	close() throws StandardException	{		beginTime = getCurrentTimeMillis();		if ( isOpen )	    {			// we don't want to keep around a pointer to the			// row ... so it can be thrown away.			// REVISIT: does this need to be in a finally			// block, to ensure that it is executed?		    clearCurrentRow();			if (closeCleanup != null) {				closeCleanup.invoke(activation); // let activation tidy up			}			currentRow = null;			sortResultRow = null;			closeSource();			if (dropGenericSort)			{				getTransactionController().dropSort(genericSortId);				dropGenericSort = false;			}			super.close();		}		else			if (SanityManager.DEBUG)				SanityManager.DEBUG("CloseRepeatInfo","Close of SortResultSet repeated");		closeTime += getElapsedMillis(beginTime);		isOpen = false;	}	public void	finish() throws StandardException	{		source.finish();		finishAndRTS();	}	/**	 * Return the total amount of time spent in this ResultSet	 *	 * @param type	CURRENT_RESULTSET_ONLY - time spent only in this ResultSet	 *				ENTIRE_RESULTSET_TREE  - time spent in this ResultSet and below.	 *	 * @return long		The total amount of time spent (in milliseconds).	 */	public long getTimeSpent(int type)	{		long totTime = constructorTime + openTime + nextTime + 						closeTime;		if (type == NoPutResultSet.CURRENT_RESULTSET_ONLY)		{			return	totTime - originalSource.getTimeSpent(ENTIRE_RESULTSET_TREE);		}		else		{			return totTime;		}	}	///////////////////////////////////////////////////////////////////////////////	//	// CursorResultSet interface	//	///////////////////////////////////////////////////////////////////////////////	/**	 * This result set has its row location from	 * the last fetch done. If the cursor is closed,	 * a null is returned.	 *	 * @see CursorResultSet	 *	 * @return the row location of the current cursor row.	 * @exception StandardException thrown on failure to get row location	 */	public RowLocation getRowLocation() throws StandardException	{		if (! isOpen) return null;		// REVISIT: could we reuse the same rowlocation object		// across several calls?		RowLocation rl;		rl = scanController.newRowLocationTemplate();		scanController.fetchLocation(rl);		return rl;	}	/**	 * This result set has its row from the last fetch done. 	 * If the cursor is closed, a null is returned.	 *	 * @see CursorResultSet	 *	 * @return the last row returned;	 * @exception StandardException thrown on failure.	 */	/* RESOLVE - this should return activation.getCurrentRow(resultSetNumber),	 * once there is such a method.  (currentRow is redundant)	 */	public ExecRow getCurrentRow() throws StandardException 	{		if (SanityManager.DEBUG)			SanityManager.ASSERT(isOpen, "SortResultSet expected to be open");		/*			DISTINCT assumes the currentRow is good, since it			is the only one with access to its sort scan result		 */		return currentRow;	}	///////////////////////////////////////////////////////////////////////////////	//	// SCAN ABSTRACTION UTILITIES	//	///////////////////////////////////////////////////////////////////////////////	/**	 * Get the next output row for processing	 */	private ExecRow getNextRowFromRS()		throws StandardException	{		return (scanController == null) ?			getRowFromResultSet() :			getRowFromSorter();	}	/**	 * Get a row from the input result set.  	 */		private ExecRow getRowFromResultSet()		throws StandardException	{		ExecRow				sourceRow;		ExecRow			inputRow = null;			if ((sourceRow = source.getNextRowCore()) != null)		{			rowsInput++;			inputRow = sourceRow;		}		return inputRow;	}	/**	 * Get a row from the sorter.  Side effects:	 * sets currentRow.	 */	private ExecRow getRowFromSorter()		throws StandardException	{		ExecRow			inputRow = null;					if (scanController.next())		{			// REMIND: HACKALERT we are assuming that result will			// point to what sortResult is manipulating when			// we complete the fetch.			currentRow = sortResultRow;			inputRow = sortResultRow;			scanController.fetch(inputRow.getRowArray());		}		return inputRow;	}	/**	 * Close the source of whatever we have been scanning.	 */	private void closeSource() throws StandardException	{		if (scanController == null)		{			/*			** NOTE: do not null out source, we			** may be opened again, in which case			** we will open source again.			*/			source.close();		}		else		{			scanController.close();			scanController = null;		}	}}

⌨️ 快捷键说明

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