EclipseLink 2.4.2, build 'v20130514-5956486' API Reference

org.eclipse.persistence.jpa.jpql
Class GenericSemanticValidatorHelper

java.lang.Object
  extended by org.eclipse.persistence.jpa.jpql.GenericSemanticValidatorHelper
All Implemented Interfaces:
SemanticValidatorHelper

public class GenericSemanticValidatorHelper
extends java.lang.Object
implements SemanticValidatorHelper

An implementation of SemanticValidatorHelper that uses JPQLQueryContext to 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.4.2
Author:
Pascal Filion
Since:
2.4

Constructor Summary
GenericSemanticValidatorHelper(JPQLQueryContext queryContext)
          Creates a new GenericSemanticValidatorHelper.
 
Method Summary
 void collectAllDeclarationIdentificationVariables(java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)
          Collects the identification variables that are defined in the FROM clause of the current query and from the parent queries.
 void collectLocalDeclarationIdentificationVariables(java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)
          Collects the identification variables that are defined in the FROM clause of the current query.
 void disposeSubqueryContext()
          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.
 IConstructor[] getConstructors(java.lang.Object type)
          Returns the constructors for the given type.
 java.util.List getDeclarations()
          Returns the ordered list of JPQLQueryDeclaration, which contain the information contained in the query's FROM clause.
 IManagedType getEmbeddable(java.lang.Object type)
          Retrieves the embeddable with the given type.
 IEntity getEntityNamed(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 given Enum type.
 JPQLGrammar getGrammar()
          Returns the JPQLGrammar that defines how the JPQL query was parsed.
 IManagedType getManagedType(Expression expression)
          Returns the managed type by resolving the given Expression.
 IMapping getMappingNamed(java.lang.Object managedType, java.lang.String path)
          Returns the mapping with the given name.
 IType getMappingType(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.
 IManagedType getReferenceManagedType(java.lang.Object relationshipMapping)
          Returns the reference managed type from the given relationship mapping.
 IType getType(Expression expression)
          Returns the type by resolving the given Expression.
 IType getType(java.lang.Object typeDeclaration)
          Returns the type defined for the Java member.
 IType getType(java.lang.String typeName)
          Retrieves the class with the given fully qualified name.
 ITypeDeclaration getTypeDeclaration(Expression expression)
          Returns the type declaration for the given Expression's type.
 ITypeHelper getTypeHelper()
          Returns the helper that gives access to the most common class metadata.
 java.lang.String getTypeName(java.lang.Object type)
          Returns the fully qualified class name of the given type.
 boolean isAssignableTo(java.lang.Object type1, java.lang.Object type2)
          Determines whether type 1 is an instance of type 2.
 boolean isCollectionIdentificationVariable(java.lang.String variableName)
          Determines whether the given identification variable is defining a join or a collection member declaration expressions.
 boolean isCollectionMapping(java.lang.Object mapping)
          Determines whether the given mapping is a collection type mapping.
 boolean isEnumType(java.lang.Object type)
          Determines whether the given type represents an Enum.
 boolean isIdentificationVariableValidInComparison(IdentificationVariable expression)
          Determines whether an identification variable can be used in a comparison expression when the operator is either '<', '<=', '>', '>='.
 boolean isManagedTypeResolvable(java.lang.Object managedType)
          Determines whether the given managed type actually exists.
 boolean isPropertyMapping(java.lang.Object mapping)
          Determines whether the given mapping is a property type mapping.
 boolean isRelationshipMapping(java.lang.Object mapping)
          Determines whether the given mapping is a relationship type mapping.
 boolean isResultVariable(java.lang.String variableName)
          Determines if the given variable is a result variable.
 boolean isTransient(java.lang.Object mapping)
          Determines whether the given mapping is a transient attribute.
 boolean isTypeDeclarationAssignableTo(java.lang.Object typeDeclaration1, java.lang.Object typeDeclaration2)
          Determines whether type declaration 1 is an instance of type declaration 2.
 boolean isTypeResolvable(java.lang.Object type)
          Determines whether the given type actually exists.
 boolean isValidatingPathExpressionAllowed(StateFieldPathExpression expression)
          Determines whether a path expression should be validated or not.
 void newSubqueryContext(SimpleSelectStatement expression)
          Changes the state of this helper to use the given subquery.
 IMapping resolveMapping(Expression expression)
          Returns the mapping for the field represented by the given Expression.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericSemanticValidatorHelper

public GenericSemanticValidatorHelper(JPQLQueryContext queryContext)
Creates a new GenericSemanticValidatorHelper.

Parameters:
queryContext - The context used to query information about the JPQL query
Throws:
java.lang.NullPointerException - The given JPQLQueryContext cannot be null
Method Detail

collectAllDeclarationIdentificationVariables

public void collectAllDeclarationIdentificationVariables(java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)
Collects the identification variables that are defined in the FROM clause of the current query and from the parent queries.

Specified by:
collectAllDeclarationIdentificationVariables in interface SemanticValidatorHelper
Parameters:
identificationVariables - The Map used to store the variables

collectLocalDeclarationIdentificationVariables

public void collectLocalDeclarationIdentificationVariables(java.util.Map<java.lang.String,java.util.List<IdentificationVariable>> identificationVariables)
Collects the identification variables that are defined in the FROM clause of the current query.

Specified by:
collectLocalDeclarationIdentificationVariables in interface SemanticValidatorHelper
Parameters:
identificationVariables - The Map used 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:
disposeSubqueryContext in interface SemanticValidatorHelper

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:
entityNames in interface SemanticValidatorHelper
Returns:
The list of entity names

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 persistence.jpa.jpql.spi.IType IType and the return type would be persistence.jpa.jpql.spi.IConstructor IConstructor.

Specified by:
getConstructors in interface SemanticValidatorHelper
Returns:
The declared constructors

getDeclarations

public java.util.List getDeclarations()
Returns the ordered list of JPQLQueryDeclaration, which contain the information contained in the query's FROM clause.

Specified by:
getDeclarations in interface SemanticValidatorHelper
Returns:
The list of JPQLQueryDeclaration of the current query that was parsed

getEmbeddable

public IManagedType getEmbeddable(java.lang.Object type)
Retrieves the embeddable with the given type.

Specified by:
getEmbeddable in interface SemanticValidatorHelper
Parameters:
type - The Java type of the embeddable to retrieve
Returns:
The embeddable for the given type if it's representing an embeddable; null otherwise

getEntityNamed

public IEntity getEntityNamed(java.lang.String entityName)
Retrieves the entity with the given entity name.

Specified by:
getEntityNamed in interface SemanticValidatorHelper
Parameters:
entityName - The abstract schema name of the entity to retrieve
Returns:
The entity with the given name; null otherwise

getEnumConstants

public java.lang.String[] getEnumConstants(java.lang.Object type)
Returns the constant names for the given Enum type.

If it was going through Hermes SPI, the type of the argument would be persistence.jpa.jpql.spi.IType IType.

Specified by:
getEnumConstants in interface SemanticValidatorHelper
Parameters:
type - The Enum type
Returns:
The list of constant names

getGrammar

public JPQLGrammar getGrammar()
Returns the JPQLGrammar that defines how the JPQL query was parsed.

Specified by:
getGrammar in interface SemanticValidatorHelper
Returns:
The JPQLGrammar that was used to parse the JPQL query

getManagedType

public IManagedType getManagedType(Expression expression)
Returns the managed type by resolving the given Expression.

If it was going through Hermes SPI, the return type would be jpa.jpql.spi.IManagedType IManagedType.

Specified by:
getManagedType in interface SemanticValidatorHelper

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 persistence.jpa.jpql.spi.IManagedType IManagedType and the return type would be IMapping.

Specified by:
getMappingNamed in interface SemanticValidatorHelper
Parameters:
managedType - The managed type that has a mapping with the given name
path - The name of the mapping to retrieve
Returns:
Either the mapping or null if 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 persistence.jpa.jpql.spi.IMapping IMapping and the return type would be persistence.jpa.jpql.spi.IType IType.

Specified by:
getMappingType in interface SemanticValidatorHelper
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 persistence.jpa.jpql.spi.IConstructor IConstructor and the return type would be ITypeDeclaration.

Specified by:
getMethodParameterTypeDeclarations in interface SemanticValidatorHelper
Parameters:
constructor - The constructor to return its parameter types
Returns:
The list of parameter types or an empty list

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 persistence.jpa.jpql.spi.IMapping IMapping and the return type would be IManagedType.

Specified by:
getReferenceManagedType in interface SemanticValidatorHelper
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 given Expression.

If it was going through Hermes SPI, the return type would be jpa.jpql.spi.IType IType.

Specified by:
getType in interface SemanticValidatorHelper
Parameters:
expression - The Expression to resolve
Returns:
The type of the given Expression or null if 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 persistence.jpa.jpql.spi.ITypeDeclaration ITypeDeclaration and the return type would be IType.

Specified by:
getType in interface SemanticValidatorHelper
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 IType would be returned.

Specified by:
getType in interface SemanticValidatorHelper
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 given Expression's type.

If it was going through Hermes SPI, the type of the argument would be persistence.jpa.jpql.spi.ITypeDeclaration ITypeDeclaration.

Specified by:
getTypeDeclaration in interface SemanticValidatorHelper
Parameters:
expression - The Expression to 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:
getTypeHelper in interface SemanticValidatorHelper
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 persistence.jpa.jpql.spi.IType IType.

Specified by:
getTypeName in interface SemanticValidatorHelper
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 persistence.jpa.jpql.spi.IType IType.

Specified by:
isAssignableTo in interface SemanticValidatorHelper
Parameters:
type1 - The type to check if it is an instance of type 2
type2 - The type used to determine if the class represented by type 1 is an instance of with one
Returns:
true if type 1 is an instance of the type 2; false otherwise

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:
isCollectionIdentificationVariable in interface SemanticValidatorHelper
Parameters:
variableName - The identification variable to check for what it maps
Returns:
true if the given identification variable maps a collection-valued field defined in a JOIN or IN expression; false if 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 persistence.jpa.jpql.spi.IMapping IMapping.

Specified by:
isCollectionMapping in interface SemanticValidatorHelper
Parameters:
mapping - The mapping object to verify if it represents a collection mapping
Returns:
true if the given mapping is a collection mapping; false otherwise

isEnumType

public boolean isEnumType(java.lang.Object type)
Determines whether the given type represents an Enum.

If it was going through Hermes SPI, the type of the argument would be persistence.jpa.jpql.spi.IType IType.

Specified by:
isEnumType in interface SemanticValidatorHelper
Returns:
true if the given type is an Enum; false otherwise

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:
isIdentificationVariableValidInComparison in interface SemanticValidatorHelper
Parameters:
expression - The IdentificationVariable that is mapped to either an entity, a singled-object value field, a collection-valued object field
Returns:
true if it can be used in a ordering comparison expression; false if 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 persistence.jpa.jpql.spi.IManagedType IManagedType.

Specified by:
isManagedTypeResolvable in interface SemanticValidatorHelper
Returns:
true if the given managed type can be located; false if 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 persistence.jpa.jpql.spi.IMapping IMapping.

Specified by:
isPropertyMapping in interface SemanticValidatorHelper
Parameters:
mapping - The mapping object to verify if it represents a property mapping
Returns:
true if the given mapping is a property mapping; false otherwise

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 persistence.jpa.jpql.spi.IMapping IMapping.

Specified by:
isRelationshipMapping in interface SemanticValidatorHelper
Parameters:
mapping - The mapping object to verify if it represents a relationship mapping
Returns:
true if the given mapping is a relationship mapping; false otherwise

isResultVariable

public boolean isResultVariable(java.lang.String variableName)
Determines if the given variable is a result variable.

Specified by:
isResultVariable in interface SemanticValidatorHelper
Parameters:
variableName - The variable to check if it's a result variable
Returns:
true if the given variable is defined as a result variable; false otherwise

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 persistence.jpa.jpql.spi.IMapping IMapping.

Specified by:
isTransient in interface SemanticValidatorHelper
Parameters:
mapping - The mapping object to verify if it represents a transient attribute
Returns:
true if the given attribute is a transient mapping; false otherwise

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 persistence.jpa.jpql.spi.ITypeDeclaration ITypeDeclaration.

Specified by:
isTypeDeclarationAssignableTo in interface SemanticValidatorHelper
Parameters:
typeDeclaration1 - The type declaration to check if it is an instance of type declaration 2
typeDeclaration2 - The type used to determine if the class represented by type declaration 1 is an instance of with one
Returns:
true if type declaration 1 is an instance of the type declaration 2; false otherwise

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 persistence.jpa.jpql.spi.IType IType.

Specified by:
isTypeResolvable in interface SemanticValidatorHelper
Returns:
true if the actual class exists; false otherwise

isValidatingPathExpressionAllowed

public boolean isValidatingPathExpressionAllowed(StateFieldPathExpression expression)
Determines whether a path expression should be validated or not. This can happen in some very specific cases.

Specified by:
isValidatingPathExpressionAllowed in interface SemanticValidatorHelper
Parameters:
expression - The StateFieldPathExpression that might not need to be validated
Returns:
true to validate the given path expression; false otherwise

newSubqueryContext

public void newSubqueryContext(SimpleSelectStatement expression)
Changes the state of this helper to use the given subquery.

Specified by:
newSubqueryContext in interface SemanticValidatorHelper
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 given Expression.

If it was going through Hermes SPI, the return type would be jpa.jpql.spi.IMapping IMapping.

Specified by:
resolveMapping in interface SemanticValidatorHelper
Parameters:
expression - The Expression representing a state field path expression or a collection-valued path expression
Returns:
Either the mapping or null if 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 jpa.jpql.spi.IMapping IMapping.

Specified by:
resolveMapping in interface SemanticValidatorHelper
Parameters:
variableName - The identification variable that is defined in the FROM clause 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 null if it could not be found

EclipseLink 2.4.2, build 'v20130514-5956486' API Reference