Package org.teiid.query.sql.lang
Class OrderBy
- java.lang.Object
-
- org.teiid.query.sql.lang.OrderBy
-
- All Implemented Interfaces:
Cloneable
,LanguageObject
public class OrderBy extends Object implements LanguageObject
Represents the ORDER BY clause of a query. The ORDER BY clause states what order the rows of a result should be returned in. Each element in the ORDER BY represents a sort that is completed in the order listed. The optional keywords ASC and DESC can be put after each element to specify whether the sort is ascending or descending.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.teiid.query.sql.LanguageObject
LanguageObject.Util
-
-
Constructor Summary
Constructors Constructor Description OrderBy()
Constructs a default instance of this class.OrderBy(List<? extends Expression> parameters)
Constructs an instance of this class from an ordered list of elements.OrderBy(List<? extends Expression> parameters, List<Boolean> types)
Constructs an instance of this class from an ordered set of elements.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acceptVisitor(LanguageVisitor visitor)
Method for accepting a visitor.OrderByItem
addVariable(Expression element)
Adds a new variable to the list of order by elements.OrderByItem
addVariable(Expression element, boolean type)
Adds a new variable to the list of order by elements with the specified sort orderOrderBy
clone()
Return deep copy of this ORDER BY clause.boolean
equals(Object obj)
Compare two OrderBys for equality.int
getExpressionPosition(int orderIndex)
List<OrderByItem>
getOrderByItems()
Boolean
getOrderType(int index)
Returns the sort order at the specified indexList<Expression>
getSortKeys()
Get the list or sort key symbols.List<Boolean>
getTypes()
Expression
getVariable(int index)
Returns the ORDER BY element at the specified index.int
getVariableCount()
Returns the number of elements in ORDER BY.int
hashCode()
Get hashcode for OrderBy.boolean
hasUnrelated()
boolean
isUserOrdering()
void
removeOrderByItem(int index)
void
setExpressionPosition(int orderIndex, int selectIndex)
void
setUserOrdering(boolean userOrdering)
String
toString()
Returns a string representation of an instance of this class.
-
-
-
Field Detail
-
ASC
public static final boolean ASC
Constant for the ascending value- See Also:
- Constant Field Values
-
DESC
public static final boolean DESC
Constant for the descending value- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OrderBy
public OrderBy()
Constructs a default instance of this class.
-
OrderBy
public OrderBy(List<? extends Expression> parameters)
Constructs an instance of this class from an ordered list of elements.- Parameters:
parameters
- The ordered list of SingleElementSymbol
-
OrderBy
public OrderBy(List<? extends Expression> parameters, List<Boolean> types)
Constructs an instance of this class from an ordered set of elements.- Parameters:
parameters
- The ordered list of SingleElementSymboltypes
- The list of directions by which the results are ordered (Boolean, true=ascending)
-
-
Method Detail
-
getVariableCount
public int getVariableCount()
Returns the number of elements in ORDER BY.- Returns:
- Number of variables in ORDER BY
-
getOrderByItems
public List<OrderByItem> getOrderByItems()
-
getVariable
public Expression getVariable(int index)
Returns the ORDER BY element at the specified index.- Parameters:
index
- Index to get- Returns:
- The element at the index
-
getOrderType
public Boolean getOrderType(int index)
Returns the sort order at the specified index- Parameters:
index
- Index to get- Returns:
- The sort order at the index
-
addVariable
public OrderByItem addVariable(Expression element)
Adds a new variable to the list of order by elements.- Parameters:
element
- Element to add
-
addVariable
public OrderByItem addVariable(Expression element, boolean type)
Adds a new variable to the list of order by elements with the specified sort order- Parameters:
element
- Element to addtype
- True for ascending, false for descending
-
acceptVisitor
public void acceptVisitor(LanguageVisitor visitor)
Description copied from interface:LanguageObject
Method for accepting a visitor. It is the responsibility of the language object to call back on the visitor.- Specified by:
acceptVisitor
in interfaceLanguageObject
- Parameters:
visitor
- Visitor being used
-
clone
public OrderBy clone()
Return deep copy of this ORDER BY clause.- Specified by:
clone
in interfaceLanguageObject
- Overrides:
clone
in classObject
- Returns:
- Deep clone of this object
-
equals
public boolean equals(Object obj)
Compare two OrderBys for equality. Order is important in the order by, so that is considered in the comparison. Also, the sort orders are considered.
-
hashCode
public int hashCode()
Get hashcode for OrderBy. WARNING: The hash code relies on the variables in the select, so changing the variables will change the hash code, causing a select to be lost in a hash structure. Do not hash a OrderBy if you plan to change it.
-
toString
public String toString()
Returns a string representation of an instance of this class.
-
setExpressionPosition
public void setExpressionPosition(int orderIndex, int selectIndex)
-
getExpressionPosition
public int getExpressionPosition(int orderIndex)
-
removeOrderByItem
public void removeOrderByItem(int index)
-
hasUnrelated
public boolean hasUnrelated()
-
getSortKeys
public List<Expression> getSortKeys()
Get the list or sort key symbols. Modifications to this list will not add or removeOrderByItem
s.- Returns:
-
setUserOrdering
public void setUserOrdering(boolean userOrdering)
-
isUserOrdering
public boolean isUserOrdering()
-
-