org.intermine.objectstore.query
Class Query

java.lang.Object
  extended by org.intermine.objectstore.query.Query
All Implemented Interfaces:
FromElement, Queryable

public class Query
extends java.lang.Object
implements FromElement, Queryable

This class provides an implementation-independent abstract representation of a query


Constructor Summary
Query()
          Empty constructor.
 
Method Summary
 Query addFrom(FromElement cls)
          Adds a FromElement to the FROM clause of this Query
 Query addFrom(FromElement cls, java.lang.String alias)
          Adds a FromElement to the FROM clause of this Query
 Query addToGroupBy(QueryNode node)
          Add a QueryNode to the GROUP BY clause of this Query
 Query addToOrderBy(QueryOrderable node)
          Add a QueryOrderable to the ORDER BY clause of this Query
 Query addToOrderBy(QueryOrderable node, java.lang.String direction)
          Add a QueryOrderable to the ORDER BY clause of this Query
 void addToSelect(QuerySelectable node)
          Add a QuerySelectable to the SELECT clause of this Query
 Query addToSelect(QuerySelectable node, java.lang.String alias)
          Add a QuerySelectable to the SELECT clause of this Query
 void alias(java.lang.Object obj, java.lang.String alias)
          Set an alias for an element in the Query.
 void clearOrderBy()
          Clears the ORDER BY clause of this Query
 void clearSelect()
          Clears the SELECT list
 Query deleteFrom(FromElement cls)
          Remove a FromElement from the FROM clause
 Query deleteFromGroupBy(QueryNode node)
          Remove a QueryNode from the GROUP BY clause
 Query deleteFromOrderBy(QueryOrderable node)
          Remove a QueryOrderable from the ORDER BY clause
 Query deleteFromSelect(QuerySelectable node)
          Remove a QuerySelectable from the SELECT clause
 java.util.Map<java.lang.Object,java.lang.String> getAliases()
          Returns the map of QuerySelectables and FromElements to String aliases
 Constraint getConstraint()
          Get the current constraint on this Query
 java.util.List<java.lang.Object> getEffectiveOrderBy()
          Gets the effective ORDER BY clause of this Query, such as may be used to create SQL.
 java.util.Set<FromElement> getFrom()
          Returns all FromElements in the FROM clause
 java.util.Set<QueryNode> getGroupBy()
          Gets the GROUP BY clause of this Query
 IqlQuery getIqlQuery()
          Returns an IqlQuery object representing this query, that may have been cached.
 int getLimit()
          Returns the LIMIT parameter for this query.
 java.util.List<QueryOrderable> getOrderBy()
          Gets the ORDER BY clause of this Query
 java.util.Map<java.lang.String,java.lang.Object> getReverseAliases()
          Returns the map of String aliases to QuerySelectables and FromElements
 java.util.List<QuerySelectable> getSelect()
          Gets the SELECT list
 boolean isDistinct()
          Get the value of the distinct property
 void setConstraint(Constraint constraint)
          Constrain this Query using either a single constraint or a set of constraints
 void setDistinct(boolean distinct)
          Set the value of the distinct property, which determines whether duplicates are permitted in the results returned by this Query
 void setLimit(int limit)
          Sets the LIMIT parameter for this query - note that this is only honoured in a subquery.
 java.lang.String toString()
          Returns a string representation of this Query object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Query

public Query()
Empty constructor.

Method Detail

setLimit

public void setLimit(int limit)
Sets the LIMIT parameter for this query - note that this is only honoured in a subquery.

Parameters:
limit - the new limit parameter - the results will be truncated to this many rows

getLimit

public int getLimit()
Returns the LIMIT parameter for this query.

Returns:
the limit parameter

addFrom

public Query addFrom(FromElement cls)
Adds a FromElement to the FROM clause of this Query

Parameters:
cls - the FromElement to be added
Returns:
the updated Query

addFrom

public Query addFrom(FromElement cls,
                     java.lang.String alias)
Adds a FromElement to the FROM clause of this Query

Parameters:
cls - the FromElement to be added
alias - the alias for this FromElement
Returns:
the updated Query

deleteFrom

public Query deleteFrom(FromElement cls)
Remove a FromElement from the FROM clause

Parameters:
cls - the FromElement to remove
Returns:
the updated Query

getFrom

public java.util.Set<FromElement> getFrom()
Returns all FromElements in the FROM clause

Returns:
set of FromElements

setConstraint

public void setConstraint(Constraint constraint)
Constrain this Query using either a single constraint or a set of constraints

Specified by:
setConstraint in interface Queryable
Parameters:
constraint - the constraint or constraint set

getConstraint

public Constraint getConstraint()
Get the current constraint on this Query

Specified by:
getConstraint in interface Queryable
Returns:
the constraint

addToGroupBy

public Query addToGroupBy(QueryNode node)
Add a QueryNode to the GROUP BY clause of this Query

Parameters:
node - the node to add
Returns:
the updated Query

deleteFromGroupBy

public Query deleteFromGroupBy(QueryNode node)
Remove a QueryNode from the GROUP BY clause

Parameters:
node - the node to remove
Returns:
the updated Query

getGroupBy

public java.util.Set<QueryNode> getGroupBy()
Gets the GROUP BY clause of this Query

Returns:
the set of GROUP BY nodes

addToOrderBy

public Query addToOrderBy(QueryOrderable node)
Add a QueryOrderable to the ORDER BY clause of this Query

Parameters:
node - the node to add
Returns:
the updated Query

addToOrderBy

public Query addToOrderBy(QueryOrderable node,
                          java.lang.String direction)
Add a QueryOrderable to the ORDER BY clause of this Query

Parameters:
node - the node to add
direction - ascending or descending
Returns:
the updated Query

deleteFromOrderBy

public Query deleteFromOrderBy(QueryOrderable node)
Remove a QueryOrderable from the ORDER BY clause

Parameters:
node - the node to remove
Returns:
the updated Query

clearOrderBy

public void clearOrderBy()
Clears the ORDER BY clause of this Query


getOrderBy

public java.util.List<QueryOrderable> getOrderBy()
Gets the ORDER BY clause of this Query

Returns:
the List of ORDER BY nodes

getEffectiveOrderBy

public java.util.List<java.lang.Object> getEffectiveOrderBy()
Gets the effective ORDER BY clause of this Query, such as may be used to create SQL.

Returns:
a List of ORDER BY nodes

addToSelect

public void addToSelect(QuerySelectable node)
Add a QuerySelectable to the SELECT clause of this Query

Specified by:
addToSelect in interface Queryable
Parameters:
node - the QuerySelectable to add

addToSelect

public Query addToSelect(QuerySelectable node,
                         java.lang.String alias)
Add a QuerySelectable to the SELECT clause of this Query

Parameters:
node - the QuerySelectable to add
alias - the alias for this FromElement
Returns:
the updated Query

deleteFromSelect

public Query deleteFromSelect(QuerySelectable node)
Remove a QuerySelectable from the SELECT clause

Parameters:
node - the QuerySelectable to remove
Returns:
the updated Query

getSelect

public java.util.List<QuerySelectable> getSelect()
Gets the SELECT list

Specified by:
getSelect in interface Queryable
Returns:
the (unmodifiable) list

clearSelect

public void clearSelect()
Clears the SELECT list


isDistinct

public boolean isDistinct()
Get the value of the distinct property

Returns:
the value of distinct

setDistinct

public void setDistinct(boolean distinct)
Set the value of the distinct property, which determines whether duplicates are permitted in the results returned by this Query

Parameters:
distinct - the value of distinct

getAliases

public java.util.Map<java.lang.Object,java.lang.String> getAliases()
Returns the map of QuerySelectables and FromElements to String aliases

Returns:
the map

getReverseAliases

public java.util.Map<java.lang.String,java.lang.Object> getReverseAliases()
Returns the map of String aliases to QuerySelectables and FromElements

Returns:
the map

toString

public java.lang.String toString()
Returns a string representation of this Query object

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

getIqlQuery

public IqlQuery getIqlQuery()
Returns an IqlQuery object representing this query, that may have been cached.

Returns:
an IqlQuery object

alias

public void alias(java.lang.Object obj,
                  java.lang.String alias)
Set an alias for an element in the Query.

Parameters:
obj - the element to alias
alias - the alias to give