Class ClassTable

  • All Implemented Interfaces:
    DatastoreClass, Table, org.datanucleus.store.schema.table.Table

    public class ClassTable
    extends AbstractClassTable
    implements DatastoreClass
    Table representing a Java class (or classes) as a first class object (FCO). Uses the inheritance strategy to control whether this represents multiple classes or just the one class.

    Mappings

    This class adds some additional mappings over what the superclass provides. Here we add
    • externalFkMappings - any mappings for Collections that have no associated field in this class, providing the foreign key column(s)
    • externalOrderMappings - mappings for any ordering column used by Lists for ordering elements of this class
    • externalFkDiscriminatorMappings - mappings for any discriminator column used when sharing external foreign keys to distinguish the element owner field

    Classes

    A table can represent multiple classes. It has a nominal owner which is the class that has an inheritance strategy of "new-table". All classes that utilise this table have their MetaData stored in this object.

    Secondary Tables

    This class represents a "primary" table. That is, the main table where objects of a class are persisted. It can have several "secondary" tables where some of the classes fields are stored at persistence.
    • Field Detail

      • managingClassCurrent

        protected transient String managingClassCurrent
        Name of class currently being processed in manageClass (if any).
      • runCallbacksAfterManageClass

        protected boolean runCallbacksAfterManageClass
        Flag to run the callbacks after the current class is managed fully.
    • Constructor Detail

      • ClassTable

        public ClassTable​(DatastoreIdentifier tableName,
                          RDBMSStoreManager storeMgr,
                          org.datanucleus.metadata.ClassMetaData cmd)
        Constructor.
        Parameters:
        tableName - Table name SQL identifier
        storeMgr - Store Manager to manage this table
        cmd - MetaData for the class.
    • Method Detail

      • preInitialize

        public void preInitialize​(org.datanucleus.ClassLoaderResolver clr)
        Pre-initialize. We require any supertable, and the PK to be ready before we start initialisation.
        Specified by:
        preInitialize in interface Table
        Overrides:
        preInitialize in class TableImpl
        Parameters:
        clr - the ClassLoaderResolver
      • initialize

        public void initialize​(org.datanucleus.ClassLoaderResolver clr)
        Method to initialise the table. This adds the columns based on the MetaData representation for the class being represented by this table.
        Specified by:
        initialize in interface Table
        Parameters:
        clr - The ClassLoaderResolver
      • postInitialize

        public void postInitialize​(org.datanucleus.ClassLoaderResolver clr)
        Post initilize. For things that must be set after all classes have been initialized before
        Specified by:
        postInitialize in interface Table
        Overrides:
        postInitialize in class TableImpl
        Parameters:
        clr - the ClassLoaderResolver
      • manageClass

        public void manageClass​(org.datanucleus.metadata.AbstractClassMetaData theCmd,
                                org.datanucleus.ClassLoaderResolver clr)
        Method that adds the specified class to be managed by this table. Will provide mapping of all persistent fields to their underlying columns, map all necessary identity fields, and manage all "unmapped" columns that have no associated field. where the columns are defined for each mapping.
        Parameters:
        theCmd - ClassMetaData for the class to be managed
        clr - The ClassLoaderResolver
      • getManagedClasses

        public String[] getManagedClasses()
        Accessor for the names of all classes managed by this table.
        Specified by:
        getManagedClasses in interface DatastoreClass
        Returns:
        Names of the classes managed (stored) here
      • managesClass

        public boolean managesClass​(String className)
        Accessor for whether this table manages the specified class
        Specified by:
        managesClass in interface DatastoreClass
        Parameters:
        className - Name of the class
        Returns:
        Whether it is managed by this table
      • initializePK

        protected void initializePK​(org.datanucleus.ClassLoaderResolver clr)
        Method to initialise the table primary key field(s).
        Specified by:
        initializePK in class AbstractClassTable
        Parameters:
        clr - The ClassLoaderResolver
      • getType

        public String getType()
        Accessor for the main class represented.
        Specified by:
        getType in interface DatastoreClass
        Returns:
        The name of the class
      • getVersionMetaData

        public final org.datanucleus.metadata.VersionMetaData getVersionMetaData()
        Accessor for versionMetaData
        Specified by:
        getVersionMetaData in interface Table
        Overrides:
        getVersionMetaData in class AbstractTable
        Returns:
        Returns the versionMetaData.
      • getTableWithDiscriminator

        public final ClassTable getTableWithDiscriminator()
        Convenience method to return the root table with a discriminator in this inheritance tree.
        Returns:
        The root table which has the discriminator in this inheritance tree
      • isBaseDatastoreClass

        public boolean isBaseDatastoreClass()
        Whether this table is the base table in the inheritance hierarchy.
        Specified by:
        isBaseDatastoreClass in interface DatastoreClass
        Returns:
        true if this table is a root table
      • getBaseDatastoreClass

        public DatastoreClass getBaseDatastoreClass()
        Description copied from interface: DatastoreClass
        Accessor for the base datastore class. Returns this object if it has no superclass table, otherwise goes up to the superclass etc.
        Specified by:
        getBaseDatastoreClass in interface DatastoreClass
        Returns:
        The base datastore class
      • isSuperDatastoreClass

        public boolean isSuperDatastoreClass​(DatastoreClass table)
        Accessor whether the supplied DatastoreClass is a supertable of this table.
        Specified by:
        isSuperDatastoreClass in interface DatastoreClass
        Parameters:
        table - The DatastoreClass to check
        Returns:
        Whether it is a supertable (somewhere up the inheritance tree)
      • getSurrogateMapping

        public JavaTypeMapping getSurrogateMapping​(org.datanucleus.store.schema.table.SurrogateColumnType colType,
                                                   boolean allowSuperclasses)
        Description copied from interface: Table
        Accessor for the mapping for the specified surrogate type.
        Specified by:
        getSurrogateMapping in interface Table
        Overrides:
        getSurrogateMapping in class AbstractClassTable
        Parameters:
        colType - Column type for the surrogate
        allowSuperclasses - Whether to allow searching superclasses when not specified in this table.
        Returns:
        The mapping
      • getBaseDatastoreClassWithMember

        public DatastoreClass getBaseDatastoreClassWithMember​(org.datanucleus.metadata.AbstractMemberMetaData mmd)
        Convenience accessor for the base table for this table which has the specified field.
        Specified by:
        getBaseDatastoreClassWithMember in interface DatastoreClass
        Parameters:
        mmd - Field MetaData for this field
        Returns:
        The base table which has the field specified
      • getClassMetaData

        public org.datanucleus.metadata.ClassMetaData getClassMetaData()
        Accessor for the (primary) class MetaData. Package-level access to restrict to other table types only.
        Specified by:
        getClassMetaData in interface org.datanucleus.store.schema.table.Table
        Overrides:
        getClassMetaData in class AbstractTable
        Returns:
        The (primary) class MetaData
      • getExpectedIndices

        protected Set<Index> getExpectedIndices​(org.datanucleus.ClassLoaderResolver clr)
        Accessor for the indices for this table. This includes both the user-defined indices (via MetaData), and the ones required by foreign keys (required by relationships).
        Overrides:
        getExpectedIndices in class TableImpl
        Parameters:
        clr - The ClassLoaderResolver
        Returns:
        The indices
      • getExpectedForeignKeys

        public List<ForeignKey> getExpectedForeignKeys​(org.datanucleus.ClassLoaderResolver clr)
        Accessor for the expected foreign keys for this table.
        Overrides:
        getExpectedForeignKeys in class TableImpl
        Parameters:
        clr - The ClassLoaderResolver
        Returns:
        The expected foreign keys.
      • getPrimaryKey

        public PrimaryKey getPrimaryKey()
        Accessor for the primary key for this table. Overrides the method in TableImpl to add on any specification of PK name in the metadata.
        Overrides:
        getPrimaryKey in class TableImpl
        Returns:
        The primary key.
      • getSQLCreateStatements

        protected List<String> getSQLCreateStatements​(Properties props)
        Accessor for the CREATE statements for this table. Creates this table followed by all secondary tables (if any).
        Overrides:
        getSQLCreateStatements in class TableImpl
        Parameters:
        props - Properties for creating the table
        Returns:
        the SQL statements to be executed for creation
      • getSQLDropStatements

        protected List<String> getSQLDropStatements()
        Accessor for the DROP statements for this table. Drops all secondary tables (if any) followed by the table itself.
        Overrides:
        getSQLDropStatements in class TableImpl
        Returns:
        List of statements
      • getIdMapping

        public JavaTypeMapping getIdMapping()
        Accessor for a mapping for the ID (persistable) for this table.
        Specified by:
        getIdMapping in interface Table
        Returns:
        The (persistable) ID mapping.
      • hasExternalFkMappings

        public boolean hasExternalFkMappings()
      • getExternalMapping

        public JavaTypeMapping getExternalMapping​(org.datanucleus.metadata.AbstractMemberMetaData mmd,
                                                  MappingType mappingType)
        Accessor for an external mapping for the specified field of the required type.
        Specified by:
        getExternalMapping in interface DatastoreClass
        Parameters:
        mmd - MetaData for the field/property
        mappingType - Type of mapping
        Returns:
        The (external) mapping
      • getMetaDataForExternalMapping

        public org.datanucleus.metadata.AbstractMemberMetaData getMetaDataForExternalMapping​(JavaTypeMapping mapping,
                                                                                             MappingType mappingType)
        Accessor for the MetaData for the (owner) field that an external mapping corresponds to.
        Specified by:
        getMetaDataForExternalMapping in interface DatastoreClass
        Parameters:
        mapping - The mapping
        mappingType - The mapping type
        Returns:
        metadata for the external mapping
      • getMemberMapping

        public JavaTypeMapping getMemberMapping​(org.datanucleus.metadata.AbstractMemberMetaData mmd)
        Accessor for the field mapping for the specified field. The field can be managed by a supertable of this table.
        Specified by:
        getMemberMapping in interface DatastoreClass
        Specified by:
        getMemberMapping in interface Table
        Parameters:
        mmd - MetaData for this field/property
        Returns:
        the Mapping for the field/property
      • getMemberMappingInDatastoreClass

        public JavaTypeMapping getMemberMappingInDatastoreClass​(org.datanucleus.metadata.AbstractMemberMetaData mmd)
        Accessor for the mapping for the specified field only in this datastore class.
        Specified by:
        getMemberMappingInDatastoreClass in interface DatastoreClass
        Parameters:
        mmd - Metadata of the field/property
        Returns:
        The Mapping for the field/property (or null if not present here)
      • getMemberMapping

        public JavaTypeMapping getMemberMapping​(String memberName)
        Accessor for the field mapping for the named field. The field may exist in a parent table or a secondary table. Throws a NoSuchPersistentFieldException if the field name is not found. TODO Use of this is discouraged since the fieldName is not fully qualified and if a superclass-table inheritance is used we could have 2 fields of that name here.
        Specified by:
        getMemberMapping in interface DatastoreClass
        Parameters:
        memberName - Name of field/property
        Returns:
        The mapping.
        Throws:
        NoSuchPersistentFieldException - Thrown when the field/property is not found
      • provideExternalMappings

        public final void provideExternalMappings​(MappingConsumer consumer,
                                                  MappingType mappingType)
        Provide the mappings to the consumer for all external fields mapped to this table of the specified type
        Specified by:
        provideExternalMappings in interface DatastoreClass
        Parameters:
        consumer - Consumer for the mappings
        mappingType - Type of external mapping
      • provideMappingsForMembers

        public void provideMappingsForMembers​(MappingConsumer consumer,
                                              org.datanucleus.metadata.AbstractMemberMetaData[] fieldMetaData,
                                              boolean includeSecondaryTables)
        Provide the mappings to the consumer for all absolute field Numbers in this table that are container in the fieldNumbers parameter.
        Specified by:
        provideMappingsForMembers in interface DatastoreClass
        Overrides:
        provideMappingsForMembers in class AbstractClassTable
        Parameters:
        consumer - Consumer for the mappings
        fieldMetaData - MetaData for the fields to provide mappings for
        includeSecondaryTables - Whether to provide fields in secondary tables
      • provideUnmappedColumns

        public void provideUnmappedColumns​(MappingConsumer consumer)
        Method to provide all unmapped columns to the consumer.
        Specified by:
        provideUnmappedColumns in interface DatastoreClass
        Parameters:
        consumer - Consumer of information
      • validateConstraints

        public boolean validateConstraints​(Connection conn,
                                           boolean autoCreate,
                                           Collection autoCreateErrors,
                                           org.datanucleus.ClassLoaderResolver clr)
                                    throws SQLException
        Method to validate the constraints of this table.
        Overrides:
        validateConstraints in class TableImpl
        Parameters:
        conn - Connection to use in validation
        autoCreate - Whether to auto create the constraints
        autoCreateErrors - Whether to log a warning only on errors during "auto create"
        clr - The ClassLoaderResolver
        Returns:
        Whether the DB was modified
        Throws:
        SQLException - Thrown when an error occurs in validation