org.datanucleus.store.rdbms.table
Class ClassTable

java.lang.Object
  extended by org.datanucleus.store.rdbms.table.AbstractTable
      extended by org.datanucleus.store.rdbms.table.TableImpl
          extended by org.datanucleus.store.rdbms.table.AbstractClassTable
              extended by org.datanucleus.store.rdbms.table.ClassTable
All Implemented Interfaces:
org.datanucleus.store.mapped.DatastoreClass, org.datanucleus.store.mapped.DatastoreContainerObject, Table

public class ClassTable
extends AbstractClassTable
implements org.datanucleus.store.mapped.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

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
protected  java.lang.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
datastoreIDMapping, discriminatorMapping, discriminatorMetaData, highestMemberNumber, idMapping, memberMappingsMap, pkMappings, versionMapping, versionMetaData
 
Fields inherited from class org.datanucleus.store.rdbms.table.AbstractTable
columns, columnsByName, dba, existsInDatastore, identifier, LOCALISER, state, storeMgr
 
Constructor Summary
ClassTable(org.datanucleus.store.mapped.DatastoreIdentifier tableName, RDBMSManager storeMgr, org.datanucleus.metadata.ClassMetaData cmd)
          Constructor.
 
Method Summary
 org.datanucleus.store.mapped.DatastoreClass getBaseDatastoreClassWithMember(org.datanucleus.metadata.AbstractMemberMetaData mmd)
          Convenience accessor for the base table for this table which has the specified field.
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getDiscriminatorMapping(boolean allowSuperclasses)
          Accessor for the discriminator mapping specified .
 org.datanucleus.metadata.DiscriminatorMetaData getDiscriminatorMetaData()
          Accessor for Discriminator MetaData
protected  java.util.List getExpectedCandidateKeys()
          Accessor for the expected candidate keys for this table.
protected  java.util.List getExpectedForeignKeys(org.datanucleus.ClassLoaderResolver clr)
          Accessor for the expected foreign keys for this table.
protected  java.util.Set getExpectedIndices(org.datanucleus.ClassLoaderResolver clr)
          Accessor for the indices for this table.
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getExternalMapping(org.datanucleus.metadata.AbstractMemberMetaData mmd, int mappingType)
          Accessor for an external mapping for the specified field of the required type.
 org.datanucleus.metadata.IdentityType getIdentityType()
          Accessor for the identity-type.
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getIDMapping()
          Accessor for a mapping for the ID (PersistenceCapable) for this table.
 java.lang.String[] getManagedClasses()
          Accessor for the names of all classes managed by this table.
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getMemberMapping(org.datanucleus.metadata.AbstractMemberMetaData mmd)
          Accessor for the field mapping for the specified field.
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getMemberMapping(java.lang.String memberName)
          Accessor for the field mapping for the named field.
 org.datanucleus.store.mapped.mapping.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(org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping, int 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.
 java.util.Collection getSecondaryDatastoreClasses()
          Accessor for any secondary tables for this table.
protected  java.util.List getSQLCreateStatements(java.util.Properties props)
          Accessor for the CREATE statements for this table.
protected  java.util.List getSQLDropStatements()
          Accessor for the DROP statements for this table.
 org.datanucleus.store.mapped.DatastoreClass getSuperDatastoreClass()
          Accessor for the supertable for this table.
 ClassTable getTableWithDiscriminator()
          Convenience method to return the root table with a discriminator in this inheritance tree.
 java.lang.String getType()
          Accessor for the main class represented.
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getVersionMapping(boolean allowSuperclasses)
          Accessor for the version mapping specified .
 org.datanucleus.metadata.VersionMetaData getVersionMetaData()
          Accessor for versionMetaData
 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 datastore
 boolean isSuperDatastoreClass(org.datanucleus.store.mapped.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(java.lang.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(org.datanucleus.store.mapped.mapping.MappingConsumer consumer, int mappingType)
          Provide the mappings to the consumer for all external fields mapped to this table of the specified type
 void provideMappingsForMembers(org.datanucleus.store.mapped.mapping.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(org.datanucleus.store.mapped.mapping.MappingConsumer consumer)
          Provide the mappings to the consumer for all primary-key fields mapped to this table.
 void provideUnmappedDatastoreFields(org.datanucleus.store.mapped.mapping.MappingConsumer consumer)
          Method to provide all unmapped datastore fields (columns) to the consumer.
 boolean validateConstraints(java.sql.Connection conn, boolean autoCreate, java.util.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, getDataStoreObjectIdMapping, getMappingForMemberName, getPrimaryDatastoreContainerObject, managesMapping, managesMember, provideDatastoreIdMappings, provideDiscriminatorMappings, provideNonPrimaryKeyMappings, provideVersionMappings
 
Methods inherited from class org.datanucleus.store.rdbms.table.TableImpl
createConstraints, dropConstraints, getSQLAddCandidateKeyStatements, getSQLAddFKStatements, getSQLCreateIndexStatements, initializeColumnInfoForPrimaryKeyColumns, initializeColumnInfoFromDatastore, validate, validateColumns, validatePrimaryKey
 
Methods inherited from class org.datanucleus.store.rdbms.table.AbstractTable
addColumnInternal, addDatastoreField, allowDDLOutput, assertIsInitialized, assertIsInitializedModified, assertIsPKInitialized, assertIsPKUninitialized, assertIsUninitialized, assertIsValidated, create, drop, equals, executeDdlStatement, executeDdlStatementList, exists, getCatalogName, getDatastoreField, getDatastoreFields, getDatastoreIdentifierFullyQualified, getIdentifier, getSchemaName, getStoreManager, hasColumnName, hasDatastoreField, hashCode, isInitialized, isInitializedModified, isPKInitialized, isValidated, tableExistsInDatastore, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.datanucleus.store.mapped.DatastoreClass
getDataStoreObjectIdMapping, managesMapping, provideDatastoreIdMappings, provideDiscriminatorMappings, provideNonPrimaryKeyMappings, provideVersionMappings, toString
 
Methods inherited from interface org.datanucleus.store.mapped.DatastoreContainerObject
addDatastoreField, getDatastoreField, getDatastoreFields, getIdentifier, getStoreManager, hasDatastoreField
 

Field Detail

managingClassCurrent

protected transient java.lang.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(org.datanucleus.store.mapped.DatastoreIdentifier tableName,
                  RDBMSManager 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 java.lang.String[] getManagedClasses()
Accessor for the names of all classes managed by this table.

Returns:
Names of the classes managed (stored) here

managesClass

public boolean managesClass(java.lang.String className)
Accessor for whether this table manages the specified class

Specified by:
managesClass in interface org.datanucleus.store.mapped.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 java.lang.String getType()
Accessor for the main class represented.

Specified by:
getType in interface org.datanucleus.store.mapped.DatastoreClass
Returns:
The name of the class

getIdentityType

public org.datanucleus.metadata.IdentityType getIdentityType()
Accessor for the identity-type.

Specified by:
getIdentityType in interface org.datanucleus.store.mapped.DatastoreClass
Specified by:
getIdentityType in class AbstractClassTable
Returns:
identity-type tag value

getVersionMetaData

public final org.datanucleus.metadata.VersionMetaData getVersionMetaData()
Accessor for versionMetaData

Specified by:
getVersionMetaData in interface org.datanucleus.store.mapped.DatastoreContainerObject
Overrides:
getVersionMetaData in class AbstractTable
Returns:
Returns the versionMetaData.

getDiscriminatorMetaData

public final org.datanucleus.metadata.DiscriminatorMetaData getDiscriminatorMetaData()
Accessor for Discriminator MetaData

Specified by:
getDiscriminatorMetaData in interface org.datanucleus.store.mapped.DatastoreContainerObject
Overrides:
getDiscriminatorMetaData in class AbstractTable
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 interface org.datanucleus.store.mapped.DatastoreClass
Specified by:
isObjectIDDatastoreAttributed in class AbstractClassTable
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 interface org.datanucleus.store.mapped.DatastoreClass
Returns:
true if this table is a root table

getSuperDatastoreClass

public org.datanucleus.store.mapped.DatastoreClass getSuperDatastoreClass()
Accessor for the supertable for this table.

Specified by:
getSuperDatastoreClass in interface org.datanucleus.store.mapped.DatastoreClass
Returns:
The supertable

isSuperDatastoreClass

public boolean isSuperDatastoreClass(org.datanucleus.store.mapped.DatastoreClass table)
Accessor whether the supplied DatastoreClass is a supertable of this table.

Specified by:
isSuperDatastoreClass in interface org.datanucleus.store.mapped.DatastoreClass
Parameters:
table - The DatastoreClass to check
Returns:
Whether it is a supertable (somewhere up the inheritance tree)

getSecondaryDatastoreClasses

public java.util.Collection getSecondaryDatastoreClasses()
Accessor for any secondary tables for this table.

Specified by:
getSecondaryDatastoreClasses in interface org.datanucleus.store.mapped.DatastoreClass
Returns:
Secondary tables (if any)

getVersionMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getVersionMapping(boolean allowSuperclasses)
Accessor for the version mapping specified .

Specified by:
getVersionMapping in interface org.datanucleus.store.mapped.DatastoreContainerObject
Overrides:
getVersionMapping in class AbstractClassTable
Parameters:
allowSuperclasses - Whether we should return just the mapping from this table or whether we should return it when this table has none and the supertable has
Returns:
The version mapping.

getDiscriminatorMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getDiscriminatorMapping(boolean allowSuperclasses)
Accessor for the discriminator mapping specified .

Specified by:
getDiscriminatorMapping in interface org.datanucleus.store.mapped.DatastoreContainerObject
Overrides:
getDiscriminatorMapping in class AbstractClassTable
Parameters:
allowSuperclasses - Whether we should return just the mapping from this table or whether we should return it when this table has none and the supertable has
Returns:
The discriminator mapping.

getBaseDatastoreClassWithMember

public org.datanucleus.store.mapped.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 org.datanucleus.store.mapped.DatastoreClass
Parameters:
mmd - Field MetaData for this field
Returns:
The base table which has the field specified

getExpectedIndices

protected java.util.Set 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

protected java.util.List 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.

getExpectedCandidateKeys

protected java.util.List getExpectedCandidateKeys()
Accessor for the expected candidate keys for this table.

Overrides:
getExpectedCandidateKeys in class TableImpl
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 class TableImpl
Returns:
The primary key.

getSQLCreateStatements

protected java.util.List getSQLCreateStatements(java.util.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 java.util.List 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 org.datanucleus.store.mapped.mapping.JavaTypeMapping getIDMapping()
Accessor for a mapping for the ID (PersistenceCapable) for this table.

Specified by:
getIDMapping in interface org.datanucleus.store.mapped.DatastoreContainerObject
Returns:
The (PersistenceCapable) ID mapping.

getExternalMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getExternalMapping(org.datanucleus.metadata.AbstractMemberMetaData mmd,
                                                                               int mappingType)
Accessor for an external mapping for the specified field of the required type.

Specified by:
getExternalMapping in interface org.datanucleus.store.mapped.DatastoreClass
Parameters:
mmd - MetaData for the field/property
mappingType - Type of mapping
Returns:
The (external) mapping

getMetaDataForExternalMapping

public org.datanucleus.metadata.AbstractMemberMetaData getMetaDataForExternalMapping(org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping,
                                                                                     int mappingType)
Accessor for the MetaData for the (owner) field that an external mapping corresponds to.

Specified by:
getMetaDataForExternalMapping in interface org.datanucleus.store.mapped.DatastoreClass
Parameters:
mapping - The mapping
mappingType - The mapping type
Returns:
metadata for the external mapping

getMemberMapping

public org.datanucleus.store.mapped.mapping.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 org.datanucleus.store.mapped.DatastoreClass
Specified by:
getMemberMapping in interface org.datanucleus.store.mapped.DatastoreContainerObject
Parameters:
mmd - MetaData for this field/property
Returns:
the Mapping for the field/property

getMemberMappingInDatastoreClass

public org.datanucleus.store.mapped.mapping.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 org.datanucleus.store.mapped.DatastoreClass
Parameters:
mmd - Metadata of the field/property
Returns:
The Mapping for the field/property (or null if not present here)

getMemberMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getMemberMapping(java.lang.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 org.datanucleus.store.mapped.DatastoreClass
Parameters:
memberName - Name of field/property
Returns:
The mapping.
Throws:
org.datanucleus.store.exceptions.NoSuchPersistentFieldException - Thrown when the field/property is not found

providePrimaryKeyMappings

public void providePrimaryKeyMappings(org.datanucleus.store.mapped.mapping.MappingConsumer consumer)
Provide the mappings to the consumer for all primary-key fields mapped to this table.

Specified by:
providePrimaryKeyMappings in interface org.datanucleus.store.mapped.DatastoreClass
Specified by:
providePrimaryKeyMappings in class AbstractClassTable
Parameters:
consumer - Consumer for the mappings

provideExternalMappings

public final void provideExternalMappings(org.datanucleus.store.mapped.mapping.MappingConsumer consumer,
                                          int mappingType)
Provide the mappings to the consumer for all external fields mapped to this table of the specified type

Specified by:
provideExternalMappings in interface org.datanucleus.store.mapped.DatastoreClass
Parameters:
consumer - Consumer for the mappings
mappingType - Type of external mapping

provideMappingsForMembers

public void provideMappingsForMembers(org.datanucleus.store.mapped.mapping.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 org.datanucleus.store.mapped.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

provideUnmappedDatastoreFields

public void provideUnmappedDatastoreFields(org.datanucleus.store.mapped.mapping.MappingConsumer consumer)
Method to provide all unmapped datastore fields (columns) to the consumer.

Specified by:
provideUnmappedDatastoreFields in interface org.datanucleus.store.mapped.DatastoreClass
Parameters:
consumer - Consumer of information

validateConstraints

public boolean validateConstraints(java.sql.Connection conn,
                                   boolean autoCreate,
                                   java.util.Collection autoCreateErrors,
                                   org.datanucleus.ClassLoaderResolver clr)
                            throws java.sql.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:
java.sql.SQLException - Thrown when an error occurs in validation


Copyright © 2009. All Rights Reserved.