Top Description Inners Fields Constructors Methods
org.eclipse.persistence.jpa.jpql.tools

public Class DefaultSemanticValidator

extends AbstractSemanticValidator
Class Inheritance
Annotations
@SuppressWarnings:nls
Static Imports
org.eclipse.persistence.jpa.jpql.JPQLQueryProblemMessages.AbsExpression_InvalidNumericExpression, .JPQLQueryProblemMessages.AvgFunction_InvalidNumericExpression, .JPQLQueryProblemMessages.BetweenExpression_WrongType, .JPQLQueryProblemMessages.CollectionMemberExpression_Embeddable, .JPQLQueryProblemMessages.ComparisonExpression_WrongComparisonType, .JPQLQueryProblemMessages.ConcatExpression_Expression_WrongType, .JPQLQueryProblemMessages.ConstructorExpression_UndefinedConstructor, .JPQLQueryProblemMessages.ConstructorExpression_UnknownType, .JPQLQueryProblemMessages.CountFunction_DistinctEmbeddable, .JPQLQueryProblemMessages.EncapsulatedIdentificationVariableExpression_NotMapValued, .JPQLQueryProblemMessages.IdentificationVariable_EntityName, .JPQLQueryProblemMessages.LengthExpression_WrongType, .JPQLQueryProblemMessages.LocateExpression_FirstExpression_WrongType, .JPQLQueryProblemMessages.LocateExpression_SecondExpression_WrongType, .JPQLQueryProblemMessages.LocateExpression_ThirdExpression_WrongType, .JPQLQueryProblemMessages.LowerExpression_WrongType, .JPQLQueryProblemMessages.ModExpression_FirstExpression_WrongType, .JPQLQueryProblemMessages.ModExpression_SecondExpression_WrongType, .JPQLQueryProblemMessages.NotExpression_WrongType, .JPQLQueryProblemMessages.NullComparisonExpression_InvalidType, .JPQLQueryProblemMessages.SqrtExpression_WrongType, .JPQLQueryProblemMessages.SubstringExpression_FirstExpression_WrongType, .JPQLQueryProblemMessages.SubstringExpression_SecondExpression_WrongType, .JPQLQueryProblemMessages.SubstringExpression_ThirdExpression_WrongType, .JPQLQueryProblemMessages.SumFunction_WrongType, .JPQLQueryProblemMessages.UpdateItem_NotAssignable, .JPQLQueryProblemMessages.UpdateItem_NotResolvable, .JPQLQueryProblemMessages.UpdateItem_NullNotAssignableToPrimitive, .JPQLQueryProblemMessages.UpperExpression_WrongType

This validator is responsible to gather the problems found in a JPQL query by validating the content to make sure it is semantically valid. The grammar is not validated by this visitor.

For instance, the function AVG accepts a state field path. The property it represents has to be of numeric type. AVG(e.name) is parsable but is not semantically valid because the type of name is a string (the property signature is: "private String name").

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.

Author
Pascal Filion
Since
2.3
Version
2.5
See Also
DefaultGrammarValidator

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
DefaultSemanticValidator.BooleanTypeValidator

This visitor validates expression that is a boolean literal to make sure the type is a Boolean.

protected static class
protected class
DefaultSemanticValidator.NumericTypeValidator

This visitor validates expression that is a numeric literal to make sure the type is an instance of Number.

protected static class
protected class
DefaultSemanticValidator.StringTypeValidator

This visitor validates that the Expression is a string primary and to make sure the type is String.

protected abstract class
DefaultSemanticValidator.TypeValidator

The basic validator for validating the type of an Expression.

protected static class

Field Summary

Modifier and TypeField and Description
protected DefaultSemanticValidator.NullValueVisitor
nullValueVisitor

This validator determines whether the Expression visited represents Expression#NULL.

protected DefaultSemanticValidator.UpdateClauseAbstractSchemaNameFinder
updateClauseAbstractSchemaNameFinder

This finder is responsible to retrieve the abstract schema name from the UPDATE range declaration expression.

protected Map<Class<? extends DefaultSemanticValidator.TypeValidator>, DefaultSemanticValidator.TypeValidator>
Inherited from org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator:
collectionValuedPathExpressionVisitorhelperregisterIdentificationVariablestateFieldPathExpressionVisitorusedIdentificationVariablesvirtualIdentificationVariableFinder

Constructor Summary

AccessConstructor and Description
public
DefaultSemanticValidator(JPQLQueryContext
The context used to query information about the JPQL query
queryContext
)

Creates a new DefaultSemanticValidator.

public
DefaultSemanticValidator(SemanticValidatorHelper
The given helper allows the validator to access the JPA artifacts without using Hermes SPI directly
helper
)

Creates a new DefaultSemanticValidator.

Method Summary

Modifier and TypeMethod and Description
protected boolean
areTypesEquivalent(Object[] typeDeclarations1, Object[] typeDeclarations2)

protected LiteralVisitor
buildLiteralVisitor()

Implements abstract org.eclipse.persistence.jpa.jpql.AbstractValidator.buildLiteralVisitor.

Creates the visitor that can retrieve some information about various literal.
protected AbstractValidator.OwningClauseVisitor
buildOwningClauseVisitor()

Implements abstract org.eclipse.persistence.jpa.jpql.AbstractValidator.buildOwningClauseVisitor.

Creates the visitor that traverses the parent hierarchy of any Expression and stops at the first Expression that is a clause.
protected DefaultSemanticValidator.ResultVariableInOrderByVisitor
protected AbstractSchemaName
protected DefaultSemanticValidator.NullValueVisitor
protected Object
getType(Expression expression)

protected ITypeHelper
protected DefaultSemanticValidator.UpdateClauseAbstractSchemaNameFinder
protected DefaultSemanticValidator.TypeValidator
protected void
protected boolean

Returns:

true if the given Expression passes the checks; false otherwise
isBooleanType
(Expression
The Expression to validate
expression
)

Determines whether the given Expression is of the correct type based on these rules:

protected boolean
protected boolean
isEquivalentBetweenType(Expression expression1, Expression expression2)

protected boolean

Returns:

true if the given Expression passes the checks; false otherwise
isIntegralType
(Expression
The Expression to validate
expression
)

Determines whether the given Expression is of the correct type based on these rules:

  • The Expression's type is an integral type (long or integer).
protected boolean
isNullValue(Expression expression)

protected boolean

Returns:

true if the given Expression passes the checks; false otherwise
isNumericType
(Expression
The Expression to validate
expression
)

Determines whether the given Expression is of the correct type based on these rules:

protected boolean

Returns:

true if the given Expression passes the checks; false otherwise
isStringType
(Expression
The Expression to validate
expression
)

Determines whether the given Expression is of the correct type based on these rules:

protected boolean

Returns:

true if the given Expression passes the checks; false otherwise
isValid
(Expression
The Expression to validate
expression
,
Class<? extends DefaultSemanticValidator.TypeValidator>
The Java class of the TypeValidator that will determine if the given Expression has the right type
validatorClass
)

Determines whether the given Expression is of the correct type by using the TypeValidator.

protected boolean
protected AbstractSemanticValidator.PathType
selectClausePathExpressionPathType()

Implements abstract org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.selectClausePathExpressionPathType.

Returns the type of path expression that is allowed in the SELECT clause.
protected boolean
validateAbsExpression(AbsExpression
The AbsExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateAbsExpression.

Validates the encapsulated expression of the given ABS expression.
protected int
validateArithmeticExpression(ArithmeticExpression
The ArithmeticExpression to validate
expression
,
String
The key used to describe the left expression does not have a valid type
leftExpressionWrongTypeMessageKey
,
String
The key used to describe the right expression does not have a valid type
rightExpressionWrongTypeMessageKey
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateArithmeticExpression.

Validates the type of the left and right expressions defined by the given ArithmeticExpression.
protected boolean
validateAvgFunction(AvgFunction
The AvgFunction to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateAvgFunction.

Validates the encapsulated expression of the given AVG expression.
protected int
protected boolean
validateBooleanType(Expression
The Expression to validate
expression
,
String
The key used to retrieve the localized message describing the problem
messageKey
)

Determines whether the given Expression is of the correct type based on these rules:

protected int
protected boolean
validateComparisonExpression(ComparisonExpression
The ConcatExpression to validate by validating its left and right expressions
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateComparisonExpression.

Validates the left and right expressions of the given ComparisonExpression.
protected boolean
validateConcatExpression(ConcatExpression
The ConcatExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateConcatExpression.

Validates the encapsulated expression of the given CONCAT expression.
protected void
protected void
protected void
protected boolean
validateIdentificationVariable(IdentificationVariable
The IdentificationVariable that is being visited
expression
,
String
The actual identification variable, which is never an empty string
variable
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateIdentificationVariable.

Validates the given identification variable.
protected boolean

Returns:

false if the given expression was validated and is invalid; true otherwise
validateIntegralType
(Expression
The Expression to validate
expression
,
String
The unique identifier of the query BNF used to validate the type
queryBNF
,
String
The key used to retrieve the localized message describing the problem
messageKey
)

Determines whether the given Expression is of the correct type based on these rules:

  • The Expression returns a integral value;
  • The Expression's type is an integral type (long or integer).
protected void
protected boolean
validateLengthExpression(LengthExpression
The LengthExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateLengthExpression.

Validates the encapsulated expression of the given LENGTH expression.
protected int
validateLocateExpression(LocateExpression
The LocateExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateLocateExpression.

Validates the encapsulated expression of the given LOCATE expression.
protected boolean
validateLowerExpression(LowerExpression
The LowerExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateLowerExpression.

Validates the encapsulated expression of the given LOWER expression.
protected void
protected int
validateModExpression(ModExpression
The ModExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateModExpression.

Validates the encapsulated expression of the given MOD expression.
protected void
protected void
protected boolean

Returns:

false if the given expression was validated and is invalid; true otherwise
validateNumericType
(Expression
The Expression to validate
expression
,
String
The key used to retrieve the localized message describing the problem
messageKey
)

Determines whether the given Expression is of the correct type based on these rules:

protected boolean
validateSqrtExpression(SqrtExpression
The SqrtExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateSqrtExpression.

Validates the encapsulated expression of the given SQRT expression.
protected boolean

Returns:

false if the given expression was validated and is invalid; true otherwise
validateStringType
(Expression
The Expression to validate
expression
,
String
The key used to retrieve the localized message describing the problem
messageKey
)

Determines whether the given Expression is of the correct type based on these rules:

protected int
validateSubstringExpression(SubstringExpression
The SubstringExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateSubstringExpression.

Validates the encapsulated expression of the given SUBSTRING expression.
protected boolean
validateSumFunction(SumFunction
The ModExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateSumFunction.

Validates the encapsulated expression of the given MOD expression.
protected boolean
validateUpdateItem(UpdateItem
UpdateItem to validate its path expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateUpdateItem.

Validates the given UpdateItem by validating the traversability of the path expression.
protected void
protected boolean
validateUpperExpression(UpperExpression
The UpperExpression to validate by validating its encapsulated expression
expression
)

Overrides org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator.validateUpperExpression.

Validates the encapsulated expression of the given UPPER expression.
protected void
Inherited from org.eclipse.persistence.jpa.jpql.AbstractSemanticValidator:
buildComparingEntityTypeLiteralVisitorbuildInItemsVisitorbuildSubqueryFirstDeclarationVisitorbuildTopLevelFirstDeclarationVisitordisposefindVirtualIdentificationVariablegetCollectionValuedPathExpressiongetCollectionValuedPathExpressionVisitorgetComparingEntityTypeLiteralVisitorgetComparisonExpressionVisitorgetGrammargetInItemsVisitorgetStateFieldPathExpressiongetStateFieldPathExpressionVisitorgetVirtualIdentificationVariableFinderisComparingEntityTypeLiteralisIdentificationVariableDeclaredAfterisIdentificationVariableValidInComparisonisOrderComparisonisValidsubqueryFirstDeclarationVisitortopLevelFirstDeclarationVisitorupdateStatusvalidateAbstractFromClausevalidateAbstractSchemaNamevalidateAdditionExpressionvalidateAllOrAnyExpressionvalidateAndExpressionvalidateArithmeticExpressionvalidateCaseExpressionvalidateCoalesceExpressionvalidateCollectionMemberDeclarationvalidateCollectionValuedPathExpressionvalidateDateTimevalidateDeleteClausevalidateDeleteStatementvalidateDivisionExpressionvalidateEntityTypeLiteralvalidateExistsExpressionvalidateFirstDeclarationvalidateFromClausevalidateFunctionExpressionvalidateFunctionPathExpressionvalidateFunctionPathExpressionvalidateGroupByClausevalidateHavingClausevalidateIdentificationVariablevalidateIdentificationVariableDeclarationvalidateIdentificationVariablesvalidateIndexExpressionvalidateInExpressionvalidateJoinvalidateJoinCollectionValuedPathExpressionvalidateJoinsIdentificationVariablevalidateLikeExpressionvalidateMaxFunctionvalidateMinFunctionvalidateMultiplicationExpressionvalidateNullIfExpressionvalidateObjectExpressionvalidateOnClausevalidateOrderByClausevalidateOrderByItemvalidateOrExpressionvalidateRangeVariableDeclarationvalidateRangeVariableDeclarationRootObjectvalidateResultVariablevalidateSelectClausevalidateSelectStatementvalidateSimpleFromClausevalidateSimpleSelectClausevalidateSimpleSelectStatementvalidateSizeExpressionvalidateStateFieldPathExpressionvalidateSubtractionExpressionvalidateThirdPartyStateFieldPathExpressionvalidateTreatExpressionvalidateTrimExpressionvalidateTypeExpressionvalidateUpdateClausevalidateUpdateStatementvalidateWhenClausevalidateWhereClausevalidPathExpressionTypeForCountFunctionvalidPathExpressionTypeForInExpressionvalidPathExpressionTypeForInItemvalidPathExpressionTypeForStringExpressionvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisit