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 class
SortProvider.Ascending
static class
SortProvider.Column
static class
SortProvider.DefaultSort
static class
SortProvider.Descending
static class
SortProvider.NullsLast
static class
SortProvider.NullsOrderer
static class
SortProvider.Ordering
static class
SortProvider.OrderOfNulls
-
Field Summary
Fields Modifier and Type Field Description protected SortProvider.Ordering
direction
protected SortProvider.OrderOfNulls
nullsOrdering
-
Constructor Summary
Constructors Modifier Constructor Description protected
SortProvider()
SortProvider(AbstractColumn exp)
SortProvider(QueryColumn<A,B,C> exp)
protected
SortProvider(AnyExpression<? extends Object,? extends AnyResult<?>,? extends QueryableDatatype<?>> exp, SortProvider.Ordering direction)
protected
SortProvider(AnyExpression<A,B,C> exp)
protected
SortProvider(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:DBExpression
Provides a blank instance of theQueryableDatatype
used 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:
getQueryableDatatypeForExpressionValue
in interfaceDBExpression
- Returns:
- the QueryableDatatype subclass that corresponds to the results of this expression
-
isAggregator
public boolean isAggregator()
Description copied from interface:DBExpression
Returns 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:
isAggregator
in interfaceDBExpression
- Returns:
- TRUE if this DBExpression represents an aggregating functions
-
isWindowingFunction
public boolean isWindowingFunction()
- Specified by:
isWindowingFunction
in interfaceDBExpression
-
getTablesInvolved
public Set<DBRow> getTablesInvolved()
Description copied from interface:DBExpression
Returns 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:
getTablesInvolved
in interfaceDBExpression
- Returns:
- a set of DBRow instances involved in this DBExpression.
-
isPurelyFunctional
public boolean isPurelyFunctional()
Description copied from interface:DBExpression
Indicates 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:
isPurelyFunctional
in interfaceDBExpression
- Returns:
- TRUE if the expression does not access table data, otherwise FALSE.
-
isComplexExpression
public boolean isComplexExpression()
- Specified by:
isComplexExpression
in interfaceDBExpression
-
createSQLForFromClause
public String createSQLForFromClause(DBDatabase database)
- Specified by:
createSQLForFromClause
in interfaceDBExpression
-
createSQLForGroupByClause
public String createSQLForGroupByClause(DBDatabase database)
- Specified by:
createSQLForGroupByClause
in 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:HasSQLString
Produces 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:
toSQLString
in 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:DBExpression
A 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:
copy
in 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()
-
-