Class Query

  • All Implemented Interfaces:
    Serializable

    public class Query
    extends Expression
    Represents a SQL Query.
    Since:
    2.0.0
    Author:
    Rui Vilao (rui.vilao@feedzai.com)
    See Also:
    Serialized Form
    • Constructor Detail

      • Query

        public Query()
        Creates a new instance of Query.
    • Method Detail

      • translate

        public String translate()
        Description copied from class: Expression
        Translates the expression.
        Specified by:
        translate in class Expression
        Returns:
        A translation of the implementing expression.
      • getSelectColumns

        public List<Expression> getSelectColumns()
        Gets the SELECT columns.
        Returns:
        The SELECT columns.
      • getFromColumns

        public List<Expression> getFromColumns()
        Gets the FROM columns.
        Returns:
        The FROM columns.
      • getWhere

        public Expression getWhere()
        Gets the WHERE expression.
        Returns:
        The WHERE expression.
      • getGroupbyColumns

        public List<Expression> getGroupbyColumns()
        Gets the GROUP BY expressions.
        Returns:
        The GROUP BY expressions.
      • getHaving

        public Expression getHaving()
        Gets the HAVING expression.
        Returns:
        The HAVING expression.
      • getOrderbyColumns

        public List<Expression> getOrderbyColumns()
        Gets the ORDER BY expressions.
        Returns:
        The ORDER BY expressions.
      • getLimit

        public Integer getLimit()
        Gets the limit. null is returned when not applicable.
        Returns:
        The limit.
      • getOffset

        public Integer getOffset()
        Gets the offset. null is returned when not applicable.
        Returns:
        The offset.
      • isDistinct

        public boolean isDistinct()
        Checks if the SELECT expression is distinct.
        Returns:
        true is the SELECT expression is distinct, false otherwise.
      • isForUpdate

        public boolean isForUpdate()
        Checks if query is a FOR UPDATE. If it is set as true the database will block reads from another transactions also using SELECT FOR UPDATE.
        Returns:
        true if it is for update; false otherwise.
        Since:
        2.8.4
      • distinct

        public Query distinct()
        Sets the SELECT expression as DISTINCT.
        Returns:
        This expression.
      • select

        public Query select​(Expression... selectColumns)
        Adds the SELECT columns.
        Parameters:
        selectColumns - The columns.
        Returns:
        This expression.
      • select

        public Query select​(Collection<? extends Expression> selectColumns)
        Adds the SELECT columns.
        Parameters:
        selectColumns - The columns.
        Returns:
        This expression.
      • from

        public Query from​(Expression... fromColumns)
        Adds the FROM columns.
        Parameters:
        fromColumns - The columns.
        Returns:
        This expression.
      • from

        public Query from​(Collection<? extends Expression> fromColumns)
        Adds the FROM columns.
        Parameters:
        fromColumns - The columns.
        Returns:
        This expression.
      • andWhere

        public Query andWhere​(Expression where)
        The WHERE clause.

        If there is no where clause already defined, sets to the defined value.

        If there is already an expression for where defined, defines an and expression between old and new clauses.

        Example:

             query.where(eq(column("col1"),k(1)).andWhere(eq(column("col2"),k(2))
        
             will be translated to
        
             ("col1" = 1) AND ("col2" = 2)
         
        Parameters:
        where - The WHERE expression.
        Returns:
        This expression.
      • where

        public Query where​(Expression where)
        The where clause.

        Note:This method replaces any where clauses previously defined.

        Parameters:
        where - The object.
        Returns:
        This expression.
      • groupby

        public Query groupby​(Expression... groupbyColumns)
        Adds the GROUP BY columns.
        Parameters:
        groupbyColumns - The columns.
        Returns:
        This expression.
      • groupby

        public Query groupby​(Collection<? extends Expression> groupbyColumns)
        Adds the GROUP BY columns.
        Parameters:
        groupbyColumns - The columns.
        Returns:
        This expression.
      • having

        public Query having​(Expression having)
        Adds the HAVING expression.
        Parameters:
        having - The having expression.
        Returns:
        This expression.
      • orderby

        public Query orderby​(Expression... orderbyColumns)
        Adds the ORDER BY columns.
        Parameters:
        orderbyColumns - The columns.
        Returns:
        This expression.
      • orderby

        public Query orderby​(Collection<? extends Expression> orderbyColumns)
        Adds the ORDER BY columns.
        Parameters:
        orderbyColumns - The columns.
        Returns:
        This expression.
      • limit

        public Query limit​(Integer limit)
        Sets the limit.
        Parameters:
        limit - The number of rows that the query returns.
        Returns:
        This expression.
      • offset

        public Query offset​(Integer offset)
        Sets the offset.
        Parameters:
        offset - The start position
        Returns:
        This expression.
      • forUpdate

        public Query forUpdate​(boolean forUpdate)
        Sets whether query is FOR UPDATE or not. If it is set as true the database will block reads from another transactions also using SELECT FOR UPDATE.
        Parameters:
        forUpdate - If it is FOR UPDATE or not.
        Returns:
        This expression.
        Since:
        2.8.4