|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.datanucleus.query.evaluator.AbstractExpressionEvaluator
org.datanucleus.store.rdbms.query.QueryToSQLMapper
public class QueryToSQLMapper
Class which maps a compiled (generic) query to an SQL query for RDBMS datastores. Takes in an SQLStatement, and use of compile() will update the SQLStatement to reflect the filter, result, grouping, having, ordering etc.
Supports the following extensions currently :-
| Field Summary | |
|---|---|
protected static org.datanucleus.util.Localiser |
LOCALISER
Localiser for messages. |
protected static org.datanucleus.util.Localiser |
LOCALISER_RDBMS
Localiser for messages. |
static String |
OPTION_BULK_UPDATE_VERSION
|
static String |
OPTION_CASE_INSENSITIVE
|
static String |
OPTION_EXPLICIT_JOINS
|
QueryToSQLMapper |
parentMapper
Parent mapper if we are processing a subquery. |
| Constructor Summary | |
|---|---|
QueryToSQLMapper(SQLStatement stmt,
org.datanucleus.query.compiler.QueryCompilation compilation,
Map parameters,
org.datanucleus.store.mapped.StatementClassMapping resultDefForClass,
StatementResultMapping resultDef,
org.datanucleus.metadata.AbstractClassMetaData cmd,
org.datanucleus.FetchPlan fetchPlan,
org.datanucleus.store.ExecutionContext ec,
org.datanucleus.util.Imports importsDefinition,
Set<String> options,
Map<String,Object> extensions)
Constructor. |
|
| Method Summary | |
|---|---|
void |
bindParameter(String paramName,
Class type)
Method to bind the specified parameter to the defined type. |
void |
bindVariable(String varName,
org.datanucleus.metadata.AbstractClassMetaData cmd,
SQLTable sqlTbl,
org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
Method to bind the specified variable to the table and mapping. |
SQLExpression |
bindVariable(UnboundExpression expr,
Class type)
Method to bind the specified unbound variable (as cross join) on the assumption that the type is a persistable class. |
void |
compile()
Method to update the supplied SQLStatement with the components of the specified query. |
protected void |
compileFilter()
Method to compile the WHERE clause of the query into the SQLStatement. |
protected void |
compileFrom()
Method to compile the FROM clause of the query into the SQLStatement. |
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. |
protected void |
compileGrouping()
Method to compile the grouping clause of the query into the SQLStatement. |
protected void |
compileHaving()
Method to compile the having clause of the query into the SQLStatement. |
protected void |
compileOrdering()
Method to compile the ordering clause of the query into the SQLStatement. |
protected void |
compileResult()
Method to compile the result clause of the query into the SQLStatement. |
String |
getAliasForSQLTable(SQLTable tbl)
Returns the alias used for the specified SQLTable. |
protected BooleanExpression |
getBooleanExpressionForUseInFilter(BooleanExpression expr)
Convenience method to return a boolean expression suitable for using in a filter. |
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.store.ExecutionContext |
getExecutionContext()
Accessor for the ExecutionContext for this query. |
Map<Integer,String> |
getParameterNameByPosition()
Convenience accessor for a map of the parameter name keyed by its position. |
Object |
getProperty(String name)
Accessor for a property affecting the query compilation. |
String |
getQueryLanguage()
Accessor for the query language that this query pertains to. |
SQLJoin.JoinType |
getRequiredJoinTypeForAlias(String alias)
Convenience method to return the required join type for the specified alias. |
SQLTable |
getSQLTableForAlias(String alias)
Method to return the SQLTable for the specified primary expression "alias". |
protected org.datanucleus.store.rdbms.query.QueryToSQLMapper.SQLTableMapping |
getSQLTableMappingForAlias(String alias)
|
protected StatementNewObjectMapping |
getStatementMappingForNewObjectExpression(NewObjectExpression expr)
Convenience method to convert a NewObjectExpression into a StatementNewObjectMapping. |
Class |
getTypeOfVariable(String varName)
Accessor for the type of a variable if already known (declared?). |
Object |
getValueForExtension(String key)
Accessor for the value of the specified query extension (or null if not defined). |
protected Object |
getValueForObjectField(Object obj,
String fieldName)
Convenience method to return the value of a field of the supplied object. |
boolean |
hasExplicitJoins()
Accessor for whether the query has explicit variables. |
boolean |
hasExtension(String key)
Accessor for whether the query being generated has the specified extension. |
protected boolean |
hasSQLTableMappingForAlias(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 Object |
processAddExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processAndExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processCaseExpression(org.datanucleus.query.expression.CaseExpression expr)
|
protected Object |
processCastExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processComExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processCreatorExpression(org.datanucleus.query.expression.CreatorExpression expr)
|
protected Object |
processDistinctExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processDivExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processEqExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processGteqExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processGtExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processInExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processInvokeExpression(org.datanucleus.query.expression.InvokeExpression expr)
|
protected Object |
processIsExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processIsnotExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processLikeExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processLiteral(org.datanucleus.query.expression.Literal expr)
|
protected Object |
processLteqExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processLtExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processModExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processMulExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processNegExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processNoteqExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processNotExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processNotInExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processOrExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processParameterExpression(org.datanucleus.query.expression.ParameterExpression expr)
|
protected Object |
processParameterExpression(org.datanucleus.query.expression.ParameterExpression expr,
boolean asLiteral)
Method to process a parameter expression. |
protected Object |
processPrimaryExpression(org.datanucleus.query.expression.PrimaryExpression expr)
|
protected Object |
processSubExpression(org.datanucleus.query.expression.Expression expr)
|
protected Object |
processSubqueryExpression(org.datanucleus.query.expression.SubqueryExpression expr)
|
protected SQLExpression |
processUnboundExpression(UnboundExpression expr)
|
protected 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). |
Class |
resolveClass(String className)
Convenience method to resolve a class name. |
protected void |
setNotPrecompilable()
|
protected void |
setSQLTableMappingForAlias(String alias,
org.datanucleus.store.rdbms.query.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). |
protected void |
validateExpressionForResult(SQLExpression sqlExpr)
Method that validates that the specified expression is valid for use in a result clause. |
| 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 |
| Field Detail |
|---|
protected static final org.datanucleus.util.Localiser LOCALISER
protected static final org.datanucleus.util.Localiser LOCALISER_RDBMS
public static final String OPTION_CASE_INSENSITIVE
public static final String OPTION_EXPLICIT_JOINS
public static final String OPTION_BULK_UPDATE_VERSION
public QueryToSQLMapper parentMapper
| Constructor Detail |
|---|
public QueryToSQLMapper(SQLStatement stmt,
org.datanucleus.query.compiler.QueryCompilation compilation,
Map parameters,
org.datanucleus.store.mapped.StatementClassMapping resultDefForClass,
StatementResultMapping resultDef,
org.datanucleus.metadata.AbstractClassMetaData cmd,
org.datanucleus.FetchPlan fetchPlan,
org.datanucleus.store.ExecutionContext ec,
org.datanucleus.util.Imports importsDefinition,
Set<String> options,
Map<String,Object> extensions)
stmt - SQL Statement to update with the query contents.compilation - The generic query compilationparameters - Parameters neededresultDefForClass - 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 classfetchPlan - Fetch Plan to applyec - execution contextimportsDefinition - Import definition to use in class lookups (optional)options - Options controlling behaviourextensions - Any query extensions that may define compilation behaviour| Method Detail |
|---|
public String getQueryLanguage()
getQueryLanguage in interface QueryGeneratorpublic org.datanucleus.ClassLoaderResolver getClassLoaderResolver()
QueryGenerator
getClassLoaderResolver in interface QueryGeneratorpublic org.datanucleus.query.compiler.CompilationComponent getCompilationComponent()
QueryGenerator
getCompilationComponent in interface QueryGeneratorpublic org.datanucleus.store.ExecutionContext getExecutionContext()
QueryGenerator
getExecutionContext in interface QueryGeneratorpublic Object getProperty(String name)
QueryGenerator
getProperty in interface QueryGeneratorname - The property name
public boolean isPrecompilable()
protected void setNotPrecompilable()
public Map<Integer,String> getParameterNameByPosition()
compileis called.
public void compile()
protected void compileFrom()
protected void compileFilter()
protected void compileResult()
protected void validateExpressionForResult(SQLExpression sqlExpr)
sqlExpr - The SQLExpressionprotected void compileGrouping()
protected void compileHaving()
protected void compileOrdering()
protected void compileFromClassExpression(org.datanucleus.query.expression.ClassExpression clsExpr)
clsExpr - The ClassExpressionprotected StatementNewObjectMapping getStatementMappingForNewObjectExpression(NewObjectExpression expr)
expr - The NewObjectExpression
protected Object processAndExpression(org.datanucleus.query.expression.Expression expr)
processAndExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processOrExpression(org.datanucleus.query.expression.Expression expr)
processOrExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processEqExpression(org.datanucleus.query.expression.Expression expr)
processEqExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processNoteqExpression(org.datanucleus.query.expression.Expression expr)
processNoteqExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processGteqExpression(org.datanucleus.query.expression.Expression expr)
processGteqExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processGtExpression(org.datanucleus.query.expression.Expression expr)
processGtExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processLteqExpression(org.datanucleus.query.expression.Expression expr)
processLteqExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processLtExpression(org.datanucleus.query.expression.Expression expr)
processLtExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processLiteral(org.datanucleus.query.expression.Literal expr)
processLiteral in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processPrimaryExpression(org.datanucleus.query.expression.PrimaryExpression expr)
processPrimaryExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processParameterExpression(org.datanucleus.query.expression.ParameterExpression expr)
processParameterExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluator
protected Object processParameterExpression(org.datanucleus.query.expression.ParameterExpression expr,
boolean asLiteral)
expr - The ParameterExpressionasLiteral - Whether to create a SQLLiteral rather than a parameter literalprotected Object processInvokeExpression(org.datanucleus.query.expression.InvokeExpression expr)
processInvokeExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processSubqueryExpression(org.datanucleus.query.expression.SubqueryExpression expr)
processSubqueryExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processAddExpression(org.datanucleus.query.expression.Expression expr)
processAddExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processDivExpression(org.datanucleus.query.expression.Expression expr)
processDivExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processMulExpression(org.datanucleus.query.expression.Expression expr)
processMulExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processSubExpression(org.datanucleus.query.expression.Expression expr)
processSubExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processDistinctExpression(org.datanucleus.query.expression.Expression expr)
processDistinctExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processComExpression(org.datanucleus.query.expression.Expression expr)
processComExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processModExpression(org.datanucleus.query.expression.Expression expr)
processModExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processNegExpression(org.datanucleus.query.expression.Expression expr)
processNegExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processNotExpression(org.datanucleus.query.expression.Expression expr)
processNotExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processCastExpression(org.datanucleus.query.expression.Expression expr)
processCastExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processCaseExpression(org.datanucleus.query.expression.CaseExpression expr)
processCaseExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processIsExpression(org.datanucleus.query.expression.Expression expr)
processIsExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processIsnotExpression(org.datanucleus.query.expression.Expression expr)
processIsnotExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processInExpression(org.datanucleus.query.expression.Expression expr)
processInExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processNotInExpression(org.datanucleus.query.expression.Expression expr)
processNotInExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processCreatorExpression(org.datanucleus.query.expression.CreatorExpression expr)
processCreatorExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processLikeExpression(org.datanucleus.query.expression.Expression expr)
processLikeExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected Object processVariableExpression(org.datanucleus.query.expression.VariableExpression expr)
processVariableExpression in class org.datanucleus.query.evaluator.AbstractExpressionEvaluatorprotected SQLExpression processUnboundExpression(UnboundExpression expr)
protected SQLExpression replaceParameterLiteral(ParameterLiteral paramLit,
org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
paramLit - The parameter literalmapping - Mapping to use
public void useParameterExpressionAsLiteral(SQLLiteral paramLiteral)
QueryGenerator
useParameterExpressionAsLiteral in interface QueryGeneratorparamLiteral - The parameter expressionpublic boolean hasExtension(String key)
QueryGenerator
hasExtension in interface QueryGeneratorkey - Extension name
public Object getValueForExtension(String key)
QueryGenerator
getValueForExtension in interface QueryGeneratorkey - Extension name
public SQLJoin.JoinType getRequiredJoinTypeForAlias(String alias)
alias - The alias
protected Object getValueForObjectField(Object obj,
String fieldName)
obj - The objectfieldName - The field name
protected org.datanucleus.store.rdbms.query.QueryToSQLMapper.SQLTableMapping getSQLTableMappingForAlias(String alias)
public SQLTable getSQLTableForAlias(String alias)
QueryGenerator
getSQLTableForAlias in interface QueryGeneratoralias - The alias ("this", fieldName)
public String getAliasForSQLTable(SQLTable tbl)
tbl - The table
protected void setSQLTableMappingForAlias(String alias,
org.datanucleus.store.rdbms.query.QueryToSQLMapper.SQLTableMapping mapping)
protected boolean hasSQLTableMappingForAlias(String alias)
public void bindVariable(String varName,
org.datanucleus.metadata.AbstractClassMetaData cmd,
SQLTable sqlTbl,
org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
bindVariable in interface QueryGeneratorvarName - Variable namecmd - Metadata for this variable typesqlTbl - Table for this variablemapping - The mapping of this variable in the table
public SQLExpression bindVariable(UnboundExpression expr,
Class type)
bindVariable in interface QueryGeneratorexpr - Unbound expressiontype - The type to bind as
public void bindParameter(String paramName,
Class type)
bindParameter in interface QueryGeneratorparamName - Name of the parametertype - The type (or subclass)public Class getTypeOfVariable(String varName)
getTypeOfVariable in interface QueryGeneratorvarName - Name of the variable
public boolean hasExplicitJoins()
hasExplicitJoins in interface QueryGeneratorprotected BooleanExpression getBooleanExpressionForUseInFilter(BooleanExpression expr)
myBoolField. In that case we return a boolean like
myBoolField == TRUE.
expr - The expression to check
public Class resolveClass(String className)
resolveClass in interface QueryGeneratorclassName - The class name
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||