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 theStateObjecthierarchy 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.StringQUERY_STATEMENT_PROPERTYNotifies 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 voidaccept(StateObjectVisitor visitor)Visits thisStateObjectby the givenvisitor.protected voidaddChildren(java.util.List<StateObject> children)Adds the children of thisStateObjectto the given list.DeleteStatementStateObjectaddDeleteStatement()Changes the query statement to be aDELETEstatement.SelectStatementStateObjectaddDistinctSelectStatement()Changes the query statement to be aSELECTstatement.SelectStatementStateObjectaddSelectStatement()Changes the query statement to be aSELECTstatement.SelectStatementStateObjectaddSelectStatement(java.lang.String jpqlFragment)Changes the query statement to be aSELECTstatement.UpdateStatementStateObjectaddUpdateStatement()Changes the query statement to be aUPDATEstatement.UpdateStatementStateObjectaddUpdateStatement(java.lang.String jpqlFragment)Changes the query statement to be aUPDATEstatement.protected StateObjectcheckParent(StateObject parent)Checks whether the given parent isnullor not.DeclarationStateObjectgetDeclaration()Returns the declaration clause which defines the domain of the query by declaring identification variables.JPQLExpressiongetExpression()Returns the actual parsed object if thisStateObjectrepresentation of the JPQL query was created by parsing an existing JPQL query.JPQLGrammargetGrammar()Returns the grammar that defines how to parse a JPQL query.IManagedTypeProvidergetManagedTypeProvider()Returns the provider of managed types.StateObjectgetParent()Returns the parent of thisStateObject.IJPQLQueryBuildergetQueryBuilder()Returns theIJPQLQueryBuilderthat is responsible to create various part of theStateObjecthierarchy.StateObjectgetQueryStatement()Returns the only child of this state object, which represents one of the three query statement.JPQLQueryStateObjectgetRoot()Returns the root of theStateObjecthierarchy.booleanhasQueryStatement()Determines whether a query statement has been defined.protected voidinitialize(IJPQLQueryBuilder queryBuilder, IManagedTypeProvider provider)Initializes thisJPQLQueryStateObject.booleanisEquivalent(StateObject stateObject)Determines whether the givenStateObjectis equivalent to this one, i.e. the information of bothStateObjectis the same.voidparse(java.lang.CharSequence jpqlFragment, java.lang.String queryBNFId)Parses the given JPQL fragment as this state object's query statement.voidsetExpression(JPQLExpression expression)Keeps a reference of theparsed objectobject, which should only be done when this object is instantiated during the conversion of a parsed JPQL query intoStateObjects.voidsetQueryStatement(StateObject queryStatement)Sets the only child of this state object, which represents one of the three query statement.protected voidtoTextInternal(java.lang.Appendable writer)Prints out a string representation of thisStateObject, which should not be used to define atruestring 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 anyStateObjectfor 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 thisStateObjectby the givenvisitor.- Parameters:
visitor- Thevisitorto visit this object
-
addChildren
protected void addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObjectto the given list.- Overrides:
addChildrenin classAbstractStateObject- Parameters:
children- The list used to store the children
-
addDeleteStatement
public DeleteStatementStateObject addDeleteStatement()
Changes the query statement to be aDELETEstatement.- Returns:
- The new root object of the
DELETEstatement
-
addDistinctSelectStatement
public SelectStatementStateObject addDistinctSelectStatement()
Changes the query statement to be aSELECTstatement. TheSELECTclause will have theDISTINCTidentifier set.- Returns:
- The new root object of the
SELECTstatement
-
addSelectStatement
public SelectStatementStateObject addSelectStatement()
Changes the query statement to be aSELECTstatement.- Returns:
- The new root object of the
SELECTstatement
-
addSelectStatement
public SelectStatementStateObject addSelectStatement(java.lang.String jpqlFragment)
Changes the query statement to be aSELECTstatement.- Parameters:
jpqlFragment- The portion of the query representing the select items, excluding theSELECTidentifier- Returns:
- The new root object of the
SELECTstatement
-
addUpdateStatement
public UpdateStatementStateObject addUpdateStatement()
Changes the query statement to be aUPDATEstatement.- Returns:
- The new root object of the
UPDTEstatement
-
addUpdateStatement
public UpdateStatementStateObject addUpdateStatement(java.lang.String jpqlFragment)
Changes the query statement to be aUPDATEstatement.- Parameters:
jpqlFragment- The portion of the query representing the select items, excluding theUPDATEidentifier- Returns:
- The new root object of the
UPDATEstatement
-
checkParent
protected StateObject checkParent(StateObject parent)
Checks whether the given parent isnullor not. If it'snullthen throw aNullPointerException.- Overrides:
checkParentin 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:
getDeclarationin interfaceStateObject- Overrides:
getDeclarationin classAbstractStateObject- Returns:
- The declaration clause of which this
StateObjectis 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 thisStateObjectrepresentation of the JPQL query was created by parsing an existing JPQL query.- Specified by:
getExpressionin interfaceStateObject- Overrides:
getExpressionin classAbstractStateObject- Returns:
- The parsed object when a JPQL query is parsed and converted into a
StateObjectornullwhen 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:
getGrammarin interfaceStateObject- Overrides:
getGrammarin classAbstractStateObject- Returns:
- The grammar that was used to parse the JPQL query
-
getManagedTypeProvider
public IManagedTypeProvider getManagedTypeProvider()
Returns the provider of managed types.- Specified by:
getManagedTypeProviderin interfaceStateObject- Overrides:
getManagedTypeProviderin classAbstractStateObject- Returns:
- The provider that gives access to the managed types
-
getParent
public StateObject getParent()
Returns the parent of thisStateObject.- Specified by:
getParentin interfaceStateObject- Overrides:
getParentin classAbstractStateObject- Returns:
- Returns the parent of this
StateObject, which isnullonly when this is the root of the hierarchy
-
getQueryBuilder
public IJPQLQueryBuilder getQueryBuilder()
Returns theIJPQLQueryBuilderthat is responsible to create various part of theStateObjecthierarchy.- Specified by:
getQueryBuilderin interfaceStateObject- Overrides:
getQueryBuilderin classAbstractStateObject- Returns:
- The builder that created this
StateObjectfrom 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 theStateObjecthierarchy.- Specified by:
getRootin interfaceStateObject- Overrides:
getRootin 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:
trueif there is a query statement defined;falseotherwise
-
initialize
protected void initialize(IJPQLQueryBuilder queryBuilder, IManagedTypeProvider provider)
Initializes thisJPQLQueryStateObject.- Parameters:
queryBuilder- The builder that can create anyStateObjectfor 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 givenStateObjectis equivalent to this one, i.e. the information of bothStateObjectis the same.- Specified by:
isEquivalentin interfaceStateObject- Overrides:
isEquivalentin classAbstractStateObject- Parameters:
stateObject- TheStateObjectto compare its content to this one- Returns:
trueif both object are equivalent;falseotherwise
-
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 objectobject, which should only be done when this object is instantiated during the conversion of a parsed JPQL query intoStateObjects.- Parameters:
expression- Theparsed objectrepresenting 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.IOExceptionPrints out a string representation of thisStateObject, which should not be used to define atruestring representation of a JPQL query but should be used for debugging purposes.- Specified by:
toTextInternalin classAbstractStateObject- Parameters:
writer- The writer used to print out the string representation- Throws:
java.io.IOException- This should never happens, it is only required becauseAppendableis used instead of any concrete class
-
-