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
public class JPQLQueryStateObject extends AbstractStateObject
This is the root of theStateObject
hierarchy that represents a JPQL query. The only child of this state object is one of the three possible query statements.- Version:
- 2.4
- See Also:
DeleteStatementStateObject
,SelectStatementStateObject
,UpdateStatementStateObject
,JPQLExpression
- Author:
- Pascal Filion
- Since:
- 2.4
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
QUERY_STATEMENT_PROPERTY
Notifies the query statement has changed.
-
Constructor Summary
Constructors Constructor Description JPQLQueryStateObject(IJPQLQueryBuilder queryBuilder, IManagedTypeProvider provider)
Creates a newJPQLQueryStateObject
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(StateObjectVisitor visitor)
Visits thisStateObject
by the givenvisitor
.protected void
addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObject
to the given list.DeleteStatementStateObject
addDeleteStatement()
Changes the query statement to be aDELETE
statement.SelectStatementStateObject
addDistinctSelectStatement()
Changes the query statement to be aSELECT
statement.SelectStatementStateObject
addSelectStatement()
Changes the query statement to be aSELECT
statement.SelectStatementStateObject
addSelectStatement(java.lang.String jpqlFragment)
Changes the query statement to be aSELECT
statement.UpdateStatementStateObject
addUpdateStatement()
Changes the query statement to be aUPDATE
statement.UpdateStatementStateObject
addUpdateStatement(java.lang.String jpqlFragment)
Changes the query statement to be aUPDATE
statement.protected StateObject
checkParent(StateObject parent)
Checks whether the given parent isnull
or not.DeclarationStateObject
getDeclaration()
Returns the declaration clause which defines the domain of the query by declaring identification variables.JPQLExpression
getExpression()
Returns the actual parsed object if thisStateObject
representation of the JPQL query was created by parsing an existing JPQL query.JPQLGrammar
getGrammar()
Returns the grammar that defines how to parse a JPQL query.IManagedTypeProvider
getManagedTypeProvider()
Returns the provider of managed types.StateObject
getParent()
Returns the parent of thisStateObject
.IJPQLQueryBuilder
getQueryBuilder()
Returns theIJPQLQueryBuilder
that is responsible to create various part of theStateObject
hierarchy.StateObject
getQueryStatement()
Returns the only child of this state object, which represents one of the three query statement.JPQLQueryStateObject
getRoot()
Returns the root of theStateObject
hierarchy.boolean
hasQueryStatement()
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. the information of bothStateObject
is the same.void
parse(java.lang.CharSequence jpqlFragment, java.lang.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(java.lang.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 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 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:
java.lang.NullPointerException
- If one of the given arguments isnull
-
-
Method Detail
-
accept
public void accept(StateObjectVisitor visitor)
Visits thisStateObject
by the givenvisitor
.- Parameters:
visitor
- Thevisitor
to visit this object
-
addChildren
protected void addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObject
to the given list.- Overrides:
addChildren
in classAbstractStateObject
- Parameters:
children
- The list used to store the children
-
addDeleteStatement
public DeleteStatementStateObject addDeleteStatement()
Changes the query statement to be aDELETE
statement.- Returns:
- The new root object of the
DELETE
statement
-
addDistinctSelectStatement
public SelectStatementStateObject 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
public SelectStatementStateObject addSelectStatement()
Changes the query statement to be aSELECT
statement.- Returns:
- The new root object of the
SELECT
statement
-
addSelectStatement
public SelectStatementStateObject addSelectStatement(java.lang.String jpqlFragment)
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
public UpdateStatementStateObject addUpdateStatement()
Changes the query statement to be aUPDATE
statement.- Returns:
- The new root object of the
UPDTE
statement
-
addUpdateStatement
public UpdateStatementStateObject addUpdateStatement(java.lang.String jpqlFragment)
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
protected StateObject checkParent(StateObject parent)
Checks whether the given parent isnull
or not. If it'snull
then throw aNullPointerException
.- Overrides:
checkParent
in classAbstractStateObject
- 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 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
public JPQLExpression getExpression()
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
public JPQLGrammar getGrammar()
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
public IManagedTypeProvider getManagedTypeProvider()
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
public StateObject getParent()
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
public IJPQLQueryBuilder getQueryBuilder()
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
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()
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
protected void initialize(IJPQLQueryBuilder queryBuilder, IManagedTypeProvider provider)
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:
java.lang.NullPointerException
- If one of the given arguments isnull
-
isEquivalent
public boolean isEquivalent(StateObject 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
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 parsequeryBNFId
- The unique identifier of the BNF that determines how to parse the fragment
-
setExpression
public 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
.- Parameters:
expression
- Theparsed 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 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:
java.io.IOException
- This should never happens, it is only required becauseAppendable
is used instead of any concrete class
-
-