EclipseLink 2.5.0, build 'v20130507-3faac2b' API Reference

org.eclipse.persistence.jpa.jpql.tools.resolver
Class DeclarationResolver

java.lang.Object
  extended by org.eclipse.persistence.jpa.jpql.tools.resolver.Resolver
      extended by org.eclipse.persistence.jpa.jpql.tools.resolver.DeclarationResolver
Direct Known Subclasses:
EclipseLinkDeclarationResolver

public class DeclarationResolver
extends Resolver

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.

Version:
2.5
Author:
Pascal Filion
Since:
2.3

Nested Class Summary
protected  class DeclarationResolver.DeclarationVisitor
           
protected  class DeclarationResolver.QualifyRangeDeclarationVisitor
           
protected  class DeclarationResolver.RootObjectExpressionVisitor
          This visitor takes care to support a subquery defined as a "root" object.
 
Constructor Summary
DeclarationResolver(DeclarationResolver parent, JPQLQueryContext queryContext)
          Creates a new DeclarationResolver.
 
Method Summary
protected  void addDeclaration(Declaration declaration)
          Adds the given Declaration at the end of the list.
 void addRangeVariableDeclaration(java.lang.String entityName, java.lang.String variableName)
          Registers a range variable declaration that will be used when a JPQL fragment is parsed.
protected  DeclarationResolver.DeclarationVisitor buildDeclarationVisitor()
           
protected  DeclarationResolver.RootObjectExpressionVisitor buildRootObjectExpressionVisitor()
           
protected  IType buildType()
          Resolves the IType of the property handled by this Resolver.
protected  ITypeDeclaration buildTypeDeclaration()
          Resolves the ITypeDeclaration of the property handled by this Resolver.
protected  void checkParent(Resolver parent)
          
 void convertUnqualifiedDeclaration(Declaration declaration, java.lang.String outerVariableName)
          Converts the given Declaration from being set as a range variable declaration to a path expression declaration.
 void dispose()
          Disposes the internal data.
 Declaration getDeclaration(java.lang.String variableName)
          Retrieves the Declaration for which the given variable name is used to navigate to the "root" object.
 java.util.List<Declaration> getDeclarations()
          Returns the ordered list of Declarations.
protected  DeclarationResolver.DeclarationVisitor getDeclarationVisitor()
           
 DeclarationResolver getParent()
          Returns the parent of this Resolver.
 IQuery getQuery()
          Returns the external form representing the JPQL query.
protected  JPQLQueryContext getQueryContext()
          Returns the JPQLQueryContext that is used by this visitor.
 Resolver getResolver(java.lang.String variableName)
          Retrieves the Resolver mapped with the given identification variable.
protected  Resolver getResolverImp(java.lang.String variableName)
          Retrieves the Resolver mapped with the given identification variable.
 java.util.Set<java.lang.String> getResultVariables()
          Returns the variables that got defined in the select expression.
 java.util.Map<IdentificationVariable,java.lang.String> getResultVariablesMap()
          Returns the map of result variables that got used to define a select expression.
protected  DeclarationResolver.RootObjectExpressionVisitor getRootObjectExpressionVisitor()
           
 boolean hasJoins()
          Determines whether the JPQL expression has JOIN expressions.
protected  void initialize(JPQLQueryContext queryContext)
          Initializes this DeclarationResolver.
 boolean isCollectionIdentificationVariable(java.lang.String variableName)
          Determines whether the given identification variable is defining a JOIN expression or in a IN expressions for a collection-valued field.
protected  boolean isCollectionIdentificationVariableImp(java.lang.String variableName)
          Determines whether the given identification variable is defining a JOIN expression or in a IN expressions for a collection-valued field.
 boolean isRangeIdentificationVariable(java.lang.String variableName)
          Determines whether the given variable name is an identification variable name mapping an entity.
protected  boolean isRangeIdentificationVariableImp(java.lang.String variableName)
          Determines whether the given variable name is an identification variable name mapping an entity.
 boolean isResultVariable(java.lang.String variable)
          Determines if the given variable is a result variable.
 void populate(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  DeclarationResolver.QualifyRangeDeclarationVisitor qualifyRangeDeclarationVisitor()
           
protected  Resolver resolveRootObject(Expression expression)
          Resolves the "root" object represented by the given Expression.
protected  java.lang.String visitDeclaration(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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeclarationResolver

public DeclarationResolver(DeclarationResolver parent,
                           JPQLQueryContext queryContext)
Creates a new DeclarationResolver.

Parameters:
parent - The parent resolver if this is used for a subquery or null if it's used for the top-level query
queryContext - The context used to query information about the query
Method Detail

addDeclaration

protected final void addDeclaration(Declaration declaration)
Adds the given Declaration at the end of the list.

Parameters:
declaration - The Declaration representing a single variable declaration

addRangeVariableDeclaration

public void addRangeVariableDeclaration(java.lang.String entityName,
                                        java.lang.String variableName)
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 name
variableName - The identification variable used to navigate to the entity

buildDeclarationVisitor

protected DeclarationResolver.DeclarationVisitor buildDeclarationVisitor()

buildRootObjectExpressionVisitor

protected DeclarationResolver.RootObjectExpressionVisitor buildRootObjectExpressionVisitor()

buildType

protected IType buildType()
Resolves the IType of the property handled by this Resolver.

Overrides:
buildType in class Resolver
Returns:
Either the IType that was resolved by this Resolver or the IType for IType.UNRESOLVABLE_TYPE if it could not be resolved

buildTypeDeclaration

protected ITypeDeclaration buildTypeDeclaration()
Resolves the ITypeDeclaration of the property handled by this Resolver.

Specified by:
buildTypeDeclaration in class Resolver
Returns:
Either the ITypeDeclaration that was resolved by this Resolver or the ITypeDeclaration for IType.UNRESOLVABLE_TYPE if it could not be resolved

checkParent

protected void checkParent(Resolver parent)

Overrides:
checkParent in class Resolver

convertUnqualifiedDeclaration

public void convertUnqualifiedDeclaration(Declaration declaration,
                                          java.lang.String outerVariableName)
Converts the given Declaration from 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 - The Declaration that was parsed to range over an abstract schema name but is actually ranging over a path expression
outerVariableName - The identification variable coming from the parent identification variable declaration

dispose

public void dispose()
Disposes the internal data.


getDeclaration

public Declaration getDeclaration(java.lang.String variableName)
Retrieves the Declaration for 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 Declaration containing the information about the identification variable declaration
Since:
2.5

getDeclarations

public java.util.List<Declaration> getDeclarations()
Returns the ordered list of Declarations.

Returns:
The Declarations of the current query that was parsed

getDeclarationVisitor

protected DeclarationResolver.DeclarationVisitor getDeclarationVisitor()

getParent

public DeclarationResolver getParent()
Returns the parent of this Resolver.

Overrides:
getParent in class Resolver
Returns:
The parent of this Resolver

getQuery

public IQuery getQuery()
Returns the external form representing the JPQL query.

Overrides:
getQuery in class Resolver
Returns:
The external form of the JPQL query

getQueryContext

protected JPQLQueryContext getQueryContext()
Returns the JPQLQueryContext that is used by this visitor.

Returns:
The JPQLQueryContext holding onto the JPQL query and the cached information

getResolver

public Resolver getResolver(java.lang.String variableName)
Retrieves the Resolver mapped 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.

Parameters:
variableName - The identification variable that maps a Resolver
Returns:
The Resolver mapped with the given identification variable

getResolverImp

protected Resolver getResolverImp(java.lang.String variableName)
Retrieves the Resolver mapped with the given identification variable. The search does not traverse the parent hierarchy.

Parameters:
variableName - The identification variable that maps a Resolver
Returns:
The Resolver mapped with the given identification variable

getResultVariables

public java.util.Set<java.lang.String> 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

public java.util.Map<IdentificationVariable,java.lang.String> 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

protected DeclarationResolver.RootObjectExpressionVisitor getRootObjectExpressionVisitor()

hasJoins

public boolean hasJoins()
Determines whether the JPQL expression has JOIN expressions.

Returns:
true if the query or subquery being traversed contains JOIN expressions; false otherwise

initialize

protected void initialize(JPQLQueryContext queryContext)
Initializes this DeclarationResolver.

Parameters:
queryContext - The context used to query information about the query

isCollectionIdentificationVariable

public boolean isCollectionIdentificationVariable(java.lang.String variableName)
Determines whether the given identification variable is defining a JOIN expression or in a IN expressions 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:
true if the given identification variable maps a collection-valued field defined in a JOIN or IN expression; false otherwise

isCollectionIdentificationVariableImp

protected boolean isCollectionIdentificationVariableImp(java.lang.String variableName)
Determines whether the given identification variable is defining a JOIN expression or in a IN expressions 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:
true if the given identification variable maps a collection-valued field defined in a JOIN or IN expression; false otherwise

isRangeIdentificationVariable

public boolean isRangeIdentificationVariable(java.lang.String variableName)
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:
true if the variable name is mapping an abstract schema name; false if it's defined in a collection member declaration

isRangeIdentificationVariableImp

protected boolean isRangeIdentificationVariableImp(java.lang.String variableName)
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:
true if the variable name is mapping an abstract schema name; false if it's defined in a collection member declaration

isResultVariable

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

Parameters:
variable - The variable to check if it's a result variable
Returns:
true if the given variable is defined as a result variable; false otherwise

populate

public void populate(Expression expression)
Visits the current query (which is either the top-level query or a subquery) and gathers the information from the declaration clause.

Parameters:
expression - The Expression to visit in order to retrieve the information contained in the given query's declaration

qualifyRangeDeclarationVisitor

protected DeclarationResolver.QualifyRangeDeclarationVisitor qualifyRangeDeclarationVisitor()

resolveRootObject

protected Resolver resolveRootObject(Expression expression)
Resolves the "root" object represented by the given Expression. This will also handle using a subquery in the FROM clause. This is only supported by EclipseLink.

Parameters:
expression - The Expression to visit, which represents the "root" object of a declaration
Returns:
The Resolver for the given Expression

visitDeclaration

protected java.lang.String visitDeclaration(Expression expression,
                                            Expression identificationVariable)

EclipseLink 2.5.0, build 'v20130507-3faac2b' API Reference