com.metamatrix.query.sql.lang
Class Query

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

public class Query
extends QueryCommand

A representation of a data query. A query consists of various parts, referred to as clauses. The following list the types of clauses that a query can hold, and their purpose:

      CLAUSE          PURPOSE
      =========       ==============================================
      Select          Defines the variables data to be retrieved for
                From                    Defines the groups to retrieve data from
      Criteria        Defines constraints on data retrieval ("where")
                GroupBy                 Defines how rows being returned should be grouped
                Having                  Defines how groups should be filtered, also a criteria
      OrderBy         Defines how the results should be sorted
                Option                  Defines any extra options on the query
 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.metamatrix.query.sql.lang.Command
tempGroupIDs, TYPE_BATCHED_UPDATE, TYPE_CREATE, TYPE_DELETE, TYPE_DROP, TYPE_DYNAMIC, TYPE_INSERT, TYPE_QUERY, TYPE_SQL, TYPE_STORED_PROCEDURE, TYPE_UNKNOWN, TYPE_UPDATE, TYPE_UPDATE_PROCEDURE, TYPE_XQUERY
 
Constructor Summary
Query()
          Constructs a default instance of this class.
Query(Select select, From from, Criteria criteria, GroupBy groupBy, Criteria having, OrderBy orderBy, Option option)
          Constructs an instance of this class given all the clauses
Query(Select select, From from, Criteria criteria, OrderBy orderBy, Option option)
          Constructs an instance of this class given the specified clauses
 
Method Summary
 void acceptVisitor(LanguageVisitor visitor)
          Method for accepting a visitor.
 boolean areResultsCachable()
          Whether the results are cachable.
 void clearCriteria()
          Set the criteria clause to null
 java.lang.Object clone()
          Deep clone Query to produce a new identical query.
 boolean equals(java.lang.Object obj)
          Compare two queries for equality.
 Criteria getCriteria()
          Get the criteria clause for the query.
 From getFrom()
          Get the from clause for the query.
 GroupBy getGroupBy()
          Get the group by clause for the query.
 Criteria getHaving()
          Get the having clause for the query.
 Into getInto()
           
 boolean getIsXML()
          Get the xml flag for the query
 Query getProjectedQuery()
           
 java.util.List getProjectedSymbols()
          Get the ordered list of all elements returned by this query.
 Select getSelect()
          Get the select clause for the query.
 int getType()
          Return type of command.
 int hashCode()
          Get hashcode for query.
 void setCriteria(Criteria criteria)
          Set the criteria clause for the query.
 void setFrom(From from)
          Set the from clause for the query.
 void setGroupBy(GroupBy groupBy)
          Set the group by clause for the query.
 void setHaving(Criteria having)
          Set the criteria clause for the query.
 void setInto(Into into)
           
 void setIsXML(boolean isXML)
          Get the xml flag for the query
 void setSelect(Select select)
          Set the select clause for the query.
 int updatingModelCount(QueryMetadataInterface metadata)
          Return the number of updates on physical sources by this command.
 
Methods inherited from class com.metamatrix.query.sql.lang.QueryCommand
getLimit, getOrderBy, setLimit, setOrderBy
 
Methods inherited from class com.metamatrix.query.sql.lang.Command
addExternalGroupsToContext, addExternalGroupToContext, copyMetadataState, getAllExternalGroups, getCorrelatedReferences, getExternalGroupContexts, getOption, getProcessorPlan, getSubCommands, getSubCommandsUpdatingModelCount, getSubCommandsUpdatingModelCount, getTemporaryMetadata, getUpdateCommandSymbol, getVirtualGroup, isResolved, printCommandTree, printCommandTree, pushNewResolvingContext, setCorrelatedReferences, setExternalGroupContexts, setIsResolved, setOption, setProcessorPlan, setTemporaryMetadata, setVirtualGroup, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Query

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


Query

public Query(Select select,
             From from,
             Criteria criteria,
             OrderBy orderBy,
             Option option)
Constructs an instance of this class given the specified clauses

Parameters:
select - SELECT clause
from - FROM clause
criteria - WHERE clause
orderBy - ORDER BY clause
option - OPTION clause

Query

public Query(Select select,
             From from,
             Criteria criteria,
             GroupBy groupBy,
             Criteria having,
             OrderBy orderBy,
             Option option)
Constructs an instance of this class given all the clauses

Parameters:
select - SELECT clause
from - FROM clause
criteria - WHERE clause
groupBy - GROUP BY clause
having - HAVING clause
orderBy - ORDER BY clause
option - OPTION clause
Method Detail

getType

public int getType()
Return type of command.

Specified by:
getType in class Command
Returns:
TYPE_QUERY

getSelect

public Select getSelect()
Get the select clause for the query.

Returns:
SELECT clause

setSelect

public void setSelect(Select select)
Set the select clause for the query.

Parameters:
select - SELECT clause

getIsXML

public boolean getIsXML()
Get the xml flag for the query

Returns:
boolean

setIsXML

public void setIsXML(boolean isXML)
Get the xml flag for the query


getFrom

public From getFrom()
Get the from clause for the query.

Returns:
FROM clause

setFrom

public void setFrom(From from)
Set the from clause for the query.

Parameters:
from - FROM clause

getCriteria

public Criteria getCriteria()
Get the criteria clause for the query.

Returns:
WHERE clause

setCriteria

public void setCriteria(Criteria criteria)
Set the criteria clause for the query.

Parameters:
criteria - WHERE clause

clearCriteria

public void clearCriteria()
Set the criteria clause to null


getGroupBy

public GroupBy getGroupBy()
Get the group by clause for the query.

Returns:
GROUP BY clause

setGroupBy

public void setGroupBy(GroupBy groupBy)
Set the group by clause for the query.

Parameters:
groupBy - GROUP BY clause

getHaving

public Criteria getHaving()
Get the having clause for the query.

Returns:
HAVING clause

setHaving

public void setHaving(Criteria having)
Set the criteria clause for the query.

Parameters:
having - HAVING clause

getInto

public Into getInto()
Returns:

setInto

public void setInto(Into into)
Parameters:
into -

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.

Parameters:
visitor - Visitor being used

getProjectedSymbols

public java.util.List getProjectedSymbols()
Get the ordered list of all elements returned by this query. These elements may be ElementSymbols or ExpressionSymbols but in all cases each represents a single column.

Specified by:
getProjectedSymbols in class Command
Returns:
Ordered list of SingleElementSymbol

clone

public java.lang.Object clone()
Deep clone Query to produce a new identical query.

Specified by:
clone in interface LanguageObject
Specified by:
clone in class Command
Returns:
Deep clone

equals

public boolean equals(java.lang.Object obj)
Compare two queries for equality. Queries will only evaluate to equal if they are IDENTICAL: select variables are in the same order, criteria are in the same exact structure.

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

hashCode

public int hashCode()
Get hashcode for query. WARNING: This hash code relies on the hash codes of the Select and Criteria clauses. If the query changes, it's hash code will change and it can be lost from collections. Hash code is only valid after query has been completely constructed.

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

areResultsCachable

public boolean areResultsCachable()
Description copied from class: Command
Whether the results are cachable.

Specified by:
areResultsCachable in class Command
Returns:
True if the results are cachable; false otherwise.
See Also:
Command.areResultsCachable()

updatingModelCount

public int updatingModelCount(QueryMetadataInterface metadata)
                       throws MetaMatrixComponentException
Description copied from class: Command
Return the number of updates on physical sources by this command.

Specified by:
updatingModelCount in class Command
Parameters:
metadata - QueryMetadataInterface
Returns:
The number of updates on physical sources by this command.
Throws:
MetaMatrixComponentException

getProjectedQuery

public Query getProjectedQuery()
Specified by:
getProjectedQuery in class QueryCommand
See Also:
QueryCommand.getProjectedQuery()


Copyright © 2009. All Rights Reserved.