Class JPQLQueryStateObject
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
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 Summary
-
Constructor Summary
ConstructorDescriptionJPQLQueryStateObject
(IJPQLQueryBuilder queryBuilder, IManagedTypeProvider provider) Creates a newJPQLQueryStateObject
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(StateObjectVisitor visitor) Visits thisStateObject
by the givenvisitor
.protected void
addChildren
(List<StateObject> children) Adds the children of thisStateObject
to the given list.Changes the query statement to be aDELETE
statement.Changes the query statement to be aSELECT
statement.Changes the query statement to be aSELECT
statement.addSelectStatement
(String jpqlFragment) Changes the query statement to be aSELECT
statement.Changes the query statement to be aUPDATE
statement.addUpdateStatement
(String jpqlFragment) Changes the query statement to be aUPDATE
statement.protected StateObject
checkParent
(StateObject parent) Checks whether the given parent isnull
or not.Returns the declaration clause which defines the domain of the query by declaring identification variables.Returns the actual parsed object if thisStateObject
representation of the JPQL query was created by parsing an existing JPQL query.Returns the grammar that defines how to parse a JPQL query.Returns the provider of managed types.Returns the parent of thisStateObject
.Returns theIJPQLQueryBuilder
that is responsible to create various part of theStateObject
hierarchy.Returns the only child of this state object, which represents one of the three query statement.getRoot()
Returns the root of theStateObject
hierarchy.boolean
Determines whether a query statement has been defined.protected void
initialize
(IJPQLQueryBuilder queryBuilder, IManagedTypeProvider provider) Initializes thisJPQLQueryStateObject
.boolean
isEquivalent
(StateObject stateObject) Determines whether the givenStateObject
is equivalent to this one, i.e.void
parse
(CharSequence jpqlFragment, String queryBNFId) Parses the given JPQL fragment as this state object's query statement.void
setExpression
(JPQLExpression expression) Keeps a reference of theparsed object
object, which should only be done when this object is instantiated during the conversion of a parsed JPQL query intoStateObjects
.void
setQueryStatement
(StateObject queryStatement) Sets the only child of this state object, which represents one of the three query statement.protected void
toTextInternal
(Appendable writer) Prints out a string representation of thisStateObject
, which should not be used to define atrue
string representation of a JPQL query but should be used for debugging purposes.Methods inherited from class org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
acceptUnknownVisitor, acceptUnknownVisitor, addProblems, addPropertyChangeListener, areEquivalent, buildProblem, buildProblem, buildStateObject, buildStateObjects, children, decorate, equals, findIdentificationVariable, firePropertyChanged, getChangeSupport, getDecorator, getType, getType, getTypeHelper, getTypeRepository, hashCode, initialize, isDecorated, parent, parent, parent, removePropertyChangeListener, setExpression, setParent, toString, toString, toStringInternal, toStringItems, toText
-
Field Details
-
QUERY_STATEMENT_PROPERTY
Notifies the query statement has changed.- See Also:
-
-
Constructor Details
-
JPQLQueryStateObject
Creates a newJPQLQueryStateObject
.- Parameters:
queryBuilder
- The builder that can create anyStateObject
for any given JPQL fragment when using a parse methodprovider
- The external form of a provider that gives access to the JPA metadata- Throws:
NullPointerException
- If one of the given arguments isnull
-
-
Method Details
-
accept
Description copied from interface:StateObject
Visits thisStateObject
by the givenvisitor
.- Parameters:
visitor
- Thevisitor
to visit this object
-
addChildren
Description copied from class:AbstractStateObject
Adds the children of thisStateObject
to the given list.- Overrides:
addChildren
in classAbstractStateObject
- Parameters:
children
- The list used to store the children
-
addDeleteStatement
Changes the query statement to be aDELETE
statement.- Returns:
- The new root object of the
DELETE
statement
-
addDistinctSelectStatement
Changes the query statement to be aSELECT
statement. TheSELECT
clause will have theDISTINCT
identifier set.- Returns:
- The new root object of the
SELECT
statement
-
addSelectStatement
Changes the query statement to be aSELECT
statement.- Returns:
- The new root object of the
SELECT
statement
-
addSelectStatement
Changes the query statement to be aSELECT
statement.- Parameters:
jpqlFragment
- The portion of the query representing the select items, excluding theSELECT
identifier- Returns:
- The new root object of the
SELECT
statement
-
addUpdateStatement
Changes the query statement to be aUPDATE
statement.- Returns:
- The new root object of the
UPDTE
statement
-
addUpdateStatement
Changes the query statement to be aUPDATE
statement.- Parameters:
jpqlFragment
- The portion of the query representing the select items, excluding theUPDATE
identifier- Returns:
- The new root object of the
UPDATE
statement
-
checkParent
Description copied from class:AbstractStateObject
- Overrides:
checkParent
in classAbstractStateObject
- Parameters:
parent
- The parent of this state object- Returns:
- The given object
-
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 interfaceStateObject
- Overrides:
getDeclaration
in classAbstractStateObject
- 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
Description copied from interface:StateObject
Returns the actual parsed object if thisStateObject
representation of the JPQL query was created by parsing an existing JPQL query.- Specified by:
getExpression
in interfaceStateObject
- Overrides:
getExpression
in classAbstractStateObject
- Returns:
- The parsed object when a JPQL query is parsed and converted into a
StateObject
ornull
when the JPQL query is manually created (i.e. not from a string)
-
getGrammar
Description copied from interface:StateObject
Returns the grammar that defines how to parse a JPQL query.- Specified by:
getGrammar
in interfaceStateObject
- Overrides:
getGrammar
in classAbstractStateObject
- Returns:
- The grammar that was used to parse the JPQL query
-
getManagedTypeProvider
Description copied from interface:StateObject
Returns the provider of managed types.- Specified by:
getManagedTypeProvider
in interfaceStateObject
- Overrides:
getManagedTypeProvider
in classAbstractStateObject
- Returns:
- The provider that gives access to the managed types
-
getParent
Description copied from interface:StateObject
Returns the parent of thisStateObject
.- Specified by:
getParent
in interfaceStateObject
- Overrides:
getParent
in classAbstractStateObject
- Returns:
- Returns the parent of this
StateObject
, which isnull
only when this is the root of the hierarchy
-
getQueryBuilder
Description copied from interface:StateObject
Returns theIJPQLQueryBuilder
that is responsible to create various part of theStateObject
hierarchy.- Specified by:
getQueryBuilder
in interfaceStateObject
- Overrides:
getQueryBuilder
in classAbstractStateObject
- Returns:
- The builder that created this
StateObject
from a JPQL query or that gives access to various sub-builders
-
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
Description copied from interface:StateObject
Returns the root of theStateObject
hierarchy.- Specified by:
getRoot
in interfaceStateObject
- Overrides:
getRoot
in classAbstractStateObject
- 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
Initializes thisJPQLQueryStateObject
.- Parameters:
queryBuilder
- The builder that can create anyStateObject
for any given JPQL fragmentprovider
- The external form that gives access to the JPA metadata- Throws:
NullPointerException
- If one of the given arguments isnull
-
isEquivalent
Description copied from interface:StateObject
Determines whether the givenStateObject
is equivalent to this one, i.e. the information of bothStateObject
is the same.- Specified by:
isEquivalent
in interfaceStateObject
- Overrides:
isEquivalent
in classAbstractStateObject
- Parameters:
stateObject
- TheStateObject
to compare its content to this one- Returns:
true
if both object are equivalent;false
otherwise
-
parse
Parses the given JPQL fragment as this state object's query statement.- Parameters:
jpqlFragment
- The portion of the query to parsequeryBNFId
- The unique identifier of the BNF that determines how to parse the fragment
-
setExpression
Keeps a reference of theparsed object
object, which should only be done when this object is instantiated during the conversion of a parsed JPQL query intoStateObjects
.- Parameters:
expression
- Theparsed object
representing the JPQL query
-
setQueryStatement
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
Description copied from class:AbstractStateObject
Prints out a string representation of thisStateObject
, which should not be used to define atrue
string representation of a JPQL query but should be used for debugging purposes.- Specified by:
toTextInternal
in classAbstractStateObject
- Parameters:
writer
- The writer used to print out the string representation- Throws:
IOException
- This should never happens, it is only required becauseAppendable
is used instead of any concrete class
-