Class AbstractExpression
java.lang.Object
org.eclipse.persistence.jpa.jpql.parser.AbstractExpression
- All Implemented Interfaces:
Expression
- Direct Known Subclasses:
AbstractConditionalClause
,AbstractEncapsulatedExpression
,AbstractFromClause
,AbstractOrderByClause
,AbstractPathExpression
,AbstractSchemaName
,AbstractSelectClause
,AbstractSelectStatement
,ArithmeticFactor
,AsOfClause
,BadExpression
,BetweenExpression
,CaseExpression
,CollectionExpression
,CollectionMemberDeclaration
,CollectionMemberExpression
,CompoundExpression
,ConnectByClause
,ConstructorExpression
,DateTime
,DefaultStringExpression
,DeleteClause
,DeleteStatement
,EmptyCollectionComparisonExpression
,EntityTypeLiteral
,GroupByClause
,HierarchicalQueryClause
,IdentificationVariable
,IdentificationVariableDeclaration
,InExpression
,InputParameter
,Join
,JPQLExpression
,KeywordExpression
,LikeExpression
,NotExpression
,NullComparisonExpression
,NullExpression
,NumericLiteral
,OrderByItem
,RangeVariableDeclaration
,RegexpExpression
,ResultVariable
,StringLiteral
,TableVariableDeclaration
,UnionClause
,UnknownExpression
,UpdateClause
,UpdateItem
,UpdateStatement
,WhenClause
This is the abstract definition of all the parts used to create the tree hierarchy representing
the parsed JPQL query.
- Version:
- 2.6
- See Also:
- Author:
- Pascal Filion
-
Field Summary
Modifier and TypeFieldDescriptionstatic final char
The constant for ','.static final char
The constant for '.'.static final char
The constant for '"'.static final char
The constant for '{'.static final char
The constant for '('.static final char
The constant for a character that is not defined.static final char
The constant for '}'.static final char
The constant for ')'.static final char
The constant for '''.static final char
The constant for ' '.static final char
The constant for '_'.Fields inherited from interface org.eclipse.persistence.jpa.jpql.parser.Expression
ABS, ALL, AND, ANY, AS, AS_OF, ASC, AVG, BETWEEN, BIT_LENGTH, BOTH, CASE, CAST, CHAR_LENGTH, CHARACTER_LENGTH, CLASS, COALESCE, COLUMN, CONCAT, CONNECT_BY, COUNT, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, DELETE, DELETE_FROM, DESC, DIFFERENT, DISTINCT, DIVISION, ELSE, EMPTY, END, ENTRY, EQUAL, ESCAPE, EXCEPT, EXISTS, EXTRACT, FALSE, FETCH, FIRST, FROM, FUNC, FUNCTION, GREATER_THAN, GREATER_THAN_OR_EQUAL, GROUP_BY, HAVING, IN, INDEX, INNER, INNER_JOIN, INNER_JOIN_FETCH, INTERSECT, IS, IS_EMPTY, IS_NOT_EMPTY, IS_NOT_NULL, IS_NULL, JOIN, JOIN_FETCH, KEY, LAST, LEADING, LEFT, LEFT_JOIN, LEFT_JOIN_FETCH, LEFT_OUTER_JOIN, LEFT_OUTER_JOIN_FETCH, LENGTH, LIKE, LOCATE, LOWER, LOWER_THAN, LOWER_THAN_OR_EQUAL, MAX, MEMBER, MEMBER_OF, MIN, MINUS, MOD, MULTIPLICATION, NAMED_PARAMETER, NEW, NOT, NOT_BETWEEN, NOT_EQUAL, NOT_EXISTS, NOT_IN, NOT_LIKE, NOT_MEMBER, NOT_MEMBER_OF, NULL, NULLIF, NULLS, NULLS_FIRST, NULLS_LAST, OBJECT, OF, ON, OPERATOR, OR, ORDER_BY, ORDER_SIBLINGS_BY, OUTER, PLUS, POSITION, POSITIONAL_PARAMETER, QUOTE, REGEXP, SCN, SELECT, SET, SIZE, SOME, SQL, SQRT, START_WITH, SUBSTRING, SUM, TABLE, THEN, TIMESTAMP, TRAILING, TREAT, TRIM, TRUE, TYPE, UNION, UNKNOWN, UPDATE, UPPER, VALUE, WHEN, WHERE
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractExpression
(AbstractExpression parent) Creates a newAbstractExpression
.protected
AbstractExpression
(AbstractExpression parent, String text) Creates a newAbstractExpression
. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
acceptUnknownVisitor
(ExpressionVisitor visitor) The givenExpressionVisitor
needs to visit this class but it is defined by a third- party provider.protected void
acceptUnknownVisitor
(ExpressionVisitor visitor, Class<?> type, Class<?> parameterType) The givenExpressionVisitor
needs to visit this class but it is defined by a third- party provider.protected void
addChildrenTo
(Collection<Expression> children) Adds the children of thisAbstractExpression
to the given collection.protected void
addOrderedChildrenTo
(List<Expression> children) Adds the children of thisAbstractExpression
to the given list.protected final AbstractExpression
buildExpressionFromFallingBack
(WordParser wordParser, String word, JPQLQueryBNF queryBNF, AbstractExpression expression, boolean tolerant) No factories were found to create anExpression
with the content ofWordParser
, this method will retrieve the fallbackExpressionFactory
defined in the givenBNF
.protected final AbstractExpression
Creates a newnull
-Expression
parented with this one.protected final Expression
buildStringExpression
(char value) Creates a newExpression
wrapping the given character value.protected final Expression
buildStringExpression
(String value) Creates a newExpression
wrapping the given string value.protected final AbstractExpression
buildUnknownExpression
(String text) Creates anExpression
that contains a malformed expression.protected final int
calculatePosition
(Expression expression, int length) Calculates the position of the givenExpression
by calculating the length of what is before.final ListIterable<Expression>
children()
Returns the children of thisExpression
.protected final ExpressionFactory
findFallBackExpressionFactory
(JPQLQueryBNF queryBNF) Retrieve theExpressionFactory
from the givenJPQLQueryBNF
by following the path of fallbackJPQLQueryBNFs
and then returns theExpressionFactory
from the leafJPQLQueryBNF
.findQueryBNF
(Expression expression) Retrieves theJPQLQueryBNF
that represents the fragment of thisExpression
that was used when parsing the givenExpression
.protected final ExpressionFactory
getExpressionFactory
(String expressionFactoryId) Retrieves the registeredExpressionFactory
that was registered for the given unique identifier.protected final ExpressionRegistry
Returns the registry containing theJPQLQueryBNFs
and theExpressionFactories
that are used to properly parse a JPQL query.Returns theJPQLGrammar
that defines how the JPQL query was parsed.getIdentifierVersion
(String identifier) Retrieves the JPA version in which the identifier was first introduced.protected JPAVersion
Returns the version of the Java Persistence to support.final int
Returns the length of the string representation of thisExpression
, which is the length of the text generated byExpression.toActualText()
.final int
Returns the position of thisExpression
within its parent hierarchy.final AbstractExpression
Returns the parent of thisExpression
.getQueryBNF
(String queryBNFID) Retrieves the BNF object that was registered for the given unique identifier.final JPQLExpression
getRoot()
Retrieves the root node of the parsed tree hierarchy.protected String
getText()
Returns the encapsulated text of thisAbstractExpression
, which can be used in various ways, it can be a keyword, a literal, etc.protected boolean
handleAggregate
(JPQLQueryBNF queryBNF) Determines whether the givenJPQLQueryBNF
handles aggregate expressions.protected boolean
handleCollection
(JPQLQueryBNF queryBNF) Determines whether the givenJPQLQueryBNF
handles a collection of sub-expressions that are separated by commas.boolean
isAncestor
(Expression expression) Determines whether thisExpression
is a parent of the givenExpression
.protected final boolean
isIdentifier
(String word) Determines if the given word is a JPQL identifier.protected boolean
isNull()
Determines whether this expression is anull
Expression
or any other subclass.protected boolean
isParsingComplete
(WordParser wordParser, String word, Expression expression) Determines whether the parsing is complete based on what is left in the given text.protected boolean
Determines if the parser is in tolerant mode or is in fast mode.protected boolean
Determines whether this expression is an unknownExpression
or any other subclass.protected boolean
Determines whether thisAbstractExpression
is virtual, meaning it's not part of the query but is required for proper navigability.final ListIterable<Expression>
Returns the list representing thisExpression
and its children.protected abstract void
parse
(WordParser wordParser, boolean tolerant) Parses the query by starting at the current position, which is part of the givenWordParser
.protected AbstractExpression
parse
(WordParser wordParser, String queryBNFId, boolean tolerant) Parses the given text by using the specified BNF.protected AbstractExpression
parseUsingExpressionFactory
(WordParser wordParser, String queryBNFId, boolean tolerant) Right away parses the text by retrieving theExpressionFactory
for the first word that is extracted fromWordParser
at the current location.void
populatePosition
(QueryPosition queryPosition, int position) Retrieves theExpression
located at the given position using the actual query, which may have extra whitespace.protected final void
Rebuilds the actual parsed text if it has been cached.protected final void
Rebuilds the parsed parsed text if it has been cached.protected final void
setParent
(AbstractExpression parent) Re-parents thisExpression
to be a child of the givenExpression
.protected final void
Sets the text of thisExpression
.protected boolean
Determines whether the parsing of the query should be performed using thefactories
first or it should automatically fallback to the fallback factory.protected boolean
shouldSkipLiteral
(AbstractExpression expression) When parsing an invalid or incomplete query, it is possible two literals would be parsed but in some cases, a CollectionExpression should not be created and the parsing should actually stop here.Generates a string representation of thisExpression
, which needs to include any characters that are considered virtual, i.e.Returns a string representation of thisExpression
and its children.protected abstract void
toParsedText
(StringBuilder writer, boolean actual) Generates a string representation of thisExpression
, including its children, if it has any.final String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.persistence.jpa.jpql.parser.Expression
accept, acceptChildren, getQueryBNF
-
Field Details
-
COMMA
public static final char COMMAThe constant for ','.- See Also:
-
DOT
public static final char DOTThe constant for '.'.- See Also:
-
DOUBLE_QUOTE
public static final char DOUBLE_QUOTEThe constant for '"'.- See Also:
-
LEFT_CURLY_BRACKET
public static final char LEFT_CURLY_BRACKETThe constant for '{'.- See Also:
-
LEFT_PARENTHESIS
public static final char LEFT_PARENTHESISThe constant for '('.- See Also:
-
NOT_DEFINED
public static final char NOT_DEFINEDThe constant for a character that is not defined.- See Also:
-
RIGHT_CURLY_BRACKET
public static final char RIGHT_CURLY_BRACKETThe constant for '}'.- See Also:
-
RIGHT_PARENTHESIS
public static final char RIGHT_PARENTHESISThe constant for ')'.- See Also:
-
SINGLE_QUOTE
public static final char SINGLE_QUOTEThe constant for '''.- See Also:
-
SPACE
public static final char SPACEThe constant for ' '.- See Also:
-
UNDERSCORE
public static final char UNDERSCOREThe constant for '_'.- See Also:
-
-
Constructor Details
-
AbstractExpression
Creates a newAbstractExpression
.- Parameters:
parent
- The parent of this expression
-
AbstractExpression
Creates a newAbstractExpression
.- Parameters:
parent
- The parent of this expressiontext
- The text to be stored in this expression,null
cannot be passed
-
-
Method Details
-
acceptUnknownVisitor
The givenExpressionVisitor
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 visitor. The method signature should be:{public|protected|private} void visit(ThirdPartyExpression expression)
or
{public|protected|private} void visit(Expression expression)
Note: The package protected visibility (default) should be used with care, if the code is running inside OSGi, then the method will not be accessible, even through reflection.
- Parameters:
visitor
- TheExpressionVisitor
to visit thisExpression
programmatically- Returns:
true
if the call was successfully executed;false
otherwise
-
acceptUnknownVisitor
protected void acceptUnknownVisitor(ExpressionVisitor visitor, Class<?> type, Class<?> parameterType) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException The givenExpressionVisitor
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 visitor. The method signature should be:{public|protected|private} void visit(ThirdPartyExpression expression)
or
{public|protected|private} void visit(Expression expression)
- Parameters:
visitor
- TheExpressionVisitor
to visit thisExpression
programmaticallytype
- The type found in the hierarchy of the givenExpressionVisitor
that will be used to retrieve the visit methodparameterType
- The parameter type of the visit method- Throws:
NoSuchMethodException
IllegalAccessException
InvocationTargetException
- See Also:
-
addChildrenTo
Adds the children of thisAbstractExpression
to the given collection.- Parameters:
children
- The collection used to store the children
-
addOrderedChildrenTo
Adds the children of thisAbstractExpression
to the given list.- Parameters:
children
- The list used to store the string representation of thisAbstractExpression
-
buildExpressionFromFallingBack
protected final AbstractExpression buildExpressionFromFallingBack(WordParser wordParser, String word, JPQLQueryBNF queryBNF, AbstractExpression expression, boolean tolerant) No factories were found to create anExpression
with the content ofWordParser
, this method will retrieve the fallbackExpressionFactory
defined in the givenBNF
.- Parameters:
wordParser
- The text to parse based on the current position of the cursorword
- The word that was retrieved from the given text, which is the first word in the textqueryBNF
- TheJPQLQueryBNF
used to determine how to parse from the current position of the cursor within the JPQL queryexpression
- TheExpression
that has just been parsed ornull
tolerant
- Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries- Returns:
- The
Expression
representing the given sub-query
-
buildNullExpression
Creates a newnull
-Expression
parented with this one.- Returns:
- A new
null
version of anExpression
-
buildStringExpression
Creates a newExpression
wrapping the given character value.- Parameters:
value
- The character to wrap as aExpression
- Returns:
- The
Expression
representation of the given identifier where the owningExpression
is this one
-
buildStringExpression
Creates a newExpression
wrapping the given string value.- Parameters:
value
- The string to wrap as aExpression
- Returns:
- The
Expression
representation of the given identifier where the owningExpression
is this one
-
buildUnknownExpression
Creates anExpression
that contains a malformed expression.- Parameters:
text
- The text causing the expression to be malformed- Returns:
- A new
Expression
wheretoActualText()
returns the given text
-
calculatePosition
Calculates the position of the givenExpression
by calculating the length of what is before.- Parameters:
expression
- TheExpression
for which its position within the parsed tree needs to be determinedlength
- The current cursor position within the JPQL query while digging into the tree until the search reaches the expression- Returns:
- The length of the string representation for what is coming before the given
Expression
-
children
Description copied from interface:Expression
Returns the children of thisExpression
.- Specified by:
children
in interfaceExpression
- Returns:
- The children of this
Expression
or an emptyListIterable
-
findFallBackExpressionFactory
Retrieve theExpressionFactory
from the givenJPQLQueryBNF
by following the path of fallbackJPQLQueryBNFs
and then returns theExpressionFactory
from the leafJPQLQueryBNF
.- Parameters:
queryBNF
- TheJPQLQueryBNF
for which its associated fallbackExpressionFactory
will be searched- Returns:
- Either the fallback
ExpressionFactory
linked to the givenJPQLQueryBNF
ornull
if none was declared
-
findQueryBNF
Description copied from interface:Expression
Retrieves theJPQLQueryBNF
that represents the fragment of thisExpression
that was used when parsing the givenExpression
.- Specified by:
findQueryBNF
in interfaceExpression
- Parameters:
expression
- TheExpression
that is a descendant of this one- Returns:
- The
JPQLQueryBNF
that was used to parse the given expression
-
getExpressionFactory
Retrieves the registeredExpressionFactory
that was registered for the given unique identifier.- Parameters:
expressionFactoryId
- The unique identifier of theExpressionFactory
to retrieve- Returns:
- The
ExpressionFactory
mapped with the given unique identifier - See Also:
-
getExpressionRegistry
Returns the registry containing theJPQLQueryBNFs
and theExpressionFactories
that are used to properly parse a JPQL query.- Returns:
- The registry containing the information related to the JPQL grammar
-
getGrammar
Description copied from interface:Expression
Returns theJPQLGrammar
that defines how the JPQL query was parsed.- Specified by:
getGrammar
in interfaceExpression
- Returns:
- The
JPQLGrammar
that was used to parse thisExpression
-
getIdentifierVersion
Retrieves the JPA version in which the identifier was first introduced.- Returns:
- The version in which the identifier was introduced
-
getJPAVersion
Returns the version of the Java Persistence to support.- Returns:
- The JPA version supported by the grammar
- See Also:
-
getLength
public final int getLength()Description copied from interface:Expression
Returns the length of the string representation of thisExpression
, which is the length of the text generated byExpression.toActualText()
.- Specified by:
getLength
in interfaceExpression
- Returns:
- The length of the string representation of this
Expression
-
getOffset
public final int getOffset()Description copied from interface:Expression
Returns the position of thisExpression
within its parent hierarchy.- Specified by:
getOffset
in interfaceExpression
- Returns:
- The length of the string representation of what is coming before this object
-
getParent
Description copied from interface:Expression
Returns the parent of thisExpression
.- Specified by:
getParent
in interfaceExpression
- Returns:
- The parent of this
Expression
, which is nevernull
except for the root of the tree
-
getQueryBNF
Retrieves the BNF object that was registered for the given unique identifier.- Parameters:
queryBNFID
- The unique identifier of theJPQLQueryBNF
to retrieve- Returns:
- The
JPQLQueryBNF
representing a section of the grammar
-
getRoot
Description copied from interface:Expression
Retrieves the root node of the parsed tree hierarchy.- Specified by:
getRoot
in interfaceExpression
- Returns:
- The root of the
Expression
tree
-
getText
Returns the encapsulated text of thisAbstractExpression
, which can be used in various ways, it can be a keyword, a literal, etc.- Returns:
- Either the JPQL identifier for this
AbstractExpression
, the literal it encapsulates or an empty string
-
handleAggregate
Determines whether the givenJPQLQueryBNF
handles aggregate expressions.- Parameters:
queryBNF
- TheJPQLQueryBNF
used to determine if the parsing should handle aggregate expressions- Returns:
true
if the given BNF handles aggregate expressions;false
otherwise
-
handleCollection
Determines whether the givenJPQLQueryBNF
handles a collection of sub-expressions that are separated by commas.- Parameters:
queryBNF
- TheJPQLQueryBNF
used to determine if the parsing should handle collection of sub-expressions- Returns:
true
if the sub-expression to parse might have several sub-expressions separated by commas;false
otherwise
-
isAncestor
Description copied from interface:Expression
Determines whether thisExpression
is a parent of the givenExpression
.- Specified by:
isAncestor
in interfaceExpression
- Parameters:
expression
- TheExpression
to verify its paternity with thisExpression
- Returns:
true
if thisExpression
is the same as the givenExpression
or one of its parent;false
otherwise
-
isIdentifier
Determines if the given word is a JPQL identifier. The check is case insensitive.- Parameters:
word
- The word to test if it is a JPQL identifier- Returns:
true
if the word is an identifier,false
otherwise- See Also:
-
isNull
protected boolean isNull()Determines whether this expression is anull
Expression
or any other subclass.- Returns:
false
by default
-
isParsingComplete
Determines whether the parsing is complete based on what is left in the given text. The text is never empty.- Parameters:
wordParser
- The text to parse based on the current position of the cursorword
- The word that was retrieved from the given text, which is the first word in the textexpression
- TheExpression
that has already been parsed- Returns:
true
if the text no longer can't be parsed by the current expression;false
if more can be parsed
-
isTolerant
protected boolean isTolerant()Determines if the parser is in tolerant mode or is in fast mode. When the tolerant is turned on, it means the parser will attempt to parse incomplete or invalid queries.- Returns:
true
if the parsing system should parse invalid or incomplete queries;false
when the query is well-formed and valid
-
isUnknown
protected boolean isUnknown()Determines whether this expression is an unknownExpression
or any other subclass.- Returns:
false
by default
-
isVirtual
protected boolean isVirtual()Determines whether thisAbstractExpression
is virtual, meaning it's not part of the query but is required for proper navigability.- Returns:
true
if thisAbstractExpression
was virtually created to fully qualify path expression;false
if it was parsed
-
orderedChildren
Description copied from interface:Expression
Returns the list representing thisExpression
and its children.- Specified by:
orderedChildren
in interfaceExpression
- Returns:
- The
Expressions
representing thisExpression
-
parse
Parses the query by starting at the current position, which is part of the givenWordParser
.- Parameters:
wordParser
- The text to parse based on the current position of the cursortolerant
- Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
-
parse
Parses the given text by using the specified BNF.- Parameters:
wordParser
- The text to parse based on the current position of the cursorqueryBNFId
- The unique identifier of theJPQLQueryBNF
that is used to determine how to parse the text at the current cursor position within the JPQL querytolerant
- Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries- Returns:
- The
Expression
representing the given sub-query
-
parseUsingExpressionFactory
protected AbstractExpression parseUsingExpressionFactory(WordParser wordParser, String queryBNFId, boolean tolerant) Right away parses the text by retrieving theExpressionFactory
for the first word that is extracted fromWordParser
at the current location.- Parameters:
wordParser
- The text to parse based on the current position of the cursorqueryBNFId
- The unique identifier of theJPQLQueryBNF
that is used to determine how to parse the text at the current cursor position within the JPQL querytolerant
- Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries- Returns:
- The
Expression
representing the given sub-query
-
populatePosition
Description copied from interface:Expression
Retrieves theExpression
located at the given position using the actual query, which may have extra whitespace.- Specified by:
populatePosition
in interfaceExpression
position
- The array has one element and is the position of theExpression
to retrieve
-
rebuildActualText
protected final void rebuildActualText()Rebuilds the actual parsed text if it has been cached. -
rebuildParsedText
protected final void rebuildParsedText()Rebuilds the parsed parsed text if it has been cached. -
setParent
Re-parents thisExpression
to be a child of the givenExpression
.- Parameters:
parent
- The new parent of this object
-
setText
Sets the text of thisExpression
.- Parameters:
text
- The immutable text wrapped by thisExpression
, which cannot benull
-
shouldParseWithFactoryFirst
protected boolean shouldParseWithFactoryFirst()Determines whether the parsing of the query should be performed using thefactories
first or it should automatically fallback to the fallback factory.- Returns:
true
is returned by default so the factories are used before falling back
-
shouldSkipLiteral
When parsing an invalid or incomplete query, it is possible two literals would be parsed but in some cases, a CollectionExpression should not be created and the parsing should actually stop here. Example: BETWEEN 10 20, when parsing 20, it should not be parsed as part of the lower bound expression.- Parameters:
expression
- TheExpression
that has just been parsed ornull
- Returns:
true
-
toActualText
Description copied from interface:Expression
Generates a string representation of thisExpression
, which needs to include any characters that are considered virtual, i.e. that was parsed when the query is incomplete and is needed for functionality like content assist.- Specified by:
toActualText
in interfaceExpression
- Returns:
- The string representation of this
Expression
-
toParsedText
Description copied from interface:Expression
Returns a string representation of thisExpression
and its children. The expression should contain whitespace even if the beautified version would not have any. For instance, "SELECT e " should be returned whereExpression.toParsedText()
would return "SELECT e".- Specified by:
toParsedText
in interfaceExpression
- Returns:
- The string representation of this
Expression
-
toParsedText
Generates a string representation of thisExpression
, including its children, if it has any.- Parameters:
writer
- The buffer used to append thisExpression
's string representationactual
- Determines whether the string representation should represent what was parsed, i.e. include any "virtual" whitespace (such as ending whitespace) and the actual case of the JPQL identifiers
-
toString
-