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 StringmanagingClassCurrentName of class currently being processed in manageClass (if any).protected booleanrunCallbacksAfterManageClassFlag 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 DatastoreClassgetBaseDatastoreClass()Accessor for the base datastore class.DatastoreClassgetBaseDatastoreClassWithMember(org.datanucleus.metadata.AbstractMemberMetaData mmd)Convenience accessor for the base table for this table which has the specified member.org.datanucleus.metadata.ClassMetaDatagetClassMetaData()Accessor for the (primary) class MetaData.org.datanucleus.metadata.DiscriminatorMetaDatagetDiscriminatorMetaData()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.JavaTypeMappinggetExternalMapping(org.datanucleus.metadata.AbstractMemberMetaData mmd, MappingType mappingType)Accessor for an external mapping for the specified field of the required type.org.datanucleus.metadata.IdentityTypegetIdentityType()Accessor for the identity-type.JavaTypeMappinggetIdMapping()Accessor for a mapping for the ID (persistable) for this table.String[]getManagedClasses()Accessor for the names of all classes managed by this table.JavaTypeMappinggetMemberMapping(String memberName)Accessor for the java mapping for the named member.JavaTypeMappinggetMemberMapping(org.datanucleus.metadata.AbstractMemberMetaData mmd)Accessor for the field mapping for the specified field.JavaTypeMappinggetMemberMappingInDatastoreClass(org.datanucleus.metadata.AbstractMemberMetaData mmd)Accessor for the mapping for the specified field only in this datastore class.org.datanucleus.metadata.AbstractMemberMetaDatagetMetaDataForExternalMapping(JavaTypeMapping mapping, MappingType mappingType)Accessor for the MetaData for the (owner) field that an external mapping corresponds to.PrimaryKeygetPrimaryKey()Accessor for the primary key for this table.CollectiongetSecondaryDatastoreClasses()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.DatastoreClassgetSuperDatastoreClass()Accessor for the supertable for this table.JavaTypeMappinggetSurrogateMapping(org.datanucleus.store.schema.table.SurrogateColumnType colType, boolean allowSuperclasses)Accessor for the mapping for the specified surrogate type.ClassTablegetTableManagingMapping(JavaTypeMapping mapping)ClassTablegetTableWithDiscriminator()Convenience method to return the root table with a discriminator in this inheritance tree.StringgetType()Accessor for the main class represented.org.datanucleus.metadata.VersionMetaDatagetVersionMetaData()Accessor for versionMetaDatabooleanhasExternalFkMappings()voidinitialize(org.datanucleus.ClassLoaderResolver clr)Method to initialise the table.protected voidinitializePK(org.datanucleus.ClassLoaderResolver clr)Method to initialise the table primary key field(s).booleanisBaseDatastoreClass()Whether this table is the base table in the inheritance hierarchy.booleanisObjectIdDatastoreAttributed()Whether this table or super table has id (primary key) attributed by the datastorebooleanisSuperDatastoreClass(DatastoreClass table)Accessor whether the supplied DatastoreClass is a supertable of this table.voidmanageClass(org.datanucleus.metadata.AbstractClassMetaData theCmd, org.datanucleus.ClassLoaderResolver clr)Method that adds the specified class to be managed by this table.booleanmanagesClass(String className)Accessor for whether this table manages the specified class.voidpostInitialize(org.datanucleus.ClassLoaderResolver clr)Post initilize.voidpreInitialize(org.datanucleus.ClassLoaderResolver clr)Pre-initialize.voidprovideExternalMappings(MappingConsumer consumer, MappingType mappingType)Provide the mappings to the consumer for all external fields mapped to this table of the specified typevoidprovideMappingsForMembers(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.voidprovidePrimaryKeyMappings(MappingConsumer consumer)Provide the mappings to the consumer for all primary-key fields mapped to this table.voidprovideUnmappedColumns(MappingConsumer consumer)Method to provide all unmapped columns to the consumer.booleanvalidateConstraints(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:
preInitializein interfaceTable- Overrides:
preInitializein 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:
initializein 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:
postInitializein interfaceTable- Overrides:
postInitializein 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:
getManagedClassesin 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:
managesClassin 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:
initializePKin classAbstractClassTable- Parameters:
clr- The ClassLoaderResolver
-
getType
public String getType()
Accessor for the main class represented.- Specified by:
getTypein interfaceDatastoreClass- Returns:
- The name of the class
-
getIdentityType
public org.datanucleus.metadata.IdentityType getIdentityType()
Accessor for the identity-type.- Specified by:
getIdentityTypein interfaceDatastoreClass- Specified by:
getIdentityTypein classAbstractClassTable- Returns:
- identity-type tag value
-
getVersionMetaData
public final org.datanucleus.metadata.VersionMetaData getVersionMetaData()
Accessor for versionMetaData- Specified by:
getVersionMetaDatain interfaceTable- Overrides:
getVersionMetaDatain classAbstractTable- Returns:
- Returns the versionMetaData.
-
getDiscriminatorMetaData
public final org.datanucleus.metadata.DiscriminatorMetaData getDiscriminatorMetaData()
Accessor for Discriminator MetaData- Specified by:
getDiscriminatorMetaDatain interfaceTable- Overrides:
getDiscriminatorMetaDatain 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:
isObjectIdDatastoreAttributedin interfaceDatastoreClass- Specified by:
isObjectIdDatastoreAttributedin 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:
isBaseDatastoreClassin interfaceDatastoreClass- Returns:
- true if this table is a root table
-
getBaseDatastoreClass
public DatastoreClass getBaseDatastoreClass()
Description copied from interface:DatastoreClassAccessor for the base datastore class. Returns this object if it has no superclass table, otherwise goes up to the superclass etc.- Specified by:
getBaseDatastoreClassin interfaceDatastoreClass- Returns:
- The base datastore class
-
getSuperDatastoreClass
public DatastoreClass getSuperDatastoreClass()
Accessor for the supertable for this table.- Specified by:
getSuperDatastoreClassin interfaceDatastoreClass- Returns:
- The supertable
-
isSuperDatastoreClass
public boolean isSuperDatastoreClass(DatastoreClass table)
Accessor whether the supplied DatastoreClass is a supertable of this table.- Specified by:
isSuperDatastoreClassin 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:
getSecondaryDatastoreClassesin interfaceDatastoreClass- Returns:
- Secondary tables (if any)
-
getSurrogateMapping
public JavaTypeMapping getSurrogateMapping(org.datanucleus.store.schema.table.SurrogateColumnType colType, boolean allowSuperclasses)
Description copied from interface:TableAccessor for the mapping for the specified surrogate type.- Specified by:
getSurrogateMappingin interfaceTable- Overrides:
getSurrogateMappingin 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:
getBaseDatastoreClassWithMemberin 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:
getClassMetaDatain interfaceorg.datanucleus.store.schema.table.Table- Overrides:
getClassMetaDatain 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:
getExpectedIndicesin 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:
getExpectedForeignKeysin 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:
getExpectedCandidateKeysin 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:
getPrimaryKeyin 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:
getSQLCreateStatementsin 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:
getSQLDropStatementsin classTableImpl- Returns:
- List of statements
-
getIdMapping
public JavaTypeMapping getIdMapping()
Accessor for a mapping for the ID (persistable) for this table.- Specified by:
getIdMappingin 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:
getExternalMappingin 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:
getMetaDataForExternalMappingin 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:
getMemberMappingin interfaceDatastoreClass- Specified by:
getMemberMappingin 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:
getMemberMappingInDatastoreClassin 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:
getMemberMappingin 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:
providePrimaryKeyMappingsin interfaceDatastoreClass- Specified by:
providePrimaryKeyMappingsin 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:
provideExternalMappingsin 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:
provideMappingsForMembersin interfaceDatastoreClass- Overrides:
provideMappingsForMembersin 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:
provideUnmappedColumnsin 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:
validateConstraintsin 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
-
-