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
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:
- Author:
- Pascal Filion
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis visitor is responsible to traverse the children of aCollectionExpressionin order to properly validate theExpression.static classThis visitor is responsible to traverse the parent hierarchy and to skipSubExpressionif it's a parent.static classThis visitor gathers the children of aCollectionExpressionor a single visitedExpression.static classThis visitor validates anyExpressionby checking its BNF against some BNFs.protected static classstatic classThis visitor retrieves the clause owning the visitedExpression.protected static classThis visitor retrieves the statement owning the visitedExpression.protected static classThis visitor retrieves the statement owning the visitedExpression. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddProblem(Expression expression, int startPosition, int endPosition, String messageKey, String... messageArguments) Adds a new validation problem that was found in the givenExpression.protected voidaddProblem(Expression expression, int startPosition, String messageKey, String... messageArguments) Adds a new validation problem that was found in the givenExpression.protected voidaddProblem(Expression expression, String messageKey) Adds a new validation problem that was found in the givenExpression.protected voidaddProblem(Expression expression, String messageKey, String... arguments) Adds a new validation problem that was found in the givenExpression.protected abstract LiteralVisitorCreates the visitor that can retrieve some information about various literal.protected AbstractValidator.NestedArrayVisitorCreates the visitor that traverses anExpressionand determines if it's a nested array or not.protected abstract AbstractValidator.OwningClauseVisitorCreates the visitor that traverses the parent hierarchy of anyExpressionand stops at the firstExpressionthat is a clause.protected AbstractValidator.OwningStatementVisitorCreates the visitor that traverses the parent hierarchy of anyExpressionand stops at the firstExpressionthat is a statement.protected JPQLQueryProblembuildProblem(Expression expression, int startPosition, int endPosition, String messageKey, String... messageArguments) Creates a new validation problem that was found in the givenExpression.protected AbstractValidator.SubqueryVisitorCreates the visitor that checks if the visited expression is a subquery or not..voiddispose()Disposes this visitor.protected List<Expression>getChildren(Expression expression) Returns a list containing either the givenExpressionif it's not aCollectionExpressionor the children of the givenCollectionExpression.protected ExpressionRegistryReturns the registry containing theJPQLQueryBNFsand theExpressionFactoriesthat are used to properly parse a JPQL query.protected AbstractValidator.JPQLQueryBNFValidatorgetExpressionValidator(String queryBNF) protected abstract JPQLGrammarReturns theJPQLGrammarthat defines how the JPQL query was parsed.protected JPAVersionReturns the version of the Java Persistence this entity for which it was defined.protected AbstractValidator.JPQLQueryBNFValidatorgetJPQLQueryBNFValidator(String queryBNF) Returns theAbstractValidator.JPQLQueryBNFValidatorthat can be used to validate anExpressionby making sure its BNF is part of the given BNF.protected AbstractValidator.JPQLQueryBNFValidatorgetJPQLQueryBNFValidator(JPQLQueryBNF queryBNF) Returns theAbstractValidator.JPQLQueryBNFValidatorthat can be used to validate anExpressionby making sure its BNF is part of the given BNF.protected LiteralVisitorReturns the visitor that can retrieve some information about various literal.protected AbstractValidator.NestedArrayVisitorReturns the visitor that can determine if anExpressionrepresents a nested array.protected AbstractValidator.OwningClauseVisitorReturns the visitor that traverses the parent hierarchy of anyExpressionand stops at the firstExpressionthat is a clause.protected AbstractValidator.OwningStatementVisitorReturns the visitor that traverses the parent hierarchy of anyExpressionand stops at the firstExpressionthat is a statement.protected StringReturns the persistence provider name.protected StringReturns the version of the persistence provider.protected JPQLQueryBNFgetQueryBNF(String queryBNFId) Retrieves the BNF object that was registered for the given unique identifier.protected AbstractValidator.SubqueryVisitorReturns the visitor that checks if the visited expression is a subquery or not.protected voidInitializes this validator.protected booleanisNestedArray(Expression expression) Determines whether the givenExpressionrepresents a nested array or not.protected booleanisSubquery(Expression expression) Determines whether the givenExpressionis a subquery.protected booleanisValid(Expression expression, String queryBNFId) Determines whether the givenExpressionis valid by checking itsJPQLQueryBNFwith theJPQLQueryBNFassociated with the given unique identifier.protected booleanisValid(Expression expression, String... queryBNFIds) Determines whether the givenExpressionis valid by checking itsJPQLQueryBNFwith the list ofJPQLQueryBNFassociated with the given unique identifiers.protected booleanisValid(Expression expression, JPQLQueryBNF queryBNF) Determines whether the givenExpressionis valid by checking itsJPQLQueryBNFwith the givenJPQLQueryBNF.protected booleanisValidWithChildCollectionBypass(Expression expression, String queryBNF) Determines whether the givenExpressionpart is an expression of the given query BNF.protected booleanisWithinSubquery(Expression expression) Determines whether the givenExpressionis part of a subquery.protected booleanisWithinTopLevelQuery(Expression expression) Determines whether the givenExpressionis part of the top-level query.protected intlength(Expression expression) Returns the length of the string representation of the givenExpression.protected Stringliteral(Expression expression, LiteralType type) Retrieves the "literal" from the givenExpression.protected intnestedArraySize(Expression expression) Returns the number of items in the nested array if the givenExpressionrepresents one.protected intposition(Expression expression) Calculates the position of the given expression by calculating the length of what is before.final intReturns the current number of problems that were registered during validation.voidsetProblems(Collection<JPQLQueryProblem> problems) Sets the collection that will be used to storeproblemsthis validator will find in the JPQL query.protected voidvisit(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
-
Constructor Details
-
AbstractValidator
protected AbstractValidator()Creates a newAbstractValidator.
-
-
Method Details
-
addProblem
protected void addProblem(Expression expression, int startPosition, int endPosition, String messageKey, String... messageArguments) Adds a new validation problem that was found in the givenExpression.- Parameters:
expression- TheExpressionthat 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, String messageKey, String... messageArguments) Adds a new validation problem that was found in the givenExpression.- Parameters:
expression- TheExpressionthat 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
Adds a new validation problem that was found in the givenExpression. The start index is the position of the givenExpressionwithin the JPQL query and the end index is the end position of theExpressionwithin the JPQL query.- Parameters:
expression- TheExpressionthat is either not following the BNF grammar or that has semantic problemsmessageKey- The key used to retrieve the localized message describing the problem
-
addProblem
Adds a new validation problem that was found in the givenExpression. The start index is the position of the givenExpressionwithin the JPQL query and the end index is the end position of theExpressionwithin the JPQL query.- Parameters:
expression- TheExpressionthat 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
-
buildLiteralVisitor
Creates the visitor that can retrieve some information about various literal.- Returns:
- A new
LiteralVisitor
-
buildNestedArrayVisitor
Creates the visitor that traverses anExpressionand determines if it's a nested array or not.- Returns:
- A new
AbstractValidator.NestedArrayVisitor
-
buildOwningClauseVisitor
Creates the visitor that traverses the parent hierarchy of anyExpressionand stops at the firstExpressionthat is a clause.- Returns:
- A new
AbstractValidator.OwningClauseVisitor
-
buildOwningStatementVisitor
Creates the visitor that traverses the parent hierarchy of anyExpressionand stops at the firstExpressionthat is a statement.- Returns:
- A new
AbstractValidator.OwningStatementVisitor
-
buildProblem
protected JPQLQueryProblem buildProblem(Expression expression, int startPosition, int endPosition, String messageKey, String... messageArguments) Creates a new validation problem that was found in the givenExpression.- Parameters:
expression- TheExpressionthat 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
JPQLQueryProblemdescribing a problem
-
buildSubqueryVisitor
Creates the visitor that checks if the visited expression is a subquery or not..- Returns:
- A new
AbstractValidator.SubqueryVisitor
-
dispose
public void dispose()Disposes this visitor. -
getBypassChildCollectionExpressionVisitor
protected AbstractValidator.BypassChildCollectionExpressionVisitor getBypassChildCollectionExpressionVisitor() -
getBypassParentSubExpressionVisitor
-
getChildren
Returns a list containing either the givenExpressionif it's not aCollectionExpressionor the children of the givenCollectionExpression.- Parameters:
expression- TheExpressionto visit- Returns:
- A list containing either the given
Expressionor the children ofCollectionExpression
-
getChildrenCollectorVisitor
-
getExpressionRegistry
Returns the registry containing theJPQLQueryBNFsand theExpressionFactoriesthat are used to properly parse a JPQL query.- Returns:
- The registry containing the information related to the JPQL grammar
-
getExpressionValidator
-
getGrammar
Returns theJPQLGrammarthat defines how the JPQL query was parsed.- Returns:
- The
JPQLGrammarthat was used to parse the JPQL query
-
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
Returns theAbstractValidator.JPQLQueryBNFValidatorthat can be used to validate anExpressionby making sure its BNF is part of the given BNF.- Parameters:
queryBNF- The BNF used to determine the validity of anExpression- Returns:
- A
AbstractValidator.JPQLQueryBNFValidatorthat can determine if anExpressionfollows the given BNF
-
getJPQLQueryBNFValidator
Returns theAbstractValidator.JPQLQueryBNFValidatorthat can be used to validate anExpressionby making sure its BNF is part of the given BNF.- Parameters:
queryBNF- The BNF used to determine the validity of anExpression- Returns:
- A
AbstractValidator.JPQLQueryBNFValidatorthat can determine if anExpressionfollows the given BNF
-
getLiteralVisitor
Returns the visitor that can retrieve some information about various literal.- Returns:
- A
LiteralVisitor
-
getNestedArrayVisitor
Returns the visitor that can determine if anExpressionrepresents a nested array.- Returns:
- A
AbstractValidator.NestedArrayVisitor
-
getOwningClauseVisitor
Returns the visitor that traverses the parent hierarchy of anyExpressionand stops at the firstExpressionthat is a clause. -
getOwningStatementVisitor
Returns the visitor that traverses the parent hierarchy of anyExpressionand stops at the firstExpressionthat is a statement. -
getProvider
Returns the persistence provider name.- Returns:
- The name of the persistence provider,
nullshould never be returned
-
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
-
getQueryBNF
Retrieves the BNF object that was registered for the given unique identifier.- Parameters:
queryBNFId- The unique identifier of theJPQLQueryBNFto retrieve- Returns:
- The
JPQLQueryBNFrepresenting a section of the grammar
-
getSubqueryVisitor
Returns the visitor that checks if the visited expression is a subquery or not.- Returns:
AbstractValidator.SubqueryVisitor
-
initialize
protected void initialize()Initializes this validator. -
isNestedArray
Determines whether the givenExpressionrepresents a nested array or not. To be a nested array, the givenExpressionis aSubExpressionand its child is aCollectionExpression.- Parameters:
expression- TheExpressionto check its size- Returns:
trueif the givenExpressionis a nested array;falseotherwise
-
isSubquery
Determines whether the givenExpressionis a subquery.- Parameters:
expression- TheExpressionto check its type- Returns:
trueif the givenExpressionis a subquery;falseotherwise
-
isValid
Determines whether the givenExpressionis valid by checking itsJPQLQueryBNFwith the givenJPQLQueryBNF.- Parameters:
expression- TheExpressionto validate based on the query BNFqueryBNF- TheJPQLQueryBNFthat determines if the givenExpressionis valid- Returns:
trueif theExpression'sJPQLQueryBNFis either theJPQLQueryBNFor a child of it;falseotherwise
-
isValid
Determines whether the givenExpressionis valid by checking itsJPQLQueryBNFwith theJPQLQueryBNFassociated with the given unique identifier.- Parameters:
expression- TheExpressionto validate based on the query BNFqueryBNFId- The unique identifier of theJPQLQueryBNFthat determines if the givenExpressionis valid- Returns:
trueif theExpression'sJPQLQueryBNFis either theJPQLQueryBNFor a child of it;falseotherwise
-
isValid
Determines whether the givenExpressionis valid by checking itsJPQLQueryBNFwith the list ofJPQLQueryBNFassociated with the given unique identifiers.- Parameters:
expression- TheExpressionto validate based on the query BNFqueryBNFIds- The unique identifier of theJPQLQueryBNFthat determines if the givenExpressionis valid- Returns:
trueif theExpression'sJPQLQueryBNFis either theJPQLQueryBNFor a child of it;falseotherwise
-
isValidWithChildCollectionBypass
Determines whether the givenExpressionpart is an expression of the given query BNF. TheCollectionExpressionthat may be the direct child of the givenExpressionwill be bypassed.- Parameters:
expression- TheExpressionto validate based on the query BNFqueryBNF- The unique identifier of theJPQLQueryBNFthat looks up theAbstractValidator.JPQLQueryBNFValidator- Returns:
trueif theExpressionpart is a child of the given query BNF;falseotherwise
-
isWithinSubquery
Determines whether the givenExpressionis part of a subquery.- Parameters:
expression- TheExpressionto start scanning its location- Returns:
trueif the givenExpressionis part of a subquery;falseif it's part of the top-level query
-
isWithinTopLevelQuery
Determines whether the givenExpressionis part of the top-level query.- Parameters:
expression- TheExpressionto start scanning its location- Returns:
trueif the givenExpressionis part of the top-level query;falseif it's part of a subquery
-
length
Returns the length of the string representation of the givenExpression.- Parameters:
expression- TheExpressionto retrieve the length of its string- Returns:
- The length of the string representation of the given
Expression
-
literal
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- TheExpressionto visittype- TheLiteralTypehelps to determine what to retrieve from the visitedExpression- Returns:
- A value from the given
Expressionor an empty string if the givenExpressionand theLiteralTypedo not match
-
nestedArraySize
Returns the number of items in the nested array if the givenExpressionrepresents one. To be a nested array, the givenExpressionis aSubExpressionand its child is aCollectionExpression.- Parameters:
expression- TheExpressionto visit- Returns:
- The number of items in the array or -1 if the
Expressionis not a nested array
-
position
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
-
setProblems
Sets the collection that will be used to storeproblemsthis validator will find in the JPQL query.- Parameters:
problems- A non-nullcollection that will be used to store theproblemsif any was found- Throws:
NullPointerException- The Collection cannot benull
-
visit
Description copied from class:AnonymousExpressionVisitorBlindly visit the givenExpression.- Overrides:
visitin classAnonymousExpressionVisitor- Parameters:
expression- TheExpressionto visit
-