Class JavaQueryCompiler
java.lang.Object
org.datanucleus.store.query.compiler.JavaQueryCompiler
- All Implemented Interfaces:
SymbolResolver
- Direct Known Subclasses:
JDOQLCompiler
,JPQLCompiler
Typical implementation of a compiler for a java-based query language.
The constructor takes in the components of the query, and the method compile() compiles it
returning the compiled query, for use elsewhere.
Each "Expression" is effectively a tree of Expressions. You can navigate through each expression based on their type. For example, a DyadicExpression has a "left" and "right" and an operator between them. The left could also be a DyadicExpression, so you would navigate to its left/right components etc etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
Alias for the primary candidate.protected String
Default candidate alias in use (only set when in a subquery and the same as the outer query).protected Class
Primary candidate class (if defined).protected Collection
protected boolean
protected final ClassLoaderResolver
protected String
protected String
protected String
protected String
protected Imports
static final String
static final String
static final String
static final String
static final String
static final String
protected final MetaDataManager
protected String
protected String
protected int
protected JavaQueryCompiler
protected Parser
Parser specific to the type of query being compiled.protected QueryManager
protected String
protected SymbolTable
Compiled Symbol Table.protected String
protected String
-
Constructor Summary
ConstructorsConstructorDescriptionJavaQueryCompiler
(PersistenceNucleusContext nucCtx, ClassLoaderResolver clr, String from, Class candidateClass, Collection candidates, String filter, Imports imports, String ordering, String result, String grouping, String having, String params, String variables, String update) -
Method Summary
Modifier and TypeMethodDescriptionabstract QueryCompilation
Method to compile the query.private void
void
compileCandidatesParametersVariables
(Map parameters) Compile the candidates, variables and parameters.Compile the filter and return the compiled expression.protected Expression[]
Method to compile the "from" clause (if present for the query language).private void
private void
private Class
getClassForSubqueryClassExpression
(String classExpr) Convenience method to find the class that a subquery class expression refers to.abstract String
Accessor for the query language name.Accessor for the candidate class of the query.(package private) Class
protected abstract boolean
Method to return if the supplied name is a keyword.resolveClass
(String className) Method to perform a lookup of the class name from the input name.void
setLinkToParentQuery
(JavaQueryCompiler parentCompiler, Map<Object, String> paramSubstitutionMap) Method to set the linkage to the parent query.void
protected void
Convenience method that takes the input node and if it is set to the original candidate alias then swaps the value to the candidate alias.protected Node
swapSubqueryParameters
(Node node) Convenience method that takes the input node if it is a parameter node and swaps the nodeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.datanucleus.store.query.compiler.SymbolResolver
caseSensitiveSymbolNames, supportsImplicitVariables
-
Field Details
-
JOIN_INNER
- See Also:
-
JOIN_INNER_FETCH
- See Also:
-
JOIN_OUTER
- See Also:
-
JOIN_OUTER_FETCH
- See Also:
-
JOIN_OUTER_RIGHT
- See Also:
-
JOIN_OUTER_FETCH_RIGHT
- See Also:
-
queryMgr
-
parentCompiler
-
parameterSubtitutionMap
-
parameterSubstitutionNumber
protected int parameterSubstitutionNumber -
metaDataManager
-
clr
-
caseSensitiveAliases
protected boolean caseSensitiveAliases -
candidateClass
Primary candidate class (if defined). -
candidateAlias
Alias for the primary candidate. Default to "this" (JDOQL) but can be set. -
candidateAliasOrig
Default candidate alias in use (only set when in a subquery and the same as the outer query). -
from
-
candidates
-
update
-
filter
-
ordering
-
parameters
-
variables
-
grouping
-
having
-
result
-
imports
-
symtbl
Compiled Symbol Table. -
parser
Parser specific to the type of query being compiled. -
options
-
-
Constructor Details
-
JavaQueryCompiler
public JavaQueryCompiler(PersistenceNucleusContext nucCtx, ClassLoaderResolver clr, String from, Class candidateClass, Collection candidates, String filter, Imports imports, String ordering, String result, String grouping, String having, String params, String variables, String update)
-
-
Method Details
-
getLanguage
Accessor for the query language name.- Returns:
- Name of the query language.
-
setOption
-
setLinkToParentQuery
public void setLinkToParentQuery(JavaQueryCompiler parentCompiler, Map<Object, String> paramSubstitutionMap) Method to set the linkage to the parent query.- Parameters:
parentCompiler
- Compiler for the parent queryparamSubstitutionMap
- Map of parameters in this subquery and what they are in the parent query.
-
compile
Method to compile the query.- Parameters:
parameters
- The parameter values keyed by name.subqueryMap
- Map of subqueries keyed by the subquery name- Returns:
- The query compilation
-
compileCandidatesParametersVariables
Compile the candidates, variables and parameters.- Parameters:
parameters
- Map of parameter values keyed by their name
-
compileFrom
Method to compile the "from" clause (if present for the query language).- Returns:
- The compiled from expression(s)
-
getClassForSubqueryClassExpression
Convenience method to find the class that a subquery class expression refers to. Allows for reference to the parent query candidate class, or to a class name.- Parameters:
classExpr
- The class expression- Returns:
- The class that it refers to
-
compileCandidates
private void compileCandidates() -
compileUpdate
-
compileFilter
Compile the filter and return the compiled expression.- Returns:
- The compiled expression
-
swapCandidateAliasNodeName
Convenience method that takes the input node and if it is set to the original candidate alias then swaps the value to the candidate alias. This is for the situation where we have a subquery which had no alias defined so defaults to "this" (the same as the outer query), so we change the subquery alias from "this" to "sub_this".- Parameters:
node
- The node to process
-
swapSubqueryParameters
Convenience method that takes the input node if it is a parameter node and swaps the node- Parameters:
node
- The node to process- Returns:
- The Node with the swap
-
compileResult
-
compileGrouping
-
compileHaving
-
compileVariables
private void compileVariables() -
compileParameters
private void compileParameters() -
compileOrdering
-
getPrimaryClass
Description copied from interface:SymbolResolver
Accessor for the candidate class of the query.- Specified by:
getPrimaryClass
in interfaceSymbolResolver
- Returns:
- The candidate class
-
resolveClass
Method to perform a lookup of the class name from the input name. Makes use of the query "imports" and the lookup to "entity name".- Specified by:
resolveClass
in interfaceSymbolResolver
- Parameters:
className
- Name of the class- Returns:
- The class corresponding to this name
- Throws:
ClassNotResolvedException
- thrown if not resolvable using imports or entity name
-
getType
- Specified by:
getType
in interfaceSymbolResolver
-
getType
-
isKeyword
Method to return if the supplied name is a keyword. Keywords can only appear at particular places in a query so we need to detect for valid queries.- Parameters:
name
- The name- Returns:
- Whether it is a keyword
-