SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

com.solarmetric.kodo.impl.jdbc.ormapping
Class ClassMapping

java.lang.Object
  |
  +--com.solarmetric.kodo.impl.jdbc.ormapping.Mapping
        |
        +--com.solarmetric.kodo.impl.jdbc.ormapping.ClassMapping

public class ClassMapping
extends Mapping

A mapping between a java class and its relational database representation.


Field Summary
static String LOCK_COL
          Metadata extension key used to mark the name of the optimistic lock column for this class.
static String PK_COL
          Metadata extension key used to mark the name of the primary key column for this class, if it uses data store identity.
static String SUBCLASS_PROVIDER
          Metadata extension key used to override the default subclass provider setting for this class.
static String TABLE_PK_COL_SUFFIX
          Metadata extension key used when designating the name of the pk column for a particular table used by an application ID class.
 
Fields inherited from class com.solarmetric.kodo.impl.jdbc.ormapping.Mapping
_loc, _log, CUSTOM_MAPPING, dict, MAPPING, TABLE
 
Constructor Summary
ClassMapping()
           
 
Method Summary
protected  void addSubclassConditions(PersistenceManagerImpl pm, ObjectSelect sel, FieldMetaData[] fmds, boolean subs)
          Adds to the where clause of the given query to only select the desired classes.
protected  void addSubclassConditions(PersistenceManagerImpl pm, QuerySelect sel, FieldMetaData[] fmds, boolean subs)
          Adds to the where clause of the given query to only select the desired classes.
 void addTableJoins(Joins joins, Table fromTable)
           
protected  void addTableJoins(PersistenceManager pm, ObjectSelect sel)
          Adds the appropriate join logic to join together multiple primary tables.
protected  void addTableJoins(PersistenceManager pm, QuerySelect sel)
          Adds the appropriate join logic to join together multiple primary tables.
(package private)  boolean canMap(ClassMetaData meta, ClassResolver resolver)
          Return true if this mapping type can handle the given class, false otherwise.
 boolean checkVersion(StateManagerImpl sm, SQLExecutionManager sqlem)
          Determine whether the given StateManager is the same version as the datastore version.
 void delete(StateManagerImpl sm, SQLExecutionManager sqlem)
          Deletes the given instance from the database.
 boolean exists(PersistenceManagerImpl pm, Object oid, SQLExecutionManager sqlem)
          Verify that a given instance exists in the data store.
 Object getDataStoreValue(Object oid, PersistenceManagerImpl pm)
          Translate the given oid into primary key column values.
 Table getDefaultPrimaryTable()
          Return the default primary table used by this class.
 ResultList getExtentResultList(Extent extent, JDBCStoreManager store)
          Return a ResultList that can be used to access all the data for the specified Extent.
static ClassMapping getInstance(ClassMetaData meta)
          Return the ClassMapping for the given ClassMetaData instance, or null if none.
 Column getLockColumn()
          Return the column used to track the optimistic lock version of the class.
 ClassMetaData getMetaData()
          Return the ClassMetaData instance this mapping is installed on.
 Object getObjectId(PersistenceManagerImpl pm, ResultSet rs, int startIndex)
          Return the object id for the object stored in the current row of the given result set.
 Column[] getPKColumns()
          Return the primary key column(s) of the class' primary table.
 Column[] getPKColumns(Table t)
          Return the primary key column(s) for a particular primary table.
 FieldMetaData[] getPrimaryMappingFields(PersistenceManagerImpl pm, boolean subs, ClassResolver resolver, DBDictionary dict, Set forcedFields, BitSet excludedFields)
          Returns an array of all FieldMetaData objects to load when loading primary mappings for this class.
protected  List getPrimaryMappingFields(PersistenceManagerImpl pm, FieldMetaData[] fmds, Set tables, Set forcedFields, BitSet excludedFields)
          Returns the primary table field meta datas from the given list that are either in the dfg, in a custom fetch group that is included in pm's active fetch groups, or in the forcedFields set.
protected  Table getPrimaryTable(FieldMetaData fmd)
          Return the primary table used by this class for this field.
 Table[] getPrimaryTables()
           
 Class[] getSubclasses()
           
protected  Class[] getSubclassesDifferentMapping(ClassResolver resolver)
          Return a list of known persistent subclasses of the mapped type that map to more tables than this mapping.
protected  Class[] getSubclassesSameMapping(ClassResolver resolver)
          Return a list of known persistent subclasses of the mapped type that map to exactly the same set of tables as this mapping.
 SubclassProvider getSubclassProvider()
          Return the SubclassProvider responsible for providing subclass services for this mapping.
 void insert(StateManagerImpl sm, SQLExecutionManager sqlem)
          Inserts the given instance into the database.
(package private)  void install(ClassMetaData meta, JDBCConfiguration conf, ClassResolver resolver, DBDictionary dict)
          Setup this ClassMapping using the given metadata.
 boolean loadByPK(StateManagerImpl sm, JDOState state, SQLExecutionManager sqlem, Set fields, boolean setVersion, boolean forUpdate)
          Load the object referenced by sm.
 void loadPrimaryMappings(StateManagerImpl sm, ResultSet rs, FieldMetaData[] fmds, int startIndex, JDOState state)
          Load the primary mappings selected in the selectPrimaryMappings(com.solarmetric.kodo.runtime.PersistenceManagerImpl, com.solarmetric.kodo.impl.jdbc.sql.ObjectSelect, com.solarmetric.kodo.impl.jdbc.SQLExecutionManager, com.solarmetric.kodo.meta.FieldMetaData[], boolean) methods into the given StateManager.
 KodoExtent newExtent(boolean subclasses, JDBCStoreManager store)
          Deprecated. use the getExtentResultList(javax.jdo.Extent, com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager) method instead
 ResultSet selectPrimaryMappings(PersistenceManagerImpl pm, ObjectSelect sel, SQLExecutionManager sqlem, FieldMetaData[] fmds, boolean subs)
          Loads the FieldData instances matching the given Select of the type mapped by this ClassMapping from the database.
 ResultSet selectPrimaryMappings(PersistenceManagerImpl pm, QuerySelect sel, SQLExecutionManager sqlem, FieldMetaData[] fmds, boolean subs)
          Loads the FieldData instances matching the given Select of the type mapped by this ClassMapping from the database.
 void setLockColumn(Column lock)
          Set the column used to track the optimistic lock version of the class.
 void setPKColumns(Column[] pks)
          Set the primary key column(s) of the class' primary table.
 void setPKColumns(Table t, Column[] pks)
          Set the primary key column(s) for the given primary table.
 void update(StateManagerImpl sm, BitSet fields, SQLExecutionManager sqlem)
          Updates the given instance in the database.
 
Methods inherited from class com.solarmetric.kodo.impl.jdbc.ormapping.Mapping
checkExtension, createMapping, createMapping, createMappings, createMappings, getClassName, getConfiguration, getDictionary, getFieldMapping, getInstance, getTable, install
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PK_COL

public static final String PK_COL
Metadata extension key used to mark the name of the primary key column for this class, if it uses data store identity.

LOCK_COL

public static final String LOCK_COL
Metadata extension key used to mark the name of the optimistic lock column for this class.

SUBCLASS_PROVIDER

public static final String SUBCLASS_PROVIDER
Metadata extension key used to override the default subclass provider setting for this class.

TABLE_PK_COL_SUFFIX

public static final String TABLE_PK_COL_SUFFIX
Metadata extension key used when designating the name of the pk column for a particular table used by an application ID class. Full extension will be in the form <tablename>-pk-column.
Constructor Detail

ClassMapping

public ClassMapping()
Method Detail

getInstance

public static ClassMapping getInstance(ClassMetaData meta)
Return the ClassMapping for the given ClassMetaData instance, or null if none.

getMetaData

public ClassMetaData getMetaData()
Return the ClassMetaData instance this mapping is installed on.

getSubclassProvider

public SubclassProvider getSubclassProvider()
Return the SubclassProvider responsible for providing subclass services for this mapping.

getPKColumns

public Column[] getPKColumns(Table t)
Return the primary key column(s) for a particular primary table.

setPKColumns

public void setPKColumns(Table t,
                         Column[] pks)
Set the primary key column(s) for the given primary table. The columns must be set in the same order in which the corresponding fields are declared in the persistent class.

getPKColumns

public Column[] getPKColumns()
Return the primary key column(s) of the class' primary table. The columns will be returned in the same order in which the corresponding fields are declared in the persistent class.

setPKColumns

public void setPKColumns(Column[] pks)
Set the primary key column(s) of the class' primary table. The columns must be set in the same order in which the corresponding fields are declared in the persistent class.

getLockColumn

public Column getLockColumn()
Return the column used to track the optimistic lock version of the class.

setLockColumn

public void setLockColumn(Column lock)
Set the column used to track the optimistic lock version of the class. This column must be in the primary table of the class, and must be of an integer type. If the column is not set, the mapped type should not be used in optimistic transactions, as concurrent modification errors will be impossible to detect.

getSubclasses

public Class[] getSubclasses()

getSubclassesSameMapping

protected Class[] getSubclassesSameMapping(ClassResolver resolver)
Return a list of known persistent subclasses of the mapped type that map to exactly the same set of tables as this mapping.

getSubclassesDifferentMapping

protected Class[] getSubclassesDifferentMapping(ClassResolver resolver)
Return a list of known persistent subclasses of the mapped type that map to more tables than this mapping.

getPrimaryTable

protected Table getPrimaryTable(FieldMetaData fmd)
Return the primary table used by this class for this field. This method is not particularly fast, so it should only be used during install if at all possible.

getPrimaryTables

public Table[] getPrimaryTables()

getDefaultPrimaryTable

public Table getDefaultPrimaryTable()
Return the default primary table used by this class.

insert

public void insert(StateManagerImpl sm,
                   SQLExecutionManager sqlem)
            throws SQLException
Inserts the given instance into the database.
Parameters:
sm - The StateManagerImpl to insert.
sqlem - The SQLExecutionManager to use for executing queries against the data store. For optimal performance, the proprietary SQLExecutionManager APIs should be used to execute SQL statements, but it is also possible to obtain the current Connection from a SQLExecutionManager and use regular JDBC APIs to perform the necessary work.

update

public void update(StateManagerImpl sm,
                   BitSet fields,
                   SQLExecutionManager sqlem)
            throws SQLException
Updates the given instance in the database.
Parameters:
sm - The StateManagerImpl to update.
fields - The fields that need to be stored.
sqlem - The SQLExecutionManager to use for executing queries against the data store. For optimal performance, the proprietary SQLExecutionManager APIs should be used to execute SQL statements, but it is also possible to obtain the current Connection from a SQLExecutionManager and use regular JDBC APIs to perform the necessary work.

delete

public void delete(StateManagerImpl sm,
                   SQLExecutionManager sqlem)
            throws SQLException
Deletes the given instance from the database.
Parameters:
sm - The StateManagerImpl to delete.
sqlem - The SQLExecutionManager to use for executing queries against the data store. For optimal performance, the proprietary SQLExecutionManager APIs should be used to execute SQL statements, but it is also possible to obtain the current Connection from a SQLExecutionManager and use regular JDBC APIs to perform the necessary work.

exists

public boolean exists(PersistenceManagerImpl pm,
                      Object oid,
                      SQLExecutionManager sqlem)
               throws SQLException
Verify that a given instance exists in the data store.
Parameters:
pm - The PersistenceManagerImpl that caused this method invocation to be made.
oid - The ID of the object to look for in the data store.
sqlem - The SQLExecutionManager to use for executing queries against the data store. For optimal performance, the proprietary SQLExecutionManager APIs should be used to execute SQL statements, but it is also possible to obtain the current Connection from a SQLExecutionManager and use regular JDBC APIs to perform the necessary work.
Returns:
true if the data exists; else false.

checkVersion

public boolean checkVersion(StateManagerImpl sm,
                            SQLExecutionManager sqlem)
                     throws SQLException
Determine whether the given StateManager is the same version as the datastore version.
Parameters:
sm - the instance for which a version check should be performed.
sqlem - The SQLExecutionManager to use for executing queries against the data store. For optimal performance, the proprietary SQLExecutionManager APIs should be used to execute SQL statements, but it is also possible to obtain the current Connection from a SQLExecutionManager and use regular JDBC APIs to perform the necessary work.
Returns:
true if the instance is up-to-date, false otherwise

getObjectId

public Object getObjectId(PersistenceManagerImpl pm,
                          ResultSet rs,
                          int startIndex)
                   throws SQLException
Return the object id for the object stored in the current row of the given result set.
Parameters:
pm - the PersistenceManagerImpl} making the request for PK values.
rs - the ResultSet produced by the selectPrimaryMappings(com.solarmetric.kodo.runtime.PersistenceManagerImpl, com.solarmetric.kodo.impl.jdbc.sql.ObjectSelect, com.solarmetric.kodo.impl.jdbc.SQLExecutionManager, com.solarmetric.kodo.meta.FieldMetaData[], boolean) method
startIndex - the column index that represents the beginning of the SELECTs made in the selectPrimaryMappings(com.solarmetric.kodo.runtime.PersistenceManagerImpl, com.solarmetric.kodo.impl.jdbc.sql.ObjectSelect, com.solarmetric.kodo.impl.jdbc.SQLExecutionManager, com.solarmetric.kodo.meta.FieldMetaData[], boolean) method

loadByPK

public boolean loadByPK(StateManagerImpl sm,
                        JDOState state,
                        SQLExecutionManager sqlem,
                        Set fields,
                        boolean setVersion,
                        boolean forUpdate)
                 throws SQLException
Load the object referenced by sm.
Parameters:
sm - The StateManagerImpl of the data to load. sm.oid contains the object ID of the data.
state - The JDOState that sm should be initialized to. This can be null if no initialization should be performed on sm. If non-null, then StateManagerImpl.initialize(javax.jdo.spi.PersistenceCapable, com.solarmetric.kodo.runtime.JDOState) should be invoked on sm.
sqlem - The SQLExecutionManager to use for executing queries against the data store. For optimal performance, the proprietary SQLExecutionManager APIs should be used to execute SQL statements, but it is also possible to obtain the current Connection from a SQLExecutionManager and use regular JDBC APIs to perform the necessary work.
fields - A Set containing the fields to be loaded. It is legal to load more than just these fields, but at least these must be loaded.
forUpdate - If this is true, then the SELECT statement created should request a lock on the selected data.

newExtent

public final KodoExtent newExtent(boolean subclasses,
                                  JDBCStoreManager store)
Deprecated. use the getExtentResultList(javax.jdo.Extent, com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager) method instead

Returns an KodoExtent for the class managed by this ClassMapping, optionally including subclasses.
Parameters:
subclasses - If true, the created extent should be capable of accessing all subclasses of the class managed by this ClassMapping. Otherwise, the created extent should only provide access to the exact managed class.
store - The JDBCStoreManager that made the request for the extent.

getExtentResultList

public ResultList getExtentResultList(Extent extent,
                                      JDBCStoreManager store)
Return a ResultList that can be used to access all the data for the specified Extent.
Parameters:
extent - the extent that is used (for information on using subclasses, etc).
store - the JDBCStoreManager in use.
Returns:
a ResultList containing all the information in the Extent.

loadPrimaryMappings

public void loadPrimaryMappings(StateManagerImpl sm,
                                ResultSet rs,
                                FieldMetaData[] fmds,
                                int startIndex,
                                JDOState state)
                         throws SQLException
Load the primary mappings selected in the selectPrimaryMappings(com.solarmetric.kodo.runtime.PersistenceManagerImpl, com.solarmetric.kodo.impl.jdbc.sql.ObjectSelect, com.solarmetric.kodo.impl.jdbc.SQLExecutionManager, com.solarmetric.kodo.meta.FieldMetaData[], boolean) methods into the given StateManager.
Parameters:
rs - the ResultSet produced by the selectPrimaryMappings(com.solarmetric.kodo.runtime.PersistenceManagerImpl, com.solarmetric.kodo.impl.jdbc.sql.ObjectSelect, com.solarmetric.kodo.impl.jdbc.SQLExecutionManager, com.solarmetric.kodo.meta.FieldMetaData[], boolean) method
startIndex - the column index that represents the beginning of the SELECTs made in the selectPrimaryMappings(com.solarmetric.kodo.runtime.PersistenceManagerImpl, com.solarmetric.kodo.impl.jdbc.sql.ObjectSelect, com.solarmetric.kodo.impl.jdbc.SQLExecutionManager, com.solarmetric.kodo.meta.FieldMetaData[], boolean) method
state - The JDOState that sm should be initialized to. Should be null if no initialization should happen.

getPrimaryMappingFields

public FieldMetaData[] getPrimaryMappingFields(PersistenceManagerImpl pm,
                                               boolean subs,
                                               ClassResolver resolver,
                                               DBDictionary dict,
                                               Set forcedFields,
                                               BitSet excludedFields)
Returns an array of all FieldMetaData objects to load when loading primary mappings for this class.

getPrimaryMappingFields

protected List getPrimaryMappingFields(PersistenceManagerImpl pm,
                                       FieldMetaData[] fmds,
                                       Set tables,
                                       Set forcedFields,
                                       BitSet excludedFields)
Returns the primary table field meta datas from the given list that are either in the dfg, in a custom fetch group that is included in pm's active fetch groups, or in the forcedFields set.

selectPrimaryMappings

public ResultSet selectPrimaryMappings(PersistenceManagerImpl pm,
                                       ObjectSelect sel,
                                       SQLExecutionManager sqlem,
                                       FieldMetaData[] fmds,
                                       boolean subs)
                                throws SQLException
Loads the FieldData instances matching the given Select of the type mapped by this ClassMapping from the database.

addSubclassConditions

protected void addSubclassConditions(PersistenceManagerImpl pm,
                                     ObjectSelect sel,
                                     FieldMetaData[] fmds,
                                     boolean subs)
Adds to the where clause of the given query to only select the desired classes.

addTableJoins

protected void addTableJoins(PersistenceManager pm,
                             ObjectSelect sel)
Adds the appropriate join logic to join together multiple primary tables.

canMap

boolean canMap(ClassMetaData meta,
               ClassResolver resolver)
Return true if this mapping type can handle the given class, false otherwise. Note that this method cannot rely on the existance of other Mappings, as it is used in bootstrapping.

install

void install(ClassMetaData meta,
             JDBCConfiguration conf,
             ClassResolver resolver,
             DBDictionary dict)
Setup this ClassMapping using the given metadata. Note that this method cannot rely on the existance of other Mappings, as it it is used in bootstrapping. This base implementation installs the proper extensions onto the metadata only; subclasses must override to properly map the type.

getDataStoreValue

public Object getDataStoreValue(Object oid,
                                PersistenceManagerImpl pm)
Translate the given oid into primary key column values.

selectPrimaryMappings

public ResultSet selectPrimaryMappings(PersistenceManagerImpl pm,
                                       QuerySelect sel,
                                       SQLExecutionManager sqlem,
                                       FieldMetaData[] fmds,
                                       boolean subs)
                                throws SQLException
Loads the FieldData instances matching the given Select of the type mapped by this ClassMapping from the database.

addSubclassConditions

protected void addSubclassConditions(PersistenceManagerImpl pm,
                                     QuerySelect sel,
                                     FieldMetaData[] fmds,
                                     boolean subs)
Adds to the where clause of the given query to only select the desired classes.

addTableJoins

protected void addTableJoins(PersistenceManager pm,
                             QuerySelect sel)
Adds the appropriate join logic to join together multiple primary tables.

addTableJoins

public void addTableJoins(Joins joins,
                          Table fromTable)

SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.