org.datanucleus.store.rdbms.query2
Class QueryToSQLMapper

java.lang.Object
  extended by org.datanucleus.query.evaluator.AbstractExpressionEvaluator
      extended by org.datanucleus.store.rdbms.query2.QueryToSQLMapper
All Implemented Interfaces:
org.datanucleus.query.expression.ExpressionEvaluator, QueryGenerator

public class QueryToSQLMapper
extends org.datanucleus.query.evaluator.AbstractExpressionEvaluator
implements QueryGenerator

Class which maps a compiled query to an SQL query. Will form part of DataNucleus AccessPlatform 1.1 and later. Takes in an SQLStatement, and use of compile() will update the SQLStatement to reflect the filter, result, grouping, having, ordering etc.


Constructor Summary
QueryToSQLMapper(SQLStatement stmt, org.datanucleus.query.compiler.QueryCompilation compilation, java.util.Map parameters, org.datanucleus.store.mapped.StatementClassMapping resultDefForClass, org.datanucleus.store.mapped.StatementResultMapping resultDef, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.FetchPlan fetchPlan, org.datanucleus.store.mapped.StatementParameterMapping paramInfo, org.datanucleus.ObjectManager om)
          Constructor.
 
Method Summary
 void compile()
          Method to update the supplied SQLStatement with the components of the specified query.
protected  void compileFromClassExpression(org.datanucleus.query.expression.ClassExpression clsExpr)
          Method to take a ClassExpression (in a FROM clause) and process the candidate and any linked JoinExpression(s), adding joins to the SQLStatement as required.
 org.datanucleus.ClassLoaderResolver getClassLoaderResolver()
          Accessor for the ClassLoader resolver to use when looking up classes.
 org.datanucleus.query.compiler.CompilationComponent getCompilationComponent()
          Accessor for the current query component being compiled.
 org.datanucleus.ObjectManager getObjectManager()
          Accessor for the ObjectManager for this query.
 java.lang.Object getProperty(java.lang.String name)
          Accessor for a property affecting the query compilation.
 java.lang.String getQueryLanguage()
          Accessor for the query language that this query pertains to.
protected  org.datanucleus.store.rdbms.query2.QueryToSQLMapper.SQLTableMapping getSQLTableMappingForAlias(java.lang.String alias)
           
protected  org.datanucleus.store.mapped.StatementNewObjectMapping getStatementMappingForNewObjectExpression(NewObjectExpression expr)
          Convenience method to convert a NewObjectExpression into a StatementNewObjectMapping.
protected  java.lang.Object getValueForObjectField(java.lang.Object obj, java.lang.String fieldName)
          Convenience method to return the value of a field of the supplied object.
protected  boolean hasSQLTableMappingForAlias(java.lang.String alias)
           
 boolean isPrecompilable()
          Accessor for whether the query is precompilable (doesn't need to know parameter values to be able to compile it).
protected  java.lang.Object processAddExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processAndExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processCastExpression(org.datanucleus.query.expression.CastExpression expr)
           
protected  java.lang.Object processComExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processCreatorExpression(org.datanucleus.query.expression.CreatorExpression expr)
           
protected  java.lang.Object processDivExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processEqExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processGteqExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processGtExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processInvokeExpression(org.datanucleus.query.expression.InvokeExpression expr)
           
protected  java.lang.Object processIsExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processLikeExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processLiteral(org.datanucleus.query.expression.Literal expr)
           
protected  java.lang.Object processLteqExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processLtExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processModExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processMulExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processNegExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processNoteqExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processNotExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processOrExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processParameterExpression(org.datanucleus.query.expression.ParameterExpression expr)
           
protected  java.lang.Object processParameterExpression(org.datanucleus.query.expression.ParameterExpression expr, boolean asLiteral)
          Method to process a parameter expression.
protected  java.lang.Object processPrimaryExpression(org.datanucleus.query.expression.PrimaryExpression expr)
           
protected  java.lang.Object processSubExpression(org.datanucleus.query.expression.Expression expr)
           
protected  java.lang.Object processVariableExpression(org.datanucleus.query.expression.VariableExpression expr)
           
protected  SQLExpression replaceParameterLiteral(ParameterLiteral paramLit, org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
          Convenience method to return a parameter-based literal using the supplied mapping to replace the provided ParameterLiteral (generated before its type was known).
protected  void setSQLTableMappingForAlias(java.lang.String alias, org.datanucleus.store.rdbms.query2.QueryToSQLMapper.SQLTableMapping mapping)
           
 void useParameterExpressionAsLiteral(SQLLiteral paramLiteral)
          Method to instruct the generator to convert the provided parameter expression to just be a literal using the value of the parameter (hence the statement cannot be precompilable since the value needs to be known).
 
Methods inherited from class org.datanucleus.query.evaluator.AbstractExpressionEvaluator
compileAdditiveMultiplicativeExpression, compileOrAndExpression, compilePrimaryExpression, compileRelationalExpression, compileUnaryExpression, evaluate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryToSQLMapper

public QueryToSQLMapper(SQLStatement stmt,
                        org.datanucleus.query.compiler.QueryCompilation compilation,
                        java.util.Map parameters,
                        org.datanucleus.store.mapped.StatementClassMapping resultDefForClass,
                        org.datanucleus.store.mapped.StatementResultMapping resultDef,
                        org.datanucleus.metadata.AbstractClassMetaData cmd,
                        org.datanucleus.FetchPlan fetchPlan,
                        org.datanucleus.store.mapped.StatementParameterMapping paramInfo,
                        org.datanucleus.ObjectManager om)
Constructor.

Parameters:
stmt - SQL Statement to update with the query contents.
compilation - The generic query compilation
parameters - Parameters needed
resultDefForClass - Definition of results for the statement (populated here)
resultDef - Definition of results if we have a result clause (populated here)
cmd - Metadata for the candidate class
fetchPlan - Fetch Plan to apply
paramInfo - Definition of parameters for the statement (populated here)
om - ObjectManager
Method Detail

getQueryLanguage

public java.lang.String getQueryLanguage()
Accessor for the query language that this query pertains to. Can be used to decide how to handle the input.

Specified by:
getQueryLanguage in interface QueryGenerator
Returns:
The query language

getClassLoaderResolver

public org.datanucleus.ClassLoaderResolver getClassLoaderResolver()
Description copied from interface: QueryGenerator
Accessor for the ClassLoader resolver to use when looking up classes.

Specified by:
getClassLoaderResolver in interface QueryGenerator
Returns:
The classloader resolver

getCompilationComponent

public org.datanucleus.query.compiler.CompilationComponent getCompilationComponent()
Description copied from interface: QueryGenerator
Accessor for the current query component being compiled.

Specified by:
getCompilationComponent in interface QueryGenerator
Returns:
Component being compiled (if any)

getObjectManager

public org.datanucleus.ObjectManager getObjectManager()
Description copied from interface: QueryGenerator
Accessor for the ObjectManager for this query.

Specified by:
getObjectManager in interface QueryGenerator
Returns:
ObjectManager

getProperty

public java.lang.Object getProperty(java.lang.String name)
Description copied from interface: QueryGenerator
Accessor for a property affecting the query compilation. This can be something like whether there is an OR in the filter, which can then impact on the type of SQL used.

Specified by:
getProperty in interface QueryGenerator
Parameters:
name - The property name
Returns:
Its value

isPrecompilable

public boolean isPrecompilable()
Accessor for whether the query is precompilable (doesn't need to know parameter values to be able to compile it).

Returns:
Whether the query is precompilable and hence cacheable

useParameterExpressionAsLiteral

public void useParameterExpressionAsLiteral(SQLLiteral paramLiteral)
Description copied from interface: QueryGenerator
Method to instruct the generator to convert the provided parameter expression to just be a literal using the value of the parameter (hence the statement cannot be precompilable since the value needs to be known).

Specified by:
useParameterExpressionAsLiteral in interface QueryGenerator
Parameters:
paramLiteral - The parameter expression

compile

public void compile()
Method to update the supplied SQLStatement with the components of the specified query. During the compilation process this updates the SQLStatement "compileComponent" to the component of the query being compiled.


compileFromClassExpression

protected void compileFromClassExpression(org.datanucleus.query.expression.ClassExpression clsExpr)
Method to take a ClassExpression (in a FROM clause) and process the candidate and any linked JoinExpression(s), adding joins to the SQLStatement as required.

Parameters:
clsExpr - The ClassExpression

getStatementMappingForNewObjectExpression

protected org.datanucleus.store.mapped.StatementNewObjectMapping getStatementMappingForNewObjectExpression(NewObjectExpression expr)
Convenience method to convert a NewObjectExpression into a StatementNewObjectMapping. Handles recursive new object calls (where a new object is an arg to a new object construction).

Parameters:
expr - The NewObjectExpression
Returns:
The mapping for the new object

processAndExpression

protected java.lang.Object processAndExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processAndExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processOrExpression

protected java.lang.Object processOrExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processOrExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processEqExpression

protected java.lang.Object processEqExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processEqExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processNoteqExpression

protected java.lang.Object processNoteqExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processNoteqExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processGteqExpression

protected java.lang.Object processGteqExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processGteqExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processGtExpression

protected java.lang.Object processGtExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processGtExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processLteqExpression

protected java.lang.Object processLteqExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processLteqExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processLtExpression

protected java.lang.Object processLtExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processLtExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processLiteral

protected java.lang.Object processLiteral(org.datanucleus.query.expression.Literal expr)
Overrides:
processLiteral in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processPrimaryExpression

protected java.lang.Object processPrimaryExpression(org.datanucleus.query.expression.PrimaryExpression expr)
Overrides:
processPrimaryExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processParameterExpression

protected java.lang.Object processParameterExpression(org.datanucleus.query.expression.ParameterExpression expr)
Overrides:
processParameterExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processParameterExpression

protected java.lang.Object processParameterExpression(org.datanucleus.query.expression.ParameterExpression expr,
                                                      boolean asLiteral)
Method to process a parameter expression. The optional argument controls whether we should create this as a parameter or as a literal (i.e the param value is known etc). If the parameter doesn't have its value defined then returns ParameterLiteral otherwise we get an XXXLiteral of the (declared) type of the parameter

Parameters:
expr - The ParameterExpression
asLiteral - Whether to create a SQLLiteral rather than a parameter literal

processInvokeExpression

protected java.lang.Object processInvokeExpression(org.datanucleus.query.expression.InvokeExpression expr)
Overrides:
processInvokeExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processAddExpression

protected java.lang.Object processAddExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processAddExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processDivExpression

protected java.lang.Object processDivExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processDivExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processMulExpression

protected java.lang.Object processMulExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processMulExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processSubExpression

protected java.lang.Object processSubExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processSubExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processComExpression

protected java.lang.Object processComExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processComExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processModExpression

protected java.lang.Object processModExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processModExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processNegExpression

protected java.lang.Object processNegExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processNegExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processNotExpression

protected java.lang.Object processNotExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processNotExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processCastExpression

protected java.lang.Object processCastExpression(org.datanucleus.query.expression.CastExpression expr)
Overrides:
processCastExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processIsExpression

protected java.lang.Object processIsExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processIsExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processCreatorExpression

protected java.lang.Object processCreatorExpression(org.datanucleus.query.expression.CreatorExpression expr)
Overrides:
processCreatorExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processLikeExpression

protected java.lang.Object processLikeExpression(org.datanucleus.query.expression.Expression expr)
Overrides:
processLikeExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

processVariableExpression

protected java.lang.Object processVariableExpression(org.datanucleus.query.expression.VariableExpression expr)
Overrides:
processVariableExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator

replaceParameterLiteral

protected SQLExpression replaceParameterLiteral(ParameterLiteral paramLit,
                                                org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
Convenience method to return a parameter-based literal using the supplied mapping to replace the provided ParameterLiteral (generated before its type was known). Also updates any entry in the parameter indices to use this mapping.

Parameters:
paramLit - The parameter literal
mapping - Mapping to use
Returns:
The replacement expression

getValueForObjectField

protected java.lang.Object getValueForObjectField(java.lang.Object obj,
                                                  java.lang.String fieldName)
Convenience method to return the value of a field of the supplied object. If the object is null then returns null for the field.

Parameters:
obj - The object
fieldName - The field name
Returns:
The field value

getSQLTableMappingForAlias

protected org.datanucleus.store.rdbms.query2.QueryToSQLMapper.SQLTableMapping getSQLTableMappingForAlias(java.lang.String alias)

setSQLTableMappingForAlias

protected void setSQLTableMappingForAlias(java.lang.String alias,
                                          org.datanucleus.store.rdbms.query2.QueryToSQLMapper.SQLTableMapping mapping)

hasSQLTableMappingForAlias

protected boolean hasSQLTableMappingForAlias(java.lang.String alias)


Copyright © 2009. All Rights Reserved.