Top Description Fields Constructors Methods
org.eclipse.persistence.internal.jpa.jpql

pack-priv final Class JPQLQueryContext

extends Object
Class Inheritance
Imports
java.lang.reflect.Constructor, java.security.AccessController, .PrivilegedActionException, java.util.Collection, .Collections, .HashMap, .HashSet, .List, .Map, .Set, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.expressions.Expression, org.eclipse.persistence.internal.security.PrivilegedAccessHelper, .PrivilegedClassForName, .PrivilegedGetConstructorFor, .PrivilegedInvokeConstructor, org.eclipse.persistence.internal.sessions.AbstractSession, org.eclipse.persistence.jpa.jpql.EclipseLinkLiteralVisitor, .ExpressionTools, .LiteralType, .LiteralVisitor, org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression, .InputParameter, .JPQLExpression, .JPQLGrammar, .Join, .SimpleSelectStatement, .StateFieldPathExpression, org.eclipse.persistence.mappings.DatabaseMapping, org.eclipse.persistence.mappings.querykeys.QueryKey, org.eclipse.persistence.queries.DatabaseQuery, .ReportQuery

This context is used when creating and populating a DatabaseQuery when traversing the parsed representation of a JPQL query.
Authors
Pascal Filion, John Bracken
Since
2.3
Version
2.5

Field Summary

Modifier and TypeField and Description
private 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 static final Class<?>[]
EMPTY_TYPE

An empty array used when the type of an JPQL Expression is not required.

private ExpressionBuilderVisitor
expressionBuilder

The builder that can convert a JPQL Expression into an EclipseLink Expression.

private Map<String, Expression>
expressions

The cached Expressions mapped by a variable name.

pack-priv Map<InputParameter, Expression>
inputParameters

The input parameter name mapped to its type.

private JPQLExpression
jpqlExpression

The parsed representation of the JPQL query.

private JPQLGrammar
jpqlGrammar

The JPQL grammar that defines how to parse a JPQL query.

private CharSequence
jpqlQuery

The JPQL query to convert into an EclipseLink Expression.

private EclipseLinkLiteralVisitor
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.

private JPQLQueryContext
parent

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

private DatabaseQuery
query

The DatabaseQuery being populated by visiting the parsed tree representation of the JPQL query.

private AbstractSession
session

The EclipseLink AbstractSession this context will use.

private TypeResolver
typeResolver

This resolver is used to calculate the type of any JPQL Expression.

private Map<String, Class<?>>
types

The types that have been cached for faster access.

private Set<String>
usedIdentificationVariables

The identification variables that were used in the current query.

Constructor Summary

AccessConstructor and Description
pack-priv
JPQLQueryContext(DatabaseQuery
The DatabaseQuery from which information will be queries
query
,
JPQLGrammar
The JPQL grammar that defines how the JPQL query was parsed
jpqlGrammar
)

Creates a new JPQLQueryContext.

pack-priv
JPQLQueryContext(JPQLGrammar
The JPQL grammar that defines how the JPQL query was parsed
jpqlGrammar
)

Creates a new JPQLQueryContext.

private
JPQLQueryContext(JPQLQueryContext
The parent of this context, which is never null
parent
,
Expression
The parsed tree representation of the subquery
currentQuery
,
ReportQuery
The ReportQuery that will be populated by visiting the parsed tree representation of the subquery
query
)

Creates a new JPQLQueryContext.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addInputParameter(InputParameter
The input parameter
inputParameter
,
Expression
The Expression that can be reused rather than being recreated
queryExpression
)

Caches the given input parameter name with its calculated type.

pack-priv void
addQueryExpression(String
The identification variable name that is the key to store the given Expression
variableName
,
Expression
The Expression that can be reused rather than being recreated
expression
)

Caches the given query Expression for future use.

pack-priv void
addQueryExpressionImp(String
The identification variable name that is the key to store the given Expression
variableName
,
Expression
The Expression that can be reused rather than being recreated
expression
)

Caches the given query Expression for future use.

pack-priv void
addRangeVariableDeclaration(String
The name of the entity to be accessible with the given variable name
entityName
,
String
The identification variable used to navigate to the entity
variableName
)

Adds a virtual range variable declaration that will be used when a JPQL fragment is parsed.

pack-priv void
addUsedIdentificationVariable(String
The identification variable that is used within a clause
variableName
)

Adds the given identification variable, which is done when it's used in a clause, except in the declaration portion of the query.

pack-priv void
addUsedIdentificationVariableImp(String
The identification variable that is used within a clause
variableName
)

Adds the given identification variable, which is done when it's used in a clause, except in the declaration portion of the query.

private <T> Class<T>

Returns:

The Java type if it could be retrieved; null otherwise
attemptLoadType
(String
The fully qualified type name
typeName
)

Retrieves the Java type for the given type name, which has to be the fully qualified type name.

pack-priv Expression

Returns:

The Expression representing the given parsed expression
buildExpression
(Expression
The JPQL Expression to visit and to convert into an Expression
expression
)

Converts the given JPQL Expression into an Expression.

pack-priv Expression

Returns:

The Expression representing the given parsed expression
buildExpression
(Expression
The JPQL Expression to visit and to convert into an Expression
expression
,
Class<?>[]
The given array will be used to store the type of the given expression
type
)

Converts the given JPQL Expression into an Expression.

pack-priv Expression

Returns:

The EclipseLink Expression representation of that path expression
buildGroupByExpression
(CollectionValuedPathExpression
The CollectionValuedPathExpression to convert into an EclipseLink Expression
expression
)

Creates a new EclipseLink Expression by visiting the given JPQL CollectionValuedPathExpression that is used in the GROUP BY clause.

pack-priv Expression

Returns:

The EclipseLink Expression representation of that path expression
buildModifiedPathExpression
(StateFieldPathExpression
The StateFieldPathExpression to convert into an EclipseLink Expression
expression
)

Creates a new EclipseLink Expression by visiting the given JPQL StateFieldPathExpression.

pack-priv ReportQuery

Returns:

A fully initialized ReportQuery
buildSubquery
(SimpleSelectStatement
The SimpleSelectStatement to convert into a ReportQuery
expression
)

Creates a new ReportQuery by visiting the given SimpleSelectStatement.

pack-priv void
cache(AbstractSession
The EclipseLink AbstractSession this context will use
session
,
DatabaseQuery
The DatabaseQuery that may already exist and it will be populated with the information contained in the JPQL query or null if the query will need to be created
query
,
JPQLExpression
The parsed tree representation of the JPQL query
jpqlExpression
,
CharSequence
The JPQL query
jpqlQuery
)

Sets the given named query and string representation of the JPQL query.

pack-priv Class<?>

Returns:

The persistent field type
calculateMappingType
(DatabaseMapping
The DatabaseMapping to retrieve its persistent field type
mapping
)

Returns the type of the given DatabaseMapping, which is the persistent field type.

pack-priv Class<?>

Returns:

The persistent field type
calculateQueryKeyType
(QueryKey
The QueryKey to retrieve its persistent field type
queryKey
)

Returns the type of the given QueryKey, which is the persistent field type.

pack-priv void
disposeSubqueryContext()

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

private ExpressionBuilderVisitor
pack-priv Declaration

Returns:

The Declaration containing the information about the identification variable declaration
findDeclaration
(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.

pack-priv Declaration
findDeclarationImp(String variableName)

pack-priv Expression

Returns:

The cached Expression associated with the given variable name or null if none was cached.
findQueryExpression
(String
The variable name for which its associated Expression is requested
variableName
)

Retrieves the cached Expression associated with the given variable name.

pack-priv Expression
pack-priv JPQLQueryContext

Returns:

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

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

pack-priv Expression

Returns:

The root Expression of the query or subquery
getBaseExpression
()

Returns the root Expression for which all new expressions a child.

private ClassLoader

Returns:

The application's ClassLoader
getClassLoader
()

Returns the ClassLoader used by EclipseLink to load the application's classes.

pack-priv <T> Constructor<T>

Returns:

The Constructor or null if none exist or the privilege access was denied
getConstructor
(Class<T>
The Java type for which its constructor should be retrieved
type
,
Class<?>[]
The types of the constructor's parameters
parameterTypes
)

Returns the Constructor for the given Java Class.

pack-priv 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.

pack-priv 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.

pack-priv <T extends DatabaseQuery> T

Returns:

The DatabaseQuery being populated, which can be the top-level query or a subquery depending on which query is been visited
getDatabaseQuery
()

Returns the current DatabaseQuery being populated.

pack-priv 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.

pack-priv DeclarationResolver

Returns:

The DeclarationResolver for the current query being visited
getDeclarationResolver
()

Returns the DeclarationResolver of the current query's declaration.

pack-priv DeclarationResolver

Returns:

The DeclarationResolver for the current query being visited
getDeclarationResolverImp
()

Returns the DeclarationResolver of the current query's declaration.

pack-priv List<Declaration>

Returns:

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

Returns the ordered list of Declarations.

pack-priv ClassDescriptor

Returns:

The EclipseLink descriptor representing the managed type
getDescriptor
(Class<?>
The type associated with the descriptor
type
)

Retrieves the descriptor associated with the given type.

pack-priv ClassDescriptor

Returns:

The EclipseLink descriptor representing the managed type
getDescriptor
(String
The managed type name associated with the managed type
abstractSchemaName
)

Retrieves the descriptor associated with the given abstract schema name, which is the descriptor's alias.

pack-priv Class<?>

Returns:

The external form for the given Enum type or null if none exists
getEnumType
(String
The fully qualified enum type with the constant
enumTypeName
)

Returns the Class representing the possible given enum constant.

pack-priv Declaration

Returns:

The first Declaration object
getFirstDeclaration
()

Returns the first Declaration of the current context that was created after visiting the declaration clause.

pack-priv Declaration

Returns:

The first Declaration object
getFirstDeclarationImp
()

Returns the first Declaration, from this context, that was created after visiting the declaration clause.

pack-priv JPQLGrammar

Returns:

The JPQLGrammar that was used to parse the JPQL query
getGrammar
()

Returns the JPQLGrammar that defines how the JPQL query was parsed.

pack-priv Collection<Join>

Returns:

The JOIN FETCH expressions used in the same declaration or an empty collection if none was defined
getJoinFetches
(String
The name of the identification variable that should be used to define an abstract schema name
variableName
)

Returns the parsed representation of a JOIN FETCH that were defined in the same declaration than the given range identification variable name.

pack-priv JPQLExpression

Returns:

The parsed tree representation of the JPQL query
getJPQLExpression
()

Returns the parsed tree representation of the JPQL query.

pack-priv CharSequence

Returns:

The string representation of the JPQL query
getJPQLQuery
()

Returns the string representation of the JPQL query.

pack-priv Class<?>

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.

pack-priv 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.

pack-priv Expression

Returns:

The cached Expression associated with the given variable name or null if none was cached.
getQueryExpression
(String
The variable name for which its associated Expression is requested
variableName
)

Retrieves the cached Expression associated with the given variable name.

pack-priv Expression

Returns:

The cached Expression associated with the given variable name or null if none was cached.
getQueryExpressionImp
(String
The variable name for which its associated Expression is requested
variableName
)

Retrieves the cached Expression associated with the given variable name.

pack-priv AbstractSession

Returns:

The current EclipseLink session
getSession
()

Returns the EclipseLink AbstractSession that this query will execute against, which gives access to the JPA artifacts.

pack-priv Class<?>

Returns:

Either the Java class that was resolved or the null if it could not be resolved
getType
(Expression
The Expression for which its type will be calculated
expression
)

Returns the Java class of the given Expression.

pack-priv Class<?>

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 for the given fully qualified class name.

private Map<String, Class<?>>
pack-priv Set<String>

Returns:

The identification variables that were used throughout the current query at the exception of their declaration
getUsedIdentificationVariables
()

Returns the identification variables that was used in the current query.

pack-priv Set<String>

Returns:

The identification variables that were used throughout the current query at the exception of their declaration
getUsedIdentificationVariablesImp
()

Returns the identification variables that are registered in this context.

pack-priv 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.

pack-priv boolean

Returns:

true if the identification is used in a clause, at the exception of where it was defined; false otherwise
isIdentificationVariableUsed
(String
The identification variable to check if it was used in a clause
variableName
)

Determines whether the given identification variable is used, at the exception of where it was defined.

private boolean
pack-priv 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.

pack-priv 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
variableName
)

Determines if the given variable is a result variable.

pack-priv 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.

private LiteralVisitor
private Class<?>
private Class<?>
loadTypeImp(String typeName)

pack-priv <T> T

Returns:

A new instance or null if a problem was encountered during instantiation
newInstance
(Class<T>
The Java type for which a new instance will be created
type
,
Class<?>
The type of the constructor's single parameter
parameterType
,
Object
The object to pass during instantiation
parameter
)

Creates a new instance from the given Java type.

pack-priv <T> T

Returns:

A new instance of the given type or null if a problem was encountered during instantiation
newInstance
(Class<T>
The Java type for which a new instance will be created
type
,
Class<?>[]
The types of the constructor's parameters
parameterTypes
,
Object[]
The objects to pass during instantiation
parameters
)

Creates a new instance from the given Java type.

pack-priv <T> T

Returns:

A new instance or null if a problem was encountered during instantiation
newInstance
(Constructor<T>
The constructor used to create the new instance
constructor
,
Object[]
The objects to pass during instantiation
parameters
)

Creates a new instance by using the given constructor.

pack-priv void
newSubQueryContext(Expression
The parsed tree representation of the subquery that will become the current DatabaseQuery
currentQuery
,
ReportQuery
The ReportQuery for the subquery
query
)

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

private ParameterTypeVisitor
private JPQLExpression
parse(String jpqlQuery)

pack-priv ClassDescriptor
resolveDescriptor(Expression expression)

Resolves the given Expression and returns the corresponding descriptor.

pack-priv DatabaseMapping

Returns:

The DatabaseMapping that is representing the last path or null if the path expression could not be resolved
resolveMapping
(Expression
The Expression to resolve by traversing its path expression
expression
)

Resolves the given Expression and returns the DatabaseMapping.

pack-priv Object

Returns:

Either the DatabaseMapping or the QueryKey that is representing the last path or null if the path expression could not be resolved
resolveMappingObject
(Expression
The Expression to resolve by traversing its path expression
expression
)

Resolves the given Expression and either returns the DatabaseMapping or the QueryKey object.

pack-priv void
setDatabasQuery(DatabaseQuery
The DatabaseQuery that was created before populating it
query
)

Sets the query to populate.

pack-priv TypeResolver
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait