org.jpox.store.mapped.mapping
Class AbstractMappingManager

java.lang.Object
  extended by org.jpox.store.mapped.mapping.AbstractMappingManager
All Implemented Interfaces:
MappingManager

public abstract class AbstractMappingManager
extends java.lang.Object
implements MappingManager

Base implementation of a MappingManager. Datastores should extend this to add their own specifics, and to add the initialisation of their supported types.

The idea behind a MappingManager is that at the Java side we have a series of Java type mappings, and at the datastore side we have a series of datastore type mappings. We need a link between the two to say that "this Java type can map to any of these 3 datastore types, and by default use this one".

Version:
$Revision: 1.77 $

Nested Class Summary
protected  class AbstractMappingManager.TypeMapping
           
 
Field Summary
protected static Localiser LOCALISER
           
 
Constructor Summary
AbstractMappingManager()
          Default constructor.
 
Method Summary
protected  java.lang.Class getDefaultJavaTypeMapping(TypeManager typeMgr, java.lang.Class javaType)
          Method to return the default java type mapping class for a specified java type.
protected  java.lang.Class getElementMappingClass(DatastoreContainerObject container, AbstractMemberMetaData fmd, DatastoreAdapter dba, ClassLoaderResolver clr)
          Convenience accessor for the mapping class of the element mapping for a collection/array of PC elements.
protected  java.lang.Class getKeyMappingClass(DatastoreContainerObject container, AbstractMemberMetaData fmd, DatastoreAdapter dba, ClassLoaderResolver clr)
          Convenience accessor for the mapping class of the key mapping for a map of PC keys.
 JavaTypeMapping getMapping(java.lang.Class c, boolean serialised, boolean embedded, MappedStoreManager storeMgr, ClassLoaderResolver clr)
          Accessor for the mapping for the specified class.
 JavaTypeMapping getMapping(java.lang.Class c, boolean serialised, boolean embedded, MappedStoreManager storeMgr, java.lang.String fieldName)
          Accessor for the mapping for the specified class.
 JavaTypeMapping getMapping(DatastoreContainerObject datastoreContainer, AbstractMemberMetaData fmd, DatastoreAdapter dba, ClassLoaderResolver clr, int roleForField)
          Accessor for the mapping for the field of the specified table.
protected  java.lang.Class getMappingClass(java.lang.Class c, boolean serialised, boolean embedded, java.lang.String fieldName, TypeManager typeMgr, ApiAdapter api)
          Accessor for the mapping class for the specified class.
protected  java.lang.Class getOverrideMappingClass(java.lang.Class mappingClass, AbstractMemberMetaData fmd, int roleForField)
          Convenience method to allow overriding of particular mapping classes.
protected  java.lang.Class getValueMappingClass(DatastoreContainerObject container, AbstractMemberMetaData fmd, DatastoreAdapter dba, ClassLoaderResolver clr)
          Convenience accessor for the mapping class of the value mapping for a map of PC values.
abstract  void loadDatastoreMapping(PluginManager mgr, ClassLoaderResolver clr, java.lang.String vendorId)
          Load all datastore mappings defined in the associated plugins.
abstract  void registerDatastoreMapping(java.lang.String javaTypeName, java.lang.Class datastoreMappingType, java.lang.String jdbcType, java.lang.String sqlType, boolean dflt)
          Utility to register a datastore mapping for a java type, and the SQL/JDBC types it can be mapped to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jpox.store.mapped.mapping.MappingManager
createDatastoreField, createDatastoreField, createDatastoreField, createDatastoreMapping, createDatastoreMapping
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Constructor Detail

AbstractMappingManager

public AbstractMappingManager()
Default constructor.

Method Detail

loadDatastoreMapping

public abstract void loadDatastoreMapping(PluginManager mgr,
                                          ClassLoaderResolver clr,
                                          java.lang.String vendorId)
Load all datastore mappings defined in the associated plugins. To be implemented by the datastore mapping managers since they have the knowledge of the attributes supported by that datastore (e.g RDBMS datastores use jdbc-type, sql-type)

Specified by:
loadDatastoreMapping in interface MappingManager
Parameters:
mgr - the PluginManager
clr - the ClassLoaderResolver
vendorId - the datastore vendor id

getMapping

public JavaTypeMapping getMapping(java.lang.Class c,
                                  boolean serialised,
                                  boolean embedded,
                                  MappedStoreManager storeMgr,
                                  java.lang.String fieldName)
Accessor for the mapping for the specified class. TODO Merge this with the method below, or at least say why use this or the other

Specified by:
getMapping in interface MappingManager
Parameters:
c - Java type
serialised - Whether the type is serialised
embedded - Whether the type is embedded
storeMgr - Manager for the datastore
fieldName - Name of the field (for logging)
Returns:
The mapping for the class.

getMapping

public JavaTypeMapping getMapping(java.lang.Class c,
                                  boolean serialised,
                                  boolean embedded,
                                  MappedStoreManager storeMgr,
                                  ClassLoaderResolver clr)
Accessor for the mapping for the specified class. Usually only called by JDOQL query expressions.

Specified by:
getMapping in interface MappingManager
Parameters:
c - Java type
serialised - Whether the type is serialised
embedded - Whether the type is embedded
storeMgr - Manager for the store
clr - ClassLoader resolver
Returns:
The mapping for the class.

getMapping

public JavaTypeMapping getMapping(DatastoreContainerObject datastoreContainer,
                                  AbstractMemberMetaData fmd,
                                  DatastoreAdapter dba,
                                  ClassLoaderResolver clr,
                                  int roleForField)
Accessor for the mapping for the field of the specified table. Can be used for fields of a class, elements of a collection of a class, elements of an array of a class, keys of a map of a class, values of a map of a class. This is controlled by the final argument "roleForField".

Specified by:
getMapping in interface MappingManager
Parameters:
datastoreContainer - Table to add the mapping to
fmd - FieldMetaData for the field to map
dba - Datastore adapter
clr - The ClassLoaderResolver
roleForField - Role that this mapping plays for the field
Returns:
The mapping for the field.

getOverrideMappingClass

protected java.lang.Class getOverrideMappingClass(java.lang.Class mappingClass,
                                                  AbstractMemberMetaData fmd,
                                                  int roleForField)
Convenience method to allow overriding of particular mapping classes.

Parameters:
mappingClass - The mapping class selected
fmd - Field meta data for the field (if appropriate)
roleForField - Role for the field (e.g collection element)
Returns:
The mapping class to use

getMappingClass

protected java.lang.Class getMappingClass(java.lang.Class c,
                                          boolean serialised,
                                          boolean embedded,
                                          java.lang.String fieldName,
                                          TypeManager typeMgr,
                                          ApiAdapter api)
Accessor for the mapping class for the specified class. Provides special handling for interface types and for classes that are being embedded in a field (detected using the FieldMetaData argument). Refers others to its mapping manager lookup.

Parameters:
c - Class to query
serialised - Whether the field is serialised
embedded - Whether the field is embedded
fieldName - The full field name (for logging only)
typeMgr - the TypeManager
api - API Adapter
Returns:
The mapping class for the class

getElementMappingClass

protected java.lang.Class getElementMappingClass(DatastoreContainerObject container,
                                                 AbstractMemberMetaData fmd,
                                                 DatastoreAdapter dba,
                                                 ClassLoaderResolver clr)
Convenience accessor for the mapping class of the element mapping for a collection/array of PC elements. Currently only used where the collection/array elements are either serialised or embedded into a join table.

Parameters:
container - The container
fmd - MetaData for the collection field containing the collection/array of PCs
dba - Database adapter
clr - ClassLoader resolver
Returns:
The mapping class

getKeyMappingClass

protected java.lang.Class getKeyMappingClass(DatastoreContainerObject container,
                                             AbstractMemberMetaData fmd,
                                             DatastoreAdapter dba,
                                             ClassLoaderResolver clr)
Convenience accessor for the mapping class of the key mapping for a map of PC keys. Currently only used where the keys are either serialised or embedded into a join table.

Parameters:
container - The container
fmd - MetaData for the field containing the map that this key is for
dba - Database adapter
clr - ClassLoader resolver
Returns:
The mapping class

getValueMappingClass

protected java.lang.Class getValueMappingClass(DatastoreContainerObject container,
                                               AbstractMemberMetaData fmd,
                                               DatastoreAdapter dba,
                                               ClassLoaderResolver clr)
Convenience accessor for the mapping class of the value mapping for a map of PC values. Currently only used where the value are either serialised or embedded into a join table.

Parameters:
container - The container
fmd - MetaData for the field containing the map that this value is for
dba - Database adapter
clr - ClassLoader resolver
Returns:
The mapping class

getDefaultJavaTypeMapping

protected java.lang.Class getDefaultJavaTypeMapping(TypeManager typeMgr,
                                                    java.lang.Class javaType)
Method to return the default java type mapping class for a specified java type.

Parameters:
javaType - java type
typeMgr - the TypeManager
Returns:
The mapping class to use (by default)

registerDatastoreMapping

public abstract void registerDatastoreMapping(java.lang.String javaTypeName,
                                              java.lang.Class datastoreMappingType,
                                              java.lang.String jdbcType,
                                              java.lang.String sqlType,
                                              boolean dflt)
Utility to register a datastore mapping for a java type, and the SQL/JDBC types it can be mapped to. This can also be called to change the default setting of a mapping - just supply the same values of java/JDBC/SQL types and a different default value

Specified by:
registerDatastoreMapping in interface MappingManager
Parameters:
javaTypeName - Name of the java type
datastoreMappingType - The datastore mapping
jdbcType - The JDBC type that can be used
sqlType - The SQL type that can be used
dflt - Whether this type should be used as the default mapping for this Java type


Copyright © -2008 . All Rights Reserved.