Package org.eclipse.persistence.jpa.jpql
Class AbstractValidator
- java.lang.Object
-
- org.eclipse.persistence.jpa.jpql.parser.AnonymousExpressionVisitor
-
- org.eclipse.persistence.jpa.jpql.AbstractValidator
-
- All Implemented Interfaces:
ExpressionVisitor
- Direct Known Subclasses:
AbstractGrammarValidator
,AbstractSemanticValidator
public abstract class AbstractValidator extends AnonymousExpressionVisitor
The abstract definition of a validator, which provides helper methods and visitors.Provisional API: This interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.
- Version:
- 2.5
- See Also:
AbstractGrammarValidator
,AbstractSemanticValidator
- Author:
- Pascal Filion
- Since:
- 2.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractValidator.BypassChildCollectionExpressionVisitor
This visitor is responsible to traverse the children of aCollectionExpression
in order to properly validate theExpression
.static class
AbstractValidator.BypassParentSubExpressionVisitor
This visitor is responsible to traverse the parent hierarchy and to skipSubExpression
if it's a parent.static class
AbstractValidator.ChildrenCollectorVisitor
This visitor gathers the children of aCollectionExpression
or a single visitedExpression
.static class
AbstractValidator.JPQLQueryBNFValidator
This visitor validates anyExpression
by checking its BNF against some BNFs.protected static class
AbstractValidator.NestedArrayVisitor
static class
AbstractValidator.OwningClauseVisitor
This visitor retrieves the clause owning the visitedExpression
.protected static class
AbstractValidator.OwningStatementVisitor
This visitor retrieves the statement owning the visitedExpression
.protected static class
AbstractValidator.SubqueryVisitor
This visitor retrieves the statement owning the visitedExpression
.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractValidator()
Creates a newAbstractValidator
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addProblem(Expression expression, int startPosition, int endPosition, java.lang.String messageKey, java.lang.String... messageArguments)
Adds a new validation problem that was found in the givenExpression
.protected void
addProblem(Expression expression, int startPosition, java.lang.String messageKey, java.lang.String... messageArguments)
Adds a new validation problem that was found in the givenExpression
.protected void
addProblem(Expression expression, java.lang.String messageKey)
Adds a new validation problem that was found in the givenExpression
.protected void
addProblem(Expression expression, java.lang.String messageKey, java.lang.String... arguments)
Adds a new validation problem that was found in the givenExpression
.protected AbstractValidator.ChildrenCollectorVisitor
buildChildrenCollector()
protected abstract LiteralVisitor
buildLiteralVisitor()
Creates the visitor that can retrieve some information about various literal.protected AbstractValidator.NestedArrayVisitor
buildNestedArrayVisitor()
Creates the visitor that traverses anExpression
and determines if it's a nested array or not.protected abstract AbstractValidator.OwningClauseVisitor
buildOwningClauseVisitor()
Creates the visitor that traverses the parent hierarchy of anyExpression
and stops at the firstExpression
that is a clause.protected AbstractValidator.OwningStatementVisitor
buildOwningStatementVisitor()
Creates the visitor that traverses the parent hierarchy of anyExpression
and stops at the firstExpression
that is a statement.protected JPQLQueryProblem
buildProblem(Expression expression, int startPosition, int endPosition, java.lang.String messageKey, java.lang.String... messageArguments)
Creates a new validation problem that was found in the givenExpression
.protected AbstractValidator.SubqueryVisitor
buildSubqueryVisitor()
Creates the visitor that checks if the visited expression is a subquery or not..void
dispose()
Disposes this visitor.protected AbstractValidator.BypassChildCollectionExpressionVisitor
getBypassChildCollectionExpressionVisitor()
protected AbstractValidator.BypassParentSubExpressionVisitor
getBypassParentSubExpressionVisitor()
protected java.util.List<Expression>
getChildren(Expression expression)
Returns a list containing either the givenExpression
if it's not aCollectionExpression
or the children of the givenCollectionExpression
.protected AbstractValidator.ChildrenCollectorVisitor
getChildrenCollectorVisitor()
protected ExpressionRegistry
getExpressionRegistry()
Returns the registry containing theJPQLQueryBNFs
and theExpressionFactories
that are used to properly parse a JPQL query.protected AbstractValidator.JPQLQueryBNFValidator
getExpressionValidator(java.lang.String queryBNF)
protected abstract JPQLGrammar
getGrammar()
Returns theJPQLGrammar
that defines how the JPQL query was parsed.protected JPAVersion
getJPAVersion()
Returns the version of the Java Persistence this entity for which it was defined.protected AbstractValidator.JPQLQueryBNFValidator
getJPQLQueryBNFValidator(java.lang.String queryBNF)
Returns theAbstractValidator.JPQLQueryBNFValidator
that can be used to validate anExpression
by making sure its BNF is part of the given BNF.protected AbstractValidator.JPQLQueryBNFValidator
getJPQLQueryBNFValidator(JPQLQueryBNF queryBNF)
Returns theAbstractValidator.JPQLQueryBNFValidator
that can be used to validate anExpression
by making sure its BNF is part of the given BNF.protected LiteralVisitor
getLiteralVisitor()
Returns the visitor that can retrieve some information about various literal.protected AbstractValidator.NestedArrayVisitor
getNestedArrayVisitor()
Returns the visitor that can determine if anExpression
represents a nested array.protected AbstractValidator.OwningClauseVisitor
getOwningClauseVisitor()
Returns the visitor that traverses the parent hierarchy of anyExpression
and stops at the firstExpression
that is a clause.protected AbstractValidator.OwningStatementVisitor
getOwningStatementVisitor()
Returns the visitor that traverses the parent hierarchy of anyExpression
and stops at the firstExpression
that is a statement.protected java.lang.String
getProvider()
Returns the persistence provider name.protected java.lang.String
getProviderVersion()
Returns the version of the persistence provider.protected JPQLQueryBNF
getQueryBNF(java.lang.String queryBNFId)
Retrieves the BNF object that was registered for the given unique identifier.protected AbstractValidator.SubqueryVisitor
getSubqueryVisitor()
Returns the visitor that checks if the visited expression is a subquery or not.protected void
initialize()
Initializes this validator.protected boolean
isNestedArray(Expression expression)
Determines whether the givenExpression
represents a nested array or not.protected boolean
isSubquery(Expression expression)
Determines whether the givenExpression
is a subquery.protected boolean
isValid(Expression expression, java.lang.String queryBNFId)
Determines whether the givenExpression
is valid by checking itsJPQLQueryBNF
with theJPQLQueryBNF
associated with the given unique identifier.protected boolean
isValid(Expression expression, java.lang.String... queryBNFIds)
Determines whether the givenExpression
is valid by checking itsJPQLQueryBNF
with the list ofJPQLQueryBNF
associated with the given unique identifiers.protected boolean
isValid(Expression expression, JPQLQueryBNF queryBNF)
Determines whether the givenExpression
is valid by checking itsJPQLQueryBNF
with the givenJPQLQueryBNF
.protected boolean
isValidWithChildCollectionBypass(Expression expression, java.lang.String queryBNF)
Determines whether the givenExpression
part is an expression of the given query BNF.protected boolean
isWithinSubquery(Expression expression)
Determines whether the givenExpression
is part of a subquery.protected boolean
isWithinTopLevelQuery(Expression expression)
Determines whether the givenExpression
is part of the top-level query.protected int
length(Expression expression)
Returns the length of the string representation of the givenExpression
.protected java.lang.String
literal(Expression expression, LiteralType type)
Retrieves the "literal" from the givenExpression
.protected int
nestedArraySize(Expression expression)
Returns the number of items in the nested array if the givenExpression
represents one.protected int
position(Expression expression)
Calculates the position of the given expression by calculating the length of what is before.int
problemsSize()
Returns the current number of problems that were registered during validation.void
setProblems(java.util.Collection<JPQLQueryProblem> problems)
Sets the collection that will be used to storeproblems
this validator will find in the JPQL query.protected void
visit(Expression expression)
Blindly visit the givenExpression
.-
Methods inherited from class org.eclipse.persistence.jpa.jpql.parser.AnonymousExpressionVisitor
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
-
-
-
-
Method Detail
-
addProblem
protected void addProblem(Expression expression, int startPosition, int endPosition, java.lang.String messageKey, java.lang.String... messageArguments)
Adds a new validation problem that was found in the givenExpression
.- Parameters:
expression
- TheExpression
that is either not following the BNF grammar or that has semantic problemsstartPosition
- The position where the problem was encounteredendPosition
- The position where the problem ends, inclusivelymessageKey
- The key used to retrieve the localized message describing the problemmessageArguments
- The list of arguments that can be used to format the localized description of the problem
-
addProblem
protected void addProblem(Expression expression, int startPosition, java.lang.String messageKey, java.lang.String... messageArguments)
Adds a new validation problem that was found in the givenExpression
.- Parameters:
expression
- TheExpression
that is either not following the BNF grammar or that has semantic problemsstartPosition
- The position where the problem was encounteredmessageKey
- The key used to retrieve the localized message describing the problemmessageArguments
- The list of arguments that can be used to format the localized description of the problem
-
addProblem
protected void addProblem(Expression expression, java.lang.String messageKey)
Adds a new validation problem that was found in the givenExpression
. The start index is the position of the givenExpression
within the JPQL query and the end index is the end position of theExpression
within the JPQL query.- Parameters:
expression
- TheExpression
that is either not following the BNF grammar or that has semantic problemsmessageKey
- The key used to retrieve the localized message describing the problem
-
addProblem
protected void addProblem(Expression expression, java.lang.String messageKey, java.lang.String... arguments)
Adds a new validation problem that was found in the givenExpression
. The start index is the position of the givenExpression
within the JPQL query and the end index is the end position of theExpression
within the JPQL query.- Parameters:
expression
- TheExpression
that is either not following the BNF grammar or that has semantic problemsmessageKey
- The key used to retrieve the localized message describing the problemarguments
- The list of arguments that can be used to format the localized description of the problem
-
buildChildrenCollector
protected AbstractValidator.ChildrenCollectorVisitor buildChildrenCollector()
-
buildLiteralVisitor
protected abstract LiteralVisitor buildLiteralVisitor()
Creates the visitor that can retrieve some information about various literal.- Returns:
- A new
LiteralVisitor
-
buildNestedArrayVisitor
protected AbstractValidator.NestedArrayVisitor buildNestedArrayVisitor()
Creates the visitor that traverses anExpression
and determines if it's a nested array or not.- Returns:
- A new
AbstractValidator.NestedArrayVisitor
- Since:
- 2.5
-
buildOwningClauseVisitor
protected abstract AbstractValidator.OwningClauseVisitor buildOwningClauseVisitor()
Creates the visitor that traverses the parent hierarchy of anyExpression
and stops at the firstExpression
that is a clause.- Returns:
- A new
AbstractValidator.OwningClauseVisitor
-
buildOwningStatementVisitor
protected AbstractValidator.OwningStatementVisitor buildOwningStatementVisitor()
Creates the visitor that traverses the parent hierarchy of anyExpression
and stops at the firstExpression
that is a statement.- Returns:
- A new
AbstractValidator.OwningStatementVisitor
- Since:
- 2.4
-
buildProblem
protected JPQLQueryProblem buildProblem(Expression expression, int startPosition, int endPosition, java.lang.String messageKey, java.lang.String... messageArguments)
Creates a new validation problem that was found in the givenExpression
.- Parameters:
expression
- TheExpression
that is either not following the BNF grammar or that has semantic problemsstartPosition
- The position where the problem was encounteredendPosition
- The position where the problem ends, inclusivelymessageKey
- The key used to retrieve the localized message describing the problemmessageArguments
- The list of arguments that can be used to format the localized description of the problem- Returns:
- The
JPQLQueryProblem
describing a problem
-
buildSubqueryVisitor
protected AbstractValidator.SubqueryVisitor buildSubqueryVisitor()
Creates the visitor that checks if the visited expression is a subquery or not..- Returns:
- A new
AbstractValidator.SubqueryVisitor
- Since:
- 2.5
-
dispose
public void dispose()
Disposes this visitor.
-
getBypassChildCollectionExpressionVisitor
protected AbstractValidator.BypassChildCollectionExpressionVisitor getBypassChildCollectionExpressionVisitor()
-
getBypassParentSubExpressionVisitor
protected AbstractValidator.BypassParentSubExpressionVisitor getBypassParentSubExpressionVisitor()
-
getChildren
protected java.util.List<Expression> getChildren(Expression expression)
Returns a list containing either the givenExpression
if it's not aCollectionExpression
or the children of the givenCollectionExpression
.- Parameters:
expression
- TheExpression
to visit- Returns:
- A list containing either the given
Expression
or the children ofCollectionExpression
-
getChildrenCollectorVisitor
protected AbstractValidator.ChildrenCollectorVisitor getChildrenCollectorVisitor()
-
getExpressionRegistry
protected ExpressionRegistry 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
-
getExpressionValidator
protected AbstractValidator.JPQLQueryBNFValidator getExpressionValidator(java.lang.String queryBNF)
-
getGrammar
protected abstract JPQLGrammar getGrammar()
Returns theJPQLGrammar
that defines how the JPQL query was parsed.- Returns:
- The
JPQLGrammar
that was used to parse the JPQL query
-
getJPAVersion
protected JPAVersion getJPAVersion()
Returns the version of the Java Persistence this entity for which it was defined.- Returns:
- The version of the Java Persistence being used
-
getJPQLQueryBNFValidator
protected AbstractValidator.JPQLQueryBNFValidator getJPQLQueryBNFValidator(JPQLQueryBNF queryBNF)
Returns theAbstractValidator.JPQLQueryBNFValidator
that can be used to validate anExpression
by making sure its BNF is part of the given BNF.- Parameters:
queryBNF
- The BNF used to determine the validity of anExpression
- Returns:
- A
AbstractValidator.JPQLQueryBNFValidator
that can determine if anExpression
follows the given BNF
-
getJPQLQueryBNFValidator
protected AbstractValidator.JPQLQueryBNFValidator getJPQLQueryBNFValidator(java.lang.String queryBNF)
Returns theAbstractValidator.JPQLQueryBNFValidator
that can be used to validate anExpression
by making sure its BNF is part of the given BNF.- Parameters:
queryBNF
- The BNF used to determine the validity of anExpression
- Returns:
- A
AbstractValidator.JPQLQueryBNFValidator
that can determine if anExpression
follows the given BNF
-
getLiteralVisitor
protected LiteralVisitor getLiteralVisitor()
Returns the visitor that can retrieve some information about various literal.- Returns:
- A
LiteralVisitor
-
getNestedArrayVisitor
protected AbstractValidator.NestedArrayVisitor getNestedArrayVisitor()
Returns the visitor that can determine if anExpression
represents a nested array.- Returns:
- A
AbstractValidator.NestedArrayVisitor
- Since:
- 2.5
-
getOwningClauseVisitor
protected AbstractValidator.OwningClauseVisitor getOwningClauseVisitor()
Returns the visitor that traverses the parent hierarchy of anyExpression
and stops at the firstExpression
that is a clause.
-
getOwningStatementVisitor
protected AbstractValidator.OwningStatementVisitor getOwningStatementVisitor()
Returns the visitor that traverses the parent hierarchy of anyExpression
and stops at the firstExpression
that is a statement.- Returns:
AbstractValidator.OwningStatementVisitor
- Since:
- 2.4
-
getProvider
protected java.lang.String getProvider()
Returns the persistence provider name.- Returns:
- The name of the persistence provider,
null
should never be returned - Since:
- 2.5
-
getProviderVersion
protected java.lang.String getProviderVersion()
Returns the version of the persistence provider.- Returns:
- The version of the persistence provider, if one is extending the default JPQL grammar defined in the Java Persistence specification, otherwise returns an empty string
- Since:
- 2.4
-
getQueryBNF
protected JPQLQueryBNF getQueryBNF(java.lang.String queryBNFId)
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
-
getSubqueryVisitor
protected AbstractValidator.SubqueryVisitor getSubqueryVisitor()
Returns the visitor that checks if the visited expression is a subquery or not.- Returns:
AbstractValidator.SubqueryVisitor
- Since:
- 2.5
-
initialize
protected void initialize()
Initializes this validator.
-
isNestedArray
protected boolean isNestedArray(Expression expression)
Determines whether the givenExpression
represents a nested array or not. To be a nested array, the givenExpression
is aSubExpression
and its child is aCollectionExpression
.- Returns:
true
if the givenExpression
is a nested array;false
otherwise- Since:
- 2.5
-
isSubquery
protected boolean isSubquery(Expression expression)
Determines whether the givenExpression
is a subquery.- Parameters:
expression
- TheExpression
to check its type- Returns:
true
if the givenExpression
is a subquery;false
otherwise- Since:
- 2.5
-
isValid
protected boolean isValid(Expression expression, JPQLQueryBNF queryBNF)
Determines whether the givenExpression
is valid by checking itsJPQLQueryBNF
with the givenJPQLQueryBNF
.- Parameters:
expression
- TheExpression
to validate based on the query BNFqueryBNF
- TheJPQLQueryBNF
that determines if the givenExpression
is valid- Returns:
true
if theExpression
'sJPQLQueryBNF
is either theJPQLQueryBNF
or a child of it;false
otherwise
-
isValid
protected boolean isValid(Expression expression, java.lang.String queryBNFId)
Determines whether the givenExpression
is valid by checking itsJPQLQueryBNF
with theJPQLQueryBNF
associated with the given unique identifier.- Parameters:
expression
- TheExpression
to validate based on the query BNFqueryBNFId
- The unique identifier of theJPQLQueryBNF
that determines if the givenExpression
is valid- Returns:
true
if theExpression
'sJPQLQueryBNF
is either theJPQLQueryBNF
or a child of it;false
otherwise
-
isValid
protected boolean isValid(Expression expression, java.lang.String... queryBNFIds)
Determines whether the givenExpression
is valid by checking itsJPQLQueryBNF
with the list ofJPQLQueryBNF
associated with the given unique identifiers.- Parameters:
expression
- TheExpression
to validate based on the query BNFqueryBNFIds
- The unique identifier of theJPQLQueryBNF
that determines if the givenExpression
is valid- Returns:
true
if theExpression
'sJPQLQueryBNF
is either theJPQLQueryBNF
or a child of it;false
otherwise
-
isValidWithChildCollectionBypass
protected boolean isValidWithChildCollectionBypass(Expression expression, java.lang.String queryBNF)
Determines whether the givenExpression
part is an expression of the given query BNF. TheCollectionExpression
that may be the direct child of the givenExpression
will be bypassed.- Parameters:
expression
- TheExpression
to validate based on the query BNF- Returns:
true
if theExpression
part is a child of the given query BNF;false
otherwise
-
isWithinSubquery
protected boolean isWithinSubquery(Expression expression)
Determines whether the givenExpression
is part of a subquery.- Parameters:
expression
- TheExpression
to start scanning its location- Returns:
true
if the givenExpression
is part of a subquery;false
if it's part of the top-level query- Since:
- 2.4
-
isWithinTopLevelQuery
protected boolean isWithinTopLevelQuery(Expression expression)
Determines whether the givenExpression
is part of the top-level query.- Parameters:
expression
- TheExpression
to start scanning its location- Returns:
true
if the givenExpression
is part of the top-level query;false
if it's part of a subquery- Since:
- 2.4
-
length
protected int length(Expression expression)
Returns the length of the string representation of the givenExpression
.- Parameters:
expression
- TheExpression
to retrieve the length of its string- Returns:
- The length of the string representation of the given
Expression
-
literal
protected java.lang.String literal(Expression expression, LiteralType type)
Retrieves the "literal" from the givenExpression
. The literal to retrieve depends on the giventype
. The literal is basically a string value like an identification variable name, an input parameter, a path expression, an abstract schema name, etc.- Parameters:
expression
- TheExpression
to visittype
- TheLiteralType
helps to determine what to retrieve from the visitedExpression
- Returns:
- A value from the given
Expression
or an empty string if the givenExpression
and theLiteralType
do not match
-
nestedArraySize
protected int nestedArraySize(Expression expression)
Returns the number of items in the nested array if the givenExpression
represents one. To be a nested array, the givenExpression
is aSubExpression
and its child is aCollectionExpression
.- Returns:
- The number of items in the array or -1 if the
Expression
is not a nested array - Since:
- 2.5
-
position
protected int position(Expression expression)
Calculates the position of the given expression by calculating the length of what is before.- Parameters:
expression
- The expression to determine its position within the parsed tree- Returns:
- The length of the string representation of what comes before the given expression
-
problemsSize
public final int problemsSize()
Returns the current number of problems that were registered during validation.- Returns:
- The current number of problems
- Since:
- 2.4
-
setProblems
public void setProblems(java.util.Collection<JPQLQueryProblem> problems)
Sets the collection that will be used to storeproblems
this validator will find in the JPQL query.- Parameters:
problems
- A non-null
collection that will be used to store theproblems
if any was found- Throws:
java.lang.NullPointerException
- The Collection cannot benull
-
visit
protected void visit(Expression expression)
Blindly visit the givenExpression
.- Overrides:
visit
in classAnonymousExpressionVisitor
- Parameters:
expression
- TheExpression
to visit
-
-