Class Query

  • All Implemented Interfaces:
    Cloneable, FilteredCommand, LanguageObject

    public class Query
    extends QueryCommand
    implements FilteredCommand
    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
     
    • 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
      • 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
      • setCriteria

        public void setCriteria​(Criteria criteria)
        Set the criteria clause for the query.
        Specified by:
        setCriteria in interface FilteredCommand
        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.
        Specified by:
        acceptVisitor in interface LanguageObject
        Parameters:
        visitor - Visitor being used
      • getProjectedSymbols

        public List<Expression> 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 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​(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 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 Object
        Returns:
        Hash code
      • areColumnsCachable

        public static boolean areColumnsCachable​(Collection<? extends Expression> projectedSymbols)
      • hasAggregates

        public boolean hasAggregates()
      • isRowConstructor

        public boolean isRowConstructor()
      • setRowConstructor

        public void setRowConstructor​(boolean isRowConstructor)