Class JoinStateObject
- java.lang.Object
-
- org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
-
- org.eclipse.persistence.jpa.jpql.tools.model.query.JoinStateObject
-
- All Implemented Interfaces:
StateObject
public class JoinStateObject extends AbstractStateObject
AJOIN
enables the fetching of an association as a side effect of the execution of a query. AJOIN
is specified over an entity and its related entities.BNF:join ::= join_spec join_association_path_expression [AS] identification_variable
A JOIN FETCH enables the fetching of an association as a side effect of the execution of a query. A JOIN FETCH is specified over an entity and its related entities.
BNF:fetch_join ::= join_spec FETCH join_association_path_expression
- Version:
- 2.4
- See Also:
Join
- Author:
- Pascal Filion
- Since:
- 2.4
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
AS_PROPERTY
Notifies the visibility of theAS
identifier has changed.static java.lang.String
JOIN_TYPE_PROPERTY
Notifies the join type property has changed.
-
Constructor Summary
Constructors Constructor Description JoinStateObject(AbstractIdentificationVariableDeclarationStateObject parent, java.lang.String joinType)
Creates a newJoinStateObject
.JoinStateObject(AbstractIdentificationVariableDeclarationStateObject parent, java.lang.String joinType, boolean as)
Creates a newJoinStateObject
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(StateObjectVisitor visitor)
Visits thisStateObject
by the givenvisitor
.JoinStateObject
addAs()
Makes sure theAS
identifier is specified.protected void
addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObject
to the given list.void
addJoinAssociationPaths(java.util.List<java.lang.String> paths)
Adds the given segments to the end of the join association path expression.Join
getExpression()
Returns the actual parsed object if thisStateObject
representation of the JPQL query was created by parsing an existing JPQL query.java.lang.String
getIdentificationVariable()
Returns the name of the identification variable that defines the join association path.IdentificationVariableStateObject
getIdentificationVariableStateObject()
Returns the state object holding the identification variable.StateObject
getJoinAssociationIdentificationVariable()
Returns theStateObject
representing the identification variable that starts the path expression, which can be a sample identification variable, a map value, map key or map entry expression.CollectionValuedPathExpressionStateObject
getJoinAssociationPathStateObject()
Returns theCollectionValuedPathExpressionStateObject
representing the join association path.java.lang.String
getJoinType()
Returns the joining type.AbstractIdentificationVariableDeclarationStateObject
getParent()
Returns the parent of thisStateObject
.boolean
hasAs()
Determines whether theAS
identifier is used or not.boolean
hasFetch()
Determines whether the identifier FETCH was parsed.boolean
hasIdentificationVariable()
Determines whether the identification variable has been defined.protected void
initialize()
Initializes this state object.boolean
isEquivalent(StateObject stateObject)
Determines whether the givenStateObject
is equivalent to this one, i.e. the information of bothStateObject
is the same.ListIterable<java.lang.String>
joinAssociationPaths()
Returns the segments in the state field path in order.int
joinAssociationPathSize()
Returns the number of segments in the path expression.void
removeNot()
Makes sure theAS
identifier is not specified.void
setAs(boolean as)
Sets whether theAS
identifier is used or not.void
setExpression(Join 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
setIdentificationVariable(java.lang.String identificationVariable)
Sets the name of the identification variable that defines the join association path.void
setJoinAssociationIdentificationVariable(StateObject identificationVariable)
Sets theStateObject
representing the identification variable that starts the path expression, which can be a sample identification variable, a map value, map key or map entry expression.void
setJoinAssociationPath(java.lang.String path)
Changes the path expression with the list of segments, the identification variable will also be updated with the first segment.void
setJoinAssociationPaths(java.lang.String[] paths)
Changes the path expression with the list of segments, the identification variable will also be updated with the first segment.void
setJoinAssociationPaths(java.util.ListIterator<java.lang.String> paths)
Changes the path expression with the list of segments, the identification variable will also be updated with the first segment.void
setJoinType(java.lang.String joinType)
Sets the joining type.void
toggleAs()
Toggles the usage of theAS
identifier.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.protected void
validateJoinType(java.lang.String joinType)
Validates the given join type.-
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 Detail
-
AS_PROPERTY
public static final java.lang.String AS_PROPERTY
Notifies the visibility of theAS
identifier has changed.- See Also:
- Constant Field Values
-
JOIN_TYPE_PROPERTY
public static final java.lang.String JOIN_TYPE_PROPERTY
Notifies the join type property has changed.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JoinStateObject
public JoinStateObject(AbstractIdentificationVariableDeclarationStateObject parent, java.lang.String joinType)
Creates a newJoinStateObject
.- Parameters:
parent
- The parent of this state objectjoinType
- One of the joining types
-
JoinStateObject
public JoinStateObject(AbstractIdentificationVariableDeclarationStateObject parent, java.lang.String joinType, boolean as)
Creates a newJoinStateObject
.- Parameters:
parent
- The parent of this state objectjoinType
- One of the joining typesas
- Determine whether theAS
identifier is used or not
-
-
Method Detail
-
accept
public void accept(StateObjectVisitor visitor)
Visits thisStateObject
by the givenvisitor
.- Parameters:
visitor
- Thevisitor
to visit this object
-
addAs
public JoinStateObject addAs()
Makes sure theAS
identifier is specified.- Returns:
- 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
-
addJoinAssociationPaths
public void addJoinAssociationPaths(java.util.List<java.lang.String> paths)
Adds the given segments to the end of the join association path expression. The identification variable will not be affected.- Parameters:
paths
- The new path expression
-
getExpression
public Join 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)
-
getIdentificationVariable
public java.lang.String getIdentificationVariable()
Returns the name of the identification variable that defines the join association path.- Returns:
- The variable defining the join association path
-
getIdentificationVariableStateObject
public IdentificationVariableStateObject getIdentificationVariableStateObject()
Returns the state object holding the identification variable.- Returns:
- The portion of the joining expression representing the identification variable
-
getJoinAssociationIdentificationVariable
public StateObject getJoinAssociationIdentificationVariable()
Returns theStateObject
representing the identification variable that starts the path expression, which can be a sample identification variable, a map value, map key or map entry expression.- Returns:
- The root of the path expression
-
getJoinAssociationPathStateObject
public CollectionValuedPathExpressionStateObject getJoinAssociationPathStateObject()
Returns theCollectionValuedPathExpressionStateObject
representing the join association path.- Returns:
- The state object representing the join association path
-
getJoinType
public java.lang.String getJoinType()
Returns the joining type.- Returns:
- The joining type of this joining expression
-
getParent
public AbstractIdentificationVariableDeclarationStateObject 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
-
hasAs
public boolean hasAs()
Determines whether theAS
identifier is used or not.- Returns:
true
if theAS
identifier is part of the expression;false
otherwise
-
hasFetch
public boolean hasFetch()
Determines whether the identifier FETCH was parsed.- Returns:
true
if the identifier FETCH was parsed;false
otherwise
-
hasIdentificationVariable
public boolean hasIdentificationVariable()
Determines whether the identification variable has been defined.- Returns:
true
if the identification has been defined;false
otherwise
-
initialize
protected void initialize()
Initializes this state object.- Overrides:
initialize
in classAbstractStateObject
-
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
-
joinAssociationPaths
public ListIterable<java.lang.String> joinAssociationPaths()
Returns the segments in the state field path in order.- Returns:
- An
Iterator
over the segments of the state field path
-
joinAssociationPathSize
public int joinAssociationPathSize()
Returns the number of segments in the path expression.- Returns:
- The number of segments
-
removeNot
public void removeNot()
Makes sure theAS
identifier is not specified.
-
setAs
public void setAs(boolean as)
Sets whether theAS
identifier is used or not.- Parameters:
as
-true
if theAS
identifier is part of the expression;false
otherwise
-
setExpression
public void setExpression(Join 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 aJOIN
expression
-
setIdentificationVariable
public void setIdentificationVariable(java.lang.String identificationVariable)
Sets the name of the identification variable that defines the join association path.- Parameters:
identificationVariable
- The new variable defining the join association path
-
setJoinAssociationIdentificationVariable
public void setJoinAssociationIdentificationVariable(StateObject identificationVariable)
Sets theStateObject
representing the identification variable that starts the path expression, which can be a sample identification variable, a map value, map key or map entry expression.- Parameters:
identificationVariable
- The root of the path expression
-
setJoinAssociationPath
public void setJoinAssociationPath(java.lang.String path)
Changes the path expression with the list of segments, the identification variable will also be updated with the first segment.- Parameters:
path
- The new path expression
-
setJoinAssociationPaths
public void setJoinAssociationPaths(java.util.ListIterator<java.lang.String> paths)
Changes the path expression with the list of segments, the identification variable will also be updated with the first segment.- Parameters:
paths
- The new path expression
-
setJoinAssociationPaths
public void setJoinAssociationPaths(java.lang.String[] paths)
Changes the path expression with the list of segments, the identification variable will also be updated with the first segment.- Parameters:
paths
- The new path expression
-
setJoinType
public void setJoinType(java.lang.String joinType)
Sets the joining type.- Parameters:
joinType
- One of the joining types
-
toggleAs
public void toggleAs()
Toggles the usage of theAS
identifier.
-
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
-
validateJoinType
protected void validateJoinType(java.lang.String joinType)
Validates the given join type.- Parameters:
joinType
- One of the possible joining types
-
-