Class JPQLQueryStateObject

    • Field Detail

      • QUERY_STATEMENT_PROPERTY

        public static final java.lang.String QUERY_STATEMENT_PROPERTY
        Notifies the query statement has changed.
        See Also:
        Constant Field Values
    • Constructor Detail

      • 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:
        java.lang.NullPointerException - If one of the given arguments is null
    • Method Detail

      • 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​(java.lang.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​(java.lang.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)
        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()
        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()
        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)
      • 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
      • 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:
        java.lang.NullPointerException - If one of the given arguments is null
      • parse

        public void parse​(java.lang.CharSequence jpqlFragment,
                          java.lang.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​(java.lang.Appendable writer)
                               throws java.io.IOException
        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:
        java.io.IOException - This should never happens, it is only required because Appendable is used instead of any concrete class