public abstract class SQLStatement extends Object
The generated SQL is cached. Any use of a mutating method, changing the composition of the statement will clear the cached SQL, and it will be regenerated when
getSQLTextis called next.
Modifier and Type | Field and Description |
---|---|
protected String |
candidateClassName
Name of class that this statement selects (optional, only typically for unioned statements).
|
protected org.datanucleus.ClassLoaderResolver |
clr
ClassLoader resolver to use.
|
static String |
EXTENSION_LOCK_FOR_UPDATE |
static String |
EXTENSION_LOCK_FOR_UPDATE_NOWAIT |
static String |
EXTENSION_SQL_TABLE_NAMING_STRATEGY |
protected Map<String,Object> |
extensions
Map of extensions for use in generating the SQL, keyed by the extension name.
|
protected List<SQLJoin> |
joins
List of joins for this statement.
|
protected SQLTableNamer |
namer |
protected SQLStatement |
parent
Parent statement, if this is a subquery SELECT.
|
protected SQLTable |
primaryTable
Primary table for this statement.
|
protected QueryGenerator |
queryGenerator
Context of any query generation.
|
protected RDBMSStoreManager |
rdbmsMgr
Manager for the RDBMS datastore.
|
protected boolean |
requiresJoinReorder |
protected SQLText |
sql
Cached SQL statement, generated by getSQLText().
|
protected Map<String,SQLTableGroup> |
tableGroups
Map of table groups keyed by the group name.
|
protected static Map<String,SQLTableNamer> |
tableNamerByName
Map of SQLTable naming instance keyed by the name of the naming scheme.
|
protected Map<String,SQLTable> |
tables
Map of tables referenced in this statement, keyed by their alias.
|
protected BooleanExpression |
where
Where clause.
|
Constructor and Description |
---|
SQLStatement(SQLStatement parentStmt,
RDBMSStoreManager rdbmsMgr,
Table table,
DatastoreIdentifier alias,
String tableGroupName,
Map<String,Object> extensions)
Constructor for an SQL statement that is a subquery of another statement.
|
Modifier and Type | Method and Description |
---|---|
void |
addAndConditionToJoinForTable(SQLTable sqlTbl,
BooleanExpression andCondition,
boolean applyToUnions)
Method to find the JOIN for the specified table and add the specified 'and' condition to the JOIN as an 'ON' clause.
|
void |
addExtension(String key,
Object value)
Method to define an extension for this query statement allowing control over its behaviour in generating a query.
|
protected void |
addJoin(SQLJoin.JoinType joinType,
SQLTable sourceTable,
SQLTable targetTable,
BooleanExpression joinCondition,
SQLJoin parentJoin)
Internal method to form a join to the specified table using the provided mappings.
|
String |
getCandidateClassName() |
org.datanucleus.ClassLoaderResolver |
getClassLoaderResolver() |
DatastoreAdapter |
getDatastoreAdapter() |
protected BooleanExpression |
getJoinConditionForJoin(SQLTable sourceTable,
JavaTypeMapping sourceMapping,
JavaTypeMapping sourceParentMapping,
SQLTable targetTable,
JavaTypeMapping targetMapping,
JavaTypeMapping targetParentMapping,
Object[] discrimValues)
Convenience method to generate the join condition between source and target tables for the supplied mappings.
|
SQLJoin |
getJoinForTable(SQLTable sqlTbl)
Accessor for the type of join used for the specified table.
|
SQLJoin.JoinType |
getJoinTypeForTable(SQLTable sqlTbl)
Accessor for the type of join used for the specified table.
|
int |
getNumberOfTableGroups()
Accessor for the number of table groups.
|
int |
getNumberOfTables()
Accessor for the number of tables defined for this statement.
|
SQLStatement |
getParentStatement() |
SQLTable |
getPrimaryTable()
Accessor for the primary table of the statement.
|
QueryGenerator |
getQueryGenerator() |
RDBMSStoreManager |
getRDBMSManager() |
SQLExpressionFactory |
getSQLExpressionFactory() |
SQLText |
getSQLText() |
SQLTable |
getTable(String alias)
Accessor for the SQLTable object with the specified alias (if defined for this statement).
|
SQLTable |
getTable(Table table,
String groupName)
Accessor for the SQLTable object for the specified table (if defined for this statement)
in the specified table group.
|
SQLTable |
getTableForDatastoreContainer(Table table)
Convenience method to find a registered SQLTable that is for the specified table
|
SQLTableGroup |
getTableGroup(String groupName)
Accessor for the table group with this name.
|
protected SQLTableNamer |
getTableNamer(String namingSchema)
Method to return the namer for a particular schema.
|
Object |
getValueForExtension(String key)
Accessor for the value for an extension.
|
protected void |
invalidateStatement()
Method to uncache the generated SQL (because some condition has changed).
|
boolean |
isChildStatementOf(SQLStatement stmt)
Convenience method to return if this statement is a child (inner) statement of the supplied
statement.
|
SQLTable |
join(SQLJoin.JoinType joinType,
SQLTable sourceTable,
JavaTypeMapping sourceMapping,
JavaTypeMapping sourceParentMapping,
Table target,
String targetAlias,
JavaTypeMapping targetMapping,
JavaTypeMapping targetParentMapping,
Object[] discrimValues,
String tableGrpName,
boolean applyToUnions,
SQLJoin parentJoin)
Method to form a join to the specified table using the provided mappings, with the join condition derived from the source-target mappings.
|
SQLTable |
join(SQLJoin.JoinType joinType,
SQLTable sourceTable,
JavaTypeMapping sourceMapping,
Table target,
String targetAlias,
JavaTypeMapping targetMapping,
Object[] discrimValues,
String tableGrpName)
Method to form a join to the specified table using the provided mappings, with the join also being applied to any UNIONed statements.
|
SQLTable |
join(SQLJoin.JoinType joinType,
SQLTable sourceTable,
JavaTypeMapping sourceMapping,
Table target,
String targetAlias,
JavaTypeMapping targetMapping,
Object[] discrimValues,
String tableGrpName,
boolean applyToUnions)
Method to form a join to the specified table using the provided mappings.
|
SQLTable |
join(SQLJoin.JoinType joinType,
SQLTable sourceTable,
JavaTypeMapping sourceMapping,
Table target,
String targetAlias,
JavaTypeMapping targetMapping,
Object[] discrimValues,
String tableGrpName,
boolean applyToUnions,
SQLJoin parentJoin)
Method to form a join to the specified table using the provided mappings.
|
SQLTable |
join(SQLJoin.JoinType joinType,
SQLTable sourceTable,
JavaTypeMapping sourceMapping,
Table target,
String targetAlias,
JavaTypeMapping targetMapping,
Object[] discrimValues,
String tableGrpName,
SQLJoin parentJoin)
Method to form a join to the specified table using the provided mappings, with the join also being applied to any UNIONed statements.
|
SQLTable |
join(SQLJoin.JoinType joinType,
SQLTable sourceTable,
Table target,
String targetAlias,
String tableGrpName,
BooleanExpression joinCondition,
boolean applyToUnions)
Method to form a join to the specified table using the provided mappings and applying the provided join condition (rather than generating one from the source/target mappings).
|
void |
log(org.datanucleus.util.NucleusLogger logger)
Method to dump the statement to the supplied log (debug level).
|
protected void |
putSQLTableInGroup(SQLTable sqlTbl,
String groupName,
SQLJoin.JoinType joinType)
Convenience method to add the SQLTable to the specified group.
|
String |
removeCrossJoin(SQLTable targetSqlTbl)
Method to remove a cross join for the specified table (if joined via cross join).
|
void |
setCandidateClassName(String name) |
void |
setClassLoaderResolver(org.datanucleus.ClassLoaderResolver clr) |
void |
setQueryGenerator(QueryGenerator gen) |
void |
whereAnd(BooleanExpression expr,
boolean applyToUnions)
Method to add an AND condition to the WHERE clause.
|
void |
whereOr(BooleanExpression expr,
boolean applyToUnions)
Method to add an OR condition to the WHERE clause.
|
public static final String EXTENSION_SQL_TABLE_NAMING_STRATEGY
public static final String EXTENSION_LOCK_FOR_UPDATE
public static final String EXTENSION_LOCK_FOR_UPDATE_NOWAIT
protected static final Map<String,SQLTableNamer> tableNamerByName
protected SQLText sql
protected RDBMSStoreManager rdbmsMgr
protected org.datanucleus.ClassLoaderResolver clr
protected QueryGenerator queryGenerator
protected SQLTableNamer namer
protected String candidateClassName
protected Map<String,Object> extensions
protected SQLStatement parent
protected SQLTable primaryTable
protected boolean requiresJoinReorder
protected Map<String,SQLTable> tables
protected Map<String,SQLTableGroup> tableGroups
protected BooleanExpression where
public SQLStatement(SQLStatement parentStmt, RDBMSStoreManager rdbmsMgr, Table table, DatastoreIdentifier alias, String tableGroupName, Map<String,Object> extensions)
parentStmt
- Parent statementrdbmsMgr
- The datastore managertable
- The primary tablealias
- Alias for this tabletableGroupName
- Name of candidate table-group (if any). Uses "Group0" if not providedextensions
- Any extensions (optional)public RDBMSStoreManager getRDBMSManager()
public void setClassLoaderResolver(org.datanucleus.ClassLoaderResolver clr)
public org.datanucleus.ClassLoaderResolver getClassLoaderResolver()
public void setCandidateClassName(String name)
public String getCandidateClassName()
public QueryGenerator getQueryGenerator()
public void setQueryGenerator(QueryGenerator gen)
public SQLExpressionFactory getSQLExpressionFactory()
public DatastoreAdapter getDatastoreAdapter()
public SQLStatement getParentStatement()
public boolean isChildStatementOf(SQLStatement stmt)
stmt
- The statement that may be parent, grandparent etc of this statementpublic void addExtension(String key, Object value)
key
- Extension keyvalue
- Value for the keypublic Object getValueForExtension(String key)
key
- Key for the extensionpublic SQLTable getPrimaryTable()
public SQLTable getTable(String alias)
alias
- Aliaspublic SQLTable getTableForDatastoreContainer(Table table)
table
- The tablepublic SQLTable getTable(Table table, String groupName)
table
- The tablegroupName
- Name of the table group where we should look for this tablepublic SQLTableGroup getTableGroup(String groupName)
groupName
- Name of the grouppublic int getNumberOfTableGroups()
public int getNumberOfTables()
public SQLTable join(SQLJoin.JoinType joinType, SQLTable sourceTable, JavaTypeMapping sourceMapping, Table target, String targetAlias, JavaTypeMapping targetMapping, Object[] discrimValues, String tableGrpName)
joinType
- Type of join.sourceTable
- SQLTable for the source (null implies primaryTable)sourceMapping
- Mapping in this table to join fromtarget
- Table to join totargetAlias
- Alias for the target table (if known)targetMapping
- Mapping in the other table to join to (also defines the table to join to)discrimValues
- Any discriminator values to apply for the joined table (null if not)tableGrpName
- Name of the table group for the target (null implies a new group)public SQLTable join(SQLJoin.JoinType joinType, SQLTable sourceTable, JavaTypeMapping sourceMapping, Table target, String targetAlias, JavaTypeMapping targetMapping, Object[] discrimValues, String tableGrpName, SQLJoin parentJoin)
joinType
- Type of join.sourceTable
- SQLTable for the source (null implies primaryTable)sourceMapping
- Mapping in this table to join fromtarget
- Table to join totargetAlias
- Alias for the target table (if known)targetMapping
- Mapping in the other table to join to (also defines the table to join to)discrimValues
- Any discriminator values to apply for the joined table (null if not)tableGrpName
- Name of the table group for the target (null implies a new group)parentJoin
- Parent join when this join will be a sub-join (part of "join grouping")public SQLTable join(SQLJoin.JoinType joinType, SQLTable sourceTable, JavaTypeMapping sourceMapping, Table target, String targetAlias, JavaTypeMapping targetMapping, Object[] discrimValues, String tableGrpName, boolean applyToUnions)
joinType
- Type of join.sourceTable
- SQLTable for the source (null implies primaryTable)sourceMapping
- Mapping in this table to join fromtarget
- Table to join totargetAlias
- Alias for the target table (if known)targetMapping
- Mapping in the other table to join to (also defines the table to join to)discrimValues
- Any discriminator values to apply for the joined table (null if not)tableGrpName
- Name of the table group for the target (null implies a new group)applyToUnions
- Whether to apply to any unioned statements (only applies to SELECT statements)public SQLTable join(SQLJoin.JoinType joinType, SQLTable sourceTable, JavaTypeMapping sourceMapping, Table target, String targetAlias, JavaTypeMapping targetMapping, Object[] discrimValues, String tableGrpName, boolean applyToUnions, SQLJoin parentJoin)
joinType
- Type of join.sourceTable
- SQLTable for the source (null implies primaryTable)sourceMapping
- Mapping in this table to join fromtarget
- Table to join totargetAlias
- Alias for the target table (if known)targetMapping
- Mapping in the other table to join to (also defines the table to join to)discrimValues
- Any discriminator values to apply for the joined table (null if not)tableGrpName
- Name of the table group for the target (null implies a new group)applyToUnions
- Whether to apply to any unioned statements (only applies to SELECT statements)parentJoin
- Parent join when this join will be a sub-join (part of "join grouping")public SQLTable join(SQLJoin.JoinType joinType, SQLTable sourceTable, JavaTypeMapping sourceMapping, JavaTypeMapping sourceParentMapping, Table target, String targetAlias, JavaTypeMapping targetMapping, JavaTypeMapping targetParentMapping, Object[] discrimValues, String tableGrpName, boolean applyToUnions, SQLJoin parentJoin)
joinType
- Type of join.sourceTable
- SQLTable for the source (null implies primaryTable)sourceMapping
- Mapping in this table to join fromsourceParentMapping
- Optional, if this source mapping is a sub mapping (e.g interface impl).target
- Table to join totargetAlias
- Alias for the target table (if known)targetMapping
- Mapping in the other table to join to (also defines the table to join to)targetParentMapping
- Optional, if this source mapping is a sub mapping (e.g interface impl).discrimValues
- Any discriminator values to apply for the joined table (null if not)tableGrpName
- Name of the table group for the target (null implies a new group)applyToUnions
- Whether to apply to any unioned statements (only applies to SELECT statements)parentJoin
- Parent join when this join will be a sub-join (part of "join grouping")public SQLTable join(SQLJoin.JoinType joinType, SQLTable sourceTable, Table target, String targetAlias, String tableGrpName, BooleanExpression joinCondition, boolean applyToUnions)
joinType
- Type of join.sourceTable
- SQLTable for the source (null implies primaryTable)target
- Table to join totargetAlias
- Alias for the target table (if known)tableGrpName
- Name of the table group for the target (null implies a new group)joinCondition
- On clause for the joinapplyToUnions
- Whether to apply to any unioned statements (only applies to SELECT statements)public SQLJoin.JoinType getJoinTypeForTable(SQLTable sqlTbl)
sqlTbl
- The table to checkpublic void addAndConditionToJoinForTable(SQLTable sqlTbl, BooleanExpression andCondition, boolean applyToUnions)
sqlTbl
- The tableandCondition
- The 'ON' condition to addapplyToUnions
- Whether to apply to unions (see SelectStatement)public SQLJoin getJoinForTable(SQLTable sqlTbl)
sqlTbl
- The table to checkpublic String removeCrossJoin(SQLTable targetSqlTbl)
targetSqlTbl
- The table to drop the cross join forprotected void putSQLTableInGroup(SQLTable sqlTbl, String groupName, SQLJoin.JoinType joinType)
sqlTbl
- SQLTable to addgroupName
- The groupjoinType
- type of join to start this table groupprotected void addJoin(SQLJoin.JoinType joinType, SQLTable sourceTable, SQLTable targetTable, BooleanExpression joinCondition, SQLJoin parentJoin)
joinType
- Type of join (INNER, LEFT OUTER, RIGHT OUTER, CROSS, NON-ANSI)sourceTable
- SQLTable to join fromtargetTable
- SQLTable to join tojoinCondition
- Condition for the joinparentJoin
- Optional parent join (which will mean this join becomes a sub-join)protected BooleanExpression getJoinConditionForJoin(SQLTable sourceTable, JavaTypeMapping sourceMapping, JavaTypeMapping sourceParentMapping, SQLTable targetTable, JavaTypeMapping targetMapping, JavaTypeMapping targetParentMapping, Object[] discrimValues)
sourceTable
- Source tablesourceMapping
- Mapping in source tablesourceParentMapping
- Optional parent of this source mapping (if joining an impl of an interface)targetTable
- Target tabletargetMapping
- Mapping in target tabletargetParentMapping
- Optional parent of this target mapping (if joining an impl of an interface)discrimValues
- Optional discriminator values to further restrictprotected SQLTableNamer getTableNamer(String namingSchema)
namingSchema
- Table naming schema to usepublic void whereAnd(BooleanExpression expr, boolean applyToUnions)
expr
- The conditionapplyToUnions
- whether to apply this and to any UNIONs in the statement (only applies to SELECT statements)public void whereOr(BooleanExpression expr, boolean applyToUnions)
expr
- The conditionapplyToUnions
- Whether to apply to unions (only applies to SELECT statements)public SQLText getSQLText()
protected void invalidateStatement()
public void log(org.datanucleus.util.NucleusLogger logger)
logger
- The loggerCopyright © 2019. All rights reserved.