Class QueryToSQLMapper
- java.lang.Object
-
- org.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
- org.datanucleus.store.rdbms.query.QueryToSQLMapper
-
- All Implemented Interfaces:
org.datanucleus.store.query.expression.ExpressionEvaluator,QueryGenerator
public class QueryToSQLMapper extends org.datanucleus.store.query.expression.AbstractExpressionEvaluator implements QueryGenerator
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 :-
- datanucleus.query.jdoql.{varName}.join defines the join type for that alias. This only currently applies if the variable is (finally) bound using the equality operator (e.g var.field == this.field). The extension should be set to "LEFTOUTERJOIN", "INNERJOIN"
TODO This class currently takes in an SQLStatement and updates it with filter, result, from etc. If the input statement is a UNION of statements it tries to update the statement by applying the filter, result etc across all UNIONs. This can cause problems in some situations, particularly around looking up tables when using COMPLETE_TABLE inheritance, or with TYPE/instanceOf operations. We currently work around these by some fixes to getSQLTableMappingForPrimaryExpression, and by manually going around the UNIONs. What may be a better long term solution would be to run this class on each of the UNIONed statements separately and merge them.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classQueryToSQLMapper.SQLTableMapping
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.StringcandidateAlias(package private) org.datanucleus.metadata.AbstractClassMetaDatacandidateCmd(package private) org.datanucleus.ClassLoaderResolverclr(package private) org.datanucleus.store.query.compiler.QueryCompilationcompilation(package private) org.datanucleus.store.query.compiler.CompilationComponentcompileComponentState variable for the component being compiled.(package private) java.util.Map<java.lang.String,java.lang.Object>compileProperties(package private) SQLJoin.JoinTypedefaultJoinType(package private) SQLJoin.JoinTypedefaultJoinTypeFilter(package private) org.datanucleus.ExecutionContextec(package private) java.util.Map<java.lang.String,java.lang.String>explicitJoinPrimaryByAliasMap of the join primary expression string keyed by the join alias (explicit joins only).(package private) java.util.Map<java.lang.Object,SQLExpression>expressionForParameter(package private) SQLExpressionFactoryexprFactory(package private) java.util.Map<java.lang.String,java.lang.Object>extensionsByNameMap of query extensions defining behaviour on the compilation.(package private) org.datanucleus.FetchPlanfetchPlan(package private) org.datanucleus.util.ImportsimportsDefinitionstatic java.lang.StringMAP_KEY_ALIAS_SUFFIXstatic java.lang.StringMAP_VALUE_ALIAS_SUFFIXstatic java.lang.StringOPTION_BULK_UPDATE_VERSIONstatic java.lang.StringOPTION_CASE_INSENSITIVEstatic java.lang.StringOPTION_EXPLICIT_JOINSstatic java.lang.StringOPTION_NON_DISTINCT_IMPLICIT_JOINSstatic java.lang.StringOPTION_NULL_PARAM_USE_IS_NULLstatic java.lang.StringOPTION_SELECT_CANDIDATE_ID_ONLY(package private) java.util.Set<java.lang.String>optionsOptions for the SQL generation process.(package private) java.util.MapparametersInput parameter values, keyed by the parameter name.(package private) java.util.Map<java.lang.String,java.lang.Object>parameterValueByNameWork Map for keying parameter value for the name, for case where parameters input as positional.(package private) java.util.Map<java.lang.String,JavaTypeMapping>paramMappingForName(package private) java.util.Map<java.lang.Integer,java.lang.String>paramNameByPositionQueryToSQLMapperparentMapperParent mapper if we are processing a subquery.(package private) intpositionalParamNumberPositional parameter that we are up to (-1 implies not being used).(package private) booleanprecompilableState variable for whether this query is precompilable (hence whether it is cacheable).protected booleanprocessingCase(package private) booleanprocessingOnClause(package private) java.util.Set<java.lang.String>resultAliasesAliases defined in the result, populated during compileResult.(package private) StatementResultMappingresultDefinitionDefinition of mapping for the results of this SQL statement (result).(package private) StatementClassMappingresultDefinitionForClassDefinition of mapping for the results of this SQL statement (candidate).(package private) java.util.Map<java.lang.String,QueryToSQLMapper.SQLTableMapping>sqlTableByPrimaryMap of SQLTable/mapping keyed by the name of the primary that it relates to.(package private) java.util.Deque<SQLExpression>stackStack of expressions, used for compilation of the query into SQL.(package private) SQLStatementstmtSQL statement that we are updating.(package private) RDBMSStoreManagerstoreMgr(package private) booleansubclasses
-
Constructor Summary
Constructors Constructor Description QueryToSQLMapper(SQLStatement stmt, org.datanucleus.store.query.compiler.QueryCompilation compilation, java.util.Map parameters, StatementClassMapping resultDefForClass, StatementResultMapping resultDef, org.datanucleus.metadata.AbstractClassMetaData cmd, boolean subclasses, org.datanucleus.FetchPlan fetchPlan, org.datanucleus.ExecutionContext ec, org.datanucleus.util.Imports importsDefinition, java.util.Set<java.lang.String> options, java.util.Map<java.lang.String,java.lang.Object> extensions)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbindParameter(java.lang.String paramName, java.lang.Class type)Method to bind the specified parameter to the defined type.voidbindVariable(java.lang.String varName, org.datanucleus.metadata.AbstractClassMetaData cmd, SQLTable sqlTbl, JavaTypeMapping mapping)Method to bind the specified variable to the table and mapping.SQLExpressionbindVariable(UnboundExpression expr, java.lang.Class type)Method to bind the specified unbound variable (as cross join) on the assumption that the type is a persistable class.private booleancheckCaseExpressionsConsistent(SQLExpression expr1, SQLExpression expr2)voidcompile()Method to update the supplied SQLStatement with the components of the specified query.protected voidcompileFilter()Method to compile the WHERE clause of the query into the SQLStatement.protected voidcompileFrom()Method to compile the FROM clause of the query into the SQLStatement.protected voidcompileFromClassExpression(org.datanucleus.store.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 voidcompileGrouping(SelectStatement stmt)Method to compile the grouping clause of the query into the SQLStatement.protected voidcompileHaving(SelectStatement stmt)Method to compile the having clause of the query into the SQLStatement.protected voidcompileOrdering(SelectStatement stmt)Method to compile the ordering clause of the query into the SQLStatement.protected voidcompileResult(SelectStatement stmt)Method to compile the result clause of the query into the SQLStatement.protected voidcompileUpdate(UpdateStatement stmt)Method to compile the result clause of the query into the SQLStatement.java.lang.StringgetAliasForSQLTable(SQLTable tbl)Returns the alias used for the specified SQLTable.java.lang.StringgetAliasForSQLTableMapping(QueryToSQLMapper.SQLTableMapping tblMapping)protected BooleanExpressiongetBooleanExpressionForUseInFilter(BooleanExpression expr)Convenience method to return a boolean expression suitable for using in a filter.org.datanucleus.ClassLoaderResolvergetClassLoaderResolver()Accessor for the ClassLoader resolver to use when looking up classes.org.datanucleus.store.query.compiler.CompilationComponentgetCompilationComponent()Accessor for the current query component being compiled.private SQLJoin.JoinTypegetDefaultJoinTypeForNavigation()Convenience method to return the default join type to use for a relation navigation.private java.lang.Object[]getDiscriminatorValuesForCastClass(org.datanucleus.metadata.AbstractClassMetaData cmd)org.datanucleus.ExecutionContextgetExecutionContext()Accessor for the ExecutionContext for this query.protected SQLExpressiongetInvokedSqlExpressionForInvokeExpression(org.datanucleus.store.query.expression.InvokeExpression expr)java.util.Map<java.lang.Integer,java.lang.String>getParameterNameByPosition()Convenience accessor for a map of the parameter name keyed by its position.java.lang.ObjectgetProperty(java.lang.String name)Accessor for a property affecting the query compilation.java.lang.StringgetQueryLanguage()Accessor for the query language that this query pertains to.SQLJoin.JoinTypegetRequiredJoinTypeForAlias(java.lang.String alias)Convenience method to return the required join type for the specified alias.protected SQLExpressiongetSQLLiteralForLiteralValue(java.lang.Object litValue)protected QueryToSQLMapper.SQLTableMappinggetSQLTableMappingForAlias(java.lang.String alias)private QueryToSQLMapper.SQLTableMappinggetSQLTableMappingForPrimaryExpression(SQLStatement theStmt, java.lang.String exprName, org.datanucleus.store.query.expression.PrimaryExpression primExpr, java.lang.Boolean forceJoin)Method to take in a PrimaryExpression and return the SQLTable mapping info that it signifies.protected StatementNewObjectMappinggetStatementMappingForNewObjectExpression(NewObjectExpression expr, SelectStatement stmt)Convenience method to convert a NewObjectExpression into a StatementNewObjectMapping.java.lang.ClassgetTypeOfVariable(java.lang.String varName)Accessor for the type of a variable if already known (declared?).java.lang.ObjectgetValueForExtension(java.lang.String key)Accessor for the value of the specified query extension (or null if not defined).protected java.lang.ObjectgetValueForObjectField(java.lang.Object obj, java.lang.String fieldName)Convenience method to return the value of a field of the supplied object.booleanhasExplicitJoins()Accessor for whether the query has explicit variables.booleanhasExtension(java.lang.String key)Accessor for whether the query being generated has the specified extension.protected booleanhasSQLTableMappingForAlias(java.lang.String alias)booleanisPrecompilable()Accessor for whether the query is precompilable (doesn't need to know parameter values to be able to compile it).protected java.lang.ObjectprocessAddExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessAndExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessBitAndExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessBitOrExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessBitXorExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessCaseExpression(org.datanucleus.store.query.expression.CaseExpression expr)protected java.lang.ObjectprocessCaseExpression(org.datanucleus.store.query.expression.CaseExpression expr, SQLExpression typeExpr)protected java.lang.ObjectprocessCastExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessComExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessCreatorExpression(org.datanucleus.store.query.expression.CreatorExpression expr)protected java.lang.ObjectprocessDistinctExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessDivExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessEqExpression(org.datanucleus.store.query.expression.Expression expr)protected voidprocessFromClauseSubquery(org.datanucleus.store.query.expression.ClassExpression clsExpr, SQLTable candSqlTbl, org.datanucleus.metadata.MetaDataManager mmgr)Method to process a ClassExpression where it represents a subquery.protected java.lang.ObjectprocessGteqExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessGtExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessInExpression(org.datanucleus.store.query.expression.Expression expr)booleanprocessingOnClause()protected java.lang.ObjectprocessInvokeExpression(org.datanucleus.store.query.expression.InvokeExpression expr)protected SQLExpressionprocessInvokeExpression(org.datanucleus.store.query.expression.InvokeExpression expr, SQLExpression invokedSqlExpr)Internal method to handle the processing of an InvokeExpression.protected java.lang.ObjectprocessIsExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessIsnotExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessLikeExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessLiteral(org.datanucleus.store.query.expression.Literal expr)protected java.lang.ObjectprocessLteqExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessLtExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessModExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessMulExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessNegExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessNoteqExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessNotExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessNotInExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessOrExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessParameterExpression(org.datanucleus.store.query.expression.ParameterExpression expr)protected java.lang.ObjectprocessParameterExpression(org.datanucleus.store.query.expression.ParameterExpression expr, boolean asLiteral)Method to process a parameter expression.protected java.lang.ObjectprocessPrimaryExpression(org.datanucleus.store.query.expression.PrimaryExpression expr)protected java.lang.ObjectprocessSubExpression(org.datanucleus.store.query.expression.Expression expr)protected java.lang.ObjectprocessSubqueryExpression(org.datanucleus.store.query.expression.SubqueryExpression expr)protected SQLExpressionprocessUnboundExpression(UnboundExpression expr)protected java.lang.ObjectprocessVariableExpression(org.datanucleus.store.query.expression.VariableExpression expr)java.lang.ClassresolveClass(java.lang.String className)Convenience method to resolve a class name.protected voidselectFetchPlanForCandidate(SelectStatement stmt, StatementClassMapping resultClassMapping, int maxFetchDepth)(package private) voidsetDefaultJoinType(SQLJoin.JoinType joinType)Method to set the default join type to be used.(package private) voidsetDefaultJoinTypeFilter(SQLJoin.JoinType joinType)protected voidsetNotPrecompilable()(package private) voidsetParentMapper(QueryToSQLMapper parent)protected voidsetSQLTableMappingForAlias(java.lang.String alias, QueryToSQLMapper.SQLTableMapping mapping)voiduseParameterExpressionAsLiteral(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 voidvalidateExpressionForResult(SQLExpression sqlExpr)Method that validates that the specified expression is valid for use in a result clause.
-
-
-
Field Detail
-
OPTION_CASE_INSENSITIVE
public static final java.lang.String OPTION_CASE_INSENSITIVE
- See Also:
- Constant Field Values
-
OPTION_EXPLICIT_JOINS
public static final java.lang.String OPTION_EXPLICIT_JOINS
- See Also:
- Constant Field Values
-
OPTION_NON_DISTINCT_IMPLICIT_JOINS
public static final java.lang.String OPTION_NON_DISTINCT_IMPLICIT_JOINS
- See Also:
- Constant Field Values
-
OPTION_BULK_UPDATE_VERSION
public static final java.lang.String OPTION_BULK_UPDATE_VERSION
- See Also:
- Constant Field Values
-
OPTION_SELECT_CANDIDATE_ID_ONLY
public static final java.lang.String OPTION_SELECT_CANDIDATE_ID_ONLY
- See Also:
- Constant Field Values
-
OPTION_NULL_PARAM_USE_IS_NULL
public static final java.lang.String OPTION_NULL_PARAM_USE_IS_NULL
- See Also:
- Constant Field Values
-
MAP_KEY_ALIAS_SUFFIX
public static final java.lang.String MAP_KEY_ALIAS_SUFFIX
- See Also:
- Constant Field Values
-
MAP_VALUE_ALIAS_SUFFIX
public static final java.lang.String MAP_VALUE_ALIAS_SUFFIX
- See Also:
- Constant Field Values
-
candidateAlias
final java.lang.String candidateAlias
-
candidateCmd
final org.datanucleus.metadata.AbstractClassMetaData candidateCmd
-
subclasses
final boolean subclasses
-
compilation
final org.datanucleus.store.query.compiler.QueryCompilation compilation
-
parameters
final java.util.Map parameters
Input parameter values, keyed by the parameter name. Will be null if compiled pre-execution.
-
parameterValueByName
java.util.Map<java.lang.String,java.lang.Object> parameterValueByName
Work Map for keying parameter value for the name, for case where parameters input as positional.
-
paramNameByPosition
java.util.Map<java.lang.Integer,java.lang.String> paramNameByPosition
-
positionalParamNumber
int positionalParamNumber
Positional parameter that we are up to (-1 implies not being used).
-
extensionsByName
java.util.Map<java.lang.String,java.lang.Object> extensionsByName
Map of query extensions defining behaviour on the compilation.
-
stmt
SQLStatement stmt
SQL statement that we are updating.
-
resultDefinitionForClass
final StatementClassMapping resultDefinitionForClass
Definition of mapping for the results of this SQL statement (candidate).
-
resultDefinition
final StatementResultMapping resultDefinition
Definition of mapping for the results of this SQL statement (result).
-
expressionForParameter
java.util.Map<java.lang.Object,SQLExpression> expressionForParameter
-
storeMgr
final RDBMSStoreManager storeMgr
-
fetchPlan
final org.datanucleus.FetchPlan fetchPlan
-
exprFactory
final SQLExpressionFactory exprFactory
-
ec
org.datanucleus.ExecutionContext ec
-
clr
org.datanucleus.ClassLoaderResolver clr
-
importsDefinition
org.datanucleus.util.Imports importsDefinition
-
compileProperties
java.util.Map<java.lang.String,java.lang.Object> compileProperties
-
compileComponent
org.datanucleus.store.query.compiler.CompilationComponent compileComponent
State variable for the component being compiled.
-
stack
java.util.Deque<SQLExpression> stack
Stack of expressions, used for compilation of the query into SQL.
-
sqlTableByPrimary
java.util.Map<java.lang.String,QueryToSQLMapper.SQLTableMapping> sqlTableByPrimary
Map of SQLTable/mapping keyed by the name of the primary that it relates to. Note that the SQLTableMapping relates to the primary statement (and not to any UNIONs).
-
resultAliases
java.util.Set<java.lang.String> resultAliases
Aliases defined in the result, populated during compileResult.
-
explicitJoinPrimaryByAlias
java.util.Map<java.lang.String,java.lang.String> explicitJoinPrimaryByAlias
Map of the join primary expression string keyed by the join alias (explicit joins only).
-
paramMappingForName
java.util.Map<java.lang.String,JavaTypeMapping> paramMappingForName
-
options
java.util.Set<java.lang.String> options
Options for the SQL generation process. See OPTION_xxx above.
-
parentMapper
public QueryToSQLMapper parentMapper
Parent mapper if we are processing a subquery.
-
defaultJoinType
SQLJoin.JoinType defaultJoinType
-
defaultJoinTypeFilter
SQLJoin.JoinType defaultJoinTypeFilter
-
precompilable
boolean precompilable
State variable for whether this query is precompilable (hence whether it is cacheable). Or in other words, whether we can compile it without knowing parameter values.
-
processingOnClause
boolean processingOnClause
-
processingCase
protected boolean processingCase
-
-
Constructor Detail
-
QueryToSQLMapper
public QueryToSQLMapper(SQLStatement stmt, org.datanucleus.store.query.compiler.QueryCompilation compilation, java.util.Map parameters, StatementClassMapping resultDefForClass, StatementResultMapping resultDef, org.datanucleus.metadata.AbstractClassMetaData cmd, boolean subclasses, org.datanucleus.FetchPlan fetchPlan, org.datanucleus.ExecutionContext ec, org.datanucleus.util.Imports importsDefinition, java.util.Set<java.lang.String> options, java.util.Map<java.lang.String,java.lang.Object> extensions)
Constructor.- Parameters:
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 classsubclasses- Whether to include subclassesfetchPlan- 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
-
setDefaultJoinType
void setDefaultJoinType(SQLJoin.JoinType joinType)
Method to set the default join type to be used. By default we use the nullability of the field to define whether to use LEFT OUTER, or INNER. In JPQL if a relation isn't specified explicitly in the FROM clause then it should use INNER hence where this method will be used, to define the default.- Parameters:
joinType- The default join type
-
setDefaultJoinTypeFilter
void setDefaultJoinTypeFilter(SQLJoin.JoinType joinType)
-
setParentMapper
void setParentMapper(QueryToSQLMapper parent)
-
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:
getQueryLanguagein interfaceQueryGenerator- Returns:
- The query language
-
getClassLoaderResolver
public org.datanucleus.ClassLoaderResolver getClassLoaderResolver()
Description copied from interface:QueryGeneratorAccessor for the ClassLoader resolver to use when looking up classes.- Specified by:
getClassLoaderResolverin interfaceQueryGenerator- Returns:
- The classloader resolver
-
getCompilationComponent
public org.datanucleus.store.query.compiler.CompilationComponent getCompilationComponent()
Description copied from interface:QueryGeneratorAccessor for the current query component being compiled.- Specified by:
getCompilationComponentin interfaceQueryGenerator- Returns:
- Component being compiled (if any)
-
getExecutionContext
public org.datanucleus.ExecutionContext getExecutionContext()
Description copied from interface:QueryGeneratorAccessor for the ExecutionContext for this query.- Specified by:
getExecutionContextin interfaceQueryGenerator- Returns:
- ExecutionContext
-
getProperty
public java.lang.Object getProperty(java.lang.String name)
Description copied from interface:QueryGeneratorAccessor 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:
getPropertyin interfaceQueryGenerator- 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
-
setNotPrecompilable
protected void setNotPrecompilable()
-
getParameterNameByPosition
public java.util.Map<java.lang.Integer,java.lang.String> getParameterNameByPosition()
Convenience accessor for a map of the parameter name keyed by its position. This is only available aftercompile
is called.- Returns:
- Map of parameter name keyed by position
-
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.
-
compileFrom
protected void compileFrom()
Method to compile the FROM clause of the query into the SQLStatement.
-
compileFilter
protected void compileFilter()
Method to compile the WHERE clause of the query into the SQLStatement.
-
compileResult
protected void compileResult(SelectStatement stmt)
Method to compile the result clause of the query into the SQLStatement. Note that this also compiles queries of the candidate (no specified result), selecting the candidate field(s).- Parameters:
stmt- SELECT statement
-
selectFetchPlanForCandidate
protected void selectFetchPlanForCandidate(SelectStatement stmt, StatementClassMapping resultClassMapping, int maxFetchDepth)
-
getStatementMappingForNewObjectExpression
protected StatementNewObjectMapping getStatementMappingForNewObjectExpression(NewObjectExpression expr, SelectStatement stmt)
Convenience method to convert a NewObjectExpression into a StatementNewObjectMapping. Handles recursive new object calls (where a new object is an argument to a new object construction).- Parameters:
expr- The NewObjectExpressionstmt- SelectStatement- Returns:
- The mapping for the new object
-
compileUpdate
protected void compileUpdate(UpdateStatement stmt)
Method to compile the result clause of the query into the SQLStatement.- Parameters:
stmt- UPDATE statement
-
validateExpressionForResult
protected void validateExpressionForResult(SQLExpression sqlExpr)
Method that validates that the specified expression is valid for use in a result clause. Throws a NucleusUserException if it finds a multi-value mapping selected (collection, map).- Parameters:
sqlExpr- The SQLExpression
-
compileGrouping
protected void compileGrouping(SelectStatement stmt)
Method to compile the grouping clause of the query into the SQLStatement.- Parameters:
stmt- SELECT statement
-
compileHaving
protected void compileHaving(SelectStatement stmt)
Method to compile the having clause of the query into the SQLStatement.- Parameters:
stmt- SELECT statement
-
compileOrdering
protected void compileOrdering(SelectStatement stmt)
Method to compile the ordering clause of the query into the SQLStatement.- Parameters:
stmt- SELECT statement
-
compileFromClassExpression
protected void compileFromClassExpression(org.datanucleus.store.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
-
getDiscriminatorValuesForCastClass
private java.lang.Object[] getDiscriminatorValuesForCastClass(org.datanucleus.metadata.AbstractClassMetaData cmd)
-
processingOnClause
public boolean processingOnClause()
- Specified by:
processingOnClausein interfaceQueryGenerator
-
processFromClauseSubquery
protected void processFromClauseSubquery(org.datanucleus.store.query.expression.ClassExpression clsExpr, SQLTable candSqlTbl, org.datanucleus.metadata.MetaDataManager mmgr)Method to process a ClassExpression where it represents a subquery. User defined the candidate of the subquery as an implied join to the outer query, for example "SELECT c FROM Customer c WHERE EXISTS (SELECT o FROM c.orders o ...)" so this method will add the join(s) to the outer query.- Parameters:
clsExpr- The ClassExpressioncandSqlTbl- Candidate SQL Tablemmgr- MetaData Manager
-
processAndExpression
protected java.lang.Object processAndExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processAndExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processOrExpression
protected java.lang.Object processOrExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processOrExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processBitAndExpression
protected java.lang.Object processBitAndExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processBitAndExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processBitOrExpression
protected java.lang.Object processBitOrExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processBitOrExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processBitXorExpression
protected java.lang.Object processBitXorExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processBitXorExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processEqExpression
protected java.lang.Object processEqExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processEqExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processNoteqExpression
protected java.lang.Object processNoteqExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processNoteqExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processGteqExpression
protected java.lang.Object processGteqExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processGteqExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processGtExpression
protected java.lang.Object processGtExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processGtExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processLteqExpression
protected java.lang.Object processLteqExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processLteqExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processLtExpression
protected java.lang.Object processLtExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processLtExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processLiteral
protected java.lang.Object processLiteral(org.datanucleus.store.query.expression.Literal expr)
- Overrides:
processLiteralin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
getSQLLiteralForLiteralValue
protected SQLExpression getSQLLiteralForLiteralValue(java.lang.Object litValue)
-
processPrimaryExpression
protected java.lang.Object processPrimaryExpression(org.datanucleus.store.query.expression.PrimaryExpression expr)
- Overrides:
processPrimaryExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
getSQLTableMappingForPrimaryExpression
private QueryToSQLMapper.SQLTableMapping getSQLTableMappingForPrimaryExpression(SQLStatement theStmt, java.lang.String exprName, org.datanucleus.store.query.expression.PrimaryExpression primExpr, java.lang.Boolean forceJoin)
Method to take in a PrimaryExpression and return the SQLTable mapping info that it signifies. If the primary expression implies joining to other objects then adds the joins to the statement. Only adds joins if necessary; so if there is a further component after the required join, or if the "forceJoin" flag is set.- Parameters:
theStmt- SQLStatement to use when looking for tables etcexprName- Name for an expression that this primary is relative to (optional) If not specified then the tuples are relative to the candidate. If specified then should have an entry in sqlTableByPrimary under this name.primExpr- The primary expressionforceJoin- Whether to force a join if a relation member (or null if leaving to this method to decide)- Returns:
- The SQL table mapping information for the specified primary
-
processParameterExpression
protected java.lang.Object processParameterExpression(org.datanucleus.store.query.expression.ParameterExpression expr)
- Overrides:
processParameterExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processParameterExpression
protected java.lang.Object processParameterExpression(org.datanucleus.store.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 ParameterExpressionasLiteral- Whether to create a SQLLiteral rather than a parameter literal- Returns:
- The processed expression
-
getInvokedSqlExpressionForInvokeExpression
protected SQLExpression getInvokedSqlExpressionForInvokeExpression(org.datanucleus.store.query.expression.InvokeExpression expr)
-
processInvokeExpression
protected java.lang.Object processInvokeExpression(org.datanucleus.store.query.expression.InvokeExpression expr)
- Overrides:
processInvokeExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processInvokeExpression
protected SQLExpression processInvokeExpression(org.datanucleus.store.query.expression.InvokeExpression expr, SQLExpression invokedSqlExpr)
Internal method to handle the processing of an InvokeExpression.- Parameters:
expr- The InvokeExpressioninvokedSqlExpr- The SQLExpression that we are invoking the method on.- Returns:
- The resultant SQLExpression
-
processSubqueryExpression
protected java.lang.Object processSubqueryExpression(org.datanucleus.store.query.expression.SubqueryExpression expr)
- Overrides:
processSubqueryExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processAddExpression
protected java.lang.Object processAddExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processAddExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processDivExpression
protected java.lang.Object processDivExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processDivExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processMulExpression
protected java.lang.Object processMulExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processMulExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processSubExpression
protected java.lang.Object processSubExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processSubExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processDistinctExpression
protected java.lang.Object processDistinctExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processDistinctExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processComExpression
protected java.lang.Object processComExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processComExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processModExpression
protected java.lang.Object processModExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processModExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processNegExpression
protected java.lang.Object processNegExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processNegExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processNotExpression
protected java.lang.Object processNotExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processNotExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processCastExpression
protected java.lang.Object processCastExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processCastExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processCaseExpression
protected java.lang.Object processCaseExpression(org.datanucleus.store.query.expression.CaseExpression expr)
- Overrides:
processCaseExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processCaseExpression
protected java.lang.Object processCaseExpression(org.datanucleus.store.query.expression.CaseExpression expr, SQLExpression typeExpr)
-
checkCaseExpressionsConsistent
private boolean checkCaseExpressionsConsistent(SQLExpression expr1, SQLExpression expr2)
-
processIsExpression
protected java.lang.Object processIsExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processIsExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processIsnotExpression
protected java.lang.Object processIsnotExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processIsnotExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processInExpression
protected java.lang.Object processInExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processInExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processNotInExpression
protected java.lang.Object processNotInExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processNotInExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processCreatorExpression
protected java.lang.Object processCreatorExpression(org.datanucleus.store.query.expression.CreatorExpression expr)
- Overrides:
processCreatorExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processLikeExpression
protected java.lang.Object processLikeExpression(org.datanucleus.store.query.expression.Expression expr)
- Overrides:
processLikeExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processVariableExpression
protected java.lang.Object processVariableExpression(org.datanucleus.store.query.expression.VariableExpression expr)
- Overrides:
processVariableExpressionin classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processUnboundExpression
protected SQLExpression processUnboundExpression(UnboundExpression expr)
-
useParameterExpressionAsLiteral
public void useParameterExpressionAsLiteral(SQLLiteral paramLiteral)
Description copied from interface:QueryGeneratorMethod 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:
useParameterExpressionAsLiteralin interfaceQueryGenerator- Parameters:
paramLiteral- The parameter expression
-
hasExtension
public boolean hasExtension(java.lang.String key)
Description copied from interface:QueryGeneratorAccessor for whether the query being generated has the specified extension.- Specified by:
hasExtensionin interfaceQueryGenerator- Parameters:
key- Extension name- Returns:
- Whether it is present
-
getValueForExtension
public java.lang.Object getValueForExtension(java.lang.String key)
Description copied from interface:QueryGeneratorAccessor for the value of the specified query extension (or null if not defined).- Specified by:
getValueForExtensionin interfaceQueryGenerator- Parameters:
key- Extension name- Returns:
- The value for the extension
-
getRequiredJoinTypeForAlias
public SQLJoin.JoinType getRequiredJoinTypeForAlias(java.lang.String alias)
Convenience method to return the required join type for the specified alias. If the table has a join type defined as an extension "datanucleus.query.jdoql.{alias}.join" then this returns the type. Otherwise returns null.- Parameters:
alias- The alias- Returns:
- The join type required (if any)
-
getDefaultJoinTypeForNavigation
private SQLJoin.JoinType getDefaultJoinTypeForNavigation()
Convenience method to return the default join type to use for a relation navigation. Uses the compilation component to decide what to use.- Returns:
- The join type to use
-
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 objectfieldName- The field name- Returns:
- The field value
-
getSQLTableMappingForAlias
protected QueryToSQLMapper.SQLTableMapping getSQLTableMappingForAlias(java.lang.String alias)
-
getAliasForSQLTableMapping
public java.lang.String getAliasForSQLTableMapping(QueryToSQLMapper.SQLTableMapping tblMapping)
-
getAliasForSQLTable
public java.lang.String getAliasForSQLTable(SQLTable tbl)
Returns the alias used for the specified SQLTable. If we have a variable "var1" and there is an access to a field also, then we may have entries for "var1" and "var1.field". In this case we return the shortest.- Parameters:
tbl- The table- Returns:
- The query name alias for this table
-
setSQLTableMappingForAlias
protected void setSQLTableMappingForAlias(java.lang.String alias, QueryToSQLMapper.SQLTableMapping mapping)
-
hasSQLTableMappingForAlias
protected boolean hasSQLTableMappingForAlias(java.lang.String alias)
-
bindVariable
public void bindVariable(java.lang.String varName, org.datanucleus.metadata.AbstractClassMetaData cmd, SQLTable sqlTbl, JavaTypeMapping mapping)Method to bind the specified variable to the table and mapping.- Specified by:
bindVariablein interfaceQueryGenerator- Parameters:
varName- Variable namecmd- Metadata for this variable typesqlTbl- Table for this variablemapping- The mapping of this variable in the table
-
bindVariable
public SQLExpression bindVariable(UnboundExpression expr, java.lang.Class type)
Method to bind the specified unbound variable (as cross join) on the assumption that the type is a persistable class.- Specified by:
bindVariablein interfaceQueryGenerator- Parameters:
expr- Unbound expressiontype- The type to bind as- Returns:
- The bound expression to use instead
-
bindParameter
public void bindParameter(java.lang.String paramName, java.lang.Class type)Method to bind the specified parameter to the defined type. If the parameter is already bound (declared in the query perhaps, or bound via an earlier usage) then does nothing.- Specified by:
bindParameterin interfaceQueryGenerator- Parameters:
paramName- Name of the parametertype- The type (or subclass)
-
getTypeOfVariable
public java.lang.Class getTypeOfVariable(java.lang.String varName)
Accessor for the type of a variable if already known (declared?).- Specified by:
getTypeOfVariablein interfaceQueryGenerator- Parameters:
varName- Name of the variable- Returns:
- The type if it is known
-
hasExplicitJoins
public boolean hasExplicitJoins()
Accessor for whether the query has explicit variables. If not then has implicit variables, meaning that they could potentially be rebound later if prematurely bound in a particular way.- Specified by:
hasExplicitJoinsin interfaceQueryGenerator- Returns:
- Whether the query has explicit variables
-
getBooleanExpressionForUseInFilter
protected BooleanExpression getBooleanExpressionForUseInFilter(BooleanExpression expr)
Convenience method to return a boolean expression suitable for using in a filter. Will return the input expression unless it is simply a reference to a field of a class such as in a filter clause likemyBoolField
. In that case we return a boolean likemyBoolField == TRUE
.- Parameters:
expr- The expression to check- Returns:
- The expression valid for use in the filter
-
resolveClass
public java.lang.Class resolveClass(java.lang.String className)
Convenience method to resolve a class name.- Specified by:
resolveClassin interfaceQueryGenerator- Parameters:
className- The class name- Returns:
- The class it relates to (if found)
-
-