Class ResultVariableStateObject
java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
org.eclipse.persistence.jpa.jpql.tools.model.query.ResultVariableStateObject
- All Implemented Interfaces:
StateObject
A result variable may be used to name a select item in the query result.
BNF: select_item ::= select_expression [[AS] result_variable]
- Since:
- 2.4
- Version:
- 2.4
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates a newResultVariableStateObject
.ResultVariableStateObject
(SelectClauseStateObject parent, StateObject stateObject, boolean as, String resultVariable) Creates a newResultVariableStateObject
.ResultVariableStateObject
(SelectClauseStateObject parent, StateObject stateObject, String resultVariable) Creates a newResultVariableStateObject
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(StateObjectVisitor visitor) Visits thisStateObject
by the givenvisitor
.addAs()
Makes sure theAS
identifier is used.protected void
addChildren
(List<StateObject> children) Adds the children of thisStateObject
to the given list.Returns the actual parsed object if thisStateObject
representation of the JPQL query was created by parsing an existing JPQL query.Returns the parent of thisStateObject
.Returns the result variable identifies the select expression, which can be used in theORDER BY
clause.Returns theStateObject
representing a single select expression.boolean
hasAs()
Determines whether theAS
identifier is used.boolean
Determines whether the result variable has been defined.boolean
Determines whether the select item has been defined.protected void
Initializes this state object.boolean
isEquivalent
(StateObject stateObject) Determines whether the givenStateObject
is equivalent to this one, i.e.void
Parses the given JPQL fragment, which represents a single select expression, and creates theStateObject
.void
removeAs()
Makes sure theAS
identifier is not used.void
setAs
(boolean as) Sets whether theAS
identifier should be used.void
setExpression
(ResultVariable 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
setResultVariable
(String resultVariable) Sets the result variable that identifies the select expression, which can be used in theORDER BY
clause.void
setStateObject
(StateObject stateObject) Sets theStateObject
representing a single select expression.void
toggleAs()
Toggles the visibility of theAS
identifier; either adds it if it's not present otherwise removes it if it's present.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, checkParent, children, decorate, equals, findIdentificationVariable, firePropertyChanged, getChangeSupport, getDeclaration, getDecorator, getGrammar, getManagedTypeProvider, getQueryBuilder, getRoot, getType, getType, getTypeHelper, getTypeRepository, hashCode, isDecorated, parent, parent, parent, removePropertyChangeListener, setExpression, setParent, toString, toString, toStringInternal, toStringItems, toText
-
Field Details
-
AS_PROPERTY
Notifies the visibility of theAS
identifier has changed.- See Also:
-
RESULT_VARIABLE_PROPERTY
Notifies the result variable property has changed.- See Also:
-
STATE_OBJECT_PROPERTY
Notifies the select state object property has changed.- See Also:
-
-
Constructor Details
-
ResultVariableStateObject
Creates a newResultVariableStateObject
.- Parameters:
parent
- The parent of this state object, which cannot benull
- Throws:
NullPointerException
- The given parent cannot benull
-
ResultVariableStateObject
public ResultVariableStateObject(SelectClauseStateObject parent, StateObject stateObject, boolean as, String resultVariable) Creates a newResultVariableStateObject
.- Parameters:
parent
- The parent of this state object, which cannot benull
stateObject
- TheStateObject
representing the select itemas
- Determines whether theAS
identifier is used or notresultVariable
- The variable identifying the select item- Throws:
NullPointerException
- The given parent cannot benull
-
ResultVariableStateObject
public ResultVariableStateObject(SelectClauseStateObject parent, StateObject stateObject, String resultVariable) Creates a newResultVariableStateObject
.- Parameters:
parent
- The parent of this state object, which cannot benull
stateObject
- TheStateObject
representing the select itemresultVariable
- The variable identifying the select item- Throws:
NullPointerException
- The given parent cannot benull
-
-
Method Details
-
accept
Description copied from interface:StateObject
Visits thisStateObject
by the givenvisitor
.- Parameters:
visitor
- Thevisitor
to visit this object
-
addAs
Makes sure theAS
identifier is used.- Returns:
- 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
-
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)
-
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
-
getResultVariable
Returns the result variable identifies the select expression, which can be used in theORDER BY
clause.- Returns:
- The unique identifier declaring the select expression
-
getStateObject
Returns theStateObject
representing a single select expression.- Returns:
- The
StateObject
representing a single select expression
-
hasAs
public boolean hasAs()Determines whether theAS
identifier is used.- Returns:
true
if theAS
identifier is used;false
otherwise
-
hasResultVariable
public boolean hasResultVariable()Determines whether the result variable has been defined.- Returns:
true
if the result variable is defined;false
otherwise
-
hasStateObject
public boolean hasStateObject()Determines whether the select item has been defined.- Returns:
true
if there the selected expression has been defined;false
if it's missing
-
initialize
protected void initialize()Description copied from class:AbstractStateObject
Initializes this state object.- Overrides:
initialize
in classAbstractStateObject
-
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, which represents a single select expression, and creates theStateObject
.- Parameters:
jpqlFragment
- The portion of the query representing a single select expression
-
removeAs
public void removeAs()Makes sure theAS
identifier is not used. -
setAs
public void setAs(boolean as) Sets whether theAS
identifier should be used.- Parameters:
as
-true
if theAS
identifier should be used part;false
otherwise
-
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 a result variable expression
-
setResultVariable
Sets the result variable that identifies the select expression, which can be used in theORDER BY
clause.- Parameters:
resultVariable
- The unique identifier declaring the select expression
-
setStateObject
Sets theStateObject
representing a single select expression.- Parameters:
stateObject
- TheStateObject
representing a single select expression
-
toggleAs
public void toggleAs()Toggles the visibility of theAS
identifier; either adds it if it's not present otherwise removes it if it's present. -
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
-