Class DeclarationResolver
java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.resolver.Resolver
org.eclipse.persistence.jpa.jpql.tools.resolver.DeclarationResolver
- Direct Known Subclasses:
EclipseLinkDeclarationResolver
This
Resolver is responsible to visit the current query (which is either the top-level
query or a subquery) and gathers the information from the declaration clause. For a SELECT
or DELETE clause, the information will be retrieved from the FROM clause. For an
UDPATE clause, it will be retrieved from the unique identification range variable
declaration.- Since:
- 2.3
- Version:
- 2.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected static classprotected classThis visitor takes care to support a subquery defined as a "root" object. -
Constructor Summary
ConstructorsConstructorDescriptionDeclarationResolver(DeclarationResolver parent, JPQLQueryContext queryContext) Creates a newDeclarationResolver. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddDeclaration(Declaration declaration) Adds the givenDeclarationat the end of the list.voidaddRangeVariableDeclaration(String entityName, String variableName) Registers a range variable declaration that will be used when a JPQL fragment is parsed.protected DeclarationResolver.DeclarationVisitorprotected ITypeprotected ITypeDeclarationResolves theITypeDeclarationof the property handled by thisResolver.protected voidcheckParent(Resolver parent) voidconvertUnqualifiedDeclaration(Declaration declaration, String outerVariableName) Converts the givenDeclarationfrom being set as a range variable declaration to a path expression declaration.voiddispose()Disposes the internal data.getDeclaration(String variableName) Retrieves theDeclarationfor which the given variable name is used to navigate to the "root" object.Returns the ordered list ofDeclarations.protected DeclarationResolver.DeclarationVisitorReturns the parent of thisResolver.getQuery()Returns the external form representing the JPQL query.protected JPQLQueryContextReturns theJPQLQueryContextthat is used by this visitor.getResolver(String variableName) Retrieves theResolvermapped with the given identification variable.protected ResolvergetResolverImp(String variableName) Retrieves theResolvermapped with the given identification variable.Returns the variables that got defined in the select expression.Returns the map of result variables that got used to define a select expression.booleanhasJoins()Determines whether the JPQL expression has JOIN expressions.protected voidinitialize(JPQLQueryContext queryContext) Initializes thisDeclarationResolver.booleanisCollectionIdentificationVariable(String variableName) Determines whether the given identification variable is defining a JOIN expression or in aINexpressions for a collection-valued field.protected booleanisCollectionIdentificationVariableImp(String variableName) Determines whether the given identification variable is defining a JOIN expression or in aINexpressions for a collection-valued field.booleanisRangeIdentificationVariable(String variableName) Determines whether the given variable name is an identification variable name mapping an entity.protected booleanisRangeIdentificationVariableImp(String variableName) Determines whether the given variable name is an identification variable name mapping an entity.booleanisResultVariable(String variable) Determines if the given variable is a result variable.voidpopulate(Expression expression) Visits the current query (which is either the top-level query or a subquery) and gathers the information from the declaration clause.protected ResolverresolveRootObject(Expression expression) Resolves the "root" object represented by the givenExpression.protected StringvisitDeclaration(Expression expression, Expression identificationVariable) Methods inherited from class org.eclipse.persistence.jpa.jpql.tools.resolver.Resolver
addChild, getChild, getManagedType, getMapping, getParentManagedType, getParentMapping, getParentType, getParentTypeDeclaration, getProvider, getType, getType, getType, getTypeDeclaration, getTypeHelper, getTypeRepository, isNullAllowed, setNullAllowed
-
Constructor Details
-
DeclarationResolver
Creates a newDeclarationResolver.- Parameters:
parent- The parent resolver if this is used for a subquery or null if it's used for the top-level queryqueryContext- The context used to query information about the query
-
-
Method Details
-
addDeclaration
Adds the givenDeclarationat the end of the list.- Parameters:
declaration- TheDeclarationrepresenting a single variable declaration
-
addRangeVariableDeclaration
Registers a range variable declaration that will be used when a JPQL fragment is parsed.- Parameters:
entityName- The name of the entity to be accessible with the given variable namevariableName- The identification variable used to navigate to the entity
-
buildDeclarationVisitor
-
buildRootObjectExpressionVisitor
-
buildType
Description copied from class:Resolver -
buildTypeDeclaration
Description copied from class:ResolverResolves theITypeDeclarationof the property handled by thisResolver.- Specified by:
buildTypeDeclarationin classResolver- Returns:
- Either the
ITypeDeclarationthat was resolved by thisResolveror theITypeDeclarationforIType.UNRESOLVABLE_TYPEif it could not be resolved
-
checkParent
- Overrides:
checkParentin classResolver
-
convertUnqualifiedDeclaration
Converts the givenDeclarationfrom being set as a range variable declaration to a path expression declaration.In this query "
UPDATE Employee SET firstName = 'MODIFIED' WHERE (SELECT COUNT(m) FROM managedEmployees m) > 0" managedEmployees is an unqualified collection-valued path expression (employee.managedEmployees).- Parameters:
declaration- TheDeclarationthat was parsed to range over an abstract schema name but is actually ranging over a path expressionouterVariableName- The identification variable coming from the parent identification variable declaration
-
dispose
public void dispose()Disposes the internal data. -
getDeclaration
Retrieves theDeclarationfor which the given variable name is used to navigate to the "root" object.- Parameters:
variableName- The name of the identification variable that is used to navigate a "root" object- Returns:
- The
Declarationcontaining the information about the identification variable declaration - Since:
- 2.5
-
getDeclarations
Returns the ordered list ofDeclarations.- Returns:
- The
Declarationsof the current query that was parsed
-
getDeclarationVisitor
-
getParent
Description copied from class:ResolverReturns the parent of thisResolver. -
getQuery
Description copied from class:ResolverReturns the external form representing the JPQL query. -
getQueryContext
Returns theJPQLQueryContextthat is used by this visitor.- Returns:
- The
JPQLQueryContextholding onto the JPQL query and the cached information
-
getResolver
Retrieves theResolvermapped with the given identification variable. If the identification is not defined in the declaration traversed by this resolver, than the search will traverse the parent hierarchy. -
getResolverImp
Retrieves theResolvermapped with the given identification variable. The search does not traverse the parent hierarchy. -
getResultVariables
Returns the variables that got defined in the select expression. This only applies to JPQL queries built for JPA 2.0 or later.- Returns:
- The variables identifying the select expressions, if any was defined or an empty set if none were defined
-
getResultVariablesMap
Returns the map of result variables that got used to define a select expression. This only applies to JPQL queries built for JPA 2.0.- Returns:
- The variables identifying the select expressions, if any was defined or an empty map if none were defined
-
getRootObjectExpressionVisitor
-
hasJoins
public boolean hasJoins()Determines whether the JPQL expression has JOIN expressions.- Returns:
trueif the query or subquery being traversed contains JOIN expressions;falseotherwise
-
initialize
Initializes thisDeclarationResolver.- Parameters:
queryContext- The context used to query information about the query
-
isCollectionIdentificationVariable
Determines whether the given identification variable is defining a JOIN expression or in aINexpressions for a collection-valued field. If the search didn't find the identification in this resolver, then it will traverse the parent hierarchy.- 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;falseotherwise
-
isCollectionIdentificationVariableImp
Determines whether the given identification variable is defining a JOIN expression or in aINexpressions for a collection-valued field. The search does not traverse the parent hierarchy.- 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;falseotherwise
-
isRangeIdentificationVariable
Determines whether the given variable name is an identification variable name mapping an entity. The search traverses the parent resolver if it is not found in this resolver, which represents the current JPQL query.- Parameters:
variableName- The name of the variable to verify if it's defined in a range variable declaration in the current query or any parent query- Returns:
trueif the variable name is mapping an abstract schema name;falseif it's defined in a collection member declaration
-
isRangeIdentificationVariableImp
Determines whether the given variable name is an identification variable name mapping an entity. The search only searches in this resolver, which represents the current JPQL query.- Parameters:
variableName- The name of the variable to verify if it's defined in a range variable declaration in the current query or any parent query- Returns:
trueif the variable name is mapping an abstract schema name;falseif it's defined in a collection member declaration
-
isResultVariable
Determines if the given variable is a result variable.- Parameters:
variable- The variable to check if it's a result variable- Returns:
trueif the given variable is defined as a result variable;falseotherwise
-
populate
Visits the current query (which is either the top-level query or a subquery) and gathers the information from the declaration clause.- Parameters:
expression- TheExpressionto visit in order to retrieve the information contained in the given query's declaration
-
qualifyRangeDeclarationVisitor
-
resolveRootObject
Resolves the "root" object represented by the givenExpression. This will also handle using a subquery in theFROMclause. This is only supported by EclipseLink.- Parameters:
expression- TheExpressionto visit, which represents the "root" object of a declaration- Returns:
- The
Resolverfor the givenExpression
-
visitDeclaration
-