Top Description Fields Constructors Methods
org.eclipse.persistence.jpa.jpql.parser

public final Class JPQLExpression

extends AbstractExpression
Class Inheritance
Annotations
@SuppressWarnings:nls
Imports
java.util.Collection, .List, org.eclipse.persistence.jpa.jpql.ExpressionTools, .JPAVersion, .WordParser

A JPQLExpression is the root of the parsed tree representation of a JPQL query. The query is parsed based on what was registered in the JPQLGrammar's ExpressionRegistry.

A JPQL statement may be either a SELECT statement, an UPDATE statement, or a DELETE FROM statement.

BNF: QL_statement ::= select_statement | update_statement | delete_statement

It is possible to parse a portion of a JPQL query. The ID of the JPQLQueryBNF is used to parse that portion and getQueryStatement() then returns only the parsed tree representation of that JPQL fragment.

Author
Pascal Filion
Since
2.3
Version
2.5

Field Summary

Modifier and TypeField and Description
private JPQLGrammar
jpqlGrammar

The JPQL grammar that defines how to parse a JPQL query.

private String
queryBNFId

By default, this is JPQLStatementBNF#ID but it can be any other unique identifier of a JPQLQueryBNF when a portion of a JPQL query needs to be parsed.

private AbstractExpression
queryStatement

The tree representation of the query.

private boolean
tolerant

Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries.

private AbstractExpression
unknownEndingStatement

If the expression could not be fully parsed, meaning some unknown text is trailing the query, this will contain it.

Inherited from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression:
COMMADOTDOUBLE_QUOTELEFT_CURLY_BRACKETLEFT_PARENTHESISNOT_DEFINEDRIGHT_CURLY_BRACKETRIGHT_PARENTHESISSINGLE_QUOTESPACEUNDERSCORE

Constructor Summary

AccessConstructor and Description
public
JPQLExpression(CharSequence
The string representation of the JPQL query to parse
query
,
JPQLGrammar
The JPQL grammar that defines how to parse a JPQL query
jpqlGrammar
)

Creates a new JPQLExpression, which is the root of the JPQL parsed tree.

public
JPQLExpression(CharSequence
The string representation of the JPQL query to parse
query
,
JPQLGrammar
The JPQL grammar that defines how to parse a JPQL query
jpqlGrammar
,
boolean
Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
tolerant
)

Creates a new JPQLExpression, which is the root of the JPQL parsed tree.

public
JPQLExpression(CharSequence
A fragment of a JPQL query, which is a portion of a complete JPQL query
jpqlFragment
,
JPQLGrammar
The JPQL grammar that defines how to parse a JPQL query
jpqlGrammar
,
String
The unique identifier of the JPQLQueryBNF
queryBNFId
,
boolean
Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
tolerant
)

Creates a new JPQLExpression that will parse the given fragment of a JPQL query.

private
JPQLExpression(JPQLGrammar
The JPQL grammar that defines how to parse a JPQL query
jpqlGrammar
,
String queryBNFId, boolean
Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
tolerant
)

Creates a new JPQLExpression, which is the root of the JPQL parsed tree.

Method Summary

Modifier and TypeMethod and Description
public void
accept(ExpressionVisitor
The ExpressionVisitor to visit this object
visitor
)

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.accept.

Visits this Expression by the given visitor.
public void
acceptChildren(ExpressionVisitor
The visitor to visit the children of this object.
visitor
)

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.acceptChildren.

Visits the children of this Expression.
protected void
addChildrenTo(Collection<Expression>
The collection used to store the children
children
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addChildrenTo.

Adds the children of this AbstractExpression to the given collection.
protected void
addOrderedChildrenTo(List<Expression>
The list used to store the string representation of this AbstractExpression
children
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addOrderedChildrenTo.

Adds the children of this AbstractExpression to the given list.
public QueryPosition

Returns:

A new QueryPosition
buildPosition
(String
The actual query is a string representation of the query that may contain extra whitespace
actualQuery
,
int
The position of the cursor in the actual query, which is used to retrieve the deepest Expression. The position will be adjusted to fit into the beautified version of the query
position
)

Creates a map of the position of the cursor within each Expression of the parsed tree.

public Expression

Returns:

The Expression located at the given position in the given query
getExpression
(String
The actual query is the text version of the query that may contain extra whitespace and different formatting than the trim down version generated by the parsed tree
actualQuery
,
int
The position in the actual query used to retrieve the Expression
position
)

Returns the deepest Expression for the given position.

public JPQLGrammar
public JPAVersion
getJPAVersion()

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.getJPAVersion.

Returns the version of the Java Persistence to support.
public JPQLQueryBNF
public Expression

Returns:

The expression representing the Java Persistence query
getQueryStatement
()

Returns the Expression representing the query, which is either a SELECT, a DELETE or an UPDATE clause.

public Expression

Returns:

The expression used when the ending of the query is unknown or malformed
getUnknownEndingStatement
()

Returns the Expression that may contain a portion of the query that could not be parsed, this happens when the query is either incomplete or malformed.

public boolean

Returns:

true the query was parsed; false otherwise
hasQueryStatement
()

Determines whether a query was parsed.

public boolean

Returns:

true if the query could not be parsed correctly because it is either incomplete or malformed
hasUnknownEndingStatement
()

Determines whether the query that got parsed had some malformed or unknown information.

protected boolean
isTolerant()

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.isTolerant.

Determines if the parser is in tolerant mode or is in fast mode.
protected void
parse(WordParser
The text to parse based on the current position of the cursor
wordParser
,
boolean
Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
tolerant
)

Implements abstract org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.parse.

Parses the query by starting at the current position, which is part of the given WordParser.
protected void
toParsedText(StringBuilder
The buffer used to append this Expression's string representation
writer
,
boolean
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
actual
)

Implements abstract org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.toParsedText.

Generates a string representation of this Expression, including its children, if it has any.
Inherited from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression:
acceptUnknownVisitoracceptUnknownVisitorbuildExpressionFromFallingBackbuildNullExpressionbuildStringExpressionbuildStringExpressionbuildUnknownExpressioncalculatePositionchildrenfindFallBackExpressionFactoryfindQueryBNFgetExpressionFactorygetExpressionRegistrygetIdentifierVersiongetLengthgetOffsetgetParentgetQueryBNFgetRootgetTexthandleAggregatehandleCollectionisAncestorisIdentifierisNullisParsingCompleteisUnknownisVirtualorderedChildrenparseparseUsingExpressionFactorypopulatePositionrebuildActualTextrebuildParsedTextsetParentsetTextshouldParseWithFactoryFirstshouldSkipLiteraltoActualTexttoParsedTexttoString

Field Detail

jpqlGrammarback to summary
private JPQLGrammar jpqlGrammar

The JPQL grammar that defines how to parse a JPQL query.

queryBNFIdback to summary
private String queryBNFId

By default, this is JPQLStatementBNF#ID but it can be any other unique identifier of a JPQLQueryBNF when a portion of a JPQL query needs to be parsed.

queryStatementback to summary
private AbstractExpression queryStatement

The tree representation of the query.

tolerantback to summary
private boolean tolerant

Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries.

unknownEndingStatementback to summary
private AbstractExpression unknownEndingStatement

If the expression could not be fully parsed, meaning some unknown text is trailing the query, this will contain it.

Constructor Detail

JPQLExpressionback to summary
public JPQLExpression(CharSequence query, JPQLGrammar jpqlGrammar)

Creates a new JPQLExpression, which is the root of the JPQL parsed tree.

Parameters
query:CharSequence

The string representation of the JPQL query to parse

jpqlGrammar:JPQLGrammar

The JPQL grammar that defines how to parse a JPQL query

JPQLExpressionback to summary
public JPQLExpression(CharSequence query, JPQLGrammar jpqlGrammar, boolean tolerant)

Creates a new JPQLExpression, which is the root of the JPQL parsed tree.

Parameters
query:CharSequence

The string representation of the JPQL query to parse

jpqlGrammar:JPQLGrammar

The JPQL grammar that defines how to parse a JPQL query

tolerant:boolean

Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries

JPQLExpressionback to summary
public JPQLExpression(CharSequence jpqlFragment, JPQLGrammar jpqlGrammar, String queryBNFId, boolean tolerant)

Creates a new JPQLExpression that will parse the given fragment of a JPQL query. This means getQueryStatement() will not return a query statement (select, delete or update) but only the parsed tree representation of the fragment if the query BNF can pare it. If the fragment of the JPQL query could not be parsed using the given JPQLQueryBNF, then getUnknownEndingStatement() will contain the non-parsable fragment.

Parameters
jpqlFragment:CharSequence

A fragment of a JPQL query, which is a portion of a complete JPQL query

jpqlGrammar:JPQLGrammar

The JPQL grammar that defines how to parse a JPQL query

queryBNFId:String

The unique identifier of the JPQLQueryBNF

tolerant:boolean

Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries

Since
2.4
JPQLExpressionback to summary
private JPQLExpression(JPQLGrammar jpqlGrammar, String queryBNFId, boolean tolerant)

Creates a new JPQLExpression, which is the root of the JPQL parsed tree.

Parameters
jpqlGrammar:JPQLGrammar

The JPQL grammar that defines how to parse a JPQL query

tolerant:boolean

Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries

Method Detail

acceptback to summary
public void accept(ExpressionVisitor visitor)

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.accept.

Doc from org.eclipse.persistence.jpa.jpql.parser.Expression.accept.

Visits this Expression by the given visitor.

Parameters
visitor:ExpressionVisitor

The ExpressionVisitor to visit this object

Annotations
@Override
acceptChildrenback to summary
public void acceptChildren(ExpressionVisitor visitor)

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.acceptChildren.

Doc from org.eclipse.persistence.jpa.jpql.parser.Expression.acceptChildren.

Visits the children of this Expression. This method can be used to optimize traversing the children since a new list is not created every time children() is called.

This does not traverse the Expression sub-hierarchy, use a subclass of AbstractTraverseChildrenVisitor in order to traverse the entire sub-hierarchy.

Parameters
visitor:ExpressionVisitor

The visitor to visit the children of this object.

Annotations
@Override
addChildrenToback to summary
protected void addChildrenTo(Collection<Expression> children)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addChildrenTo.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addChildrenTo.

Adds the children of this AbstractExpression to the given collection.

Parameters
children:Collection<Expression>

The collection used to store the children

Annotations
@Override
addOrderedChildrenToback to summary
protected void addOrderedChildrenTo(List<Expression> children)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addOrderedChildrenTo.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addOrderedChildrenTo.

Adds the children of this AbstractExpression to the given list.

Parameters
children:List<Expression>

The list used to store the string representation of this AbstractExpression

Annotations
@Override
buildPositionback to summary
public QueryPosition buildPosition(String actualQuery, int position)

Creates a map of the position of the cursor within each Expression of the parsed tree.

Parameters
actualQuery:String

The actual query is a string representation of the query that may contain extra whitespace

position:int

The position of the cursor in the actual query, which is used to retrieve the deepest Expression. The position will be adjusted to fit into the beautified version of the query

Returns:QueryPosition

A new QueryPosition

getExpressionback to summary
public Expression getExpression(String actualQuery, int position)

Returns the deepest Expression for the given position.

Parameters
actualQuery:String

The actual query is the text version of the query that may contain extra whitespace and different formatting than the trim down version generated by the parsed tree

position:int

The position in the actual query used to retrieve the Expression

Returns:Expression

The Expression located at the given position in the given query

getGrammarback to summary
public JPQLGrammar getGrammar()

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.getGrammar.

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.getGrammar.

Doc from org.eclipse.persistence.jpa.jpql.parser.Expression.getGrammar.

Returns the JPQLGrammar that defines how the JPQL query was parsed.

Returns:JPQLGrammar

The JPQLGrammar that was used to parse this Expression

Annotations
@Override
getJPAVersionback to summary
public JPAVersion getJPAVersion()

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.getJPAVersion.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.getJPAVersion.

Returns the version of the Java Persistence to support.

Returns:JPAVersion

The JPA version supported by the grammar

Annotations
@Override
getQueryBNFback to summary
public JPQLQueryBNF getQueryBNF()

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.getQueryBNF.

Doc from org.eclipse.persistence.jpa.jpql.parser.Expression.getQueryBNF.

Returns the BNF of this Expression.

Returns:JPQLQueryBNF

The JPQLQueryBNF, which represents the grammar of this Expression

Annotations
@Override
getQueryStatementback to summary
public Expression getQueryStatement()

Returns the Expression representing the query, which is either a SELECT, a DELETE or an UPDATE clause.

Returns:Expression

The expression representing the Java Persistence query

getUnknownEndingStatementback to summary
public Expression getUnknownEndingStatement()

Returns the Expression that may contain a portion of the query that could not be parsed, this happens when the query is either incomplete or malformed.

Returns:Expression

The expression used when the ending of the query is unknown or malformed

hasQueryStatementback to summary
public boolean hasQueryStatement()

Determines whether a query was parsed. The query may be incomplete but it started with one of the three clauses (SELECT, DELETE FROM, or UPDATE).

Returns:boolean

true the query was parsed; false otherwise

hasUnknownEndingStatementback to summary
public boolean hasUnknownEndingStatement()

Determines whether the query that got parsed had some malformed or unknown information.

Returns:boolean

true if the query could not be parsed correctly because it is either incomplete or malformed

isTolerantback to summary
protected boolean isTolerant()

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.isTolerant.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.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:boolean

true if the parsing system should parse invalid or incomplete queries; false when the query is well-formed and valid

Annotations
@Override
parseback to summary
protected void parse(WordParser wordParser, boolean tolerant)

Implements abstract org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.parse.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.parse.

Parses the query by starting at the current position, which is part of the given WordParser.

Parameters
wordParser:WordParser

The text to parse based on the current position of the cursor

tolerant:boolean

Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries

Annotations
@Override
toParsedTextback to summary
protected void toParsedText(StringBuilder writer, boolean actual)

Implements abstract org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.toParsedText.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.toParsedText.

Generates a string representation of this Expression, including its children, if it has any.

Parameters
writer:StringBuilder

The buffer used to append this Expression's string representation

actual:boolean

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

Annotations
@Override