Class SelectStatement

All Implemented Interfaces:
Expression

public final class SelectStatement extends AbstractSelectStatement
A SELECT query is an operation that retrieves data from one or more tables or views.

JPA:

BNF: select_statement ::= select_clause from_clause [where_clause] [groupby_clause] [having_clause] [orderby_clause]

EclipseLink 2.4:

BNF: select_statement ::= select_clause from_clause [where_clause] [groupby_clause] [having_clause] [orderby_clause] {union_clause}*

HQL query (EclipseLink 2.5):

BNF: select_statement ::= [select_clause] from_clause [where_clause] [groupby_clause] [having_clause] [orderby_clause] {union_clause}*

Version:
2.5
See Also:
Author:
Pascal Filion
  • Constructor Details

    • SelectStatement

      public SelectStatement(AbstractExpression parent)
      Creates a new SelectStatement.
      Parameters:
      parent - The parent of this expression
  • Method Details

    • accept

      public void accept(ExpressionVisitor visitor)
      Description copied from interface: Expression
      Visits this Expression by the given visitor.
      Parameters:
      visitor - The ExpressionVisitor to visit this object
    • acceptChildren

      public void acceptChildren(ExpressionVisitor visitor)
      Description copied from interface: Expression
      Visits the children of this Expression. This method can be used to optimize traversing the children since a new list is not created every time Expression.children() is called.

      This does not traverse the Expression sub-hierarchy, use a subclass of AbstractTraverseChildrenVisitor in order to traverse the entire sub-hierarchy.

      Specified by:
      acceptChildren in interface Expression
      Overrides:
      acceptChildren in class AbstractSelectStatement
      Parameters:
      visitor - The visitor to visit the children of this object.
    • addChildrenTo

      protected void addChildrenTo(Collection<Expression> children)
      Description copied from class: AbstractExpression
      Adds the children of this AbstractExpression to the given collection.
      Overrides:
      addChildrenTo in class AbstractSelectStatement
      Parameters:
      children - The collection used to store the children
    • addOrderedChildrenTo

      protected void addOrderedChildrenTo(List<Expression> children)
      Description copied from class: AbstractExpression
      Adds the children of this AbstractExpression to the given list.
      Overrides:
      addOrderedChildrenTo in class AbstractSelectStatement
      Parameters:
      children - The list used to store the string representation of this AbstractExpression
    • buildFromClause

      protected FromClause buildFromClause()
      Description copied from class: AbstractSelectStatement
      Creates the expression representing the from clause of this select statement.
      Specified by:
      buildFromClause in class AbstractSelectStatement
      Returns:
      A new from clause, null can't be returned
    • buildSelectClause

      protected SelectClause buildSelectClause()
      Description copied from class: AbstractSelectStatement
      Creates the expression representing the select clause of this select statement.
      Specified by:
      buildSelectClause in class AbstractSelectStatement
      Returns:
      A new from clause, null can't be returned
    • findQueryBNF

      public JPQLQueryBNF findQueryBNF(Expression expression)
      Description copied from interface: Expression
      Retrieves the JPQLQueryBNF that represents the fragment of this Expression that was used when parsing the given Expression.
      Specified by:
      findQueryBNF in interface Expression
      Overrides:
      findQueryBNF in class AbstractSelectStatement
      Parameters:
      expression - The Expression that is a descendant of this one
      Returns:
      The JPQLQueryBNF that was used to parse the given expression
    • getOrderByClause

      public Expression getOrderByClause()
      Returns the Expression representing the ORDER BY clause.
      Returns:
      The expression representing the ORDER BY clause
    • getQueryBNF

      public JPQLQueryBNF getQueryBNF()
      Description copied from interface: Expression
      Returns the BNF of this Expression.
      Returns:
      The JPQLQueryBNF, which represents the grammar of this Expression
    • getUnionClauses

      public Expression getUnionClauses()
      Returns the Expression representing the UNION clauses.
      Returns:
      The Expression representing the UNION clauses
    • hasOrderByClause

      public boolean hasOrderByClause()
      Determines whether the ORDER BY clause is defined or not.
      Returns:
      true if the query that got parsed had the ORDER BY clause
    • hasSpaceBeforeOrderBy

      public boolean hasSpaceBeforeOrderBy()
      Determines whether a whitespace was parsed before the ORDER BY clause. In some cases, the space could be owned by a child of the previous clause.
      Returns:
      true if there was a whitespace before the ORDER BY; false otherwise
    • hasSpaceBeforeUnion

      public boolean hasSpaceBeforeUnion()
      Determines whether a whitespace was parsed before the UNION clause. In some cases, the space could be owned by a child of the previous clause.
      Returns:
      true if there was a whitespace before the UNION; false otherwise
    • hasUnionClauses

      public boolean hasUnionClauses()
      Determines whether at least one UNION clause was defined.
      Returns:
      true if the query that got parsed had the UNION clauses
    • isParsingComplete

      protected boolean isParsingComplete(WordParser wordParser, String word, Expression expression)
      Description copied from class: AbstractExpression
      Determines whether the parsing is complete based on what is left in the given text. The text is never empty.
      Overrides:
      isParsingComplete in class AbstractExpression
      Parameters:
      wordParser - The text to parse based on the current position of the cursor
      word - The word that was retrieved from the given text, which is the first word in the text
      expression - The Expression that has already been parsed
      Returns:
      true if the text no longer can't be parsed by the current expression; false if more can be parsed
    • parse

      protected void parse(WordParser wordParser, boolean tolerant)
      Description copied from class: AbstractExpression
      Parses the query by starting at the current position, which is part of the given WordParser.
      Overrides:
      parse in class AbstractSelectStatement
      Parameters:
      wordParser - The text to parse based on the current position of the cursor
      tolerant - Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
    • toParsedText

      protected void toParsedText(StringBuilder writer, boolean actual)
      Description copied from class: AbstractExpression
      Generates a string representation of this Expression, including its children, if it has any.
      Overrides:
      toParsedText in class AbstractSelectStatement
      Parameters:
      writer - The buffer used to append this Expression's string representation
      actual - Determines whether the string representation should represent what was parsed, i.e. include any "virtual" whitespace (such as ending whitespace) and the actual case of the JPQL identifiers