Top Description Fields Constructors Methods
org.h2.result

public final Class SortOrder

extends Object
implements Comparator<Value[]>
Class Inheritance
All Implemented Interfaces
java.util.Comparator
Imports
java.util.ArrayList, .Collections, .Comparator, org.h2.command.query.QueryOrderBy, org.h2.engine.Database, .SessionLocal, org.h2.expression.Expression, .ExpressionColumn, org.h2.mode.DefaultNullOrdering, org.h2.table.Column, .TableFilter, org.h2.util.Utils, org.h2.value.Value, .ValueNull, .ValueRow

A sort order represents an ORDER BY clause in a query.

Field Summary

Modifier and TypeField and Description
public static final int
ASCENDING

This bit mask means the values should be sorted in ascending order.

public static final int
DESCENDING

This bit mask means the values should be sorted in descending order.

public static final int
NULLS_FIRST

This bit mask means NULLs should be sorted before other data, no matter if ascending or descending order is used.

public static final int
NULLS_LAST

This bit mask means NULLs should be sorted after other data, no matter if ascending or descending order is used.

private final ArrayList<QueryOrderBy>
orderList

The order list.

private final int[]
queryColumnIndexes

The column indexes of the order by expressions within the query.

private final SessionLocal
private final int[]
sortTypes

The sort type bit mask (DESCENDING, NULLS_FIRST, NULLS_LAST).

Constructor Summary

AccessConstructor and Description
public
SortOrder(SessionLocal
the session
session
,
int[]
the column index list
queryColumnIndexes
)

Construct a new sort order object with default sort directions.

public
SortOrder(SessionLocal
the session
session
,
int[]
the column index list
queryColumnIndexes
,
int[]
the sort order bit masks
sortType
,
ArrayList<QueryOrderBy>
the original query order list (if this is a query)
orderList
)

Construct a new sort order object.

Method Summary

Modifier and TypeMethod and Description
public static int[]

Returns:

the specified array with possibly modified bit masks
addNullOrdering
(Database
the database
database
,
int[]
bit masks
sortTypes
)

Add explicit SortOrder#NULLS_FIRST or SortOrder#NULLS_LAST where they aren't already specified.

public int

Returns:

the result of the comparison
compare
(Value[]
the first expression list
a
,
Value[]
the second expression list
b
)

Implements java.util.Comparator.compare.

Compare two expression lists.

public int

Returns:

the result of the comparison
compare
(Value[]
the first expression list
a
,
Value[]
the second expression list
b
,
int
number of columns to compare
count
)

Compare two expression lists.

private int
compareImpl(Value[] a, Value[] b, int count)

public Column

Returns:

the column, or null
getColumn
(int
the column index (0, 1,..)
index
,
TableFilter
the table filter
filter
)

Get the column for the given table filter, if the sort column is for this filter.

public ArrayList<QueryOrderBy>

Returns:

the original query order list
getOrderList
()

Returns the original query order list.

public int[]

Returns:

the list
getQueryColumnIndexes
()

Get the column index list.

public Comparator<Value>

Returns:

comparator for row values.
getRowValueComparator
()

Returns comparator for row values.

public int[]

Returns:

the list
getSortTypes
()

Get the sort order bit masks.

public int[]

Returns:

bit masks with either SortOrder#NULLS_FIRST or SortOrder#NULLS_LAST explicitly set.
getSortTypesWithNullOrdering
()

Returns sort order bit masks with SortOrder#NULLS_FIRST or SortOrder#NULLS_LAST explicitly set.

public StringBuilder

Returns:

the specified string builder
getSQL
(StringBuilder
string builder to append to
builder
,
Expression[]
the expression list
list
,
int
the number of columns in the select list
visible
,
int
formatting flags
sqlFlags
)

Create the SQL snippet that describes this sort order.

public static int
inverse(int sortTypeWithNull)

public void
sort(ArrayList<Value[]>
the list of rows
rows
)

Sort a list of rows.

public void
sort(ArrayList<Value[]>
the list of rows
rows
,
int
the start index, inclusive
fromInclusive
,
int
the end index, exclusive
toExclusive
)

Sort a list of rows using offset and limit.

public static void
typeToString(StringBuilder
string builder
builder
,
int
sort type
type
)

Appends type information (DESC, NULLS FIRST, NULLS LAST) to the specified statement builder.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ASCENDINGback to summary
public static final int ASCENDING

This bit mask means the values should be sorted in ascending order.

DESCENDINGback to summary
public static final int DESCENDING

This bit mask means the values should be sorted in descending order.

NULLS_FIRSTback to summary
public static final int NULLS_FIRST

This bit mask means NULLs should be sorted before other data, no matter if ascending or descending order is used.

NULLS_LASTback to summary
public static final int NULLS_LAST

This bit mask means NULLs should be sorted after other data, no matter if ascending or descending order is used.

orderListback to summary
private final ArrayList<QueryOrderBy> orderList

The order list.

queryColumnIndexesback to summary
private final int[] queryColumnIndexes

The column indexes of the order by expressions within the query.

sessionback to summary
private final SessionLocal session
sortTypesback to summary
private final int[] sortTypes

The sort type bit mask (DESCENDING, NULLS_FIRST, NULLS_LAST).

Constructor Detail

SortOrderback to summary
public SortOrder(SessionLocal session, int[] queryColumnIndexes)

Construct a new sort order object with default sort directions.

Parameters
session:SessionLocal

the session

queryColumnIndexes:int[]

the column index list

SortOrderback to summary
public SortOrder(SessionLocal session, int[] queryColumnIndexes, int[] sortType, ArrayList<QueryOrderBy> orderList)

Construct a new sort order object.

Parameters
session:SessionLocal

the session

queryColumnIndexes:int[]

the column index list

sortType:int[]

the sort order bit masks

orderList:ArrayList<QueryOrderBy>

the original query order list (if this is a query)

Method Detail

addNullOrderingback to summary
public static int[] addNullOrdering(Database database, int[] sortTypes)

Add explicit SortOrder#NULLS_FIRST or SortOrder#NULLS_LAST where they aren't already specified.

Parameters
database:Database

the database

sortTypes:int[]

bit masks

Returns:int[]

the specified array with possibly modified bit masks

compareback to summary
public int compare(Value[] a, Value[] b)

Implements java.util.Comparator.compare.

Compare two expression lists.

Parameters
a:Value[]

the first expression list

b:Value[]

the second expression list

Returns:int

the result of the comparison

Annotations
@Override
compareback to summary
public int compare(Value[] a, Value[] b, int count)

Compare two expression lists.

Parameters
a:Value[]

the first expression list

b:Value[]

the second expression list

count:int

number of columns to compare

Returns:int

the result of the comparison

compareImplback to summary
private int compareImpl(Value[] a, Value[] b, int count)
getColumnback to summary
public Column getColumn(int index, TableFilter filter)

Get the column for the given table filter, if the sort column is for this filter.

Parameters
index:int

the column index (0, 1,..)

filter:TableFilter

the table filter

Returns:Column

the column, or null

getOrderListback to summary
public ArrayList<QueryOrderBy> getOrderList()

Returns the original query order list.

Returns:ArrayList<QueryOrderBy>

the original query order list

getQueryColumnIndexesback to summary
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:int[]

the list

getRowValueComparatorback to summary
public Comparator<Value> getRowValueComparator()

Returns comparator for row values.

Returns:Comparator<Value>

comparator for row values.

getSortTypesback to summary
public int[] getSortTypes()

Get the sort order bit masks.

Returns:int[]

the list

getSortTypesWithNullOrderingback to summary
public int[] getSortTypesWithNullOrdering()

Returns sort order bit masks with SortOrder#NULLS_FIRST or SortOrder#NULLS_LAST explicitly set.

Returns:int[]

bit masks with either SortOrder#NULLS_FIRST or SortOrder#NULLS_LAST explicitly set.

getSQLback to summary
public StringBuilder getSQL(StringBuilder builder, Expression[] list, int visible, int sqlFlags)

Create the SQL snippet that describes this sort order. This is the SQL snippet that usually appears after the ORDER BY clause.

Parameters
builder:StringBuilder

string builder to append to

list:Expression[]

the expression list

visible:int

the number of columns in the select list

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

inverseback to summary
public static int inverse(int sortTypeWithNull)
sortback to summary
public void sort(ArrayList<Value[]> rows)

Sort a list of rows.

Parameters
rows:ArrayList<Value[]>

the list of rows

sortback to summary
public void sort(ArrayList<Value[]> rows, int fromInclusive, int toExclusive)

Sort a list of rows using offset and limit.

Parameters
rows:ArrayList<Value[]>

the list of rows

fromInclusive:int

the start index, inclusive

toExclusive:int

the end index, exclusive

typeToStringback to summary
public static void typeToString(StringBuilder builder, int type)

Appends type information (DESC, NULLS FIRST, NULLS LAST) to the specified statement builder.

Parameters
builder:StringBuilder

string builder

type:int

sort type