Class 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.
    • 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 form
         SELECT 
         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 datastore
        clr - ClassLoader resolver
        candidateType - Base object type that we are looking for
        includeSubclasses - 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 datastore
        clr - ClassLoader resolver
        candidateTypes - Base object type(s) that we are looking for
        includeSubclasses - 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 form
         SELECT 
         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 datastore
        clr - ClassLoader resolver
        candidateType - Base object type(s) that we are looking for
        includeSubclasses - 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 elements
        joinTableAlias - any alias to use for the join table in the SQL
        joinElementMapping - 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 datastore
        clr - ClassLoader resolver
        candidateTypes - Base object type(s) that we are looking for
        includeSubclasses - 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 elements
        joinTableAlias - any alias to use for the join table in the SQL
        joinElementMapping - 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