EclipseLink 2.4.2, build 'v20130514-5956486' API Reference

org.eclipse.persistence.jpa.jpql
Class AbstractValidator

java.lang.Object
  extended by org.eclipse.persistence.jpa.jpql.parser.AnonymousExpressionVisitor
      extended by 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.4
See Also:
AbstractGrammarValidator, AbstractSemanticValidator
Author:
Pascal Filion
Since:
2.4

Nested Class Summary
protected static class AbstractValidator.BypassChildCollectionExpressionVisitor
          This visitor is responsible to traverse the children of a CollectionExpression in order to properly validate the Expression.
protected static class AbstractValidator.BypassParentSubExpressionVisitor
          This visitor is responsible to traverse the parent hierarchy and to skip SubExpression if it's a parent.
protected 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.
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.
 
Constructor Summary
protected AbstractValidator()
          Creates a new AbstractValidator.
 
Method Summary
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 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.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 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 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 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.
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractValidator

protected AbstractValidator()
Creates a new AbstractValidator.

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 given Expression.

Parameters:
expression - The Expression that is either not following the BNF grammar or that has semantic problems
startPosition - The position where the problem was encountered
endPosition - The position where the problem ends, inclusively
messageKey - The key used to retrieve the localized message describing the problem
messageArguments - 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 given Expression.

Parameters:
expression - The Expression that is either not following the BNF grammar or that has semantic problems
startPosition - The position where the problem was encountered
messageKey - The key used to retrieve the localized message describing the problem
messageArguments - 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 given 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.

Parameters:
expression - The Expression that is either not following the BNF grammar or that has semantic problems
messageKey - 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 given 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.

Parameters:
expression - The Expression that is either not following the BNF grammar or that has semantic problems
messageKey - The key used to retrieve the localized message describing the problem
arguments - 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

buildOwningClauseVisitor

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.

Returns:
A new AbstractValidator.OwningClauseVisitor

buildOwningStatementVisitor

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.

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 given Expression.

Parameters:
expression - The Expression that is either not following the BNF grammar or that has semantic problems
startPosition - The position where the problem was encountered
endPosition - The position where the problem ends, inclusively
messageKey - The key used to retrieve the localized message describing the problem
messageArguments - 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 given Expression if it's not a CollectionExpression or the children of the given CollectionExpression.

Parameters:
expression - The Expression to visit
Returns:
A list containing either the given Expression or the children of CollectionExpression

getChildrenCollectorVisitor

protected AbstractValidator.ChildrenCollectorVisitor getChildrenCollectorVisitor()

getExpressionRegistry

protected ExpressionRegistry getExpressionRegistry()
Returns the registry containing the JPQLQueryBNFs and the ExpressionFactories 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 the JPQLGrammar 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 the AbstractValidator.JPQLQueryBNFValidator that can be used to validate an Expression by making sure its BNF is part of the given BNF.

Parameters:
queryBNF - The BNF used to determine the validity of an Expression
Returns:
A AbstractValidator.JPQLQueryBNFValidator that can determine if an Expression follows the given BNF

getJPQLQueryBNFValidator

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.

Parameters:
queryBNF - The BNF used to determine the validity of an Expression
Returns:
A AbstractValidator.JPQLQueryBNFValidator that can determine if an Expression follows the given BNF

getLiteralVisitor

protected LiteralVisitor getLiteralVisitor()
Returns the visitor that can retrieve some information about various literal.

Returns:
A LiteralVisitor

getOwningClauseVisitor

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.

Returns:
AbstractValidator.OwningClauseVisitor

getOwningStatementVisitor

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.

Returns:
AbstractValidator.OwningStatementVisitor
Since:
2.4

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 the JPQLQueryBNF 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.


isSubquery

protected boolean isSubquery(Expression expression)
Determines whether the given Expression is a subquery.

Parameters:
expression - The Expression to check its type
Returns:
true if the given Expression is a subquery; false otherwise
Since:
2.4.2

isValid

protected boolean isValid(Expression expression,
                          JPQLQueryBNF queryBNF)
Determines whether the given Expression is valid by checking its JPQLQueryBNF with the given JPQLQueryBNF.

Parameters:
expression - The Expression to validate based on the query BNF
queryBNF - The JPQLQueryBNF that determines if the given Expression is valid
Returns:
true if the Expression's JPQLQueryBNF is either the JPQLQueryBNF or a child of it; false otherwise

isValid

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.

Parameters:
expression - The Expression to validate based on the query BNF
queryBNFId - The unique identifier of the JPQLQueryBNF that determines if the given Expression is valid
Returns:
true if the Expression's JPQLQueryBNF is either the JPQLQueryBNF or a child of it; false otherwise

isValid

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.

Parameters:
expression - The Expression to validate based on the query BNF
queryBNFId - The unique identifier of the JPQLQueryBNF that determines if the given Expression is valid
Returns:
true if the Expression's JPQLQueryBNF is either the JPQLQueryBNF or a child of it; false otherwise

isValidWithChildCollectionBypass

protected boolean isValidWithChildCollectionBypass(Expression expression,
                                                   java.lang.String queryBNF)
Determines whether the given 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.

Parameters:
expression - The Expression to validate based on the query BNF
Returns:
true if the Expression part is a child of the given query BNF; false otherwise

isWithinSubquery

protected boolean isWithinSubquery(Expression expression)
Determines whether the given Expression is part of a subquery.

Parameters:
expression - The Expression to start scanning its location
Returns:
true if the given Expression 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 given Expression is part of the top-level query.

Parameters:
expression - The Expression to start scanning its location
Returns:
true if the given Expression 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 given Expression.

Parameters:
expression - The Expression 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 given 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.

Parameters:
expression - The Expression to visit
type - The LiteralType helps to determine what to retrieve from the visited Expression
Returns:
A value from the given Expression or an empty string if the given Expression and the LiteralType do not match

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 store problems this validator will find in the JPQL query.

Parameters:
problems - A non-null collection that will be used to store the problems if any was found
Throws:
java.lang.NullPointerException - The Collection cannot be null

visit

protected void visit(Expression expression)
Blindly visit the given Expression.

Overrides:
visit in class AnonymousExpressionVisitor
Parameters:
expression - The Expression to visit

EclipseLink 2.4.2, build 'v20130514-5956486' API Reference