Class ClassTable
- java.lang.Object
-
- org.datanucleus.store.rdbms.table.AbstractTable
-
- org.datanucleus.store.rdbms.table.TableImpl
-
- org.datanucleus.store.rdbms.table.AbstractClassTable
-
- org.datanucleus.store.rdbms.table.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 Summary
Fields Modifier and Type Field Description protected String
managingClassCurrent
Name of class currently being processed in manageClass (if any).protected boolean
runCallbacksAfterManageClass
Flag to run the callbacks after the current class is managed fully.-
Fields inherited from class org.datanucleus.store.rdbms.table.AbstractClassTable
createTimestampMapping, createUserMapping, datastoreIdMapping, discriminatorMapping, discriminatorMetaData, highestMemberNumber, idMapping, memberMappingsMap, multitenancyMapping, pkMappings, softDeleteMapping, updateTimestampMapping, updateUserMapping, versionMapping, versionMetaData
-
Fields inherited from class org.datanucleus.store.rdbms.table.AbstractTable
columns, columnsByIdentifier, dba, existsInDatastore, identifier, state, storeMgr, TABLE_STATE_INITIALIZED, TABLE_STATE_INITIALIZED_MODIFIED, TABLE_STATE_NEW, TABLE_STATE_PK_INITIALIZED, TABLE_STATE_VALIDATED
-
-
Constructor Summary
Constructors Constructor Description ClassTable(DatastoreIdentifier tableName, RDBMSStoreManager storeMgr, org.datanucleus.metadata.ClassMetaData cmd)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DatastoreClass
getBaseDatastoreClass()
Accessor for the base datastore class.DatastoreClass
getBaseDatastoreClassWithMember(org.datanucleus.metadata.AbstractMemberMetaData mmd)
Convenience accessor for the base table for this table which has the specified member.org.datanucleus.metadata.ClassMetaData
getClassMetaData()
Accessor for the (primary) class MetaData.org.datanucleus.metadata.DiscriminatorMetaData
getDiscriminatorMetaData()
Accessor for Discriminator MetaDataprotected List<CandidateKey>
getExpectedCandidateKeys()
Accessor for the expected candidate keys for this table.List<ForeignKey>
getExpectedForeignKeys(org.datanucleus.ClassLoaderResolver clr)
Accessor for the expected foreign keys for this table.protected Set<Index>
getExpectedIndices(org.datanucleus.ClassLoaderResolver clr)
Accessor for the indices for this table.JavaTypeMapping
getExternalMapping(org.datanucleus.metadata.AbstractMemberMetaData mmd, MappingType mappingType)
Accessor for an external mapping for the specified field of the required type.org.datanucleus.metadata.IdentityType
getIdentityType()
Accessor for the identity-type.JavaTypeMapping
getIdMapping()
Accessor for a mapping for the ID (persistable) for this table.String[]
getManagedClasses()
Accessor for the names of all classes managed by this table.JavaTypeMapping
getMemberMapping(String memberName)
Accessor for the java mapping for the named member.JavaTypeMapping
getMemberMapping(org.datanucleus.metadata.AbstractMemberMetaData mmd)
Accessor for the field mapping for the specified field.JavaTypeMapping
getMemberMappingInDatastoreClass(org.datanucleus.metadata.AbstractMemberMetaData mmd)
Accessor for the mapping for the specified field only in this datastore class.org.datanucleus.metadata.AbstractMemberMetaData
getMetaDataForExternalMapping(JavaTypeMapping mapping, MappingType mappingType)
Accessor for the MetaData for the (owner) field that an external mapping corresponds to.PrimaryKey
getPrimaryKey()
Accessor for the primary key for this table.Collection
getSecondaryDatastoreClasses()
Accessor for any secondary tables for this table.protected List<String>
getSQLCreateStatements(Properties props)
Accessor for the CREATE statements for this table.protected List<String>
getSQLDropStatements()
Accessor for the DROP statements for this table.DatastoreClass
getSuperDatastoreClass()
Accessor for the supertable for this table.JavaTypeMapping
getSurrogateMapping(org.datanucleus.store.schema.table.SurrogateColumnType colType, boolean allowSuperclasses)
Accessor for the mapping for the specified surrogate type.ClassTable
getTableManagingMapping(JavaTypeMapping mapping)
ClassTable
getTableWithDiscriminator()
Convenience method to return the root table with a discriminator in this inheritance tree.String
getType()
Accessor for the main class represented.org.datanucleus.metadata.VersionMetaData
getVersionMetaData()
Accessor for versionMetaDataboolean
hasExternalFkMappings()
void
initialize(org.datanucleus.ClassLoaderResolver clr)
Method to initialise the table.protected void
initializePK(org.datanucleus.ClassLoaderResolver clr)
Method to initialise the table primary key field(s).boolean
isBaseDatastoreClass()
Whether this table is the base table in the inheritance hierarchy.boolean
isObjectIdDatastoreAttributed()
Whether this table or super table has id (primary key) attributed by the datastoreboolean
isSuperDatastoreClass(DatastoreClass table)
Accessor whether the supplied DatastoreClass is a supertable of this table.void
manageClass(org.datanucleus.metadata.AbstractClassMetaData theCmd, org.datanucleus.ClassLoaderResolver clr)
Method that adds the specified class to be managed by this table.boolean
managesClass(String className)
Accessor for whether this table manages the specified class.void
postInitialize(org.datanucleus.ClassLoaderResolver clr)
Post initilize.void
preInitialize(org.datanucleus.ClassLoaderResolver clr)
Pre-initialize.void
provideExternalMappings(MappingConsumer consumer, MappingType mappingType)
Provide the mappings to the consumer for all external fields mapped to this table of the specified typevoid
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.void
providePrimaryKeyMappings(MappingConsumer consumer)
Provide the mappings to the consumer for all primary-key fields mapped to this table.void
provideUnmappedColumns(MappingConsumer consumer)
Method to provide all unmapped columns to the consumer.boolean
validateConstraints(Connection conn, boolean autoCreate, Collection autoCreateErrors, org.datanucleus.ClassLoaderResolver clr)
Method to validate the constraints of this table.-
Methods inherited from class org.datanucleus.store.rdbms.table.AbstractClassTable
addMemberMapping, getMappingForMemberName, getPrimaryTable, getSurrogateColumn, managesMapping, managesMember, provideNonPrimaryKeyMappings, provideSurrogateMapping
-
Methods inherited from class org.datanucleus.store.rdbms.table.TableImpl
createConstraints, dropConstraints, getSQLAddCandidateKeyStatements, getSQLAddFKStatements, getSQLCreateIndexStatements, initializeColumnInfoForPrimaryKeyColumns, initializeColumnInfoFromDatastore, logMapping, validate, validateColumns, validatePrimaryKey
-
Methods inherited from class org.datanucleus.store.rdbms.table.AbstractTable
addColumn, addColumnInternal, allowDDLOutput, assertIsInitialized, assertIsInitializedModified, assertIsPKInitialized, assertIsPKUninitialized, assertIsUninitialized, assertIsValidated, create, drop, equals, executeDdlStatement, executeDdlStatementList, exists, getCatalogName, getColumn, getColumnForName, getColumnForPosition, getColumns, getDatastoreIdentifierFullyQualified, getIdentifier, getMemberColumnMappingForEmbeddedMember, getMemberColumnMappingForMember, getMemberColumnMappings, getName, getNumberOfColumns, getSchemaName, getStoreManager, hasColumn, hasColumnName, hashCode, isInitialized, isInitializedModified, isPKInitialized, isValidated, tableExistsInDatastore, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.datanucleus.store.rdbms.table.DatastoreClass
managesMapping, provideNonPrimaryKeyMappings, provideSurrogateMapping, toString
-
Methods inherited from interface org.datanucleus.store.rdbms.table.Table
addColumn, create, drop, exists, getColumn, getIdentifier, getStoreManager, hasColumn, isInitialized, isInitializedModified, isValidated, validate
-
Methods inherited from interface org.datanucleus.store.schema.table.Table
getCatalogName, getColumnForName, getColumnForPosition, getColumns, getMemberColumnMappingForEmbeddedMember, getMemberColumnMappingForMember, getMemberColumnMappings, getName, getNumberOfColumns, getSchemaName, getSurrogateColumn
-
-
-
-
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 identifierstoreMgr
- Store Manager to manage this tablecmd
- 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 interfaceTable
- Overrides:
preInitialize
in classAbstractTable
- 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 interfaceTable
- 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 interfaceTable
- Overrides:
postInitialize
in classAbstractTable
- 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.- Parameters:
theCmd
- ClassMetaData for the class to be managedclr
- The ClassLoaderResolver
-
getManagedClasses
public String[] getManagedClasses()
Accessor for the names of all classes managed by this table.- Specified by:
getManagedClasses
in interfaceDatastoreClass
- 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 interfaceDatastoreClass
- 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 classAbstractClassTable
- Parameters:
clr
- The ClassLoaderResolver
-
getType
public String getType()
Accessor for the main class represented.- Specified by:
getType
in interfaceDatastoreClass
- Returns:
- The name of the class
-
getIdentityType
public org.datanucleus.metadata.IdentityType getIdentityType()
Accessor for the identity-type.- Specified by:
getIdentityType
in interfaceDatastoreClass
- Specified by:
getIdentityType
in classAbstractClassTable
- Returns:
- identity-type tag value
-
getVersionMetaData
public final org.datanucleus.metadata.VersionMetaData getVersionMetaData()
Accessor for versionMetaData- Specified by:
getVersionMetaData
in interfaceTable
- Overrides:
getVersionMetaData
in classAbstractTable
- Returns:
- Returns the versionMetaData.
-
getDiscriminatorMetaData
public final org.datanucleus.metadata.DiscriminatorMetaData getDiscriminatorMetaData()
Accessor for Discriminator MetaData- Specified by:
getDiscriminatorMetaData
in interfaceTable
- Overrides:
getDiscriminatorMetaData
in classAbstractTable
- Returns:
- Returns the Discriminator MetaData.
-
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
-
isObjectIdDatastoreAttributed
public boolean isObjectIdDatastoreAttributed()
Whether this table or super table has id (primary key) attributed by the datastore- Specified by:
isObjectIdDatastoreAttributed
in interfaceDatastoreClass
- Specified by:
isObjectIdDatastoreAttributed
in classAbstractClassTable
- Returns:
- true if the id attributed by the datastore
-
isBaseDatastoreClass
public boolean isBaseDatastoreClass()
Whether this table is the base table in the inheritance hierarchy.- Specified by:
isBaseDatastoreClass
in interfaceDatastoreClass
- 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 interfaceDatastoreClass
- Returns:
- The base datastore class
-
getSuperDatastoreClass
public DatastoreClass getSuperDatastoreClass()
Accessor for the supertable for this table.- Specified by:
getSuperDatastoreClass
in interfaceDatastoreClass
- Returns:
- The supertable
-
isSuperDatastoreClass
public boolean isSuperDatastoreClass(DatastoreClass table)
Accessor whether the supplied DatastoreClass is a supertable of this table.- Specified by:
isSuperDatastoreClass
in interfaceDatastoreClass
- Parameters:
table
- The DatastoreClass to check- Returns:
- Whether it is a supertable (somewhere up the inheritance tree)
-
getSecondaryDatastoreClasses
public Collection getSecondaryDatastoreClasses()
Accessor for any secondary tables for this table.- Specified by:
getSecondaryDatastoreClasses
in interfaceDatastoreClass
- Returns:
- Secondary tables (if any)
-
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 interfaceTable
- Overrides:
getSurrogateMapping
in classAbstractClassTable
- Parameters:
colType
- Column type for the surrogateallowSuperclasses
- Whether to allow searching superclasses when not specified in this table.- Returns:
- The mapping
-
getTableManagingMapping
public ClassTable getTableManagingMapping(JavaTypeMapping mapping)
-
getBaseDatastoreClassWithMember
public DatastoreClass getBaseDatastoreClassWithMember(org.datanucleus.metadata.AbstractMemberMetaData mmd)
Convenience accessor for the base table for this table which has the specified member.- Specified by:
getBaseDatastoreClassWithMember
in interfaceDatastoreClass
- Parameters:
mmd
- Member 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 interfaceorg.datanucleus.store.schema.table.Table
- Overrides:
getClassMetaData
in classAbstractTable
- 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 classTableImpl
- 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 classTableImpl
- Parameters:
clr
- The ClassLoaderResolver- Returns:
- The expected foreign keys.
-
getExpectedCandidateKeys
protected List<CandidateKey> getExpectedCandidateKeys()
Accessor for the expected candidate keys for this table.- Overrides:
getExpectedCandidateKeys
in classTableImpl
- Returns:
- The expected candidate 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 classTableImpl
- 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 classTableImpl
- 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 classTableImpl
- Returns:
- List of statements
-
getIdMapping
public JavaTypeMapping getIdMapping()
Accessor for a mapping for the ID (persistable) for this table.- Specified by:
getIdMapping
in interfaceTable
- 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 interfaceDatastoreClass
- Parameters:
mmd
- MetaData for the field/propertymappingType
- 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 interfaceDatastoreClass
- Parameters:
mapping
- The mappingmappingType
- 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 interfaceDatastoreClass
- Specified by:
getMemberMapping
in interfaceTable
- 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 interfaceDatastoreClass
- 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 java mapping for the named member. The member may exist in a parent table or a secondary table. Throws a NoSuchPersistentFieldException if the member name is not found. TODO Use of this is discouraged since the memberName is not fully qualified and if a superclass-table inheritance is used we could have 2 members of that name here.- Specified by:
getMemberMapping
in interfaceDatastoreClass
- Parameters:
memberName
- Name of member- Returns:
- The mapping
- Throws:
NoSuchPersistentFieldException
- Thrown when the field/property is not found
-
providePrimaryKeyMappings
public void providePrimaryKeyMappings(MappingConsumer consumer)
Provide the mappings to the consumer for all primary-key fields mapped to this table.- Specified by:
providePrimaryKeyMappings
in interfaceDatastoreClass
- Specified by:
providePrimaryKeyMappings
in classAbstractClassTable
- Parameters:
consumer
- Consumer for the mappings
-
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 interfaceDatastoreClass
- Parameters:
consumer
- Consumer for the mappingsmappingType
- 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 interfaceDatastoreClass
- Overrides:
provideMappingsForMembers
in classAbstractClassTable
- Parameters:
consumer
- Consumer for the mappingsfieldMetaData
- MetaData for the fields to provide mappings forincludeSecondaryTables
- 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 interfaceDatastoreClass
- 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 classTableImpl
- Parameters:
conn
- Connection to use in validationautoCreate
- Whether to auto create the constraintsautoCreateErrors
- 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
-
-