public abstract class AbstractValidator extends AnonymousExpressionVisitor
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.
AbstractGrammarValidator
,
AbstractSemanticValidator
Modifier and Type | Class and Description |
---|---|
static class |
AbstractValidator.BypassChildCollectionExpressionVisitor
This visitor is responsible to traverse the children of a
CollectionExpression in
order to properly validate the Expression . |
static class |
AbstractValidator.BypassParentSubExpressionVisitor
This visitor is responsible to traverse the parent hierarchy and to skip
SubExpression
if it's a parent. |
static class |
AbstractValidator.ChildrenCollectorVisitor
This visitor gathers the children of a
CollectionExpression or a single visited
Expression . |
static class |
AbstractValidator.JPQLQueryBNFValidator
This visitor validates any
Expression by checking its BNF against some BNFs. |
protected static class |
AbstractValidator.NestedArrayVisitor |
static class |
AbstractValidator.OwningClauseVisitor
This visitor retrieves the clause owning the visited
Expression . |
protected static class |
AbstractValidator.OwningStatementVisitor
This visitor retrieves the statement owning the visited
Expression . |
protected static class |
AbstractValidator.SubqueryVisitor
This visitor retrieves the statement owning the visited
Expression . |
Modifier | Constructor and Description |
---|---|
protected |
AbstractValidator()
Creates a new
AbstractValidator . |
Modifier and Type | Method and 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 given
Expression . |
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 given
Expression . |
protected void |
addProblem(Expression expression,
java.lang.String messageKey)
Adds a new validation problem that was found in the given
Expression . |
protected void |
addProblem(Expression expression,
java.lang.String messageKey,
java.lang.String... arguments)
Adds a new validation problem that was found in the given
Expression . |
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 an
Expression and determines if it's a nested array
or not. |
protected abstract AbstractValidator.OwningClauseVisitor |
buildOwningClauseVisitor()
Creates the visitor that traverses the parent hierarchy of any
Expression and stops at
the first Expression that is a clause. |
protected AbstractValidator.OwningStatementVisitor |
buildOwningStatementVisitor()
Creates the visitor that traverses the parent hierarchy of any
Expression and stops at
the first Expression 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 given
Expression . |
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 given
Expression if it's not a CollectionExpression or the children of the given CollectionExpression . |
protected AbstractValidator.ChildrenCollectorVisitor |
getChildrenCollectorVisitor() |
protected ExpressionRegistry |
getExpressionRegistry()
Returns the registry containing the
JPQLQueryBNFs and the ExpressionFactories that are used
to properly parse a JPQL query. |
protected AbstractValidator.JPQLQueryBNFValidator |
getExpressionValidator(java.lang.String queryBNF) |
protected abstract JPQLGrammar |
getGrammar()
Returns the
JPQLGrammar 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(JPQLQueryBNF queryBNF)
Returns the
AbstractValidator.JPQLQueryBNFValidator that can be used to validate an Expression
by making sure its BNF is part of the given BNF. |
protected AbstractValidator.JPQLQueryBNFValidator |
getJPQLQueryBNFValidator(java.lang.String queryBNF)
Returns the
AbstractValidator.JPQLQueryBNFValidator that can be used to validate an Expression
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 an
Expression represents a nested array. |
protected AbstractValidator.OwningClauseVisitor |
getOwningClauseVisitor()
Returns the visitor that traverses the parent hierarchy of any
Expression and stops at
the first Expression that is a clause. |
protected AbstractValidator.OwningStatementVisitor |
getOwningStatementVisitor()
Returns the visitor that traverses the parent hierarchy of any
Expression and stops at
the first Expression 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 given
Expression represents a nested array or not. |
protected boolean |
isSubquery(Expression expression)
Determines whether the given
Expression is a subquery. |
protected boolean |
isValid(Expression expression,
JPQLQueryBNF queryBNF)
Determines whether the given
Expression is valid by checking its JPQLQueryBNF
with the given JPQLQueryBNF . |
protected boolean |
isValid(Expression expression,
java.lang.String... queryBNFIds)
Determines whether the given
Expression is valid by checking its JPQLQueryBNF
with the list of JPQLQueryBNF associated with the given unique identifiers. |
protected boolean |
isValid(Expression expression,
java.lang.String queryBNFId)
Determines whether the given
Expression is valid by checking its JPQLQueryBNF
with the JPQLQueryBNF associated with the given unique identifier. |
protected boolean |
isValidWithChildCollectionBypass(Expression expression,
java.lang.String queryBNF)
Determines whether the given
Expression part is an expression of the given query BNF. |
protected boolean |
isWithinSubquery(Expression expression)
Determines whether the given
Expression is part of a subquery. |
protected boolean |
isWithinTopLevelQuery(Expression expression)
Determines whether the given
Expression is part of the top-level query. |
protected int |
length(Expression expression)
Returns the length of the string representation of the given
Expression . |
protected java.lang.String |
literal(Expression expression,
LiteralType type)
Retrieves the "literal" from the given
Expression . |
protected int |
nestedArraySize(Expression expression)
Returns the number of items in the nested array if the given
Expression 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 store
problems this
validator will find in the JPQL query. |
protected void |
visit(Expression expression)
Blindly visit the given
Expression . |
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
protected void addProblem(Expression expression, int startPosition, int endPosition, java.lang.String messageKey, java.lang.String... messageArguments)
Expression
.expression
- The Expression
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 problemprotected void addProblem(Expression expression, int startPosition, java.lang.String messageKey, java.lang.String... messageArguments)
Expression
.expression
- The Expression
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 problemprotected void addProblem(Expression expression, java.lang.String messageKey)
Expression
. The start index
is the position of the given Expression
within the JPQL query and the end index is
the end position of the Expression
within the JPQL query.expression
- The Expression
that is either not following the BNF grammar or that
has semantic problemsmessageKey
- The key used to retrieve the localized message describing the problemprotected void addProblem(Expression expression, java.lang.String messageKey, java.lang.String... arguments)
Expression
. The start index
is the position of the given Expression
within the JPQL query and the end index is
the end position of the Expression
within the JPQL query.expression
- The Expression
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 problemprotected AbstractValidator.ChildrenCollectorVisitor buildChildrenCollector()
protected abstract LiteralVisitor buildLiteralVisitor()
LiteralVisitor
protected AbstractValidator.NestedArrayVisitor buildNestedArrayVisitor()
Expression
and determines if it's a nested array
or not.AbstractValidator.NestedArrayVisitor
protected abstract AbstractValidator.OwningClauseVisitor buildOwningClauseVisitor()
Expression
and stops at
the first Expression
that is a clause.AbstractValidator.OwningClauseVisitor
protected AbstractValidator.OwningStatementVisitor buildOwningStatementVisitor()
Expression
and stops at
the first Expression
that is a statement.AbstractValidator.OwningStatementVisitor
protected JPQLQueryProblem buildProblem(Expression expression, int startPosition, int endPosition, java.lang.String messageKey, java.lang.String... messageArguments)
Expression
.expression
- The Expression
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 problemJPQLQueryProblem
describing a problemprotected AbstractValidator.SubqueryVisitor buildSubqueryVisitor()
AbstractValidator.SubqueryVisitor
public void dispose()
protected AbstractValidator.BypassChildCollectionExpressionVisitor getBypassChildCollectionExpressionVisitor()
protected AbstractValidator.BypassParentSubExpressionVisitor getBypassParentSubExpressionVisitor()
protected java.util.List<Expression> getChildren(Expression expression)
Expression
if it's not a CollectionExpression
or the children of the given CollectionExpression
.expression
- The Expression
to visitExpression
or the children of CollectionExpression
protected AbstractValidator.ChildrenCollectorVisitor getChildrenCollectorVisitor()
protected ExpressionRegistry getExpressionRegistry()
JPQLQueryBNFs
and the ExpressionFactories
that are used
to properly parse a JPQL query.protected AbstractValidator.JPQLQueryBNFValidator getExpressionValidator(java.lang.String queryBNF)
protected abstract JPQLGrammar getGrammar()
JPQLGrammar
that defines how the JPQL query was parsed.JPQLGrammar
that was used to parse the JPQL queryprotected JPAVersion getJPAVersion()
protected AbstractValidator.JPQLQueryBNFValidator getJPQLQueryBNFValidator(JPQLQueryBNF queryBNF)
AbstractValidator.JPQLQueryBNFValidator
that can be used to validate an Expression
by making sure its BNF is part of the given BNF.queryBNF
- The BNF used to determine the validity of an Expression
AbstractValidator.JPQLQueryBNFValidator
that can determine if an Expression
follows
the given BNFprotected AbstractValidator.JPQLQueryBNFValidator getJPQLQueryBNFValidator(java.lang.String queryBNF)
AbstractValidator.JPQLQueryBNFValidator
that can be used to validate an Expression
by making sure its BNF is part of the given BNF.queryBNF
- The BNF used to determine the validity of an Expression
AbstractValidator.JPQLQueryBNFValidator
that can determine if an Expression
follows
the given BNFprotected LiteralVisitor getLiteralVisitor()
LiteralVisitor
protected AbstractValidator.NestedArrayVisitor getNestedArrayVisitor()
Expression
represents a nested array.AbstractValidator.NestedArrayVisitor
protected AbstractValidator.OwningClauseVisitor getOwningClauseVisitor()
Expression
and stops at
the first Expression
that is a clause.protected AbstractValidator.OwningStatementVisitor getOwningStatementVisitor()
Expression
and stops at
the first Expression
that is a statement.AbstractValidator.OwningStatementVisitor
protected java.lang.String getProvider()
null
should never be returnedprotected java.lang.String getProviderVersion()
protected JPQLQueryBNF getQueryBNF(java.lang.String queryBNFId)
queryBNFId
- The unique identifier of the JPQLQueryBNF
to retrieveJPQLQueryBNF
representing a section of the grammarprotected AbstractValidator.SubqueryVisitor getSubqueryVisitor()
AbstractValidator.SubqueryVisitor
protected void initialize()
protected boolean isNestedArray(Expression expression)
Expression
represents a nested array or not. To be a
nested array, the given Expression
is a SubExpression
and its child is a
CollectionExpression
.true
if the given Expression
is a nested array; false
otherwiseprotected boolean isSubquery(Expression expression)
Expression
is a subquery.expression
- The Expression
to check its typetrue
if the given Expression
is a subquery; false
otherwiseprotected boolean isValid(Expression expression, JPQLQueryBNF queryBNF)
Expression
is valid by checking its JPQLQueryBNF
with the given JPQLQueryBNF
.expression
- The Expression
to validate based on the query BNFqueryBNF
- The JPQLQueryBNF
that determines if the given Expression
is validtrue
if the Expression
's JPQLQueryBNF
is either the
JPQLQueryBNF
or a child of it; false
otherwiseprotected boolean isValid(Expression expression, java.lang.String queryBNFId)
Expression
is valid by checking its JPQLQueryBNF
with the JPQLQueryBNF
associated with the given unique identifier.expression
- The Expression
to validate based on the query BNFqueryBNFId
- The unique identifier of the JPQLQueryBNF
that determines if the
given Expression
is validtrue
if the Expression
's JPQLQueryBNF
is either the
JPQLQueryBNF
or a child of it; false
otherwiseprotected boolean isValid(Expression expression, java.lang.String... queryBNFIds)
Expression
is valid by checking its JPQLQueryBNF
with the list of JPQLQueryBNF
associated with the given unique identifiers.expression
- The Expression
to validate based on the query BNFqueryBNFIds
- The unique identifier of the JPQLQueryBNF
that determines if the
given Expression
is validtrue
if the Expression
's JPQLQueryBNF
is either the
JPQLQueryBNF
or a child of it; false
otherwiseprotected boolean isValidWithChildCollectionBypass(Expression expression, java.lang.String queryBNF)
Expression
part is an expression of the given query BNF.
The CollectionExpression
that may be the direct child of the given Expression
will be bypassed.expression
- The Expression
to validate based on the query BNFtrue
if the Expression
part is a child of the given query BNF;
false
otherwiseprotected boolean isWithinSubquery(Expression expression)
Expression
is part of a subquery.expression
- The Expression
to start scanning its locationtrue
if the given Expression
is part of a subquery; false
if it's part of the top-level queryprotected boolean isWithinTopLevelQuery(Expression expression)
Expression
is part of the top-level query.expression
- The Expression
to start scanning its locationtrue
if the given Expression
is part of the top-level query;
false
if it's part of a subqueryprotected int length(Expression expression)
Expression
.expression
- The Expression
to retrieve the length of its stringExpression
protected java.lang.String literal(Expression expression, LiteralType type)
Expression
. The literal to retrieve depends on
the given type
. The literal is basically a string value like an
identification variable name, an input parameter, a path expression, an abstract schema name,
etc.expression
- The Expression
to visittype
- The LiteralType
helps to determine what to retrieve from the visited
Expression
Expression
or an empty string if the given Expression
and the LiteralType
do not matchprotected int nestedArraySize(Expression expression)
Expression
represents one.
To be a nested array, the given Expression
is a SubExpression
and its child is
a CollectionExpression
.Expression
is not a nested arrayprotected int position(Expression expression)
expression
- The expression to determine its position within the parsed treepublic final int problemsSize()
public void setProblems(java.util.Collection<JPQLQueryProblem> problems)
problems
this
validator will find in the JPQL query.problems
- A non-null
collection that will be used to store the problems
if any was foundjava.lang.NullPointerException
- The Collection cannot be null
protected void visit(Expression expression)
Expression
.visit
in class AnonymousExpressionVisitor
expression
- The Expression
to visit