Class GenericSemanticValidatorHelper
- java.lang.Object
-
- org.eclipse.persistence.jpa.jpql.tools.GenericSemanticValidatorHelper
-
- All Implemented Interfaces:
SemanticValidatorHelper
public class GenericSemanticValidatorHelper extends java.lang.Object implements SemanticValidatorHelper
An implementation ofSemanticValidatorHelperthat usesJPQLQueryContextto return the required information and Hermes SPI.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
- Author:
- Pascal Filion
- Since:
- 2.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classGenericSemanticValidatorHelper.IdentificationVariableVisitor
-
Constructor Summary
Constructors Constructor Description GenericSemanticValidatorHelper(JPQLQueryContext queryContext)Creates a newGenericSemanticValidatorHelper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddIdentificationVariable(IdentificationVariable identificationVariable, java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)protected GenericSemanticValidatorHelper.IdentificationVariableVisitorbuildIdentificationVariableVisitor()voidcollectAllDeclarationIdentificationVariables(java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)Collects the identification variables that are defined in theFROMclause of the current query and from the parent queries.voidcollectLocalDeclarationIdentificationVariables(java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)Collects the identification variables that are defined in theFROMclause of the current query.protected voidcollectLocalDeclarationIdentificationVariables(JPQLQueryContext queryContext, java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)voiddisposeSubqueryContext()Disposes this context, which is the current context being used by a subquery.java.lang.String[]entityNames()Returns the name of the all entities that are present in the context of a persistence unit.java.util.List<JPQLQueryDeclaration>getAllDeclarations()Returns the ordered list ofJPQLQueryDeclaration, which contain the information contained in the query'sFROMclause.IConstructor[]getConstructors(java.lang.Object type)Returns the constructors for the given type.java.util.ListgetDeclarations()Returns the ordered list ofJPQLQueryDeclaration, which contain the information contained in the query'sFROMclause.IManagedTypegetEmbeddable(java.lang.Object type)Retrieves the embeddable with the given type.IEntitygetEntityNamed(java.lang.String entityName)Retrieves the entity with the given entity name.java.lang.String[]getEnumConstants(java.lang.Object type)Returns the constant names for the givenEnumtype.JPQLGrammargetGrammar()Returns theJPQLGrammarthat defines how the JPQL query was parsed.protected IdentificationVariablegetIdentificationVariable(Expression expression)protected GenericSemanticValidatorHelper.IdentificationVariableVisitorgetIdentificationVariableVisitor()IManagedTypegetManagedType(Expression expression)Returns the managed type by resolving the givenExpression.IMappinggetMappingNamed(java.lang.Object managedType, java.lang.String path)Returns the mapping with the given name.ITypegetMappingType(java.lang.Object mapping)Returns the type of the given mapping object.ITypeDeclaration[]getMethodParameterTypeDeclarations(java.lang.Object constructor)Returns the list of type declarations representing the given constructor's parameter types.JPQLQueryContextgetQueryContext()Returns the context used to query information about the JPQL query.IManagedTypegetReferenceManagedType(java.lang.Object relationshipMapping)Returns the reference managed type from the given relationship mapping.ITypegetType(java.lang.Object typeDeclaration)Returns the type defined for the Java member.ITypegetType(java.lang.String typeName)Retrieves the class with the given fully qualified name.ITypegetType(Expression expression)Returns the type by resolving the givenExpression.ITypeDeclarationgetTypeDeclaration(Expression expression)Returns the type declaration for the givenExpression's type.ITypeHelpergetTypeHelper()Returns the helper that gives access to the most common class metadata.java.lang.StringgetTypeName(java.lang.Object type)Returns the fully qualified class name of the given type.booleanisAssignableTo(java.lang.Object type1, java.lang.Object type2)Determines whether type 1 is an instance of type 2.booleanisCollectionIdentificationVariable(java.lang.String variableName)Determines whether the given identification variable is defining a join or a collection member declaration expressions.booleanisCollectionMapping(java.lang.Object mapping)Determines whether the given mapping is a collection type mapping.booleanisEmbeddableMapping(java.lang.Object mapping)Determines whether the given mapping is an embeddable type mapping.booleanisEnumType(java.lang.Object type)Determines whether the given type represents anEnum.booleanisIdentificationVariableValidInComparison(IdentificationVariable expression)Determines whether an identification variable can be used in a comparison expression when the operator is either '<', '<=', '>', '>='.booleanisManagedTypeResolvable(java.lang.Object managedType)Determines whether the given managed type actually exists.booleanisPropertyMapping(java.lang.Object mapping)Determines whether the given mapping is a property type mapping.booleanisRelationshipMapping(java.lang.Object mapping)Determines whether the given mapping is a relationship type mapping.booleanisResultVariable(java.lang.String variableName)Determines if the given variable is a result variable.booleanisTransient(java.lang.Object mapping)Determines whether the given mapping is a transient attribute.booleanisTypeDeclarationAssignableTo(java.lang.Object typeDeclaration1, java.lang.Object typeDeclaration2)Determines whether type declaration 1 is an instance of type declaration 2.booleanisTypeResolvable(java.lang.Object type)Determines whether the given type actually exists.voidnewSubqueryContext(SimpleSelectStatement expression)Changes the state of this helper to use the given subquery.IMappingresolveMapping(java.lang.String variableName, java.lang.String name)Returns the mapping that should be a persistence field from the entity defined by the given identification variable.IMappingresolveMapping(Expression expression)Returns the mapping for the field represented by the givenExpression.
-
-
-
Constructor Detail
-
GenericSemanticValidatorHelper
public GenericSemanticValidatorHelper(JPQLQueryContext queryContext)
Creates a newGenericSemanticValidatorHelper.- Parameters:
queryContext- The context used to query information about the JPQL query- Throws:
java.lang.NullPointerException- The givenJPQLQueryContextcannot benull
-
-
Method Detail
-
addIdentificationVariable
protected void addIdentificationVariable(IdentificationVariable identificationVariable, java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)
-
buildIdentificationVariableVisitor
protected GenericSemanticValidatorHelper.IdentificationVariableVisitor buildIdentificationVariableVisitor()
-
collectAllDeclarationIdentificationVariables
public void collectAllDeclarationIdentificationVariables(java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)
Collects the identification variables that are defined in theFROMclause of the current query and from the parent queries.- Specified by:
collectAllDeclarationIdentificationVariablesin interfaceSemanticValidatorHelper- Parameters:
identificationVariables- TheMapused to store the variables
-
collectLocalDeclarationIdentificationVariables
protected void collectLocalDeclarationIdentificationVariables(JPQLQueryContext queryContext, java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)
-
collectLocalDeclarationIdentificationVariables
public void collectLocalDeclarationIdentificationVariables(java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)
Collects the identification variables that are defined in theFROMclause of the current query.- Specified by:
collectLocalDeclarationIdentificationVariablesin interfaceSemanticValidatorHelper- Parameters:
identificationVariables- TheMapused to store the variables
-
disposeSubqueryContext
public void disposeSubqueryContext()
Disposes this context, which is the current context being used by a subquery. Once it is disposed, any information retrieved will be for the subquery's parent query.- Specified by:
disposeSubqueryContextin interfaceSemanticValidatorHelper
-
entityNames
public java.lang.String[] entityNames()
Returns the name of the all entities that are present in the context of a persistence unit.- Specified by:
entityNamesin interfaceSemanticValidatorHelper- Returns:
- The list of entity names
-
getAllDeclarations
public java.util.List<JPQLQueryDeclaration> getAllDeclarations()
Returns the ordered list ofJPQLQueryDeclaration, which contain the information contained in the query'sFROMclause.- Specified by:
getAllDeclarationsin interfaceSemanticValidatorHelper- Returns:
- The list of
JPQLQueryDeclarationof the current query that was parsed and from the parent queries
-
getConstructors
public IConstructor[] getConstructors(java.lang.Object type)
Returns the constructors for the given type. All public, protected, default (package) access, and private constructors should be included.If it was going through Hermes SPI, the type of the argument would be
ITypeand the return type would beIConstructor.- Specified by:
getConstructorsin interfaceSemanticValidatorHelper- Returns:
- The declared constructors
-
getDeclarations
public java.util.List getDeclarations()
Returns the ordered list ofJPQLQueryDeclaration, which contain the information contained in the query'sFROMclause.- Specified by:
getDeclarationsin interfaceSemanticValidatorHelper- Returns:
- The list of
JPQLQueryDeclarationof the current query that was parsed
-
getEmbeddable
public IManagedType getEmbeddable(java.lang.Object type)
Retrieves the embeddable with the given type.- Specified by:
getEmbeddablein interfaceSemanticValidatorHelper- Parameters:
type- The Java type of the embeddable to retrieve- Returns:
- The embeddable for the given type if it's representing an embeddable;
nullotherwise
-
getEntityNamed
public IEntity getEntityNamed(java.lang.String entityName)
Retrieves the entity with the given entity name.- Specified by:
getEntityNamedin interfaceSemanticValidatorHelper- Parameters:
entityName- The abstract schema name of the entity to retrieve- Returns:
- The entity with the given name;
nullotherwise
-
getEnumConstants
public java.lang.String[] getEnumConstants(java.lang.Object type)
Returns the constant names for the givenEnumtype.If it was going through Hermes SPI, the type of the argument would be
IType.- Specified by:
getEnumConstantsin interfaceSemanticValidatorHelper- Parameters:
type- TheEnumtype- Returns:
- The list of constant names
-
getGrammar
public JPQLGrammar getGrammar()
Returns theJPQLGrammarthat defines how the JPQL query was parsed.- Specified by:
getGrammarin interfaceSemanticValidatorHelper- Returns:
- The
JPQLGrammarthat was used to parse the JPQL query
-
getIdentificationVariable
protected IdentificationVariable getIdentificationVariable(Expression expression)
-
getIdentificationVariableVisitor
protected GenericSemanticValidatorHelper.IdentificationVariableVisitor getIdentificationVariableVisitor()
-
getManagedType
public IManagedType getManagedType(Expression expression)
Returns the managed type by resolving the givenExpression.If it was going through Hermes SPI, the return type would be
IManagedType.- Specified by:
getManagedTypein interfaceSemanticValidatorHelper
-
getMappingNamed
public IMapping getMappingNamed(java.lang.Object managedType, java.lang.String path)
Returns the mapping with the given name.If it was going through Hermes SPI, the type of the argument would be
IManagedTypeand the return type would beIMapping.- Specified by:
getMappingNamedin interfaceSemanticValidatorHelper- Parameters:
managedType- The managed type that has a mapping with the given namepath- The name of the mapping to retrieve- Returns:
- Either the mapping or
nullif it could not be found
-
getMappingType
public IType getMappingType(java.lang.Object mapping)
Returns the type of the given mapping object.If it was going through Hermes SPI, the type of the argument would be
IMappingand the return type would beIType.- Specified by:
getMappingTypein interfaceSemanticValidatorHelper- Parameters:
mapping- The mapping object- Returns:
- The type of the given mapping
-
getMethodParameterTypeDeclarations
public ITypeDeclaration[] getMethodParameterTypeDeclarations(java.lang.Object constructor)
Returns the list of type declarations representing the given constructor's parameter types. If this is the default constructor, then an empty array should be returned.If it was going through Hermes SPI, the type of the argument would be
IConstructorand the return type would beITypeDeclaration.- Specified by:
getMethodParameterTypeDeclarationsin interfaceSemanticValidatorHelper- Parameters:
constructor- The constructor to return its parameter types- Returns:
- The list of parameter types or an empty list
-
getQueryContext
public JPQLQueryContext getQueryContext()
Returns the context used to query information about the JPQL query.- Returns:
- The context used to query information about the JPQL query
-
getReferenceManagedType
public IManagedType getReferenceManagedType(java.lang.Object relationshipMapping)
Returns the reference managed type from the given relationship mapping.If it was going through Hermes SPI, the type of the argument would be
IMappingand the return type would beIManagedType.- Specified by:
getReferenceManagedTypein interfaceSemanticValidatorHelper- Parameters:
relationshipMapping- The relationship mapping- Returns:
- The managed type referenced by the given relationship mapping
-
getType
public IType getType(Expression expression)
Returns the type by resolving the givenExpression.If it was going through Hermes SPI, the return type would be
IType.- Specified by:
getTypein interfaceSemanticValidatorHelper- Parameters:
expression- TheExpressionto resolve- Returns:
- The type of the given
Expressionornullif it could not be validated
-
getType
public IType getType(java.lang.Object typeDeclaration)
Returns the type defined for the Java member.If it was going through Hermes SPI, the type of the argument would be
ITypeDeclarationand the return type would beIType.- Specified by:
getTypein interfaceSemanticValidatorHelper- Returns:
- The type defined for the Java member
-
getType
public IType getType(java.lang.String typeName)
Retrieves the class with the given fully qualified name.If it was going through Hermes SPI, an
ITypewould be returned.- Specified by:
getTypein interfaceSemanticValidatorHelper- Parameters:
typeName- The fully qualified name of the class to retrieve- Returns:
- The class to retrieve
-
getTypeDeclaration
public ITypeDeclaration getTypeDeclaration(Expression expression)
Returns the type declaration for the givenExpression's type.If it was going through Hermes SPI, the type of the argument would be
ITypeDeclaration.- Specified by:
getTypeDeclarationin interfaceSemanticValidatorHelper- Parameters:
expression- TheExpressionto resolve- Returns:
- Either the type declaration that was resolved for the given
Expression
-
getTypeHelper
public ITypeHelper getTypeHelper()
Returns the helper that gives access to the most common class metadata.- Specified by:
getTypeHelperin interfaceSemanticValidatorHelper- Returns:
- A helper containing a collection of methods related to class metadata
-
getTypeName
public java.lang.String getTypeName(java.lang.Object type)
Returns the fully qualified class name of the given type.If it was going through Hermes SPI, the type of the argument would be
IType.- Specified by:
getTypeNamein interfaceSemanticValidatorHelper- Parameters:
type- The type to retrieve its name- Returns:
- The name of the class represented by this one
-
isAssignableTo
public boolean isAssignableTo(java.lang.Object type1, java.lang.Object type2)Determines whether type 1 is an instance of type 2.If it was going through Hermes SPI, the type of the arguments would be
IType.- Specified by:
isAssignableToin interfaceSemanticValidatorHelper- Parameters:
type1- The type to check if it is an instance of type 2type2- The type used to determine if the class represented by type 1 is an instance of with one- Returns:
trueif type 1 is an instance of the type 2;falseotherwise
-
isCollectionIdentificationVariable
public boolean isCollectionIdentificationVariable(java.lang.String variableName)
Determines whether the given identification variable is defining a join or a collection member declaration expressions.- Specified by:
isCollectionIdentificationVariablein interfaceSemanticValidatorHelper- Parameters:
variableName- The identification variable to check for what it maps- Returns:
trueif the given identification variable maps a collection-valued field defined in aJOINorINexpression;falseif it's not defined or it's mapping an abstract schema name
-
isCollectionMapping
public boolean isCollectionMapping(java.lang.Object mapping)
Determines whether the given mapping is a collection type mapping.If it was going through Hermes SPI, the type of the arguments would be
IMapping.- Specified by:
isCollectionMappingin interfaceSemanticValidatorHelper- Parameters:
mapping- The mapping object to verify if it represents a collection mapping- Returns:
trueif the given mapping is a collection mapping;falseotherwise
-
isEmbeddableMapping
public boolean isEmbeddableMapping(java.lang.Object mapping)
Description copied from interface:SemanticValidatorHelperDetermines whether the given mapping is an embeddable type mapping.If it was going through Hermes SPI, the type of the arguments would be
IMapping.- Specified by:
isEmbeddableMappingin interfaceSemanticValidatorHelper- Parameters:
mapping- The mapping object to verify if it represents an embeddable mapping- Returns:
trueif the given mapping is an embeddable mapping;falseotherwise
-
isEnumType
public boolean isEnumType(java.lang.Object type)
Determines whether the given type represents anEnum.If it was going through Hermes SPI, the type of the argument would be
IType.- Specified by:
isEnumTypein interfaceSemanticValidatorHelper- Returns:
trueif the given type is anEnum;falseotherwise
-
isIdentificationVariableValidInComparison
public boolean isIdentificationVariableValidInComparison(IdentificationVariable expression)
Determines whether an identification variable can be used in a comparison expression when the operator is either '<', '<=', '>', '>='.- Specified by:
isIdentificationVariableValidInComparisonin interfaceSemanticValidatorHelper- Parameters:
expression- TheIdentificationVariablethat is mapped to either an entity, a singled-object value field, a collection-valued object field- Returns:
trueif it can be used in a ordering comparison expression;falseif it can't
-
isManagedTypeResolvable
public boolean isManagedTypeResolvable(java.lang.Object managedType)
Determines whether the given managed type actually exists.If it was going through Hermes SPI, the type of the argument would be
IManagedType.- Specified by:
isManagedTypeResolvablein interfaceSemanticValidatorHelper- Returns:
trueif the given managed type can be located;falseif it could not be found
-
isPropertyMapping
public boolean isPropertyMapping(java.lang.Object mapping)
Determines whether the given mapping is a property type mapping.If it was going through Hermes SPI, the type of the arguments would be
IMapping.- Specified by:
isPropertyMappingin interfaceSemanticValidatorHelper- Parameters:
mapping- The mapping object to verify if it represents a property mapping- Returns:
trueif the given mapping is a property mapping;falseotherwise
-
isRelationshipMapping
public boolean isRelationshipMapping(java.lang.Object mapping)
Determines whether the given mapping is a relationship type mapping.If it was going through Hermes SPI, the type of the arguments would be
IMapping.- Specified by:
isRelationshipMappingin interfaceSemanticValidatorHelper- Parameters:
mapping- The mapping object to verify if it represents a relationship mapping- Returns:
trueif the given mapping is a relationship mapping;falseotherwise
-
isResultVariable
public boolean isResultVariable(java.lang.String variableName)
Determines if the given variable is a result variable.- Specified by:
isResultVariablein interfaceSemanticValidatorHelper- Parameters:
variableName- The variable to check if it's a result variable- Returns:
trueif the given variable is defined as a result variable;falseotherwise
-
isTransient
public boolean isTransient(java.lang.Object mapping)
Determines whether the given mapping is a transient attribute.If it was going through Hermes SPI, the type of the arguments would be
IMapping.- Specified by:
isTransientin interfaceSemanticValidatorHelper- Parameters:
mapping- The mapping object to verify if it represents a transient attribute- Returns:
trueif the given attribute is a transient mapping;falseotherwise
-
isTypeDeclarationAssignableTo
public boolean isTypeDeclarationAssignableTo(java.lang.Object typeDeclaration1, java.lang.Object typeDeclaration2)Determines whether type declaration 1 is an instance of type declaration 2.If it was going through Hermes SPI, the type of the arguments would be
ITypeDeclaration.- Specified by:
isTypeDeclarationAssignableToin interfaceSemanticValidatorHelper- Parameters:
typeDeclaration1- The type declaration to check if it is an instance of type declaration 2typeDeclaration2- The type used to determine if the class represented by type declaration 1 is an instance of with one- Returns:
trueif type declaration 1 is an instance of the type declaration 2;falseotherwise
-
isTypeResolvable
public boolean isTypeResolvable(java.lang.Object type)
Determines whether the given type actually exists.If it was going through Hermes SPI, the type of the argument would be
IType.- Specified by:
isTypeResolvablein interfaceSemanticValidatorHelper- Returns:
trueif the actual class exists;falseotherwise
-
newSubqueryContext
public void newSubqueryContext(SimpleSelectStatement expression)
Changes the state of this helper to use the given subquery.- Specified by:
newSubqueryContextin interfaceSemanticValidatorHelper- Parameters:
expression- The parsed tree representation of the subquery that will become the current query- See Also:
SemanticValidatorHelper.disposeSubqueryContext()
-
resolveMapping
public IMapping resolveMapping(Expression expression)
Returns the mapping for the field represented by the givenExpression.If it was going through Hermes SPI, the return type would be
IMapping.- Specified by:
resolveMappingin interfaceSemanticValidatorHelper- Parameters:
expression- TheExpressionrepresenting a state field path expression or a collection-valued path expression- Returns:
- Either the mapping or
nullif none exists
-
resolveMapping
public IMapping resolveMapping(java.lang.String variableName, java.lang.String name)
Returns the mapping that should be a persistence field from the entity defined by the given identification variable.If it was going through Hermes SPI, the return type would be
IMapping.- Specified by:
resolveMappingin interfaceSemanticValidatorHelper- Parameters:
variableName- The identification variable that is defined in theFROMclause of the query (which can be in the current subquery) or in one of the parent queries.name- The name of the persistent field to retrieve- Returns:
- The persistence field with the given name or
nullif it could not be found
-
-