com.metamatrix.query.sql.lang
Class OrderBy

java.lang.Object
  extended by com.metamatrix.query.sql.lang.OrderBy
All Implemented Interfaces:
LanguageObject, java.io.Serializable, java.lang.Cloneable

public class OrderBy
extends java.lang.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.

See Also:
Serialized Form

Field Summary
static boolean ASC
          Constant for the ascending value
static boolean DESC
          Constant for the descending value
 
Constructor Summary
OrderBy()
          Constructs a default instance of this class.
OrderBy(java.util.List parameters)
          Constructs an instance of this class from an ordered set of elements.
OrderBy(java.util.List parameters, java.util.List types)
          Constructs an instance of this class from an ordered set of elements.
 
Method Summary
 void acceptVisitor(LanguageVisitor visitor)
          Method for accepting a visitor.
 void addVariable(SingleElementSymbol element)
          Adds a new variable to the list of order by elements.
 void addVariable(SingleElementSymbol element, boolean type)
          Adds a new variable to the list of order by elements with the specified sort order
 java.lang.Object clone()
          Return deep copy of this ORDER BY clause.
 boolean equals(java.lang.Object obj)
          Compare two OrderBys for equality.
 java.lang.Boolean getOrderType(int index)
          Returns the sort order at the specified index
 java.util.List getTypes()
          Returns an ordered list of sort direction for each order.
 SingleElementSymbol getVariable(int index)
          Returns the ORDER BY element at the specified index.
 int getVariableCount()
          Returns the number of elements in ORDER BY.
 java.util.List getVariables()
          Returns an ordered list of the symbols in ORDER BY
 int hashCode()
          Get hashcode for OrderBy.
 boolean isInPlanForm()
           
 void replaceVariables(java.util.Collection elements)
          Sets a new collection of variables to be used.
 void setInPlanForm(boolean inPlanForm)
           
 java.lang.String toString()
          Returns a string representation of an instance of this class.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ASC

public static final boolean ASC
Constant for the ascending value


DESC

public static final boolean DESC
Constant for the descending value

Constructor Detail

OrderBy

public OrderBy()
Constructs a default instance of this class.


OrderBy

public OrderBy(java.util.List parameters)
Constructs an instance of this class from an ordered set of elements.

Parameters:
parameters - The ordered list of SingleElementSymbol

OrderBy

public OrderBy(java.util.List parameters,
               java.util.List types)
Constructs an instance of this class from an ordered set of elements.

Parameters:
parameters - The ordered list of SingleElementSymbol
types - 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

getVariables

public java.util.List getVariables()
Returns an ordered list of the symbols in ORDER BY

Parameters:
List - of SingleElementSymbol in ORDER BY

getTypes

public java.util.List getTypes()
Returns an ordered list of sort direction for each order.

Parameters:
List - of Boolean, Boolean.TRUE represents ascending

getVariable

public SingleElementSymbol 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 java.lang.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 void addVariable(SingleElementSymbol element)
Adds a new variable to the list of order by elements.

Parameters:
element - Element to add

addVariable

public void addVariable(SingleElementSymbol element,
                        boolean type)
Adds a new variable to the list of order by elements with the specified sort order

Parameters:
element - Element to add
type - True for ascending, false for descending

replaceVariables

public void replaceVariables(java.util.Collection elements)
Sets a new collection of variables to be used. The replacement set must be of the same size as the previous set.

Parameters:
elements - Collection of SingleElementSymbol
Throws:
java.lang.IllegalArgumentException - if element is null or size of elements != size of existing elements

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 interface LanguageObject
Parameters:
visitor - Visitor being used

clone

public java.lang.Object clone()
Return deep copy of this ORDER BY clause.

Specified by:
clone in interface LanguageObject
Overrides:
clone in class java.lang.Object
Returns:
Deep clone of this object

equals

public boolean equals(java.lang.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.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Other object
Returns:
True if equal

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.

Overrides:
hashCode in class java.lang.Object
Returns:
Hash code

toString

public java.lang.String toString()
Returns a string representation of an instance of this class.

Overrides:
toString in class java.lang.Object
Returns:
String representation of object

isInPlanForm

public boolean isInPlanForm()

setInPlanForm

public void setInPlanForm(boolean inPlanForm)


Copyright © 2009. All Rights Reserved.