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 -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final String
(package private) final org.datanucleus.metadata.AbstractClassMetaData
(package private) org.datanucleus.ClassLoaderResolver
(package private) final org.datanucleus.store.query.compiler.QueryCompilation
(package private) org.datanucleus.store.query.compiler.CompilationComponent
State variable for the component being compiled.(package private) SQLJoin.JoinType
(package private) SQLJoin.JoinType
(package private) org.datanucleus.ExecutionContext
Map of the join primary expression string keyed by the join alias (explicit joins only).(package private) Map
<Object, SQLExpression> (package private) final SQLExpressionFactory
Map of query extensions defining behaviour on the compilation.(package private) final org.datanucleus.FetchPlan
(package private) org.datanucleus.util.Imports
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Options for the SQL generation process.(package private) final Map
Input parameter values, keyed by the parameter name.Work Map for keying parameter value for the name, for case where parameters input as positional.(package private) Map
<String, JavaTypeMapping> Parent mapper if we are processing a subquery.(package private) int
Positional parameter that we are up to (-1 implies not being used).(package private) boolean
State variable for whether this query is precompilable (hence whether it is cacheable).protected boolean
(package private) boolean
Aliases defined in the result, populated during compileResult.(package private) final StatementResultMapping
Definition of mapping for the results of this SQL statement (result).(package private) final StatementClassMapping
Definition of mapping for the results of this SQL statement (candidate).(package private) Map
<String, QueryToSQLMapper.SQLTableMapping> Map of SQLTable/mapping keyed by the name of the primary that it relates to.(package private) Deque
<SQLExpression> Stack of expressions, used for compilation of the query into SQL.(package private) SQLStatement
SQL statement that we are updating.(package private) final RDBMSStoreManager
(package private) final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionQueryToSQLMapper
(SQLStatement stmt, org.datanucleus.store.query.compiler.QueryCompilation compilation, 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, Set<String> options, Map<String, Object> extensions) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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, JavaTypeMapping mapping) Method to bind the specified variable to the table and mapping.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.private boolean
checkCaseExpressionsConsistent
(SQLExpression expr1, SQLExpression expr2) void
compile()
Method to update the supplied SQLStatement with the components of the specified query.protected void
Method to compile the WHERE clause of the query into the SQLStatement.protected void
Method to compile the FROM clause of the query into the SQLStatement.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.protected void
Method to compile the grouping clause of the query into the SQLStatement.protected void
compileHaving
(SelectStatement stmt) Method to compile the having clause of the query into the SQLStatement.protected void
Method to compile the ordering clause of the query into the SQLStatement.protected void
compileResult
(SelectStatement stmt) Method to compile the result clause of the query into the SQLStatement.protected void
compileUpdate
(UpdateStatement stmt) Method to compile the result clause of the query into the SQLStatement.Returns the alias used for the specified SQLTable.protected BooleanExpression
Convenience method to return a boolean expression suitable for using in a filter.org.datanucleus.ClassLoaderResolver
Accessor for the ClassLoader resolver to use when looking up classes.org.datanucleus.store.query.compiler.CompilationComponent
Accessor for the current query component being compiled.private SQLJoin.JoinType
Convenience method to return the default join type to use for a relation navigation.private Object[]
getDiscriminatorValuesForCastClass
(org.datanucleus.metadata.AbstractClassMetaData cmd) org.datanucleus.ExecutionContext
Accessor for the ExecutionContext for this query.protected SQLExpression
getInvokedSqlExpressionForInvokeExpression
(org.datanucleus.store.query.expression.InvokeExpression expr) Convenience accessor for a map of the parameter name keyed by its position.getProperty
(String name) Accessor for a property affecting the query compilation.Accessor for the query language that this query pertains to.Convenience method to return the required join type for the specified alias.protected SQLExpression
getSQLLiteralForLiteralValue
(Object litValue) protected QueryToSQLMapper.SQLTableMapping
getSQLTableMappingForAlias
(String alias) private QueryToSQLMapper.SQLTableMapping
getSQLTableMappingForPrimaryExpression
(SQLStatement theStmt, String exprName, org.datanucleus.store.query.expression.PrimaryExpression primExpr, Boolean forceJoin) Method to take in a PrimaryExpression and return the SQLTable mapping info that it signifies.protected StatementNewObjectMapping
Convenience method to convert a NewObjectExpression into a StatementNewObjectMapping.getTypeOfVariable
(String varName) Accessor for the type of a variable if already known (declared?).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
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
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.store.query.expression.Expression expr) protected Object
processAndExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processBitAndExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processBitOrExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processBitXorExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processCaseExpression
(org.datanucleus.store.query.expression.CaseExpression expr) protected Object
processCaseExpression
(org.datanucleus.store.query.expression.CaseExpression expr, SQLExpression typeExpr) protected Object
processCastExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processComExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processCreatorExpression
(org.datanucleus.store.query.expression.CreatorExpression expr) protected Object
processDistinctExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processDivExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processEqExpression
(org.datanucleus.store.query.expression.Expression expr) 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.protected Object
processGteqExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processGtExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processInExpression
(org.datanucleus.store.query.expression.Expression expr) boolean
protected Object
processInvokeExpression
(org.datanucleus.store.query.expression.InvokeExpression expr) protected SQLExpression
processInvokeExpression
(org.datanucleus.store.query.expression.InvokeExpression expr, SQLExpression invokedSqlExpr) Internal method to handle the processing of an InvokeExpression.protected Object
processIsExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processIsnotExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processLikeExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processLiteral
(org.datanucleus.store.query.expression.Literal expr) protected Object
processLteqExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processLtExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processModExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processMulExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processNegExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processNoteqExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processNotExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processNotInExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processOrExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processParameterExpression
(org.datanucleus.store.query.expression.ParameterExpression expr) protected Object
processParameterExpression
(org.datanucleus.store.query.expression.ParameterExpression expr, boolean asLiteral) Method to process a parameter expression.protected Object
processPrimaryExpression
(org.datanucleus.store.query.expression.PrimaryExpression expr) protected Object
processSubExpression
(org.datanucleus.store.query.expression.Expression expr) protected Object
processSubqueryExpression
(org.datanucleus.store.query.expression.SubqueryExpression expr) protected SQLExpression
protected Object
processVariableExpression
(org.datanucleus.store.query.expression.VariableExpression expr) resolveClass
(String className) Convenience method to resolve a class name.protected void
selectFetchPlanForCandidate
(SelectStatement stmt, StatementClassMapping resultClassMapping, int maxFetchDepth) (package private) void
setDefaultJoinType
(SQLJoin.JoinType joinType) Method to set the default join type to be used.(package private) void
setDefaultJoinTypeFilter
(SQLJoin.JoinType joinType) protected void
(package private) void
setParentMapper
(QueryToSQLMapper parent) protected void
setSQLTableMappingForAlias
(String alias, 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.store.query.expression.AbstractExpressionEvaluator
compileAdditiveMultiplicativeExpression, compileOrAndExpression, compilePrimaryExpression, compileRelationalExpression, compileUnaryExpression, evaluate
-
Field Details
-
OPTION_CASE_INSENSITIVE
- See Also:
-
OPTION_EXPLICIT_JOINS
- See Also:
-
OPTION_NON_DISTINCT_IMPLICIT_JOINS
- See Also:
-
OPTION_BULK_UPDATE_VERSION
- See Also:
-
OPTION_SELECT_CANDIDATE_ID_ONLY
- See Also:
-
OPTION_NULL_PARAM_USE_IS_NULL
- See Also:
-
MAP_KEY_ALIAS_SUFFIX
- See Also:
-
MAP_VALUE_ALIAS_SUFFIX
- See Also:
-
candidateAlias
-
candidateCmd
final org.datanucleus.metadata.AbstractClassMetaData candidateCmd -
subclasses
final boolean subclasses -
compilation
final org.datanucleus.store.query.compiler.QueryCompilation compilation -
parameters
Input parameter values, keyed by the parameter name. Will be null if compiled pre-execution. -
parameterValueByName
Work Map for keying parameter value for the name, for case where parameters input as positional. -
paramNameByPosition
-
positionalParamNumber
int positionalParamNumberPositional parameter that we are up to (-1 implies not being used). -
extensionsByName
Map of query extensions defining behaviour on the compilation. -
stmt
SQLStatement stmtSQL statement that we are updating. -
resultDefinitionForClass
Definition of mapping for the results of this SQL statement (candidate). -
resultDefinition
Definition of mapping for the results of this SQL statement (result). -
expressionForParameter
Map<Object,SQLExpression> expressionForParameter -
storeMgr
-
fetchPlan
final org.datanucleus.FetchPlan fetchPlan -
exprFactory
-
ec
org.datanucleus.ExecutionContext ec -
clr
org.datanucleus.ClassLoaderResolver clr -
importsDefinition
org.datanucleus.util.Imports importsDefinition -
compileProperties
-
compileComponent
org.datanucleus.store.query.compiler.CompilationComponent compileComponentState variable for the component being compiled. -
stack
Deque<SQLExpression> stackStack of expressions, used for compilation of the query into SQL. -
sqlTableByPrimary
Map<String,QueryToSQLMapper.SQLTableMapping> sqlTableByPrimaryMap 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
Aliases defined in the result, populated during compileResult. -
explicitJoinPrimaryByAlias
Map of the join primary expression string keyed by the join alias (explicit joins only). -
paramMappingForName
Map<String,JavaTypeMapping> paramMappingForName -
options
Options for the SQL generation process. See OPTION_xxx above. -
parentMapper
Parent mapper if we are processing a subquery. -
defaultJoinType
SQLJoin.JoinType defaultJoinType -
defaultJoinTypeFilter
SQLJoin.JoinType defaultJoinTypeFilter -
precompilable
boolean precompilableState 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 Details
-
QueryToSQLMapper
public QueryToSQLMapper(SQLStatement stmt, org.datanucleus.store.query.compiler.QueryCompilation compilation, 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, Set<String> options, Map<String, 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 Details
-
setDefaultJoinType
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
-
setParentMapper
-
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 interfaceQueryGenerator
- 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 interfaceQueryGenerator
- Returns:
- The classloader resolver
-
getCompilationComponent
public org.datanucleus.store.query.compiler.CompilationComponent getCompilationComponent()Description copied from interface:QueryGenerator
Accessor for the current query component being compiled.- Specified by:
getCompilationComponent
in interfaceQueryGenerator
- Returns:
- Component being compiled (if any)
-
getExecutionContext
public org.datanucleus.ExecutionContext getExecutionContext()Description copied from interface:QueryGenerator
Accessor for the ExecutionContext for this query.- Specified by:
getExecutionContext
in interfaceQueryGenerator
- Returns:
- ExecutionContext
-
getProperty
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 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
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
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
Method to compile the result clause of the query into the SQLStatement.- Parameters:
stmt
- UPDATE statement
-
validateExpressionForResult
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
Method to compile the grouping clause of the query into the SQLStatement.- Parameters:
stmt
- SELECT statement
-
compileHaving
Method to compile the having clause of the query into the SQLStatement.- Parameters:
stmt
- SELECT statement
-
compileOrdering
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 Object[] getDiscriminatorValuesForCastClass(org.datanucleus.metadata.AbstractClassMetaData cmd) -
processingOnClause
public boolean processingOnClause()- Specified by:
processingOnClause
in 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
- Overrides:
processAndExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processOrExpression
- Overrides:
processOrExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processBitAndExpression
- Overrides:
processBitAndExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processBitOrExpression
- Overrides:
processBitOrExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processBitXorExpression
- Overrides:
processBitXorExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processEqExpression
- Overrides:
processEqExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processNoteqExpression
- Overrides:
processNoteqExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processGteqExpression
- Overrides:
processGteqExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processGtExpression
- Overrides:
processGtExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processLteqExpression
- Overrides:
processLteqExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processLtExpression
- Overrides:
processLtExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processLiteral
- Overrides:
processLiteral
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
getSQLLiteralForLiteralValue
-
processPrimaryExpression
protected Object processPrimaryExpression(org.datanucleus.store.query.expression.PrimaryExpression expr) - Overrides:
processPrimaryExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
getSQLTableMappingForPrimaryExpression
private QueryToSQLMapper.SQLTableMapping getSQLTableMappingForPrimaryExpression(SQLStatement theStmt, String exprName, org.datanucleus.store.query.expression.PrimaryExpression primExpr, 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 Object processParameterExpression(org.datanucleus.store.query.expression.ParameterExpression expr) - Overrides:
processParameterExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processParameterExpression
protected 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 Object processInvokeExpression(org.datanucleus.store.query.expression.InvokeExpression expr) - Overrides:
processInvokeExpression
in 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 Object processSubqueryExpression(org.datanucleus.store.query.expression.SubqueryExpression expr) - Overrides:
processSubqueryExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processAddExpression
- Overrides:
processAddExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processDivExpression
- Overrides:
processDivExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processMulExpression
- Overrides:
processMulExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processSubExpression
- Overrides:
processSubExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processDistinctExpression
- Overrides:
processDistinctExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processComExpression
- Overrides:
processComExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processModExpression
- Overrides:
processModExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processNegExpression
- Overrides:
processNegExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processNotExpression
- Overrides:
processNotExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processCastExpression
- Overrides:
processCastExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processCaseExpression
- Overrides:
processCaseExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processCaseExpression
protected Object processCaseExpression(org.datanucleus.store.query.expression.CaseExpression expr, SQLExpression typeExpr) -
checkCaseExpressionsConsistent
-
processIsExpression
- Overrides:
processIsExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processIsnotExpression
- Overrides:
processIsnotExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processInExpression
- Overrides:
processInExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processNotInExpression
- Overrides:
processNotInExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processCreatorExpression
protected Object processCreatorExpression(org.datanucleus.store.query.expression.CreatorExpression expr) - Overrides:
processCreatorExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processLikeExpression
- Overrides:
processLikeExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processVariableExpression
protected Object processVariableExpression(org.datanucleus.store.query.expression.VariableExpression expr) - Overrides:
processVariableExpression
in classorg.datanucleus.store.query.expression.AbstractExpressionEvaluator
-
processUnboundExpression
-
useParameterExpressionAsLiteral
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 interfaceQueryGenerator
- Parameters:
paramLiteral
- The parameter expression
-
hasExtension
Description copied from interface:QueryGenerator
Accessor for whether the query being generated has the specified extension.- Specified by:
hasExtension
in interfaceQueryGenerator
- Parameters:
key
- Extension name- Returns:
- Whether it is present
-
getValueForExtension
Description copied from interface:QueryGenerator
Accessor for the value of the specified query extension (or null if not defined).- Specified by:
getValueForExtension
in interfaceQueryGenerator
- Parameters:
key
- Extension name- Returns:
- The value for the extension
-
getRequiredJoinTypeForAlias
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)
-
getValueForObjectField
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
-
getAliasForSQLTableMapping
-
getAliasForSQLTable
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
-
hasSQLTableMappingForAlias
-
bindVariable
public void bindVariable(String varName, org.datanucleus.metadata.AbstractClassMetaData cmd, SQLTable sqlTbl, JavaTypeMapping mapping) Method to bind the specified variable to the table and mapping.- Specified by:
bindVariable
in interfaceQueryGenerator
- Parameters:
varName
- Variable namecmd
- Metadata for this variable typesqlTbl
- Table for this variablemapping
- The mapping of this variable in the table
-
bindVariable
Method to bind the specified unbound variable (as cross join) on the assumption that the type is a persistable class.- Specified by:
bindVariable
in interfaceQueryGenerator
- Parameters:
expr
- Unbound expressiontype
- The type to bind as- Returns:
- The bound expression to use instead
-
bindParameter
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:
bindParameter
in interfaceQueryGenerator
- Parameters:
paramName
- Name of the parametertype
- The type (or subclass)
-
getTypeOfVariable
Accessor for the type of a variable if already known (declared?).- Specified by:
getTypeOfVariable
in 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:
hasExplicitJoins
in interfaceQueryGenerator
- Returns:
- Whether the query has explicit variables
-
getBooleanExpressionForUseInFilter
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
Convenience method to resolve a class name.- Specified by:
resolveClass
in interfaceQueryGenerator
- Parameters:
className
- The class name- Returns:
- The class it relates to (if found)
-