|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.datanucleus.store.rdbms.query.QueryCompiler
public abstract class QueryCompiler
Base definition of a query compiler for a query language. Should be extended to compile details of individual query languages. This was designed for the old-style compilation process, and is being phased out. New implementations of querying in DataNucleus should make use of compilers under "org.datanucleus.query.compiler".
| Field Summary | |
|---|---|
protected java.lang.String |
candidateAlias
Alias for the candidate class. |
protected java.lang.Class |
candidateClass
Candidate class for the query. |
protected org.datanucleus.metadata.AbstractClassMetaData |
candidateCmd
ClassMetaData for the candidate. |
protected org.datanucleus.store.mapped.expression.Queryable |
candidates
Candidates for the query. |
static int |
COMPILE_EXECUTION
|
static int |
COMPILE_EXPLICIT_PARAMETERS
|
static int |
COMPILE_EXPLICIT_VARIABLES
|
static int |
COMPILE_SYNTAX
|
protected boolean |
executionCompile
Flag for whether the current compile is for execution (using param values). |
protected java.util.Map<java.lang.String,org.datanucleus.store.mapped.expression.ScalarExpression> |
expressionsByVariableName
|
protected org.datanucleus.util.Imports |
imports
Imports to use for the resolution of classes. |
protected java.lang.String |
language
Language of this query (e.g JDOQL, JPQL). |
protected static org.datanucleus.util.Localiser |
LOCALISER
Localiser for messages. |
protected Parser |
p
Parser for the query. |
protected java.util.List<java.lang.String> |
parameterNames
The parameter names. |
protected java.util.Map |
parameters
Map of parameter values, keyed by their name. |
protected java.util.Map<java.lang.String,java.lang.Class> |
parameterTypesByName
Look-up for the parameter types, keyed by the name. |
protected org.datanucleus.store.mapped.expression.QueryExpression |
parentExpr
Parent query expression (if this is a subquery). |
protected org.datanucleus.store.mapped.expression.QueryExpression |
qs
QueryExpression for this query. |
protected org.datanucleus.store.query.Query |
query
The query being compiled. |
protected long |
rangeFromIncl
Range from position (inclusive). |
protected long |
rangeToExcl
Range to position (exclusive). |
protected java.lang.Class |
resultClass
Result class to be used. |
protected QueryResultsMetaData |
resultMetaData
ResultMetaData for the query (set in the compile process, so is null before that). |
protected java.lang.String |
subqueryCandidateExpr
Candidate expression when treating as a subquery. |
protected org.datanucleus.store.rdbms.query.QueryCompiler.AliasJoinInformation |
subqueryCandidateExprRootAliasInfo
Alias join info for the subquery candidate expression root (if not using parent query candidate). |
protected static java.util.Map |
userDefinedScalarExpressions
Register of user-defined ScalarExpression, provided via plugins. |
protected java.util.List<java.lang.String> |
variableNames
List of variable names. |
protected java.util.Map<java.lang.String,java.lang.Class> |
variableTypesByName
Look-up for the variables types, keyed by the name. |
| Constructor Summary | |
|---|---|
QueryCompiler(org.datanucleus.store.query.Query query,
org.datanucleus.util.Imports imports,
java.util.Map parameters)
Constructor for a compiler of java queries. |
|
| Method Summary | |
|---|---|
void |
bindVariable(java.lang.String name,
org.datanucleus.store.mapped.expression.ScalarExpression expr)
Bind a variable to the query. |
protected org.datanucleus.store.mapped.expression.ScalarExpression |
callUserDefinedScalarExpression(java.lang.String method)
Instanciate a ScalarExpression and invoke a method |
protected void |
checkExpressionsAgainstGrouping(org.datanucleus.store.mapped.expression.ScalarExpression[] exprs,
org.datanucleus.store.mapped.expression.ScalarExpression[] groupExprs,
java.lang.String localiserErrorString)
Convenience method to check the expressions against those specified in the grouping. |
protected void |
checkVariableBinding()
Convenience method to check that all variables have been bound to the query. |
void |
close()
Method to close the Compiler. |
java.lang.Object |
compile(int type)
Method to compile the query. |
protected org.datanucleus.store.mapped.expression.ScalarExpression |
compileAdditiveExpression()
|
protected abstract void |
compileCandidates()
Convenience method to process the candidates for this query. |
protected org.datanucleus.store.mapped.expression.ScalarExpression |
compileCastExpression()
|
protected void |
compileExplicitParameters()
Method to compile all parameters declared for this query. |
protected org.datanucleus.store.mapped.expression.ScalarExpression |
compileExplicitVariable(java.lang.String id)
Method to compile an explicit variable. |
protected void |
compileExplicitVariables()
Method to compile all variables declared for this query. |
protected abstract org.datanucleus.store.mapped.expression.ScalarExpression |
compileExpression()
Principal method for compiling an expression. |
protected abstract org.datanucleus.store.mapped.expression.ScalarExpression |
compileExpressionFromString(java.lang.String str)
Convenience method to parse an expression string into its query expression. |
protected org.datanucleus.store.mapped.expression.ScalarExpression[] |
compileExpressionsFromString(java.lang.String str)
Convenience method to parse an expression string into its component query expressions. |
protected void |
compileFilter(org.datanucleus.store.mapped.expression.QueryExpression qs,
java.lang.String filter)
Convenience method to compile the filter. |
protected void |
compileGrouping(org.datanucleus.store.mapped.expression.QueryExpression qs,
java.lang.String groupingClause)
Convenience method to compile the grouping. |
protected void |
compileHaving(org.datanucleus.store.mapped.expression.QueryExpression qs,
java.lang.String havingClause)
Convenience method to compile the having clause |
protected org.datanucleus.store.mapped.expression.ScalarExpression |
compileLiteral()
A literal is one value of any type. |
protected org.datanucleus.store.mapped.expression.ScalarExpression |
compileMultiplicativeExpression()
|
protected org.datanucleus.store.mapped.expression.ScalarExpression |
compileNewObject()
Method to generate an expression for a new object. |
protected abstract org.datanucleus.store.mapped.expression.ScalarExpression |
compilePrimary()
Compiles a primary. |
protected void |
compileRange(org.datanucleus.store.mapped.expression.QueryExpression qs)
Convenience method to compile the range. |
protected void |
compileResult(org.datanucleus.store.mapped.expression.QueryExpression qs,
java.lang.String result)
Compile the result expressions and class. |
protected void |
compileSubqueryCandidateExpression(boolean caseSensitive)
Method to process any " |
protected org.datanucleus.store.mapped.expression.ScalarExpression |
compileUnaryExpression()
|
protected org.datanucleus.store.mapped.expression.ScalarExpression |
compileUnaryExpressionNotPlusMinus()
|
protected org.datanucleus.store.mapped.expression.QueryExpression |
executionCompile()
Method to execution-compile the query. |
java.lang.String |
getCandidateAlias()
Accessor for the candidate alias. |
java.lang.Class |
getCandidateClass()
Accessor for the candidate class. |
org.datanucleus.store.mapped.expression.Queryable |
getCandidates()
Accessor for the candidates for the query. |
java.lang.String[] |
getParameterNames()
Accessor for the (explicit) parameter names. |
java.util.Map |
getParameterTypesByName()
Accessor for the parameter types keyed by the parameter name. |
long |
getRangeFromIncl()
Accessor for the range "from" value. |
long |
getRangeToExcl()
Accessor for the range "to" value. |
java.lang.Class |
getResultClass()
Accessor for the result class. |
QueryResultsMetaData |
getResultMetaData()
Accessor for the result MetaData. |
static java.util.Map |
getUserDefinedScalarExpressions()
Accessor for the user-defined scalar expressions. |
protected abstract void |
performCompile(org.datanucleus.store.mapped.expression.QueryExpression qs)
Perform the actual compilation of the query. |
protected void |
preCompile()
Method to provide pre-compilation checks to catch errors. |
static void |
registerScalarExpression(java.lang.Class literal,
java.lang.Class scalarExpressionClass,
java.lang.String name)
Register ScalarExpressions for the given cls. |
protected void |
registerScalarExpressions(org.datanucleus.plugin.PluginManager pluginMgr,
org.datanucleus.ClassLoaderResolver clr)
Register ScalarExpression classes delcared as plug-ins extensions |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int COMPILE_EXPLICIT_PARAMETERS
public static final int COMPILE_EXPLICIT_VARIABLES
public static final int COMPILE_SYNTAX
public static final int COMPILE_EXECUTION
protected static final org.datanucleus.util.Localiser LOCALISER
protected java.lang.String language
protected org.datanucleus.store.query.Query query
protected org.datanucleus.util.Imports imports
protected java.util.Map parameters
protected boolean executionCompile
protected java.lang.Class candidateClass
protected java.lang.String candidateAlias
protected java.util.List<java.lang.String> parameterNames
protected java.util.Map<java.lang.String,java.lang.Class> parameterTypesByName
protected java.util.List<java.lang.String> variableNames
protected java.util.Map<java.lang.String,java.lang.Class> variableTypesByName
protected QueryResultsMetaData resultMetaData
protected org.datanucleus.store.mapped.expression.QueryExpression qs
protected org.datanucleus.store.mapped.expression.QueryExpression parentExpr
protected java.util.Map<java.lang.String,org.datanucleus.store.mapped.expression.ScalarExpression> expressionsByVariableName
protected Parser p
protected org.datanucleus.metadata.AbstractClassMetaData candidateCmd
protected org.datanucleus.store.mapped.expression.Queryable candidates
protected java.lang.Class resultClass
protected long rangeFromIncl
protected long rangeToExcl
protected java.lang.String subqueryCandidateExpr
protected org.datanucleus.store.rdbms.query.QueryCompiler.AliasJoinInformation subqueryCandidateExprRootAliasInfo
protected static transient java.util.Map userDefinedScalarExpressions
| Constructor Detail |
|---|
public QueryCompiler(org.datanucleus.store.query.Query query,
org.datanucleus.util.Imports imports,
java.util.Map parameters)
query - The query to compileimports - The imports to useparameters - Any parameters| Method Detail |
|---|
public void close()
public java.lang.Object compile(int type)
type - Type of compilation. This compiler only supports explicit parameters, explicit variables
protected void preCompile()
protected org.datanucleus.store.mapped.expression.QueryExpression executionCompile()
protected abstract void performCompile(org.datanucleus.store.mapped.expression.QueryExpression qs)
qs - The QueryExpression to use during compilation (if required)protected abstract void compileCandidates()
public QueryResultsMetaData getResultMetaData()
public org.datanucleus.store.mapped.expression.Queryable getCandidates()
public java.lang.Class getResultClass()
public long getRangeFromIncl()
public long getRangeToExcl()
public java.lang.Class getCandidateClass()
public java.lang.String getCandidateAlias()
public java.lang.String[] getParameterNames()
public java.util.Map getParameterTypesByName()
protected void compileExplicitParameters()
protected void compileExplicitVariables()
protected void compileSubqueryCandidateExpression(boolean caseSensitive)
Method to process any "this.department.employees
would result in a table expression for the
Department table being added to this subquery FROM, with an INNER JOIN to the subquery candidate table,
and an AND condition from the Department table back to the outer query candidate table.
The subqueryCandidateExpr should either start "this." (hence from the parent query candidate) or, if not, the "subqueryCandidateExprRootAliasInfo" will be set and will define the candidate root of the subquery candidate expression. This second use is used in JPQL where we have a subquery using a field of another alias from the parent query e.g
SELECT c FROM Customer c JOIN c.orders o WHERE EXISTS (SELECT o FROM o.lineItems l where l.quantity > 3)so "o" is the root alias for the subquery, and the "subqueryCandidateExprRootAliasInfo" will define the table expression in the parent query, and the class it represents.
protected void compileFilter(org.datanucleus.store.mapped.expression.QueryExpression qs,
java.lang.String filter)
qs - The Query Expression to apply the filter to (if specified)filter - The filter specification
protected void compileResult(org.datanucleus.store.mapped.expression.QueryExpression qs,
java.lang.String result)
qs - Query Expression to apply the result to (if required)result - Result clause to compile
protected void compileGrouping(org.datanucleus.store.mapped.expression.QueryExpression qs,
java.lang.String groupingClause)
qs - The QueryExpression to update (if specified)groupingClause - The grouping clause string
protected void compileHaving(org.datanucleus.store.mapped.expression.QueryExpression qs,
java.lang.String havingClause)
qs - The QueryExpression to update (if specified)havingClause - The having clause stringprotected void compileRange(org.datanucleus.store.mapped.expression.QueryExpression qs)
qs - QueryExpression to apply the range to (if specified)
protected void checkExpressionsAgainstGrouping(org.datanucleus.store.mapped.expression.ScalarExpression[] exprs,
org.datanucleus.store.mapped.expression.ScalarExpression[] groupExprs,
java.lang.String localiserErrorString)
exprs - The expressions to checkgroupExprs - The grouping expressionslocaliserErrorString - Name of a localiser error message to throw as the JPOXUserException message.
public void bindVariable(java.lang.String name,
org.datanucleus.store.mapped.expression.ScalarExpression expr)
bindVariable in interface org.datanucleus.store.mapped.expression.UnboundVariable.VariableBindername - Name of the variableexpr - The expressionprotected void checkVariableBinding()
org.datanucleus.exceptions.NucleusUserException - Thrown if a variable is found that is not bound.protected org.datanucleus.store.mapped.expression.ScalarExpression[] compileExpressionsFromString(java.lang.String str)
str - The string
protected abstract org.datanucleus.store.mapped.expression.ScalarExpression compileExpressionFromString(java.lang.String str)
str - The string
protected abstract org.datanucleus.store.mapped.expression.ScalarExpression compileExpression()
protected org.datanucleus.store.mapped.expression.ScalarExpression compileAdditiveExpression()
protected org.datanucleus.store.mapped.expression.ScalarExpression compileMultiplicativeExpression()
protected org.datanucleus.store.mapped.expression.ScalarExpression compileUnaryExpression()
protected org.datanucleus.store.mapped.expression.ScalarExpression compileUnaryExpressionNotPlusMinus()
protected org.datanucleus.store.mapped.expression.ScalarExpression compileCastExpression()
protected abstract org.datanucleus.store.mapped.expression.ScalarExpression compilePrimary()
protected org.datanucleus.store.mapped.expression.ScalarExpression compileLiteral()
protected org.datanucleus.store.mapped.expression.ScalarExpression compileNewObject()
new MyObject(param1, param2)
protected org.datanucleus.store.mapped.expression.ScalarExpression compileExplicitVariable(java.lang.String id)
id - Identifier of the variable
protected org.datanucleus.store.mapped.expression.ScalarExpression callUserDefinedScalarExpression(java.lang.String method)
method - the method name prefixed by the class name (fully qualified or not)
protected void registerScalarExpressions(org.datanucleus.plugin.PluginManager pluginMgr,
org.datanucleus.ClassLoaderResolver clr)
pluginMgr - The PluginManagerclr - The ClassLoaderResolver to load the literal and ScalarExpression classes
public static void registerScalarExpression(java.lang.Class literal,
java.lang.Class scalarExpressionClass,
java.lang.String name)
cls. It allows
to perform operations in the query on cls.method([arglist]).
literal - the class providing the operations; e.g. java.lang.Math.classscalarExpressionClass - the class with the corresponding ScalarExpression. eg. org.datanucleus.store.expression.MathExpression.classname - alternative name of the given literal classpublic static java.util.Map getUserDefinedScalarExpressions()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||