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

public abstract Class JPQLQueryContext

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.jpa.jpql.tools.DefaultJPQLQueryContext, org.eclipse.persistence.jpa.jpql.tools.EclipseLinkJPQLQueryContext
Annotations
@SuppressWarnings:nls
Imports
java.util.ArrayList, .Collection, .HashMap, .List, .Map, .Set, org.eclipse.persistence.jpa.jpql.ExpressionTools, .JPAVersion, .LiteralType, .LiteralVisitor, .ParameterTypeVisitor, org.eclipse.persistence.jpa.jpql.parser.AbstractTraverseChildrenVisitor, .AbstractTraverseParentVisitor, .Expression, .ExpressionRegistry, .InputParameter, .JPQLExpression, .JPQLGrammar, .SimpleSelectStatement, org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration, .DeclarationResolver, .Resolver, .ResolverBuilder, org.eclipse.persistence.jpa.jpql.tools.spi.IManagedTypeProvider, .IMapping, .IQuery, .IType, .ITypeDeclaration, .ITypeRepository

This context is used to store information related to the JPQL query.
 IQuery externalQuery = ...;

JPQLQueryContext context = new JPQLQueryContext(DefaultJPQLGrammar.instance());
context.setQuery(query);
If the JPQL query is already parsed, then the context can use it and it needs to be set before setting the IQuery:
 JPQLExpression jpqlExpression = ...;

JPQLQueryContext context = new JPQLQueryContext(DefaultJPQLGrammar.instance());
context.setJPQLExpression(jpqlExpression);
context.setQuery(query);

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JPQLQueryContext.InputParameterVisitor

This visitor is responsible to find the InputParameters with a certain parameter name.

protected static class
JPQLQueryContext.QueryExpressionVisitor

This visitor is responsible to retrieve the Expression that is the beginning of a query.

Field Summary

Modifier and TypeField and Description
private Map<Expression, JPQLQueryContext>
contexts

This map caches the contexts in order to keep them in memory and for fast access to the information of any query (top-level query and subqueries).

protected JPQLQueryContext
currentContext

The current JPQLQueryContext is the context used for the current query or subquery.

private Expression
currentQuery

The parsed JPQL Expression currently visited.

private DeclarationResolver
declarationResolver

The resolver of the current query's declaration.

private JPQLQueryContext.InputParameterVisitor
inputParameterVisitor

This visitor is responsible to find the InputParameter with a specific named parameter or positional parameter.

private JPQLExpression
jpqlExpression

The parsed tree representation of the JPQL query.

private JPQLGrammar
jpqlGrammar

The grammar that defines how to parse a JPQL query.

private LiteralVisitor
literalVisitor

This visitor is used to retrieve a variable name from various type of JPQL Expression.

private ParameterTypeVisitor
parameterTypeVisitor

This visitor is responsible to calculate the closest type of any input parameter.

protected JPQLQueryContext
parent

When this context is a sub-context used for a subquery, then this is the context for the parent query.

private IQuery
query

The external form of the JPQL query being manipulated.

private JPQLQueryContext.QueryExpressionVisitor
queryExpressionVisitor

This visitor is responsible to retrieve the Expression that is the beginning of a query.

private ResolverBuilder
resolverBuilder

This visitor creates a Resolver that gives information about the visited Expression.

private boolean
tolerant

Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries.

private boolean
traversed

Internal flag used to determine if the declaration portion of the query was visited.

Constructor Summary

AccessConstructor and Description
public
JPQLQueryContext(JPQLGrammar
The JPQLGrammar defines how to parse a JPQL query
jpqlGrammar
)

Creates a new JPQLQueryContext.

protected
JPQLQueryContext(JPQLQueryContext
The parent context
parent
,
Expression
The parsed tree representation of the subquery
currentQuery
)

Creates a new sub-JPQLQueryContext.

Method Summary

Modifier and TypeMethod and Description
protected DeclarationResolver
protected DeclarationResolver
protected JPQLQueryContext.InputParameterVisitor
protected abstract JPQLQueryContext
buildJPQLQueryContext(JPQLQueryContext currentContext, Expression currentQuery)

protected abstract LiteralVisitor
protected abstract ParameterTypeVisitor
protected JPQLQueryContext.QueryExpressionVisitor
protected abstract ResolverBuilder
public void
convertUnqualifiedDeclaration(Declaration
The Declaration that was parsed to range over an abstract schema name but is actually ranging over a path expression
declaration
)

Converts the given Declaration from being set as a range variable declaration to a path expression declaration.

public void
dispose()

Disposes the internal data.

public void
disposeSubqueryContext()

Disposes this context, which is the current context being used by a subquery.

public Collection<InputParameter>

Returns:

Either the InputParameters that has the given parameter or an empty collection
findInputParameters
(String
The parameter used to find the InputParameters with the same value
parameterName
)

Retrieves all the InputParameters with the given parameter name.

public Expression

Returns:

Either the top-level query or a subquery
getActualCurrentQuery
()

Returns the current Expression being manipulated, which is either the top-level query or a subquery.

public DeclarationResolver

Returns:

The DeclarationResolver for this context
getActualDeclarationResolver
()

Returns the DeclarationResolver of this context and not from the current query's declaration.

public JPQLQueryContext

Returns:

The active context
getCurrentContext
()

Returns the current JPQLQueryContext, i.e. the context of the query being manipulated, which can either be the top-level query or a subquery.

public Expression

Returns:

Either the top-level query or a subquery
getCurrentQuery
()

Returns the current Expression being manipulated, which is either the top-level query or a subquery.

public Declaration

Returns:

The Declaration containing the information about the identification variable declaration
getDeclaration
(String
The name of the identification variable that is used to navigate a "root" object
variableName
)

Retrieves the Declaration for which the given variable name is used to navigate to the "root" object.

public DeclarationResolver

Returns:

The DeclarationResolver for the current query being visited
getDeclarationResolver
()

Returns the DeclarationResolver of the current query's declaration.

public DeclarationResolver

Returns:

The DeclarationResolver for the current query being visited
getDeclarationResolver
(Expression
The Expression that will be used to retrieve its query expression, i.e. either JPQLExpression or SimpleSelectStatement
expression
)

Returns the DeclarationResolver of the current query's declaration.

protected DeclarationResolver

Returns:

The DeclarationResolver for the current query being visited
getDeclarationResolverImp
()

Returns the DeclarationResolver of the current query's declaration.

public List<Declaration>

Returns:

The Declarations of the current query that was parsed
getDeclarations
()

Returns the ordered list of Declarations.

public IType

Returns:

The external form for the given Enum type
getEnumType
(String
The fully qualified enum type with the constant
enumTypeName
)

Returns the IType representing the possible given enum type.

public ExpressionRegistry

Returns:

The registry containing the information related to the JPQL grammar
getExpressionRegistry
()

Returns the registry containing the JPQLQueryBNFs and the ExpressionFactories that are used to properly parse a JPQL query.

public JPQLGrammar

Returns:

The grammar that was used to parse this Expression
getGrammar
()

Returns the JPQL grammar that will be used to define how to parse a JPQL query.

protected JPQLQueryContext.InputParameterVisitor
public JPAVersion

Returns:

The version of the supported Java Persistence functional specification
getJPAVersion
()

Returns the version of the Java Persistence to support, which dictates which version of the JPQL grammar to support.

public JPQLExpression

Returns:

The parsed tree representation of the JPQL query
getJPQLExpression
()

Returns the parsed tree representation of the JPQL query.

public String

Returns:

The string representation of the JPQL query
getJPQLQuery
()

Returns the string representation of the JPQL query.

protected LiteralVisitor
public IMapping

Returns:

Either the IMapping or null if none exists
getMapping
(Expression
The Expression representing a state field path expression or a collection-valued path expression
expression
)

Returns the IMapping for the field represented by the given Expression.

public IType

Returns:

Either the closest type of the input parameter or null if the type could not be determined
getParameterType
(InputParameter
The InputParameter to retrieve its type
inputParameter
)

Retrieves, if it can be determined, the type of the given InputParameter.

protected ParameterTypeVisitor
public JPQLQueryContext

Returns:

The parent context or null if the current context is the root
getParent
()

Returns the parent context if the current context is not the root context.

public IManagedTypeProvider

Returns:

The object that has access to the application's managed types.
getProvider
()

Retrieves the provider of managed types.

public String

Returns:

The version of the persistence provider, if one is extending the default JPQL grammar defined in the Java Persistence specification, otherwise returns an empty string
getProviderVersion
()

Returns the version of the persistence provider.

public IQuery

Returns:

The external form of the JPQL query
getQuery
()

Returns the external form of the JPQL query.

public Expression

Returns:

The query statement that is the "root" parent of the given Expression
getQueryExpression
(Expression
A child of the "root" Expression to retrieve
expression
)

Retrieves the Expression representing the query statement (either the top-level query JPQLExpression or the subquery SimpleSelectStatement) owning the given Expression.

protected JPQLQueryContext.QueryExpressionVisitor
public Resolver

Returns:

Resolver for the given Expression
getResolver
(Expression
The Expression for which its Resolver will be retrieved
expression
)

Creates or retrieved the cached Resolver for the given Expression.

public Resolver

Returns:

The Resolver mapped with the given identification variable
getResolver
(String
The identification variable that maps a Resolver
variableName
)

Retrieves the Resolver mapped with the given identification variable.

protected ResolverBuilder
public Set<String>

Returns:

The variables identifying the select expressions, if any was defined or an empty set if none were defined
getResultVariables
()

Returns the variables that got defined in the select expression.

public IType

Returns:

The external form of the given type
getType
(Class<?>
The Java type to wrap with an external form
type
)

Retrieves the external type for the given Java type.

public IType

Returns:

Either the IType that was resolved by this Resolver or the IType for IType#UNRESOLVABLE_TYPE if it could not be resolved
getType
(Expression
The Expression for which its type will be calculated
expression
)

Returns the IType of the given Expression.

public IType

Returns:

The external form of the class to retrieve
getType
(String
The fully qualified class name of the class to retrieve
typeName
)

Retrieves the external class with the given fully qualified class name.

public ITypeDeclaration

Returns:

Either the ITypeDeclaration that was resolved by this Resolver or the ITypeDeclaration for IType#UNRESOLVABLE_TYPE if it could not be resolved
getTypeDeclaration
(Expression
The Expression for which its type declaration will be calculated
expression
)

Returns the ITypeDeclaration of the field handled by this Resolver.

public TypeHelper

Returns:

A helper containing a collection of methods related to IType
getTypeHelper
()

Returns a helper that gives access to the most common types.

public ITypeRepository

Returns:

The repository of ITypes
getTypeRepository
()

Returns the type repository for the application.

public boolean

Returns:

true if the query or subquery being traversed contains JOIN expressions; false otherwise
hasJoins
()

Determines whether the JPQL expression has JOIN expressions.

protected void
initialize(JPQLGrammar
The grammar that defines how to parse a JPQL query
jpqlGrammar
)

Initializes this JPQLQueryContext.

protected void
initializeRoot()

Initializes the parsed tree representation of the JPQL query if it has not been set before setting the IQuery.

public boolean

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
isCollectionIdentificationVariable
(String
The identification variable to check for what it maps
variableName
)

Determines whether the given identification variable is defining a join or a collection member declaration expressions.

public boolean

Returns:

true if the variable name is mapping an abstract schema name; false if it's defined in a collection member declaration
isRangeIdentificationVariable
(String
The name of the variable to verify if it's defined in a range variable declaration in the current query or any parent query
variableName
)

Determines whether the given variable name is an identification variable name used to define an abstract schema name.

public boolean

Returns:

true if the given variable is defined as a result variable; false otherwise
isResultVariable
(String
The variable to check if it's a result variable
variable
)

Determines if the given variable is a result variable.

public boolean

Returns:

true if the current context is for a subquery; false for the top-level query
isSubquery
()

Determines whether this JPQLQueryContext currently holds the information of a subquery or for the top-level query.

public boolean

Returns:

true if the parsing system should parse invalid or incomplete queries; false when the query is well-formed and valid
isTolerant
()

Determines if the parser is in tolerant mode or is in fast mode.

public String

Returns:

A value from the given Expression or an empty string if the given Expression and the LiteralType do not match
literal
(Expression
The Expression to visit
expression
,
LiteralType
The LiteralType helps to determine what to retrieve from the visited Expression
type
)

Retrieves the "literal" from the given Expression.

public void
newSubqueryContext(Expression
The parsed tree representation of the subquery that will become the current query
currentQuery
)

Changes the state of this context to use the given subquery.

public void
setJPQLExpression(JPQLExpression
The parsed representation of the JPQL query to manipulate
jpqlExpression
)

Sets the parsed tree representation of the JPQL query.

public void
setQuery(IQuery
The external form of the JPQL query
query
)

Sets the external form of the JPQL query, which will be parsed and information will be extracted for later access.

public void
setTolerant(boolean
Determines if the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
tolerant
)

Sets whether the parser is in tolerant mode or is in fast mode.

protected void
store(JPQLQueryContext
The parent context, which is the context of the parent query
parent
,
Expression
The subquery becoming the current query
currentQuery
)

Stores the information contained in the given parent into this one.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait