org.jpox.store.rdbms.table
Class ClassTable

java.lang.Object
  extended byorg.jpox.store.rdbms.table.AbstractTable
      extended byorg.jpox.store.rdbms.table.TableImpl
          extended byorg.jpox.store.rdbms.table.AbstractClassTable
              extended byorg.jpox.store.rdbms.table.ClassTable
All Implemented Interfaces:
DatastoreClass, DatastoreContainerObject, DatastoreObject, 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

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.

Version:
$Revision: 1.165 $

Field Summary
 
Fields inherited from class org.jpox.store.rdbms.table.AbstractClassTable
datastoreIDMapping, discriminatorMapping, fieldMappingsMap, highestFieldNumber, idMapping, pkMappings, versionMapping
 
Fields inherited from class org.jpox.store.rdbms.table.AbstractTable
columns, columnsByName, dba, ddlDumpWriter, identifier, LOCALISER, state, storeMgr
 
Fields inherited from interface org.jpox.store.rdbms.table.Table
TABLE_STATE_INITIALIZED, TABLE_STATE_INITIALIZED_MODIFIED, TABLE_STATE_NEW, TABLE_STATE_PK_INITIALIZED, TABLE_STATE_VALIDATED, TABLE_TYPE_MISSING, TABLE_TYPE_TABLE, TABLE_TYPE_UNKNOWN, TABLE_TYPE_VIEW
 
Constructor Summary
ClassTable(DatastoreIdentifier tableName, ClassMetaData cmd, RDBMSManager storeMgr, ClassLoaderResolver clr)
          Constructor.
 
Method Summary
 void delete(StateManager sm)
          Method to delete an object from this table.
 void deleteDependent(StateManager sm, AbstractPropertyMetaData[] fieldMetaData)
          Delete dependent objects of a persistent object.
 void fetch(StateManager sm, AbstractPropertyMetaData[] fieldMetaData)
          Method to fetch an object in this table.
 DatastoreClass getBaseDatastoreClassWithField(AbstractPropertyMetaData fmd)
          Convenience accessor for the base table for this table which has the specified field.
 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(ClassLoaderResolver clr)
          Accessor for the expected foreign keys for this table.
protected  java.util.Set getExpectedIndices(ClassLoaderResolver clr)
          Accessor for the indices for this table.
 JavaTypeMapping getExternalFkDiscriminatorMapping(AbstractPropertyMetaData fmd)
          Accessor for the external FK discriminator mapping for an owner field.
 java.util.HashMap getExternalFkDiscriminatorMappings()
          Accessor for all of the external FK discriminator mappings.
 JavaTypeMapping getExternalFkMapping(AbstractPropertyMetaData fmd)
          Accessor for the external FK mapping for an owner field.
 java.util.HashMap getExternalFkMappings()
          Accessor for all of the external FK mappings.
 JavaTypeMapping getExternalOrderMapping(AbstractPropertyMetaData fmd)
          Accessor for the index mapping specified by the field.
 JavaTypeMapping getFieldMapping(AbstractPropertyMetaData fmd)
          Accessor for the field mapping for the specified field.
 JavaTypeMapping getFieldMapping(java.lang.String fieldName)
          Accessor for the field mapping for the named field.
 AbstractPropertyMetaData getFieldMetaData(java.lang.String fieldName)
          Acessor for the FieldMetaData for the field with the specified name.
protected  ForeignKey getForeignKeyForForeignKeyMetaData(ForeignKeyMetaData fkmd)
          Convenience method to create a FK for the specified ForeignKeyMetaData.
 IdentityType getIdentityType()
          Accessor for the identity-type.
 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.
 PrimaryKey getPrimaryKey()
          Accessor for the primary key 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.
 ClassTable getSupertable()
          Accessor for the supertable for this table.
 java.lang.String getType()
          Accessor for the main class represented.
 VersionMetaData getVersionMetaData()
          Accessor for versionMetaData
 void initialize(ClassLoaderResolver clr)
          Method to initialise the table.
protected  void initializePK(ClassLoaderResolver clr)
          Method to initialise the table primary key field(s).
 void insert(StateManager sm)
          Method to fetch an insert into this table.
 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
 void locate(StateManager sm)
          Locates this object in the datastore.
 void manageClass(AbstractClassMetaData theCmd, ClassLoaderResolver clr)
          Method to give management of the persistence of the fields of the specified class to this table.
 boolean managesClass(java.lang.String className)
          Accessor for whether this table manages the specified class
 java.lang.Object newOID(PersistenceManager pm, javax.jdo.spi.PersistenceCapable pcClass)
          Create a newOID for a class.
 void postInitialize(ClassLoaderResolver clr)
          Post initilize.
 void preInitialize(ClassLoaderResolver clr)
          Pre-initialize.
 void provideExternalFkMappings(MappingConsumer consumer)
          Provide the mappings to the consumer for all foreign-key fields mapped to this table.
 void provideExternalOrderMappings(MappingConsumer consumer)
          Provide the mappings to the consumer for all external order fields mapped to this table.
 void provideMappingsForFields(MappingConsumer consumer, AbstractPropertyMetaData[] 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 update(StateManager sm, AbstractPropertyMetaData[] fieldMetaData)
          Method to update an object in this table.
 boolean validateConstraints(java.sql.Connection conn, boolean autoCreate, java.util.Collection autoCreateErrors, ClassLoaderResolver clr)
          Method to validate the constraints of this table.
 
Methods inherited from class org.jpox.store.rdbms.table.AbstractClassTable
addFieldMapping, getDataStoreObjectIdMapping, getDefaultNameForType, getDiscriminatorMapping, getPrimaryDatastoreContainerObject, getVersionMapping, managesField, provideDatastoreIdMappings, provideDiscriminatorMappings, provideNonPrimaryKeyMappings, provideVersionMappings
 
Methods inherited from class org.jpox.store.rdbms.table.TableImpl
dropConstraints, getSQLAddCandidateKeyStatements, getSQLAddFKStatements, getSQLCreateIndexStatements, initializeColumnInfoForPrimaryKeyColumns, initializeColumnInfoFromDatastore, validate, validateColumns, validatePrimaryKey
 
Methods inherited from class org.jpox.store.rdbms.table.AbstractTable
addColumnInternal, addDatastoreField, allowDdlDump, assertIsInitialized, assertIsInitializedModified, assertIsPKInitialized, assertIsPKUninitialized, assertIsUninitialized, assertIsValidated, create, drop, equals, executeDdlStatement, executeDdlStatementList, exists, getCatalogName, getDatastoreIdentifierFullyQualified, getIdentifier, getSchemaName, getStoreManager, hasColumnName, hasDatastoreField, hashCode, isDumpingDdl, isInitialized, isInitializedModified, isPKInitialized, isValidated, setDdlDumpWriter, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jpox.store.DatastoreClass
getDataStoreObjectIdMapping, provideDatastoreIdMappings, provideDiscriminatorMappings, provideNonPrimaryKeyMappings, provideVersionMappings, toString
 
Methods inherited from interface org.jpox.store.DatastoreContainerObject
addDatastoreField, getDiscriminatorMapping, getVersionMapping, hasDatastoreField
 
Methods inherited from interface org.jpox.store.DatastoreObject
getIdentifier, getStoreManager
 

Constructor Detail

ClassTable

public ClassTable(DatastoreIdentifier tableName,
                  ClassMetaData cmd,
                  RDBMSManager storeMgr,
                  ClassLoaderResolver clr)
Constructor.

Parameters:
tableName - Table name SQL identifier
cmd - MetaData for the class.
storeMgr - Store Manager to manage this table
clr - The ClassLoaderResolver
Method Detail

preInitialize

public void preInitialize(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(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(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(AbstractClassMetaData theCmd,
                        ClassLoaderResolver clr)
Method to give management of the persistence of the fields of the specified class to this table. Goes through all (non-PK) fields in the specified class and adds a mapping for each. Each mapping will then call prepareDatastoreMapping() 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

Parameters:
className - Name of the class
Returns:
Whether it is managed by this table

initializePK

protected void initializePK(ClassLoaderResolver clr)
Method to initialise the table primary key field(s).

Specified by:
initializePK in class AbstractClassTable
Parameters:
clr - The ClassLoaderResolver

newOID

public final java.lang.Object newOID(PersistenceManager pm,
                                     javax.jdo.spi.PersistenceCapable pcClass)
Create a newOID for a class. Works for datastore identity, or application identity (inc composite keys)

Specified by:
newOID in interface DatastoreClass
Parameters:
pm - The PersistenceManager
pcClass - The persistence capable class
Returns:
The new OID

getType

public java.lang.String getType()
Accessor for the main class represented.

Specified by:
getType in interface DatastoreClass
Returns:
The name of the class

getIdentityType

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

Specified by:
getIdentityType in interface DatastoreClass
Specified by:
getIdentityType in class AbstractClassTable
Returns:
identity-type tag value

getVersionMetaData

public final VersionMetaData getVersionMetaData()
Accessor for versionMetaData

Specified by:
getVersionMetaData in interface DatastoreContainerObject
Overrides:
getVersionMetaData in class AbstractTable
Returns:
Returns the versionMetaData.

getDiscriminatorMetaData

public final DiscriminatorMetaData getDiscriminatorMetaData()
Accessor for Discriminator MetaData

Specified by:
getDiscriminatorMetaData in interface DatastoreContainerObject
Overrides:
getDiscriminatorMetaData in class AbstractTable
Returns:
Returns the Discriminator MetaData.

isObjectIDDatastoreAttributed

public boolean isObjectIDDatastoreAttributed()
Whether this table or super table has id (primary key) attributed by the datastore

Specified by:
isObjectIDDatastoreAttributed in interface 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 DatastoreClass
Returns:
true if this table is a root table

getSupertable

public ClassTable getSupertable()
Accessor for the supertable for this table.

Returns:
The supertable

getBaseDatastoreClassWithField

public DatastoreClass getBaseDatastoreClassWithField(AbstractPropertyMetaData fmd)
Convenience accessor for the base table for this table which has the specified field.

Specified by:
getBaseDatastoreClassWithField in interface DatastoreClass
Parameters:
fmd - Field MetaData for this field
Returns:
The base table which has the field specified

getExpectedIndices

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

getForeignKeyForForeignKeyMetaData

protected ForeignKey getForeignKeyForForeignKeyMetaData(ForeignKeyMetaData fkmd)
Convenience method to create a FK for the specified ForeignKeyMetaData. Typically used for foreign-keys specified at <class> level.

Parameters:
fkmd - ForeignKey MetaData
Returns:
The ForeignKey

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 JavaTypeMapping getIDMapping()
Accessor for a mapping for the ID (PersistenceCapable) for this table.

Specified by:
getIDMapping in interface DatastoreContainerObject
Returns:
The (PersistenceCapable) ID mapping.

getExternalOrderMapping

public JavaTypeMapping getExternalOrderMapping(AbstractPropertyMetaData fmd)
Accessor for the index mapping specified by the field.

Specified by:
getExternalOrderMapping in interface DatastoreClass
Parameters:
fmd - The metadata for the List field.
Returns:
The index mapping for the specified field.

getExternalFkMappings

public java.util.HashMap getExternalFkMappings()
Accessor for all of the external FK mappings.

Returns:
The mappings for external FKs

getExternalFkMapping

public JavaTypeMapping getExternalFkMapping(AbstractPropertyMetaData fmd)
Accessor for the external FK mapping for an owner field.

Specified by:
getExternalFkMapping in interface DatastoreClass
Parameters:
fmd - The metadata for the field.
Returns:
The external mapping for the specified field.

getExternalFkDiscriminatorMappings

public java.util.HashMap getExternalFkDiscriminatorMappings()
Accessor for all of the external FK discriminator mappings.

Returns:
The mappings for external FKs

getExternalFkDiscriminatorMapping

public JavaTypeMapping getExternalFkDiscriminatorMapping(AbstractPropertyMetaData fmd)
Accessor for the external FK discriminator mapping for an owner field.

Specified by:
getExternalFkDiscriminatorMapping in interface DatastoreClass
Parameters:
fmd - The metadata for the field.
Returns:
The external mapping for the specified field.

getFieldMapping

public JavaTypeMapping getFieldMapping(AbstractPropertyMetaData fmd)
Accessor for the field mapping for the specified field. The field can be managed by a supertable of this table.

Specified by:
getFieldMapping in interface DatastoreClass
Parameters:
fmd - Field MetaData for this field
Returns:
the Mapping for the field

getFieldMapping

public JavaTypeMapping getFieldMapping(java.lang.String fieldName)
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.

Specified by:
getFieldMapping in interface DatastoreClass
Parameters:
fieldName - Name of field
Returns:
The field mapping.
Throws:
NoSuchPersistentFieldException - Thrown when the field is not found

getFieldMetaData

public AbstractPropertyMetaData getFieldMetaData(java.lang.String fieldName)
Acessor for the FieldMetaData for the field with the specified name. Searches the MetaData of all classes managed by this table. Doesn't allow for cases where the table manages subclasses with the same field name. In that case you should use the equivalent method passing FieldMetaData. TODO Support subclasses with fields of the same name

Specified by:
getFieldMetaData in interface DatastoreClass
Parameters:
fieldName - the field name
Returns:
the FieldMetaData

insert

public void insert(StateManager sm)
Method to fetch an insert into this table. Will insert any superclass records as well (recursive).

Specified by:
insert in interface DatastoreClass
Parameters:
sm - StateManager for the object to insert.

fetch

public void fetch(StateManager sm,
                  AbstractPropertyMetaData[] fieldMetaData)
Method to fetch an object in this table. Will fetch any superclass records as well (recursive).

Specified by:
fetch in interface DatastoreClass
Parameters:
sm - StateManager for the object to fetch.
fieldMetaData - MetaDat afor the fields to be fetched

update

public void update(StateManager sm,
                   AbstractPropertyMetaData[] fieldMetaData)
Method to update an object in this table. Will update any superclass records as well (recursive).

Specified by:
update in interface DatastoreClass
Parameters:
sm - StateManager for the object to update.
fieldMetaData - MetaData for the fields to be updated

delete

public void delete(StateManager sm)
Method to delete an object from this table. Will delete any superclass records as well (recursive).

Specified by:
delete in interface DatastoreClass
Parameters:
sm - StateManager for the object to delete.

locate

public void locate(StateManager sm)
Locates this object in the datastore. Returns normally if it is present, or throws an exception if not found.

Specified by:
locate in interface DatastoreClass
Parameters:
sm - The StateManager for the object to be found
Throws:
javax.jdo.JDOObjectNotFoundException - If the instance does not exist in the datastore

deleteDependent

public void deleteDependent(StateManager sm,
                            AbstractPropertyMetaData[] fieldMetaData)
Delete dependent objects of a persistent object.

Specified by:
deleteDependent in interface DatastoreClass
Parameters:
sm - StateManager for the object being deleted.
fieldMetaData - MetaData for the fields to delete.
Since:
1.1

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 interface DatastoreClass
Specified by:
providePrimaryKeyMappings in class AbstractClassTable
Parameters:
consumer - Consumer for the mappings

provideExternalFkMappings

public final void provideExternalFkMappings(MappingConsumer consumer)
Provide the mappings to the consumer for all foreign-key fields mapped to this table.

Specified by:
provideExternalFkMappings in interface DatastoreClass
Parameters:
consumer - Consumer for the mappings

provideExternalOrderMappings

public final void provideExternalOrderMappings(MappingConsumer consumer)
Provide the mappings to the consumer for all external order fields mapped to this table.

Specified by:
provideExternalOrderMappings in interface DatastoreClass
Parameters:
consumer - Consumer for the mappings

provideMappingsForFields

public void provideMappingsForFields(MappingConsumer consumer,
                                     AbstractPropertyMetaData[] 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:
provideMappingsForFields in interface DatastoreClass
Overrides:
provideMappingsForFields 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

validateConstraints

public boolean validateConstraints(java.sql.Connection conn,
                                   boolean autoCreate,
                                   java.util.Collection autoCreateErrors,
                                   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 © -2007 . All Rights Reserved.