Class AbstractSelectStatementStateObject

java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractSelectStatementStateObject
All Implemented Interfaces:
StateObject
Direct Known Subclasses:
SelectStatementStateObject, SimpleSelectStatementStateObject

public abstract class AbstractSelectStatementStateObject extends AbstractStateObject
This state object represents the select statement, which has at least a SELECT clause and a FROM clause.
Since:
2.4
Version:
2.5
See Also:
  • Field Details

    • GROUP_BY_CLAUSE_PROPERTY

      public static final String GROUP_BY_CLAUSE_PROPERTY
      Notify the state object representing the GROUP BY clause has changed.
      See Also:
    • HAVING_CLAUSE_PROPERTY

      public static final String HAVING_CLAUSE_PROPERTY
      Notify the state object representing the HAVING clause has changed.
      See Also:
    • WHERE_CLAUSE_PROPERTY

      public static final String WHERE_CLAUSE_PROPERTY
      Notify the state object representing the WHERE clause has changed.
      See Also:
  • Constructor Details

    • AbstractSelectStatementStateObject

      protected AbstractSelectStatementStateObject(StateObject parent)
      Creates a new AbstractSelectStatementStateObject.
      Parameters:
      parent - The parent of this state object, which cannot be null
      Throws:
      NullPointerException - The given parent cannot be null
  • Method Details

    • addChildren

      protected void addChildren(List<StateObject> children)
      Description copied from class: AbstractStateObject
      Adds the children of this StateObject to the given list.
      Overrides:
      addChildren in class AbstractStateObject
      Parameters:
      children - The list used to store the children
    • addCollectionDeclaration

      public CollectionMemberDeclarationStateObject addCollectionDeclaration()
      Adds a new collection declaration to the FROM clause.
      Returns:
      The CollectionMemberDeclarationStateObject representing the collection declaration
    • addCollectionDeclaration

      public CollectionMemberDeclarationStateObject addCollectionDeclaration(String collectionValuedPath, String identificationVariable)
      Adds a new collection declaration to the FROM clause.
      Parameters:
      collectionValuedPath - The collection-valued path expression
      identificationVariable - The variable defining the collection-valued path expression
      Returns:
      The CollectionMemberDeclarationStateObject representing the collection declaration
    • addGroupByClause

      public GroupByClauseStateObject addGroupByClause()
      Adds the GROUP BY clause. The clause is not added if it's already present.
      Returns:
      The GroupByClauseStateObject
    • addGroupByClause

      public GroupByClauseStateObject addGroupByClause(String jpqlFragment)
      Adds the GROUP BY clause and parses the given JPQL fragment. The clause is not added if it's already present.
      Parameters:
      jpqlFragment - The fragment of the JPQL to parse that represents the group by items, the fragment cannot start with GROUP BY
      Returns:
      The GroupByClauseStateObject
    • addHavingClause

      public HavingClauseStateObject addHavingClause()
      Adds the HAVING clause. The clause is not added if it's already present.
      Returns:
      The GroupByClauseStateObject
    • addHavingClause

      public HavingClauseStateObject addHavingClause(String jpqlFragment)
      Adds the HAVING clause and parses the given JPQL fragment. The clause is not added if it's already present.
      Parameters:
      jpqlFragment - The fragment of the JPQL to parse that represents the conditional expression, the fragment cannot start with HAVING
      Returns:
      The HavingClauseStateObject
    • addRangeDeclaration

      public IdentificationVariableDeclarationStateObject addRangeDeclaration()
      Adds a new range variable declaration to the FROM clause.
      Returns:
      The StateObject representing the new range variable declaration
    • addRangeDeclaration

      public IdentificationVariableDeclarationStateObject addRangeDeclaration(IEntity entity, String identificationVariable)
      Adds to this select statement a new range variable declaration.
      Parameters:
      entity - The external form of the entity to add to the declaration list
      identificationVariable - The unique identifier identifying the given IEntity
      Returns:
      The StateObject representing the new range variable declaration
    • addRangeDeclaration

      public IdentificationVariableDeclarationStateObject addRangeDeclaration(String entityName, String identificationVariable)
      Adds to this select statement a new range variable declaration.
      Parameters:
      entityName - The name of the entity
      identificationVariable - The unique identifier identifying the entity
      Returns:
      The StateObject representing the range variable declaration
    • addWhereClause

      public WhereClauseStateObject addWhereClause()
      Adds the WHERE clause. The clause is not added if it's already present.
      Returns:
      The GroupByClauseStateObject
    • addWhereClause

      public WhereClauseStateObject addWhereClause(String jpqlFragment)
      Adds the WHERE clause and parses the given JPQL fragment. The clause is not added if it's already present.
      Parameters:
      jpqlFragment - The fragment of the JPQL to parse that represents the conditional expression, the fragment cannot start with WHERE
      Returns:
      The WhereClauseStateObject
    • buildFromClause

      protected abstract AbstractFromClauseStateObject buildFromClause()
      Creates the state object representing the FROM clause.
      Returns:
      A concrete instance of AbstractFromClauseStateObject
    • buildSelectClause

      protected abstract AbstractSelectClauseStateObject buildSelectClause()
      Creates the state object representing the SELECT clause.
      Returns:
      A concrete instance of AbstractSelectClauseStateObject
    • declarations

      public ListIterable<? extends VariableDeclarationStateObject> declarations()
      Returns the list of VariableDeclarationStateObject defining the variable declarations, which are mapping an entity to a variable or a collection-valued member to a variable.

      Example:

      • Employee e
      • IN (e.employees) AS emps
      Returns:
      The list of VariableDeclarationStateObject
    • findIdentificationVariable

      public IdentificationVariableStateObject findIdentificationVariable(String identificationVariable)
      Description copied from interface: StateObject
      Returns the IdentificationVariableStateObject representing the given identification variable.
      Specified by:
      findIdentificationVariable in interface StateObject
      Overrides:
      findIdentificationVariable in class AbstractStateObject
      Parameters:
      identificationVariable - The name of the identification variable to retrieve its state object
      Returns:
      The IdentificationVariableStateObject defining the given identification variable
    • getDeclaration

      public DeclarationStateObject getDeclaration()
      Description copied from interface: StateObject
      Returns the declaration clause which defines the domain of the query by declaring identification variables.
      Specified by:
      getDeclaration in interface StateObject
      Overrides:
      getDeclaration in class AbstractStateObject
      Returns:
      The declaration clause of which this StateObject is a child; i.e. either the top-level declaration if this is part of the top query or the sub-level declaration if this is part of a subquery
    • getExpression

      public AbstractSelectStatement getExpression()
      Description copied from interface: StateObject
      Returns the actual parsed object if this StateObject representation of the JPQL query was created by parsing an existing JPQL query.
      Specified by:
      getExpression in interface StateObject
      Overrides:
      getExpression in class AbstractStateObject
      Returns:
      The parsed object when a JPQL query is parsed and converted into a StateObject or null when the JPQL query is manually created (i.e. not from a string)
    • getFromClause

      public AbstractFromClauseStateObject getFromClause()
      Returns the state object representing the FROM clause.
      Returns:
      The state object representing the FROM clause, which is never null
    • getGroupByClause

      public GroupByClauseStateObject getGroupByClause()
      Returns the state object representing the GROUP BY clause.
      Returns:
      Either the actual state object representing the GROUP BY clause or null if it's not present
    • getHavingClause

      public HavingClauseStateObject getHavingClause()
      Returns the state object representing the HAVING clause.
      Returns:
      Either the actual state object representing the HAVING clause or null if it's not present
    • getSelectClause

      public AbstractSelectClauseStateObject getSelectClause()
      Returns the state object representing the SELECT clause.
      Returns:
      Either the actual state object representing the SELECT clause, which is never null
    • getWhereClause

      public WhereClauseStateObject getWhereClause()
      Returns the state object representing the WHERE clause.
      Returns:
      Either the actual state object representing the WHERE clause or the null state object since null is never returned
    • hasGroupByClause

      public boolean hasGroupByClause()
      Returns the state object representing the GROUP BY clause.
      Returns:
      Either the actual state object representing the GROUP BY clause or null if it's not present
    • hasHavingClause

      public boolean hasHavingClause()
      Returns the state object representing the HAVING clause.
      Returns:
      Either the actual state object representing the HAVING clause or null if it's not present
    • hasWhereClause

      public boolean hasWhereClause()
      Returns the state object representing the WHERE clause.
      Returns:
      Either the actual state object representing the WHERE clause or null if it's not present
    • identificationVariables

      public Iterable<IdentificationVariableStateObject> identificationVariables()
      Returns the IdentificationVariableStateObjects holding onto the identification variables, which are the variables defined in the FROM clause.

      Example:

      • Employee e; e is returned
      • IN (e.employees) AS emps; emps is returned
      • Manager m JOIN m.employees emps; m and emps are returned
      Returns:
      The list of IdentificationVariableStateObjects
    • initialize

      protected void initialize()
      Description copied from class: AbstractStateObject
      Initializes this state object.
      Overrides:
      initialize in class AbstractStateObject
    • isEquivalent

      public boolean isEquivalent(StateObject stateObject)
      Description copied from interface: StateObject
      Determines whether the given StateObject is equivalent to this one, i.e. the information of both StateObject is the same.
      Specified by:
      isEquivalent in interface StateObject
      Overrides:
      isEquivalent in class AbstractStateObject
      Parameters:
      stateObject - The StateObject to compare its content to this one
      Returns:
      true if both object are equivalent; false otherwise
    • parseSelect

      public void parseSelect(String jpqlFragment)
      Parses the given JPQL fragment and create the select item. For the top-level query, the fragment can contain several select items but for a subquery, it can represent only one.
      Parameters:
      jpqlFragment - The portion of the query representing one or several select items
    • removeGroupByClause

      public void removeGroupByClause()
      Removes the GROUP BY clause.
    • removeHavingClause

      public void removeHavingClause()
      Removes the HAVING clause.
    • removeWhereClause

      public void removeWhereClause()
      Removes the WHERE clause.
    • toggleGroupByClause

      public void toggleGroupByClause()
      Either adds or removes the state object representing the GROUP BY clause.
    • toggleHavingClause

      public void toggleHavingClause()
      Either adds or removes the state object representing the HAVING clause.
    • toggleWhereClause

      public void toggleWhereClause()
      Either adds or removes the state object representing the WHERE clause.
    • toTextInternal

      protected void toTextInternal(Appendable writer) throws IOException
      Description copied from class: AbstractStateObject
      Prints out a string representation of this StateObject, which should not be used to define a true string representation of a JPQL query but should be used for debugging purposes.
      Specified by:
      toTextInternal in class AbstractStateObject
      Parameters:
      writer - The writer used to print out the string representation
      Throws:
      IOException - This should never happens, it is only required because Appendable is used instead of any concrete class