java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
org.eclipse.persistence.jpa.jpql.tools.model.query.JPQLQueryStateObject
All Implemented Interfaces:
StateObject

public class JPQLQueryStateObject extends AbstractStateObject
This is the root of the StateObject hierarchy that represents a JPQL query. The only child of this state object is one of the three possible query statements.
Since:
2.4
Version:
2.4
See Also:
  • Field Details

    • QUERY_STATEMENT_PROPERTY

      public static final String QUERY_STATEMENT_PROPERTY
      Notifies the query statement has changed.
      See Also:
  • Constructor Details

    • JPQLQueryStateObject

      public JPQLQueryStateObject(IJPQLQueryBuilder queryBuilder, IManagedTypeProvider provider)
      Creates a new JPQLQueryStateObject.
      Parameters:
      queryBuilder - The builder that can create any StateObject for any given JPQL fragment when using a parse method
      provider - The external form of a provider that gives access to the JPA metadata
      Throws:
      NullPointerException - If one of the given arguments is null
  • Method Details

    • accept

      public void accept(StateObjectVisitor visitor)
      Description copied from interface: StateObject
      Visits this StateObject by the given visitor.
      Parameters:
      visitor - The visitor to visit this object
    • 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
    • addDeleteStatement

      public DeleteStatementStateObject addDeleteStatement()
      Changes the query statement to be a DELETE statement.
      Returns:
      The new root object of the DELETE statement
    • addDistinctSelectStatement

      public SelectStatementStateObject addDistinctSelectStatement()
      Changes the query statement to be a SELECT statement. The SELECT clause will have the DISTINCT identifier set.
      Returns:
      The new root object of the SELECT statement
    • addSelectStatement

      public SelectStatementStateObject addSelectStatement()
      Changes the query statement to be a SELECT statement.
      Returns:
      The new root object of the SELECT statement
    • addSelectStatement

      public SelectStatementStateObject addSelectStatement(String jpqlFragment)
      Changes the query statement to be a SELECT statement.
      Parameters:
      jpqlFragment - The portion of the query representing the select items, excluding the SELECT identifier
      Returns:
      The new root object of the SELECT statement
    • addUpdateStatement

      public UpdateStatementStateObject addUpdateStatement()
      Changes the query statement to be a UPDATE statement.
      Returns:
      The new root object of the UPDTE statement
    • addUpdateStatement

      public UpdateStatementStateObject addUpdateStatement(String jpqlFragment)
      Changes the query statement to be a UPDATE statement.
      Parameters:
      jpqlFragment - The portion of the query representing the select items, excluding the UPDATE identifier
      Returns:
      The new root object of the UPDATE statement
    • checkParent

      protected StateObject checkParent(StateObject parent)
      Description copied from class: AbstractStateObject
      Checks whether the given parent is null or not. If it's null then throw a NullPointerException.
      Overrides:
      checkParent in class AbstractStateObject
      Parameters:
      parent - The parent of this state object
      Returns:
      The given object
    • 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 JPQLExpression 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)
    • getGrammar

      public JPQLGrammar getGrammar()
      Description copied from interface: StateObject
      Returns the grammar that defines how to parse a JPQL query.
      Specified by:
      getGrammar in interface StateObject
      Overrides:
      getGrammar in class AbstractStateObject
      Returns:
      The grammar that was used to parse the JPQL query
    • getManagedTypeProvider

      public IManagedTypeProvider getManagedTypeProvider()
      Description copied from interface: StateObject
      Returns the provider of managed types.
      Specified by:
      getManagedTypeProvider in interface StateObject
      Overrides:
      getManagedTypeProvider in class AbstractStateObject
      Returns:
      The provider that gives access to the managed types
    • getParent

      public StateObject getParent()
      Description copied from interface: StateObject
      Returns the parent of this StateObject.
      Specified by:
      getParent in interface StateObject
      Overrides:
      getParent in class AbstractStateObject
      Returns:
      Returns the parent of this StateObject, which is null only when this is the root of the hierarchy
    • getQueryBuilder

      public IJPQLQueryBuilder getQueryBuilder()
      Description copied from interface: StateObject
      Returns the IJPQLQueryBuilder that is responsible to create various part of the StateObject hierarchy.
      Specified by:
      getQueryBuilder in interface StateObject
      Overrides:
      getQueryBuilder in class AbstractStateObject
      Returns:
      The builder that created this StateObject from a JPQL query or that gives access to various sub-builders
    • getQueryStatement

      public StateObject getQueryStatement()
      Returns the only child of this state object, which represents one of the three query statement.
      Returns:
      The state object representing the query statement, which was created based on the query type
    • getRoot

      public JPQLQueryStateObject getRoot()
      Description copied from interface: StateObject
      Returns the root of the StateObject hierarchy.
      Specified by:
      getRoot in interface StateObject
      Overrides:
      getRoot in class AbstractStateObject
      Returns:
      The root of the state model representing the JPQL query
    • hasQueryStatement

      public boolean hasQueryStatement()
      Determines whether a query statement has been defined.
      Returns:
      true if there is a query statement defined; false otherwise
    • initialize

      protected void initialize(IJPQLQueryBuilder queryBuilder, IManagedTypeProvider provider)
      Initializes this JPQLQueryStateObject.
      Parameters:
      queryBuilder - The builder that can create any StateObject for any given JPQL fragment
      provider - The external form that gives access to the JPA metadata
      Throws:
      NullPointerException - If one of the given arguments is null
    • 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
    • parse

      public void parse(CharSequence jpqlFragment, String queryBNFId)
      Parses the given JPQL fragment as this state object's query statement.
      Parameters:
      jpqlFragment - The portion of the query to parse
      queryBNFId - The unique identifier of the BNF that determines how to parse the fragment
    • setExpression

      public void setExpression(JPQLExpression expression)
      Keeps a reference of the parsed object object, which should only be done when this object is instantiated during the conversion of a parsed JPQL query into StateObjects.
      Parameters:
      expression - The parsed object representing the JPQL query
    • setQueryStatement

      public void setQueryStatement(StateObject queryStatement)
      Sets the only child of this state object, which represents one of the three query statement.
      Parameters:
      queryStatement - The state object representing the query statement, which was created based on the query type
    • 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