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

📄 orderbylist.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.OrderByList   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.compile;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.CostEstimate;import org.apache.derby.iapi.sql.compile.RequiredRowOrdering;import org.apache.derby.iapi.sql.compile.RowOrdering;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.impl.sql.compile.ActivationClassBuilder;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.services.compiler.MethodBuilder;import org.apache.derby.iapi.services.loader.GeneratedMethod;import org.apache.derby.iapi.store.access.ColumnOrdering;import org.apache.derby.iapi.store.access.SortCostController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.reference.ClassName;import org.apache.derby.iapi.reference.Limits;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.util.JBitSet;import org.apache.derby.iapi.services.classfile.VMOpcode;import java.util.Properties;/** * An OrderByList is an ordered list of columns in the ORDER BY clause. * That is, the order of columns in this list is significant - the * first column in the list is the most significant in the ordering, * and the last column in the list is the least significant. *	@author ames */public class OrderByList extends OrderedColumnList						implements RequiredRowOrdering {	private boolean allAscending = true;	private boolean alwaysSort;	private ResultSetNode resultToSort;	private SortCostController scc;	private Object[] resultRow;	private ColumnOrdering[] columnOrdering;	private int estimatedRowSize;	private boolean sortNeeded = true;	/**		Add a column to the list			@param column	The column to add to the list	 */	public void addOrderByColumn(OrderByColumn column) 	{		addElement(column);		if (! column.isAscending())			allAscending = false;	}	/**	 * Are all columns in the list ascending.	 *	 * @return	Whether or not all columns in the list ascending.	 */	boolean allAscending()	{		return allAscending;	}	/**		Get a column from the list			@param position	The column to get from the list	 */	public OrderByColumn getOrderByColumn(int position) {		if (SanityManager.DEBUG)		SanityManager.ASSERT(position >=0 && position < size());		return (OrderByColumn) elementAt(position);	}	/**		Print the list.			@param depth		The depth at which to indent the sub-nodes	 */	public void printSubNodes(int depth) {		if (SanityManager.DEBUG) 		{			for (int index = 0; index < size(); index++)			{				( (OrderByColumn) (elementAt(index)) ).treePrint(depth);			}		}	}	/**		Bind the update columns by their names to the target resultset		of the cursor specification.		@param target	The underlying result set			@exception StandardException		Thrown on error	 */	public void bindOrderByColumns(ResultSetNode target)					throws StandardException {		/* Remember the target for use in optimization */		resultToSort = target;		int size = size();		/* Only 1012 columns allowed in ORDER BY clause */		if (size > Limits.DB2_MAX_ELEMENTS_IN_ORDER_BY)		{			throw StandardException.newException(SQLState.LANG_TOO_MANY_ELEMENTS);		}		for (int index = 0; index < size; index++)		{			OrderByColumn obc = (OrderByColumn) elementAt(index);			obc.bindOrderByColumn(target);			/*			** Always sort if we are ordering on an expression, and not			** just a column.			*/			if ( !			 (obc.getResultColumn().getExpression() instanceof ColumnReference))			{				alwaysSort = true;			}		}	}	/**		Pull up Order By columns by their names to the target resultset		of the cursor specification.		@param target	The underlying result set		 */	public void pullUpOrderByColumns(ResultSetNode target)					throws StandardException {		/* Remember the target for use in optimization */		resultToSort = target;		int size = size();		for (int index = 0; index < size; index++)		{			OrderByColumn obc = (OrderByColumn) elementAt(index);			obc.pullUpOrderByColumn(target);		}	}	/**	 * Is this order by list an in order prefix of the specified RCL.	 * This is useful when deciding if an order by list can be eliminated	 * due to a sort from an underlying distinct or union.	 *	 * @param sourceRCL	The source RCL.	 *	 * @return Whether or not this order by list an in order prefix of the specified RCL.	 */	boolean isInOrderPrefix(ResultColumnList sourceRCL)	{		boolean inOrderPrefix = true;		int rclSize = sourceRCL.size();		if (SanityManager.DEBUG)		{			if (size() > sourceRCL.size())			{				SanityManager.THROWASSERT(					"size() (" + size() + 					") expected to be <= sourceRCL.size() (" +					sourceRCL.size() + ")");			}		}		int size = size();		for (int index = 0; index < size; index++)		{			if (((OrderByColumn) elementAt(index)).getResultColumn() !=				(ResultColumn) sourceRCL.elementAt(index))			{				return false;			}		}		return true;	}	/**	 * Order by columns now point to the PRN above the node of interest.	 * We need them to point to the RCL under that one.  This is useful	 * when combining sorts where we need to reorder the sorting	 * columns.	 *	 * @return Nothing.	 */	void resetToSourceRCs()	{		int size = size();		for (int index = 0; index < size; index++)		{			OrderByColumn obc = (OrderByColumn) elementAt(index);			obc.resetToSourceRC();		}	}	/**	 * Build a new RCL with the same RCs as the passed in RCL	 * but in an order that matches the ordering columns.	 *	 * @param resultColumns	The RCL to reorder.	 *		 *	@exception StandardException		Thrown on error	 */	ResultColumnList reorderRCL(ResultColumnList resultColumns)		throws StandardException	{		ResultColumnList newRCL = (ResultColumnList) getNodeFactory().getNode(												C_NodeTypes.RESULT_COLUMN_LIST,												getContextManager());		/* The new RCL starts with the ordering columns */		int size = size();		for (int index = 0; index < size; index++)		{			OrderByColumn obc = (OrderByColumn) elementAt(index);			newRCL.addElement(obc.getResultColumn());			resultColumns.removeElement(obc.getResultColumn());		}		/* And ends with the non-ordering columns */		newRCL.destructiveAppend(resultColumns);		newRCL.resetVirtualColumnIds();		return newRCL;	}	/**		Remove any constant columns from this order by list.		Constant columns are ones where all of the column references		are equal to constant expressions according to the given		predicate list.	 */	void removeConstantColumns(PredicateList whereClause)	{		/* Walk the list backwards so we can remove elements safely */		for (int loc = size() - 1;			 loc >= 0;			 loc--)		{			OrderByColumn obc = (OrderByColumn) elementAt(loc);			if (obc.constantColumn(whereClause))			{				removeElementAt(loc);			}		}	}	/**		Remove any duplicate columns from this order by list.		For example, one may "ORDER BY 1, 1, 2" can be reduced		to "ORDER BY 1, 2".		Beetle 5401.	 */	void removeDupColumns()	{		/* Walk the list backwards so we can remove elements safely */		for (int loc = size() - 1; loc > 0; loc--)		{			OrderByColumn obc = (OrderByColumn) elementAt(loc);			int           colPosition = obc.getColumnPosition();			for (int inner = 0; inner < loc; inner++)			{

⌨️ 快捷键说明

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