Class JavaQueryCompiler
- java.lang.Object
-
- org.datanucleus.store.query.compiler.JavaQueryCompiler
-
- All Implemented Interfaces:
SymbolResolver
- Direct Known Subclasses:
JDOQLCompiler,JPQLCompiler
public abstract class JavaQueryCompiler extends java.lang.Object implements SymbolResolver
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
Fields Modifier and Type Field Description protected java.lang.StringcandidateAliasAlias for the primary candidate.protected java.lang.StringcandidateAliasOrigDefault candidate alias in use (only set when in a subquery and the same as the outer query).protected java.lang.ClasscandidateClassPrimary candidate class (if defined).protected java.util.Collectioncandidatesprotected booleancaseSensitiveAliasesprotected ClassLoaderResolverclrprotected java.lang.Stringfilterprotected java.lang.Stringfromprotected java.lang.Stringgroupingprotected java.lang.Stringhavingprotected Importsimportsstatic java.lang.StringJOIN_INNERstatic java.lang.StringJOIN_INNER_FETCHstatic java.lang.StringJOIN_OUTERstatic java.lang.StringJOIN_OUTER_FETCHstatic java.lang.StringJOIN_OUTER_FETCH_RIGHTstatic java.lang.StringJOIN_OUTER_RIGHTprotected MetaDataManagermetaDataManagerprotected java.util.Map<java.lang.String,java.lang.Object>optionsprotected java.lang.Stringorderingprotected java.lang.Stringparametersprotected intparameterSubstitutionNumberprotected java.util.Map<java.lang.Object,java.lang.String>parameterSubtitutionMapprotected JavaQueryCompilerparentCompilerprotected ParserparserParser specific to the type of query being compiled.protected QueryManagerqueryMgrprotected java.lang.Stringresultprotected SymbolTablesymtblCompiled Symbol Table.protected java.lang.Stringupdateprotected java.lang.Stringvariables
-
Constructor Summary
Constructors Constructor Description JavaQueryCompiler(PersistenceNucleusContext nucCtx, ClassLoaderResolver clr, java.lang.String from, java.lang.Class candidateClass, java.util.Collection candidates, java.lang.String filter, Imports imports, java.lang.String ordering, java.lang.String result, java.lang.String grouping, java.lang.String having, java.lang.String params, java.lang.String variables, java.lang.String update)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract QueryCompilationcompile(java.util.Map parameters, java.util.Map<java.lang.String,java.lang.Object> subqueryMap)Method to compile the query.private voidcompileCandidates()voidcompileCandidatesParametersVariables(java.util.Map parameters)Compile the candidates, variables and parameters.ExpressioncompileFilter()Compile the filter and return the compiled expression.protected Expression[]compileFrom()Method to compile the "from" clause (if present for the query language).Expression[]compileGrouping()ExpressioncompileHaving()Expression[]compileOrdering()private voidcompileParameters()Expression[]compileResult()Expression[]compileUpdate()private voidcompileVariables()private java.lang.ClassgetClassForSubqueryClassExpression(java.lang.String classExpr)Convenience method to find the class that a subquery class expression refers to.abstract java.lang.StringgetLanguage()Accessor for the query language name.java.lang.ClassgetPrimaryClass()Accessor for the candidate class of the query.(package private) java.lang.ClassgetType(java.lang.Class cls, java.lang.String fieldName, boolean lastEntry)java.lang.ClassgetType(java.util.List<java.lang.String> tuples)protected abstract booleanisKeyword(java.lang.String name)Method to return if the supplied name is a keyword.java.lang.ClassresolveClass(java.lang.String className)Method to perform a lookup of the class name from the input name.voidsetLinkToParentQuery(JavaQueryCompiler parentCompiler, java.util.Map<java.lang.Object,java.lang.String> paramSubstitutionMap)Method to set the linkage to the parent query.voidsetOption(java.lang.String name, java.lang.Object value)protected voidswapCandidateAliasNodeName(Node node)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 NodeswapSubqueryParameters(Node node)Convenience method that takes the input node if it is a parameter node and swaps the node-
Methods 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 Detail
-
JOIN_INNER
public static final java.lang.String JOIN_INNER
- See Also:
- Constant Field Values
-
JOIN_INNER_FETCH
public static final java.lang.String JOIN_INNER_FETCH
- See Also:
- Constant Field Values
-
JOIN_OUTER
public static final java.lang.String JOIN_OUTER
- See Also:
- Constant Field Values
-
JOIN_OUTER_FETCH
public static final java.lang.String JOIN_OUTER_FETCH
- See Also:
- Constant Field Values
-
JOIN_OUTER_RIGHT
public static final java.lang.String JOIN_OUTER_RIGHT
- See Also:
- Constant Field Values
-
JOIN_OUTER_FETCH_RIGHT
public static final java.lang.String JOIN_OUTER_FETCH_RIGHT
- See Also:
- Constant Field Values
-
queryMgr
protected QueryManager queryMgr
-
parentCompiler
protected JavaQueryCompiler parentCompiler
-
parameterSubtitutionMap
protected java.util.Map<java.lang.Object,java.lang.String> parameterSubtitutionMap
-
parameterSubstitutionNumber
protected int parameterSubstitutionNumber
-
metaDataManager
protected final MetaDataManager metaDataManager
-
clr
protected final ClassLoaderResolver clr
-
caseSensitiveAliases
protected boolean caseSensitiveAliases
-
candidateClass
protected java.lang.Class candidateClass
Primary candidate class (if defined).
-
candidateAlias
protected java.lang.String candidateAlias
Alias for the primary candidate. Default to "this" (JDOQL) but can be set.
-
candidateAliasOrig
protected java.lang.String candidateAliasOrig
Default candidate alias in use (only set when in a subquery and the same as the outer query).
-
from
protected java.lang.String from
-
candidates
protected java.util.Collection candidates
-
update
protected java.lang.String update
-
filter
protected java.lang.String filter
-
ordering
protected java.lang.String ordering
-
parameters
protected java.lang.String parameters
-
variables
protected java.lang.String variables
-
grouping
protected java.lang.String grouping
-
having
protected java.lang.String having
-
result
protected java.lang.String result
-
imports
protected Imports imports
-
symtbl
protected SymbolTable symtbl
Compiled Symbol Table.
-
parser
protected Parser parser
Parser specific to the type of query being compiled.
-
options
protected java.util.Map<java.lang.String,java.lang.Object> options
-
-
Constructor Detail
-
JavaQueryCompiler
public JavaQueryCompiler(PersistenceNucleusContext nucCtx, ClassLoaderResolver clr, java.lang.String from, java.lang.Class candidateClass, java.util.Collection candidates, java.lang.String filter, Imports imports, java.lang.String ordering, java.lang.String result, java.lang.String grouping, java.lang.String having, java.lang.String params, java.lang.String variables, java.lang.String update)
-
-
Method Detail
-
getLanguage
public abstract java.lang.String getLanguage()
Accessor for the query language name.- Returns:
- Name of the query language.
-
setOption
public void setOption(java.lang.String name, java.lang.Object value)
-
setLinkToParentQuery
public void setLinkToParentQuery(JavaQueryCompiler parentCompiler, java.util.Map<java.lang.Object,java.lang.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
public abstract QueryCompilation compile(java.util.Map parameters, java.util.Map<java.lang.String,java.lang.Object> subqueryMap)
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
public void compileCandidatesParametersVariables(java.util.Map parameters)
Compile the candidates, variables and parameters.- Parameters:
parameters- Map of parameter values keyed by their name
-
compileFrom
protected Expression[] compileFrom()
Method to compile the "from" clause (if present for the query language).- Returns:
- The compiled from expression(s)
-
getClassForSubqueryClassExpression
private java.lang.Class getClassForSubqueryClassExpression(java.lang.String classExpr)
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
public Expression[] compileUpdate()
-
compileFilter
public Expression compileFilter()
Compile the filter and return the compiled expression.- Returns:
- The compiled expression
-
swapCandidateAliasNodeName
protected void swapCandidateAliasNodeName(Node node)
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
protected Node swapSubqueryParameters(Node node)
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
public Expression[] compileResult()
-
compileGrouping
public Expression[] compileGrouping()
-
compileHaving
public Expression compileHaving()
-
compileVariables
private void compileVariables()
-
compileParameters
private void compileParameters()
-
compileOrdering
public Expression[] compileOrdering()
-
getPrimaryClass
public java.lang.Class getPrimaryClass()
Description copied from interface:SymbolResolverAccessor for the candidate class of the query.- Specified by:
getPrimaryClassin interfaceSymbolResolver- Returns:
- The candidate class
-
resolveClass
public java.lang.Class resolveClass(java.lang.String className)
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:
resolveClassin 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
public java.lang.Class getType(java.util.List<java.lang.String> tuples)
- Specified by:
getTypein interfaceSymbolResolver
-
getType
java.lang.Class getType(java.lang.Class cls, java.lang.String fieldName, boolean lastEntry)
-
isKeyword
protected abstract boolean isKeyword(java.lang.String name)
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
-
-