Class AbstractStateObject
- java.lang.Object
-
- org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
-
- All Implemented Interfaces:
StateObject
- Direct Known Subclasses:
AbstractConditionalClauseStateObject
,AbstractEncapsulatedExpressionStateObject
,AbstractListHolderStateObject
,AbstractModifyClauseStateObject
,AbstractModifyStatementStateObject
,AbstractPathExpressionStateObject
,AbstractRangeVariableDeclarationStateObject
,AbstractSelectClauseStateObject
,AbstractSelectStatementStateObject
,ArithmeticFactorStateObject
,BetweenExpressionStateObject
,CollectionExpressionStateObject
,CollectionMemberDeclarationStateObject
,CollectionMemberExpressionStateObject
,CompoundExpressionStateObject
,EmptyCollectionComparisonExpressionStateObject
,FunctionExpressionStateObject
,JoinStateObject
,JPQLQueryStateObject
,LikeExpressionStateObject
,NotExpressionStateObject
,NullComparisonExpressionStateObject
,OrderByItemStateObject
,ResultVariableStateObject
,SimpleStateObject
,TreatExpressionStateObject
,UpdateItemStateObject
public abstract class AbstractStateObject extends java.lang.Object implements StateObject
The abstract definition of aStateObject
.- Version:
- 2.5
- Author:
- Pascal Filion
- Since:
- 2.4
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractStateObject(StateObject parent)
Creates a newAbstractStateObject
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
acceptUnknownVisitor(StateObjectVisitor visitor)
The givenStateObjectVisitor
needs to visit this class but it is defined by a third-party provider.protected void
acceptUnknownVisitor(StateObjectVisitor visitor, java.lang.Class<?> type, java.lang.Class<?> parameterType)
The givenStateObjectVisitor
needs to visit this class but it is defined by a third-party provider.protected void
addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObject
to the given list.protected void
addProblems(java.util.List<Problem> problems)
Adds to the given list the problems that were found with the current state of thisStateObject
, which means there are validation issues.void
addPropertyChangeListener(java.lang.String propertyName, IPropertyChangeListener<?> listener)
Registers the givenIPropertyChangeListener
for the specified property.protected boolean
areEquivalent(StateObject stateObject1, StateObject stateObject2)
Determines whether the given twoStateObject
are equivalent, i.e. the information of bothStateObject
is the same.protected Problem
buildProblem(java.lang.String messageKey)
Creates a newProblem
describing a single issue found with the information contained in thisStateObject
.protected Problem
buildProblem(java.lang.String messageKey, java.lang.String... arguments)
Creates a newProblem
describing a single issue found with the information contained in thisStateObject
.protected <T extends StateObject>
TbuildStateObject(java.lang.CharSequence jpqlFragment, java.lang.String queryBNFId)
Parses the given JPQL fragment using the given JPQL query BNF.protected <T extends StateObject>
java.util.List<T>buildStateObjects(java.lang.CharSequence jpqlFragment, java.lang.String queryBNFId)
Parses the given JPQL fragment using the given JPQL query BNF.protected StateObject
checkParent(StateObject parent)
Checks whether the given parent isnull
or not.java.lang.Iterable<StateObject>
children()
Returns the ordered children of thisStateObject
.void
decorate(StateObject decorator)
Decorates thisStateObject
with the given decorator.boolean
equals(java.lang.Object object)
IdentificationVariableStateObject
findIdentificationVariable(java.lang.String identificationVariable)
Returns theIdentificationVariableStateObject
representing the given identification variable.protected void
firePropertyChanged(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
Notifies theIPropertyChangeListeners
that have been registered with the given property name that the property has changed.protected ChangeSupport
getChangeSupport()
Returns the object responsible to actually register the listeners and to notify them upon changes made to thisStateObject
.DeclarationStateObject
getDeclaration()
Returns the declaration clause which defines the domain of the query by declaring identification variables.StateObject
getDecorator()
Returns theStateObject
decorating this one if one has been set, which means the behavior of thisStateObject
is modified by the decorator.Expression
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.JPQLQueryStateObject
getRoot()
Returns the root of theStateObject
hierarchy.IType
getType(java.lang.Class<?> type)
Retrieves the external type for the given Java type.IType
getType(java.lang.String typeName)
Retrieves the external class for the given fully qualified class name.TypeHelper
getTypeHelper()
Returns a helper that gives access to the most commontypes
.ITypeRepository
getTypeRepository()
Returns the type repository for the application.int
hashCode()
protected void
initialize()
Initializes this state object.boolean
isDecorated()
Determines whether thisStateObject
is being decorated by anotherStateObject
, which means the behavior is modified by the given one.boolean
isEquivalent(StateObject stateObject)
Determines whether the givenStateObject
is equivalent to this one, i.e. the information of bothStateObject
is the same.protected <T extends StateObject>
java.util.List<T>parent(java.util.List<T> stateObjects)
Makes sure the given list ofStateObject
has this one as its parent.protected <T extends StateObject>
Tparent(T stateObject)
Makes sure the givenStateObject
has this one as its parent.protected <T extends StateObject>
T[]parent(T... stateObjects)
Makes sure the given list ofStateObject
has this one as its parent.void
removePropertyChangeListener(java.lang.String propertyName, IPropertyChangeListener<?> listener)
Unregisters the givenIPropertyChangeListener
that was registered for the specified property.void
setExpression(Expression expression)
Sets the actual parsed object if thisStateObject
representation of the JPQL query is created by converting the parsed representation of the JPQL query.void
setParent(StateObject parent)
Sets the givenStateObject
to become the parent of this one.java.lang.String
toString()
void
toString(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.protected void
toStringInternal(java.lang.Appendable writer)
Prints out a string representation of thisStateObject
.protected void
toStringItems(java.lang.Appendable writer, java.util.List<? extends StateObject> items, boolean useComma)
void
toText(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.protected abstract 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 java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject
accept
-
-
-
-
Constructor Detail
-
AbstractStateObject
protected AbstractStateObject(StateObject parent)
Creates a newAbstractStateObject
.- Parameters:
parent
- The parent of this state object, which cannot benull
- Throws:
java.lang.NullPointerException
- The given parent cannot benull
, unlesschangeSupport
is overridden and does not throw the exception
-
-
Method Detail
-
acceptUnknownVisitor
protected boolean acceptUnknownVisitor(StateObjectVisitor visitor)
The givenStateObjectVisitor
needs to visit this class but it is defined by a third-party provider. This method will programmatically invoke the visit method defined on the given visitor which signature should be.{public|protected|private} void visit(ThirdPartyStateObject stateObject)
or
{public|protected|private} void visit(StateObject stateObject)
- Parameters:
visitor
- TheStateObjectVisitor
to visit thisStateObject
programmatically- Returns:
true
if the call was successfully executed;false
otherwise- Since:
- 2.4
-
acceptUnknownVisitor
protected void acceptUnknownVisitor(StateObjectVisitor visitor, java.lang.Class<?> type, java.lang.Class<?> parameterType) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
The givenStateObjectVisitor
needs to visit this class but it is defined by a third-party provider. This method will programmatically invoke the visit method defined on the given visitor which signature should be.{public|protected|private} void visit(ThirdPartyStateObject stateObject)
or
{public|protected|private} void visit(StateObject stateObject)
- Parameters:
visitor
- TheStateObjectVisitor
to visit thisStateObject
programmaticallytype
- The type found in the hierarchy of the givenStateObjectVisitor
that will be used to retrieve the visit methodparameterType
- The parameter type of the visit method- Throws:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
- See Also:
acceptUnknownVisitor(StateObjectVisitor)
- Since:
- 2.4
-
addChildren
protected void addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObject
to the given list.- Parameters:
children
- The list used to store the children
-
addProblems
protected void addProblems(java.util.List<Problem> problems)
Adds to the given list the problems that were found with the current state of thisStateObject
, which means there are validation issues.- Parameters:
problems
- The list to which the problems are added
-
addPropertyChangeListener
public final void addPropertyChangeListener(java.lang.String propertyName, IPropertyChangeListener<?> listener)
Registers the givenIPropertyChangeListener
for the specified property. The listener will be notified only for changes to the specified property.- Specified by:
addPropertyChangeListener
in interfaceStateObject
- Parameters:
propertyName
- The name of the property for which the listener was registeredlistener
- The listener to be notified upon changes
-
areEquivalent
protected final boolean areEquivalent(StateObject stateObject1, StateObject stateObject2)
Determines whether the given twoStateObject
are equivalent, i.e. the information of bothStateObject
is the same.- Parameters:
stateObject1
- The firstStateObject
to compare its content with the other onestateObject2
- The secondStateObject
to compare its content with the other one- Returns:
true
if both objects are equivalent;false
otherwise
-
buildProblem
protected final Problem buildProblem(java.lang.String messageKey)
Creates a newProblem
describing a single issue found with the information contained in thisStateObject
.- Parameters:
messageKey
- The key used to retrieve the localized message describing the problem found with the current state of thisStateObject
- Returns:
- The new
Problem
-
buildProblem
protected final Problem buildProblem(java.lang.String messageKey, java.lang.String... arguments)
Creates a newProblem
describing a single issue found with the information contained in thisStateObject
.- Parameters:
messageKey
- The key used to retrieve the localized message describing the problem found with the current state of thisStateObject
arguments
- A list of arguments that can be used to complete the message or an empty list if no additional information is necessary- Returns:
- The new
Problem
-
buildStateObject
protected <T extends StateObject> T buildStateObject(java.lang.CharSequence jpqlFragment, java.lang.String queryBNFId)
Parses the given JPQL fragment using the given JPQL query BNF.- Parameters:
jpqlFragment
- A portion of a JPQL query that will be parsed and converted into aStateObject
queryBNFId
- The unique identifier of the BNF that determines how to parse the fragment- Returns:
- A
StateObject
representation of the given JPQL fragment
-
buildStateObjects
protected <T extends StateObject> java.util.List<T> buildStateObjects(java.lang.CharSequence jpqlFragment, java.lang.String queryBNFId)
Parses the given JPQL fragment using the given JPQL query BNF.- Parameters:
jpqlFragment
- A portion of a JPQL query that will be parsed and converted into either a singleStateObject
or a list ofStateObject
, which happens when the fragment contains a collection of items separated by either a comma or a spacequeryBNFId
- The unique identifier of the BNF that will be used to parse the fragment- Returns:
- A list of
StateObjects
representing the given JPQL fragment, which means the list may contain a singleStateObject
or a multipleStateObjects
if the fragment contains more than one expression of the same type. Example: "JOIN e.employees e LEFT JOIN e.address a", this would be parsed in two state objects
-
checkParent
protected StateObject checkParent(StateObject parent)
Checks whether the given parent isnull
or not. If it'snull
then throw aNullPointerException
.- Parameters:
parent
- The parent of this state object- Returns:
- The given object
-
children
public final java.lang.Iterable<StateObject> children()
Returns the ordered children of thisStateObject
.- Specified by:
children
in interfaceStateObject
- Returns:
- The children of this
StateObject
or an empty iterable this state object does not have children
-
decorate
public void decorate(StateObject decorator)
Decorates thisStateObject
with the given decorator. It means the behavior of thisStateObject
is modified by the given one. By default, thisStateObject
becomes the parent of the given one.- Specified by:
decorate
in interfaceStateObject
- Parameters:
decorator
- TheStateObject
decorating this one
-
equals
public final boolean equals(java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
findIdentificationVariable
public IdentificationVariableStateObject findIdentificationVariable(java.lang.String identificationVariable)
Returns theIdentificationVariableStateObject
representing the given identification variable.- Specified by:
findIdentificationVariable
in interfaceStateObject
- Parameters:
identificationVariable
- The name of the identification variable to retrieve its state object- Returns:
- The
IdentificationVariableStateObject
defining the given identification variable
-
firePropertyChanged
protected final void firePropertyChanged(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
Notifies theIPropertyChangeListeners
that have been registered with the given property name that the property has changed.- Parameters:
propertyName
- The name of the property associated with the property changeoldValue
- The old value of the property that changednewValue
- The new value of the property that changed
-
getChangeSupport
protected final ChangeSupport getChangeSupport()
Returns the object responsible to actually register the listeners and to notify them upon changes made to thisStateObject
.- Returns:
- The manager of listeners and notification
-
getDeclaration
public DeclarationStateObject getDeclaration()
Returns the declaration clause which defines the domain of the query by declaring identification variables.- Specified by:
getDeclaration
in interfaceStateObject
- 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
-
getDecorator
public StateObject getDecorator()
Returns theStateObject
decorating this one if one has been set, which means the behavior of thisStateObject
is modified by the decorator.- Specified by:
getDecorator
in interfaceStateObject
- Returns:
- The
StateObject
decorating this one
-
getExpression
public Expression 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
- 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
- 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
- Returns:
- The provider that gives access to the managed types
-
getParent
public StateObject getParent()
Returns the parent of thisStateObject
.- Specified by:
getParent
in interfaceStateObject
- 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
- Returns:
- The builder that created this
StateObject
from a JPQL query or that gives access to various sub-builders
-
getRoot
public JPQLQueryStateObject getRoot()
Returns the root of theStateObject
hierarchy.- Specified by:
getRoot
in interfaceStateObject
- Returns:
- The root of the state model representing the JPQL query
-
getType
public IType getType(java.lang.Class<?> type)
Retrieves the external type for the given Java type.- Parameters:
type
- The Java type to wrap with an external form- Returns:
- The external form of the given type
-
getType
public IType getType(java.lang.String typeName)
Retrieves the external class for the given fully qualified class name.- Parameters:
typeName
- The fully qualified class name of the class to retrieve- Returns:
- The external form of the class to retrieve
-
getTypeHelper
public TypeHelper getTypeHelper()
Returns a helper that gives access to the most commontypes
.- Returns:
- A helper containing a collection of methods related to
IType
-
getTypeRepository
public ITypeRepository getTypeRepository()
Returns the type repository for the application.- Returns:
- The repository of
ITypes
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
initialize
protected void initialize()
Initializes this state object.
-
isDecorated
public boolean isDecorated()
Determines whether thisStateObject
is being decorated by anotherStateObject
, which means the behavior is modified by the given one. returntrue
if thisStateObject
is being decorated;false
otherwise- Specified by:
isDecorated
in interfaceStateObject
-
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
- Parameters:
stateObject
- TheStateObject
to compare its content to this one- Returns:
true
if both object are equivalent;false
otherwise
-
parent
protected <T extends StateObject> java.util.List<T> parent(java.util.List<T> stateObjects)
Makes sure the given list ofStateObject
has this one as its parent.- Parameters:
stateObjects
- The list ofStateObject
to have this one as its parent- Returns:
- The given list of
StateObject
-
parent
protected <T extends StateObject> T[] parent(T... stateObjects)
Makes sure the given list ofStateObject
has this one as its parent.- Parameters:
stateObjects
- The list ofStateObject
to have this one as its parent- Returns:
- The given list of
StateObject
-
parent
protected <T extends StateObject> T parent(T stateObject)
Makes sure the givenStateObject
has this one as its parent.- Parameters:
stateObject
- TheStateObject
to have this one as its parent- Returns:
- The given
StateObject
-
removePropertyChangeListener
public final void removePropertyChangeListener(java.lang.String propertyName, IPropertyChangeListener<?> listener)
Unregisters the givenIPropertyChangeListener
that was registered for the specified property. The listener will no longer be notified when the property changes.- Specified by:
removePropertyChangeListener
in interfaceStateObject
- Parameters:
propertyName
- The name of the property for which the listener was registeredlistener
- The listener to unregister
-
setExpression
public void setExpression(Expression expression)
Sets the actual parsed object if thisStateObject
representation of the JPQL query is created by converting the parsed representation of the JPQL query.- Parameters:
expression
- The parsed object when a JPQL query is parsed
-
setParent
public final void setParent(StateObject parent)
Sets the givenStateObject
to become the parent of this one.- Specified by:
setParent
in interfaceStateObject
- Parameters:
parent
- The new parentStateObject
of this one, which cannot benull
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
public final void toString(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.Important: If this
StateObject
is decorated by another one, thenStateObject.toString(Appendable)
from that decorator is invoked, otherwise the information contained in this one will be printed out.- Specified by:
toString
in interfaceStateObject
- Parameters:
writer
- The writer used to print out the string representation- See Also:
StateObject.toText(Appendable)
-
toStringInternal
protected final void toStringInternal(java.lang.Appendable writer) throws java.io.IOException
Prints out a string representation of thisStateObject
.Important: If this
StateObject
is decorated by another one, thentoString(Appendable)
from that decorator is invoked, otherwisetoTextInternal(Appendable)
from this one is invoked.- Parameters:
writer
- The writer used to print out the string representation- Throws:
java.io.IOException
- This should never happens, it is only required becauseAppendable.append(CharSequence)
throws anIOException
-
toStringItems
protected void toStringItems(java.lang.Appendable writer, java.util.List<? extends StateObject> items, boolean useComma) throws java.io.IOException
- Throws:
java.io.IOException
-
toText
public final void toText(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.Important: Even if this
StateObject
is decorated by another one, the decorator will not be used to print out a string representation of this one.- Specified by:
toText
in interfaceStateObject
- Parameters:
writer
- The writer used to print out the string representation- See Also:
StateObject.toString(Appendable)
-
toTextInternal
protected abstract 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.- 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
-
-