|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.datanucleus.store.rdbms.sql.AbstractStatementGenerator
org.datanucleus.store.rdbms.sql.UnionStatementGenerator
public class UnionStatementGenerator
Class to generate an SQLStatement for iterating through instances of a particular type (and optionally subclasses). Based around the candidate type having subclasses and we use UNIONs to return all possible types of candidate. Also allows select of a dummy column to return the type for the part of the UNION that the object came from. Please refer to the specific constructors for the usages.
This generator supports
| Field Summary | |
|---|---|
static String |
NUC_TYPE_COLUMN
Name of column added when using "selectNucleusType" |
| Fields inherited from class org.datanucleus.store.rdbms.sql.AbstractStatementGenerator |
|---|
candidateTable, candidateTableAlias, candidateTableGroupName, candidateType, clr, includeSubclasses, parentStmt, storeMgr |
| Fields inherited from interface org.datanucleus.store.rdbms.sql.StatementGenerator |
|---|
OPTION_ALLOW_NULLS, OPTION_RESTRICT_DISCRIM, OPTION_SELECT_NUCLEUS_TYPE |
| Constructor Summary | |
|---|---|
UnionStatementGenerator(RDBMSStoreManager storeMgr,
org.datanucleus.ClassLoaderResolver clr,
Class candidateType,
boolean includeSubclasses,
org.datanucleus.store.mapped.DatastoreIdentifier candidateTableAlias,
String candidateTableGroupName)
Constructor using the candidateTable as the primary table. |
|
UnionStatementGenerator(RDBMSStoreManager storeMgr,
org.datanucleus.ClassLoaderResolver clr,
Class candidateType,
boolean includeSubclasses,
org.datanucleus.store.mapped.DatastoreIdentifier candidateTableAlias,
String candidateTableGroupName,
org.datanucleus.store.mapped.DatastoreContainerObject joinTable,
org.datanucleus.store.mapped.DatastoreIdentifier joinTableAlias,
org.datanucleus.store.mapped.mapping.JavaTypeMapping joinElementMapping)
Constructor using a join table as the primary table. |
|
| Method Summary | |
|---|---|
protected SQLStatement |
getSQLStatementForCandidate(String className)
Convenience method to return the SQLStatement for a particular class. |
protected SQLStatement |
getSQLStatementForCandidateViaJoin(String className)
Convenience method to return the SQLStatement for a particular class selecting a join table. |
SQLStatement |
getStatement()
Accessor for the SQL Statement for the candidate [+ subclasses]. |
void |
setParentStatement(SQLStatement stmt)
Method to set the parent statement. |
| Methods inherited from class org.datanucleus.store.rdbms.sql.AbstractStatementGenerator |
|---|
hasOption, setOption, unsetOption |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String NUC_TYPE_COLUMN
| Constructor Detail |
|---|
public UnionStatementGenerator(RDBMSStoreManager storeMgr,
org.datanucleus.ClassLoaderResolver clr,
Class candidateType,
boolean includeSubclasses,
org.datanucleus.store.mapped.DatastoreIdentifier candidateTableAlias,
String candidateTableGroupName)
SELECT ['mydomain.A' AS NUCLEUS_TYPE] FROM A THIS LEFT OUTER JOIN A1 SUBELEMENT0 ON SUBELEMENT0.A1_ID = THIS.A_ID LEFT OUTER JOIN A1 SUBELEMENT1 ON SUBELEMENT0.A2_ID = THIS.A_ID WHERE SUBELEMENT0.A1_ID IS NULL AND SUBELEMENT0.A2_ID IS NULL UNION SELECT ['mydomain.A1' AS NUCLEUS_TYPE] FROM A THIS INNER JOIN A1 'ELEMENT' ON 'ELEMENT'.A1_ID = THIS.A_ID UNION SELECT ['mydomain.A2' AS NUCLEUS_TYPE] FROM A THIS INNER JOIN A2 'ELEMENT' ON 'ELEMENT'.A2_ID = THIS.A_IDSo the first part of the UNION returns the objects just present in the A table, whilst the second part returns those just in table A1, and the third part returns those just in table A2.
storeMgr - the store managerclr - ClassLoader resolvercandidateType - the candidate that we are looking forincludeSubclasses - if the subclasses of the candidate should be included in the resultcandidateTableAlias - Alias to use for the candidate table (optional)candidateTableGroupName - Name of the table group for the candidate(s) (optional)
public UnionStatementGenerator(RDBMSStoreManager storeMgr,
org.datanucleus.ClassLoaderResolver clr,
Class candidateType,
boolean includeSubclasses,
org.datanucleus.store.mapped.DatastoreIdentifier candidateTableAlias,
String candidateTableGroupName,
org.datanucleus.store.mapped.DatastoreContainerObject joinTable,
org.datanucleus.store.mapped.DatastoreIdentifier joinTableAlias,
org.datanucleus.store.mapped.mapping.JavaTypeMapping joinElementMapping)
SELECT ['mydomain.B' AS NUCLEUS_TYPE] FROM A_B T0 INNER JOIN B T1 ON T0.B_ID_EID = T1.B_ID LEFT OUTER JOIN B1 T2 ON T2.B1_ID = T0.B_ID_EID LEFT OUTER JOIN B2 T3 ON T3.B2_ID = T0.B_ID_EID WHERE T2.B1_ID IS NULL AND T3.B2_ID IS NULL UNION SELECT ['mydomain.B1' AS NUCLEUS_TYPE] FROM A_B THIS INNER JOIN B T1 ON T1.B_ID = T0.B_ID_EID INNER JOIN B1 T2 ON T2.B1_ID = T1.B_ID UNION SELECT ['mydomain.A2' AS NUCLEUS_TYPE] FROM A_B THIS INNER JOIN B T1 ON T1.B_ID = T0.B_ID_EID INNER JOIN B2 T2 ON T2.B2_ID = T1.B_IDSo the first part of the UNION returns the objects just present in the B table, whilst the second part returns those just in table B1, and the third part returns those just in table B2. When we have a join table collection we MUST select the join table since this then caters for the situation of having null elements (if we had selected the root element table we wouldn't know if there was a null element in the collection).
storeMgr - the store managerclr - ClassLoader resolvercandidateType - the candidate that we are looking forincludeSubclasses - if the subclasses of the candidate should be included in the resultcandidateTableAlias - Alias to use for the candidate table (optional)candidateTableGroupName - Name of the table group for the candidate(s) (optional)joinTable - Join table linking owner to elementsjoinTableAlias - any alias to use for the join table in the SQLjoinElementMapping - Mapping in the join table to link to the element| Method Detail |
|---|
public void setParentStatement(SQLStatement stmt)
StatementGenerator
stmt - The parent statementpublic SQLStatement getStatement()
protected SQLStatement getSQLStatementForCandidate(String className)
className - The class name to generate the statement for
protected SQLStatement getSQLStatementForCandidateViaJoin(String className)
className - The class name to generate the statement for
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||