org.datanucleus.store.mapped.mapping
Class AbstractMappingManager

java.lang.Object
  extended by org.datanucleus.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".


Nested Class Summary
protected  class AbstractMappingManager.TypeMapping
           
 
Field Summary
protected static Localiser LOCALISER
           
protected  MappedStoreManager storeMgr
          Store Manager that this relates to.
 
Constructor Summary
AbstractMappingManager(MappedStoreManager storeMgr)
          Constructor for a mapping manager for an ORM datastore.
 
Method Summary
protected  java.lang.Class getDefaultJavaTypeMapping(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 mmd, DatastoreAdapter dba, ClassLoaderResolver clr)
          Convenience accessor for the mapping class of the element mapping for a collection/array of elements.
protected  java.lang.Class getKeyMappingClass(DatastoreContainerObject container, AbstractMemberMetaData mmd, 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)
          Accessor for the mapping for the specified class.
 JavaTypeMapping getMapping(java.lang.Class c, boolean serialised, boolean embedded, java.lang.String fieldName)
          Accessor for the mapping for the specified class.
 JavaTypeMapping getMapping(DatastoreContainerObject datastoreContainer, AbstractMemberMetaData fmd, ClassLoaderResolver clr, int fieldRole)
          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)
          Accessor for the mapping class for the specified class.
 JavaTypeMapping getMappingWithDatastoreMapping(java.lang.Class c, boolean serialised, boolean embedded, ClassLoaderResolver clr)
          Accessor for the mapping for the specified class.
protected  java.lang.Class getOverrideMappingClass(java.lang.Class mappingClass, AbstractMemberMetaData fmd, int fieldRole)
          Convenience method to allow overriding of particular mapping classes.
protected  java.lang.Class getValueMappingClass(DatastoreContainerObject container, AbstractMemberMetaData mmd, DatastoreAdapter dba, ClassLoaderResolver clr)
          Convenience accessor for the mapping class of the value mapping for a map of 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.datanucleus.store.mapped.mapping.MappingManager
createDatastoreField, createDatastoreField, createDatastoreField, createDatastoreMapping, createDatastoreMapping
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER

storeMgr

protected final MappedStoreManager storeMgr
Store Manager that this relates to.

Constructor Detail

AbstractMappingManager

public AbstractMappingManager(MappedStoreManager storeMgr)
Constructor for a mapping manager for an ORM datastore.

Parameters:
storeMgr - The StoreManager
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

getMappingWithDatastoreMapping

public JavaTypeMapping getMappingWithDatastoreMapping(java.lang.Class c,
                                                      boolean serialised,
                                                      boolean embedded,
                                                      ClassLoaderResolver clr)
Accessor for the mapping for the specified class. Usually only called by JDOQL query expressions. If the type has its own table returns the id mapping of the table. If the type doesn't have its own table then creates the mapping and, if it has a simple datastore representation, creates the datastore mapping. The JavaTypeMapping has no metadata/table associated.

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

getMapping

public JavaTypeMapping getMapping(java.lang.Class c)
Accessor for the mapping for the specified class. This simply creates a JavaTypeMapping for the java type and returns it. The mapping has no underlying datastore mapping(s) and no associated field/table.

Specified by:
getMapping in interface MappingManager
Parameters:
c - Java type
Returns:
The mapping for the class.

getMapping

public JavaTypeMapping getMapping(java.lang.Class c,
                                  boolean serialised,
                                  boolean embedded,
                                  java.lang.String fieldName)
Accessor for the mapping for the specified class. This simply creates a JavaTypeMapping for the java type and returns it. The mapping has no underlying datastore mapping(s) and no associated field/table.

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

getMapping

public JavaTypeMapping getMapping(DatastoreContainerObject datastoreContainer,
                                  AbstractMemberMetaData fmd,
                                  ClassLoaderResolver clr,
                                  int fieldRole)
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 role argument.

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

getOverrideMappingClass

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

Parameters:
mappingClass - The mapping class selected
fmd - Field meta data for the field (if appropriate)
fieldRole - 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)
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. 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)
Returns:
The mapping class for the class

getElementMappingClass

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

Parameters:
container - The container
mmd - MetaData for the collection field/property 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 mmd,
                                             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
mmd - 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 mmd,
                                               DatastoreAdapter dba,
                                               ClassLoaderResolver clr)
Convenience accessor for the mapping class of the value mapping for a map of values. Currently only used where the value are either serialised or embedded into a join table.

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

getDefaultJavaTypeMapping

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

Parameters:
javaType - java type
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 © 2010. All Rights Reserved.