Package org.datanucleus.store.rdbms.sql
Class DiscriminatorStatementGenerator
- java.lang.Object
-
- org.datanucleus.store.rdbms.sql.AbstractSelectStatementGenerator
-
- org.datanucleus.store.rdbms.sql.DiscriminatorStatementGenerator
-
- All Implemented Interfaces:
SelectStatementGenerator
public class DiscriminatorStatementGenerator extends AbstractSelectStatementGenerator
Class to generate a SelectStatement for iterating through instances of a particular type (and optionally subclasses). Based around the candidate type having subclasses the candidate has a discriminator column, and so can be used as the way of determining the type of the object. Also allows select of the discriminator column to allow retrieval of the type of the object. Please refer to the specific constructors for the usages. Note that the statement returned by getStatement() has nothing selected, solely providing the basic structure. Column selection should be performed when generating the mapping definition.Supported options
This generator supports the following "options" :-- restrictDiscriminator : Whether to add a WHERE clause to restrict the discriminator to only valid values (default="true")
- allowNulls : whether we allow for null objects (only happens when we have a join table collection.
-
-
Field Summary
-
Fields inherited from class org.datanucleus.store.rdbms.sql.AbstractSelectStatementGenerator
candidateTable, candidateTableAlias, candidateTableGroupName, candidateType, clr, includeSubclasses, parentStmt, storeMgr
-
Fields inherited from interface org.datanucleus.store.rdbms.sql.SelectStatementGenerator
OPTION_ALLOW_NULLS, OPTION_DONT_RESTRICT_DISCRIM, OPTION_INCLUDE_SOFT_DELETES, OPTION_RESTRICT_DISCRIM, OPTION_SELECT_DN_TYPE
-
-
Constructor Summary
Constructors Constructor Description DiscriminatorStatementGenerator(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr, Class[] candidateTypes, boolean includeSubclasses, DatastoreIdentifier candidateTableAlias, String candidateTableGroupName)
Constructor, using the candidateTable as the primary table of the SQL SELECT.DiscriminatorStatementGenerator(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr, Class[] candidateTypes, boolean includeSubclasses, DatastoreIdentifier candidateTableAlias, String candidateTableGroupName, Table joinTable, DatastoreIdentifier joinTableAlias, JavaTypeMapping joinElementMapping)
Constructor, using the joinTable as the primary table of the SQL SELECT and joining to the table of the candidate(s).DiscriminatorStatementGenerator(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr, Class candidateType, boolean includeSubclasses, DatastoreIdentifier candidateTableAlias, String candidateTableGroupName)
Constructor, using the candidateTable as the primary table of the SQL SELECT.DiscriminatorStatementGenerator(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr, Class candidateType, boolean includeSubclasses, DatastoreIdentifier candidateTableAlias, String candidateTableGroupName, Table joinTable, DatastoreIdentifier joinTableAlias, JavaTypeMapping joinElementMapping)
Constructor, using the joinTable as the primary table of the SQL SELECT and joining to the table of the candidate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SelectStatement
getStatement(org.datanucleus.ExecutionContext ec)
Accessor for the SelectStatement.void
setParentStatement(SQLStatement stmt)
Method to set the parent statement.-
Methods inherited from class org.datanucleus.store.rdbms.sql.AbstractSelectStatementGenerator
hasOption, setOption, unsetOption
-
-
-
-
Constructor Detail
-
DiscriminatorStatementGenerator
public DiscriminatorStatementGenerator(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr, Class candidateType, boolean includeSubclasses, DatastoreIdentifier candidateTableAlias, String candidateTableGroupName)
Constructor, using the candidateTable as the primary table of the SQL SELECT. Let's assume that we have class A which is the candidate and this has subclasses A1, A2 that are stored in the same table (with different values of the discriminator), and has subclasses A3, A4 of A2 that are stored in a different table. We want to find all objects of the candidate type and optionally its subclasses and we want information about what type the object is (A or A1 or A2 or A3 or A4). The query will be of the formSELECT FROM A T0 [WHERE (T0.DISCRIMINATOR = A0value || T0.DISCRIMINATOR = A1value || T0.DISCRIMINATOR = A2value || T0.DISCRIMINATOR = A3value || T0.DISCRIMINATOR = A4value)]
The "candidateType" will provide the primary table of the SQL SELECT.- Parameters:
storeMgr
- Manager for the datastoreclr
- ClassLoader resolvercandidateType
- Base object type that we are looking forincludeSubclasses
- Should we include subclasses of this candidate?candidateTableAlias
- Alias to use for the candidate table (optional)candidateTableGroupName
- Name of the table group for the candidate(s) (optional)
-
DiscriminatorStatementGenerator
public DiscriminatorStatementGenerator(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr, Class[] candidateTypes, boolean includeSubclasses, DatastoreIdentifier candidateTableAlias, String candidateTableGroupName)
Constructor, using the candidateTable as the primary table of the SQL SELECT. Differs from the other similar constructor in that it provides multiple candidates. The first of these candidates should always be considered the primary.- Parameters:
storeMgr
- Manager for the datastoreclr
- ClassLoader resolvercandidateTypes
- Base object type(s) that we are looking forincludeSubclasses
- Should we include subclasses of this candidate(s)?candidateTableAlias
- Alias to use for the candidate table (optional)candidateTableGroupName
- Name of the table group for the candidate(s) (optional)
-
DiscriminatorStatementGenerator
public DiscriminatorStatementGenerator(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr, Class candidateType, boolean includeSubclasses, DatastoreIdentifier candidateTableAlias, String candidateTableGroupName, Table joinTable, DatastoreIdentifier joinTableAlias, JavaTypeMapping joinElementMapping)
Constructor, using the joinTable as the primary table of the SQL SELECT and joining to the table of the candidate. Let's assume that we have class A with collection with elements of type B (join table A_B) and candidate B has subclasses B1, B2 that are stored in the same table (with different values of the discriminator), and has subclasses B3, B4 of B2 that are stored in a different table. We want to find all objects of the candidate type and optionally its subclasses and we want information about what type the object is (B or B1 or B2 or B3 or B4). The query will be of the formSELECT FROM A_B T0 INNER JOIN B T1 ON T1.B_ID = A_B.B_ID_EID [WHERE (T1.DISCRIMINATOR = B0value || T1.DISCRIMINATOR = B1value || T1.DISCRIMINATOR = B2value || T1.DISCRIMINATOR = B3value || T1.DISCRIMINATOR = B4value)]
The join table will provide the primary table of the SQL SELECT. The join is INNER JOIN when no nulls are allowed in the collection, and LEFT OUTER JOIN when it allows nulls.- Parameters:
storeMgr
- Manager for the datastoreclr
- ClassLoader resolvercandidateType
- Base object type(s) that we are looking forincludeSubclasses
- Should we include subclasses of this candidate?candidateTableAlias
- 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
-
DiscriminatorStatementGenerator
public DiscriminatorStatementGenerator(RDBMSStoreManager storeMgr, org.datanucleus.ClassLoaderResolver clr, Class[] candidateTypes, boolean includeSubclasses, DatastoreIdentifier candidateTableAlias, String candidateTableGroupName, Table joinTable, DatastoreIdentifier joinTableAlias, JavaTypeMapping joinElementMapping)
Constructor, using the joinTable as the primary table of the SQL SELECT and joining to the table of the candidate(s). Same as the other join table constructor except allows multiple candidates.- Parameters:
storeMgr
- Manager for the datastoreclr
- ClassLoader resolvercandidateTypes
- Base object type(s) that we are looking forincludeSubclasses
- Should we include subclasses of this candidate?candidateTableAlias
- 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
-
setParentStatement
public void setParentStatement(SQLStatement stmt)
Description copied from interface:SelectStatementGenerator
Method to set the parent statement. Must be set before calling getStatement().- Parameters:
stmt
- The parent statement
-
getStatement
public SelectStatement getStatement(org.datanucleus.ExecutionContext ec)
Accessor for the SelectStatement.- Parameters:
ec
- ExecutionContext- Returns:
- The SelectStatement for iterating through objects with a discriminator column
-
-