Class SortProvider
- java.lang.Object
-
- nz.co.gregs.dbvolution.expressions.SortProvider
-
- All Implemented Interfaces:
Serializable,DBExpression,HasSQLString
- Direct Known Subclasses:
SortProvider.Ascending,SortProvider.Column,SortProvider.DefaultSort,SortProvider.Descending,SortProvider.NullsOrderer
public class SortProvider extends Object implements DBExpression, Serializable
Provides the sorting expressions used in the ORDER BY clause.The best way to create a SortProvider is to use the appropriate
AnyExpression.ascending()orAnyExpression.descending()method of an expression or columnFor instance: myDBRow.column(myDBRow.myDBString).substring(0,2).ascending()
- Author:
- gregorygraham
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSortProvider.Ascendingstatic classSortProvider.Columnstatic classSortProvider.DefaultSortstatic classSortProvider.Descendingstatic classSortProvider.NullsLaststatic classSortProvider.NullsOrdererstatic classSortProvider.Orderingstatic classSortProvider.OrderOfNulls
-
Field Summary
Fields Modifier and Type Field Description protected SortProvider.Orderingdirectionprotected SortProvider.OrderOfNullsnullsOrdering
-
Constructor Summary
Constructors Modifier Constructor Description protectedSortProvider()SortProvider(AbstractColumn exp)SortProvider(QueryColumn<A,B,C> exp)protectedSortProvider(AnyExpression<? extends Object,? extends AnyResult<?>,? extends QueryableDatatype<?>> exp, SortProvider.Ordering direction)protectedSortProvider(AnyExpression<A,B,C> exp)protectedSortProvider(SortProvider sort)
-
Method Summary
-
-
-
Field Detail
-
direction
protected SortProvider.Ordering direction
-
nullsOrdering
protected SortProvider.OrderOfNulls nullsOrdering
-
-
Constructor Detail
-
SortProvider
protected SortProvider()
-
SortProvider
protected SortProvider(SortProvider sort)
-
SortProvider
protected SortProvider(AnyExpression<A,B,C> exp)
-
SortProvider
protected SortProvider(AnyExpression<? extends Object,? extends AnyResult<?>,? extends QueryableDatatype<?>> exp, SortProvider.Ordering direction)
-
SortProvider
public SortProvider(AbstractColumn exp)
-
SortProvider
public SortProvider(QueryColumn<A,B,C> exp)
-
-
Method Detail
-
getSortProviders
public static SortProvider[] getSortProviders(ColumnProvider[] columns)
-
getGroupByClauses
public List<String> getGroupByClauses(DBDefinition defn)
-
getQueryableDatatypeForExpressionValue
public QueryableDatatype<?> getQueryableDatatypeForExpressionValue()
Description copied from interface:DBExpressionProvides a blank instance of theQueryableDatatypeused by this expression.You are probably looking for
ExpressionColumn.asExpressionColumn().Note that this method is not good for use in everyday DBvolution code and should probably be reserved for meta-programming.
Support DBvolution at Patreon
- Specified by:
getQueryableDatatypeForExpressionValuein interfaceDBExpression- Returns:
- the QueryableDatatype subclass that corresponds to the results of this expression
-
isAggregator
public boolean isAggregator()
Description copied from interface:DBExpressionReturns TRUE if this expression is an Aggregator like SUM() or LEAST().Subclasses must implement this method returning TRUE if the expression will combine the results of several rows to produce a result. If the expression relies on subexpressions, then the isAggregator method must return TRUE if the subexpressions include an aggregator.
Aggregators collect several rows together to produce a single result. Examples are MAX, MIN, and AVERAGE.
They are only appropriate in the SELECT clause and generally require the GROUP BY clause to be useful.
Aggregators are used with
DBReport. Aggregator expressions are included in the SELECT clause but excluded from the GROUP BY clause.Support DBvolution at Patreon
- Specified by:
isAggregatorin interfaceDBExpression- Returns:
- TRUE if this DBExpression represents an aggregating functions
-
isWindowingFunction
public boolean isWindowingFunction()
- Specified by:
isWindowingFunctionin interfaceDBExpression
-
getTablesInvolved
public Set<DBRow> getTablesInvolved()
Description copied from interface:DBExpressionReturns a Set of the DBRow instances involved in this expression.Used by QueryGraph to plot the connections between tables and avoid cartesian joins.
Support DBvolution at Patreon
- Specified by:
getTablesInvolvedin interfaceDBExpression- Returns:
- a set of DBRow instances involved in this DBExpression.
-
isPurelyFunctional
public boolean isPurelyFunctional()
Description copied from interface:DBExpressionIndicates whether or not the expression includes table columns.Purely functional expressions use only in-built functions or literal values to produce results and do not require data from tables.
Some databases, notably MS SQLServer, can not group purely functional expressions.
Support DBvolution at Patreon
- Specified by:
isPurelyFunctionalin interfaceDBExpression- Returns:
- TRUE if the expression does not access table data, otherwise FALSE.
-
isComplexExpression
public boolean isComplexExpression()
- Specified by:
isComplexExpressionin interfaceDBExpression
-
createSQLForFromClause
public String createSQLForFromClause(DBDatabase database)
- Specified by:
createSQLForFromClausein interfaceDBExpression
-
createSQLForGroupByClause
public String createSQLForGroupByClause(DBDatabase database)
- Specified by:
createSQLForGroupByClausein interfaceDBExpression
-
getInnerExpression
public AnyExpression<? extends Object,? extends AnyResult<?>,? extends QueryableDatatype<?>> getInnerExpression()
- Returns:
- the innerExpression
-
hasQueryColumn
public boolean hasQueryColumn()
-
hasColumn
public boolean hasColumn()
-
getColumn
protected AbstractColumn getColumn()
-
setQueryColumn
public void setQueryColumn(QueryColumn<?,? extends AnyResult<?>,?> qc)
-
getQueryColumn
public QueryColumn<?,?,?> getQueryColumn()
-
asExpressionColumn
public QueryableDatatype<?> asExpressionColumn()
-
toSQLString
public String toSQLString(DBDefinition defn)
Description copied from interface:HasSQLStringProduces the snippet provided by this class.This is only used internally.
If you are extending DBvolution and adding a new function this is the place to format the information for use in SQL. A DBDefinition instance is provided to supply context and so your SQL can used on multiple database engines.
- Specified by:
toSQLStringin interfaceHasSQLString- Parameters:
defn- the target databaseSupport DBvolution at Patreon
- Returns:
- the DBValue formatted as a SQL snippet
-
getExpressionSQL
protected String getExpressionSQL(DBDefinition defn)
-
usesEmptyStringForNull
protected boolean usesEmptyStringForNull(DBDefinition defn)
-
hasInnerExpression
public boolean hasInnerExpression()
-
copy
public SortProvider copy()
Description copied from interface:DBExpressionA Complete Copy Of This DBValue.Immutability in DBvolution is maintain by internally copying objects.
This method enables immutability by performing a deep copy of the object.
Singletons may return themselves but all other objects must return a new instance with copies of all mutable fields.
Support DBvolution at Patreon
- Specified by:
copyin interfaceDBExpression- Returns:
- a copy of this
DBValue
-
getSortDirectionSQL
public String getSortDirectionSQL(DBDefinition defn)
Returns the sort order set for the provider.defaults to ASCENDING
- Parameters:
defn- the database definition- Returns:
- SQL for the sort direction.
-
getOrdering
public SortProvider.Ordering getOrdering()
-
nullsLast
public SortProvider nullsLast()
-
nullsFirst
public SortProvider nullsFirst()
-
nullsHighest
public SortProvider nullsHighest()
-
nullsLowest
public SortProvider nullsLowest()
-
-