Package org.h2.result
Class SortOrder
java.lang.Object
org.h2.result.SortOrder
- All Implemented Interfaces:
Comparator<Value[]>
A sort order represents an ORDER BY clause in a query.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThis bit mask means the values should be sorted in ascending order.static final intThis bit mask means the values should be sorted in descending order.static final intThis bit mask means NULLs should be sorted before other data, no matter if ascending or descending order is used.static final intThis bit mask means NULLs should be sorted after other data, no matter if ascending or descending order is used. -
Constructor Summary
ConstructorsConstructorDescriptionSortOrder(SessionLocal session, int[] queryColumnIndexes) Construct a new sort order object with default sort directions.SortOrder(SessionLocal session, int[] queryColumnIndexes, int[] sortType, ArrayList<QueryOrderBy> orderList) Construct a new sort order object. -
Method Summary
Modifier and TypeMethodDescriptionstatic int[]addNullOrdering(Database database, int[] sortTypes) Add explicitNULLS_FIRSTorNULLS_LASTwhere they aren't already specified.intCompare two expression lists.intCompare two expression lists.getColumn(int index, TableFilter filter) Get the column for the given table filter, if the sort column is for this filter.Returns the original query order list.int[]Get the column index list.Returns comparator for row values.int[]Get the sort order bit masks.int[]Returns sort order bit masks withNULLS_FIRSTorNULLS_LASTexplicitly set.getSQL(StringBuilder builder, Expression[] list, int visible, int sqlFlags) Create the SQL snippet that describes this sort order.static intinverse(int sortTypeWithNull) voidSort a list of rows.voidSort a list of rows using offset and limit.static voidtypeToString(StringBuilder builder, int type) Appends type information (DESC, NULLS FIRST, NULLS LAST) to the specified statement builder.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
ASCENDING
public static final int ASCENDINGThis bit mask means the values should be sorted in ascending order.- See Also:
-
DESCENDING
public static final int DESCENDINGThis bit mask means the values should be sorted in descending order.- See Also:
-
NULLS_FIRST
public static final int NULLS_FIRSTThis bit mask means NULLs should be sorted before other data, no matter if ascending or descending order is used.- See Also:
-
NULLS_LAST
public static final int NULLS_LASTThis bit mask means NULLs should be sorted after other data, no matter if ascending or descending order is used.- See Also:
-
-
Constructor Details
-
SortOrder
Construct a new sort order object with default sort directions.- Parameters:
session- the sessionqueryColumnIndexes- the column index list
-
SortOrder
public SortOrder(SessionLocal session, int[] queryColumnIndexes, int[] sortType, ArrayList<QueryOrderBy> orderList) Construct a new sort order object.- Parameters:
session- the sessionqueryColumnIndexes- the column index listsortType- the sort order bit masksorderList- the original query order list (if this is a query)
-
-
Method Details
-
getSQL
Create the SQL snippet that describes this sort order. This is the SQL snippet that usually appears after the ORDER BY clause.- Parameters:
builder- string builder to append tolist- the expression listvisible- the number of columns in the select listsqlFlags- formatting flags- Returns:
- the specified string builder
-
typeToString
Appends type information (DESC, NULLS FIRST, NULLS LAST) to the specified statement builder.- Parameters:
builder- string buildertype- sort type
-
compare
Compare two expression lists.- Specified by:
comparein interfaceComparator<Value[]>- Parameters:
a- the first expression listb- the second expression list- Returns:
- the result of the comparison
-
compare
Compare two expression lists.- Parameters:
a- the first expression listb- the second expression listcount- number of columns to compare- Returns:
- the result of the comparison
-
sort
Sort a list of rows.- Parameters:
rows- the list of rows
-
sort
Sort a list of rows using offset and limit.- Parameters:
rows- the list of rowsfromInclusive- the start index, inclusivetoExclusive- the end index, exclusive
-
getQueryColumnIndexes
public int[] getQueryColumnIndexes()Get the column index list. This is the column indexes of the order by expressions within the query.For the query "select name, id from test order by id, name" this is {1, 0} as the first order by expression (the column "id") is the second column of the query, and the second order by expression ("name") is the first column of the query.
- Returns:
- the list
-
getColumn
Get the column for the given table filter, if the sort column is for this filter.- Parameters:
index- the column index (0, 1,..)filter- the table filter- Returns:
- the column, or null
-
getSortTypes
public int[] getSortTypes()Get the sort order bit masks.- Returns:
- the list
-
getOrderList
Returns the original query order list.- Returns:
- the original query order list
-
getSortTypesWithNullOrdering
public int[] getSortTypesWithNullOrdering()Returns sort order bit masks withNULLS_FIRSTorNULLS_LASTexplicitly set.- Returns:
- bit masks with either
NULLS_FIRSTorNULLS_LASTexplicitly set.
-
addNullOrdering
Add explicitNULLS_FIRSTorNULLS_LASTwhere they aren't already specified.- Parameters:
database- the databasesortTypes- bit masks- Returns:
- the specified array with possibly modified bit masks
-
inverse
public static int inverse(int sortTypeWithNull) -
getRowValueComparator
Returns comparator for row values.- Returns:
- comparator for row values.
-