org.datanucleus.store.mapped
Class MappedStoreManager

java.lang.Object
  extended by org.datanucleus.store.AbstractStoreManager
      extended by org.datanucleus.store.mapped.MappedStoreManager
All Implemented Interfaces:
StoreManager

public abstract class MappedStoreManager
extends AbstractStoreManager

Manager for a datastore that has a schema and maps classes to associated objects in the datastore. Datastores such as RDBMS will extend this type of StoreManager.

In a "mapped" datastore, a class is associated with a DatastoreClass. Similarly a field of a class is associated with a DatastoreField. Where a relation is stored separately this is associated with a DatastoreContainerObject. In an RDBMS datastore this will be

This type of StoreManager allows creation/validation of the schema. A schema is split into "tables", "columns", "constraints" currently. The PMF/EMF allows specification of a set of properties that will apply to this type of datastore.


Field Summary
protected  boolean autoCreateColumns
          Whether to auto create any columns that are missing.
protected  boolean autoCreateConstraints
          Whether to auto create any constraints
protected  boolean autoCreateTables
          Whether to auto create any tables.
protected  boolean autoCreateWarnOnError
          Whether to warn only when any errors occur on auto-create.
protected  java.util.Map<DatastoreIdentifier,DatastoreContainerObject> datastoreContainerByIdentifier
          Map of all managed datastore containers (tables) keyed by the datastore identifier.
protected  DatastoreAdapter dba
          Adapter for the datastore being used.
protected  IdentifierFactory identifierFactory
          Factory for identifiers for this datastore.
protected  java.util.Map<StateManager,DatastoreClass> insertedDatastoreClassByStateManager
          Map of DatastoreClass keyed by StateManager, for objects currently being inserted.
protected  MappedTypeManager mappedTypeMgr
          TypeManager for mapped information.
protected  MappingManager mappingManager
          Manager for the mapping between Java and datastore types.
protected  boolean validateColumns
          Whether to validate any columns
protected  boolean validateConstraints
          Whether to validate any constraints
protected  boolean validateTables
          Whether to validate any tables
 
Fields inherited from class org.datanucleus.store.AbstractStoreManager
autoStartMechanism, connectionMgr, fixedDatastore, LOCALISER, nontxConnectionFactoryName, omfContext, persistenceHandler, persistenceHandler2, readOnlyDatastore, schemaHandler, starter, starterInitialised, storeDataMgr, storeManagerKey, storeManagerRuntime, txConnectionFactoryName, valueGenerationMgr
 
Constructor Summary
protected MappedStoreManager(java.lang.String key, ClassLoaderResolver clr, OMFContext omfContext)
          Constructor.
 
Method Summary
 void addDatastoreContainer(DatastoreContainerObject table)
          Method to add a datastore container to the managed datastore classes.
abstract  boolean allowsBatching()
          Convenience method to return if the datastore supports batching and the user wants batching.
 void close()
          Release of resources.
 Store getBackingStoreForField(ClassLoaderResolver clr, AbstractMemberMetaData fmd, java.lang.Class type)
          Accessor for the backing store for the specified field.
 AbstractClassMetaData[] getClassesManagingTableForClass(AbstractClassMetaData cmd, ClassLoaderResolver clr)
          Method to return the class(es) that has a table managing the persistence of the fields of the supplied class.
 AbstractClassMetaData getClassWithPrimaryKeyForClass(AbstractClassMetaData cmd, ClassLoaderResolver clr)
          Utility to navigate the inheritance hierarchy to find the base class that defines the primary keys for this tree.
 DatastoreAdapter getDatastoreAdapter()
          Gets the DatastoreAdapter to use for this store.
 DatastoreClass getDatastoreClass(DatastoreIdentifier name)
          Returns the datastore table having the given SQL identifier.
 DatastoreClass getDatastoreClass(java.lang.String className, ClassLoaderResolver clr)
          Returns the primary datastore table serving as backing for the given class.
 DatastoreContainerObject getDatastoreContainerObject(AbstractMemberMetaData fmd)
          Returns the datastore container (table) for the specified field.
abstract  FieldManager getFieldManagerForResultProcessing(StateManager sm, java.lang.Object resultSet, StatementClassMapping resultMappings)
          Method to return a FieldManager for extracting information from the supplied results.
abstract  FieldManager getFieldManagerForStatementGeneration(StateManager sm, java.lang.Object stmt, StatementClassMapping stmtMappings, boolean checkNonNullable)
          Method to return a FieldManager for populating information in statements.
 IdentifierFactory getIdentifierFactory()
          Accessor for the factory for creating identifiers (table/column names etc).
 MappedTypeManager getMappedTypeManager()
          Accessor for the manager of mapped type information.
 MappingManager getMappingManager()
          Gets the MappingManager to use for this store.
abstract  java.lang.Object getResultValueAtPosition(java.lang.Object resultSet, JavaTypeMapping mapping, int position)
          Method to return the value from the results at the specified position.
 StoreData[] getStoreDataForDatastoreContainerObject(DatastoreIdentifier tableIdentifier)
          Utility to return all StoreData for a Datastore Container identifier.
abstract  boolean insertValuesOnInsert(DatastoreMapping datastoreMapping)
          Accessor for whether this mapping requires values inserting on an INSERT.
 boolean isObjectInserted(StateManager sm, int fieldNumber)
          Accessor for whether the specified field of the object is inserted in the datastore yet.
 boolean isObjectInserted(StateManager sm, java.lang.String className)
          Returns whether this object is inserted in the datastore far enough to be considered to be the supplied type.
protected abstract  FKArrayStore newFKArrayStore(AbstractMemberMetaData clr, ClassLoaderResolver amd)
           
protected abstract  FKListStore newFKListStore(AbstractMemberMetaData clr, ClassLoaderResolver amd)
           
protected abstract  FKMapStore newFKMapStore(AbstractMemberMetaData clr, ClassLoaderResolver amd)
           
protected abstract  FKSetStore newFKSetStore(AbstractMemberMetaData clr, ClassLoaderResolver mmd)
           
protected abstract  JoinArrayStore newJoinArrayStore(AbstractMemberMetaData amd, ClassLoaderResolver clr, DatastoreContainerObject arrayTable)
           
abstract  DatastoreContainerObject newJoinDatastoreContainerObject(AbstractMemberMetaData fmd, ClassLoaderResolver clr)
          Called by Mapping objects to request the creation of a DatastoreObject (table).
protected abstract  JoinListStore newJoinListStore(AbstractMemberMetaData amd, ClassLoaderResolver clr, DatastoreContainerObject listTable)
           
protected abstract  JoinMapStore newJoinMapStore(AbstractMemberMetaData amd, ClassLoaderResolver clr, DatastoreContainerObject mapTable)
           
protected abstract  JoinSetStore newJoinSetStore(AbstractMemberMetaData amd, ClassLoaderResolver clr, DatastoreContainerObject setTable)
           
abstract  ResultObjectFactory newResultObjectFactory(AbstractClassMetaData acmd, StatementClassMapping mappingDefinition, boolean ignoreCache, FetchPlan fetchPlan, java.lang.Class persistentClass)
          Factory method for allocating a ResultObjectFactory of the appropriate concrete type.
 void setObjectIsInsertedToLevel(StateManager sm, DatastoreClass table)
          Method to set that the specified object is inserted down to the defined datastore class.
 boolean supportsValueStrategy(java.lang.String strategy)
          Accessor for whether this value strategy is supported.
 
Methods inherited from class org.datanucleus.store.AbstractStoreManager
addClass, addClasses, assertReadOnlyForUpdateOfObject, assertReadOnlyForUpdateOfObject, clearAutoStarter, deregisterAllStoreData, getApiAdapter, getClassNameForObjectID, getConnection, getConnection, getConnection, getConnection, getConnection, getConnectionDriverName, getConnectionFactory, getConnectionFactory2, getConnectionFactory2Name, getConnectionFactoryName, getConnectionManager, getConnectionPassword, getConnectionURL, getConnectionUserName, getDatastoreDate, getExtent, getMetaDataManager, getNucleusConnection, getNucleusSequence, getOMFContext, getPersistenceHandler, getPersistenceHandler2, getPropertiesForGenerator, getQueryCacheKey, getRuntimeManager, getSchemaHandler, getStoreManagerKey, getStrategyForNative, getStrategyValue, getStrategyValueForGenerator, getSubClassesForClass, getSupportedOptions, getValueGenerationManager, initialiseAutoStart, isStrategyDatastoreAttributed, logConfiguration, manageClassForIdentity, managesClass, newStoreData, notifyObjectIsOutdated, performVersionCheck, printInformation, registerConnectionFactory, registerConnectionMgr, registerStoreData, removeAllClasses, supportsQueryLanguage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dba

protected DatastoreAdapter dba
Adapter for the datastore being used.


identifierFactory

protected IdentifierFactory identifierFactory
Factory for identifiers for this datastore. Really should be on MappedStoreManager.


autoCreateTables

protected final boolean autoCreateTables
Whether to auto create any tables.


autoCreateColumns

protected final boolean autoCreateColumns
Whether to auto create any columns that are missing.


autoCreateConstraints

protected final boolean autoCreateConstraints
Whether to auto create any constraints


autoCreateWarnOnError

protected final boolean autoCreateWarnOnError
Whether to warn only when any errors occur on auto-create.


validateTables

protected final boolean validateTables
Whether to validate any tables


validateColumns

protected final boolean validateColumns
Whether to validate any columns


validateConstraints

protected final boolean validateConstraints
Whether to validate any constraints


datastoreContainerByIdentifier

protected java.util.Map<DatastoreIdentifier,DatastoreContainerObject> datastoreContainerByIdentifier
Map of all managed datastore containers (tables) keyed by the datastore identifier. Only currently used for storing SequenceTable.


mappedTypeMgr

protected MappedTypeManager mappedTypeMgr
TypeManager for mapped information.


mappingManager

protected MappingManager mappingManager
Manager for the mapping between Java and datastore types.


insertedDatastoreClassByStateManager

protected java.util.Map<StateManager,DatastoreClass> insertedDatastoreClassByStateManager
Map of DatastoreClass keyed by StateManager, for objects currently being inserted. Defines to what level an object is inserted in the datastore.

Constructor Detail

MappedStoreManager

protected MappedStoreManager(java.lang.String key,
                             ClassLoaderResolver clr,
                             OMFContext omfContext)
Constructor. Stores the basic information required for the datastore management.

Parameters:
key - Key for this StoreManager
clr - the ClassLoaderResolver
omfContext - The corresponding ObjectManagerFactory context.
Method Detail

close

public void close()
Description copied from interface: StoreManager
Release of resources.

Specified by:
close in interface StoreManager
Overrides:
close in class AbstractStoreManager

supportsValueStrategy

public boolean supportsValueStrategy(java.lang.String strategy)
Accessor for whether this value strategy is supported. Overrides the setting in the superclass for identity/sequence if the adapter doesn't support them.

Specified by:
supportsValueStrategy in interface StoreManager
Overrides:
supportsValueStrategy in class AbstractStoreManager
Parameters:
strategy - The strategy
Returns:
Whether it is supported.

getMappedTypeManager

public MappedTypeManager getMappedTypeManager()
Accessor for the manager of mapped type information.

Returns:
MappedTypeManager

getIdentifierFactory

public IdentifierFactory getIdentifierFactory()
Accessor for the factory for creating identifiers (table/column names etc).

Returns:
Identifier factory

getDatastoreAdapter

public DatastoreAdapter getDatastoreAdapter()
Gets the DatastoreAdapter to use for this store.

Returns:
Returns the DatastoreAdapter

getMappingManager

public MappingManager getMappingManager()
Gets the MappingManager to use for this store.

Returns:
Returns the MappingManager.

newJoinDatastoreContainerObject

public abstract DatastoreContainerObject newJoinDatastoreContainerObject(AbstractMemberMetaData fmd,
                                                                         ClassLoaderResolver clr)
Called by Mapping objects to request the creation of a DatastoreObject (table).

Parameters:
fmd - The field metadata describing the field.
clr - The ClassLoaderResolver
Returns:
The DatastoreContainerObject

getStoreDataForDatastoreContainerObject

public StoreData[] getStoreDataForDatastoreContainerObject(DatastoreIdentifier tableIdentifier)
Utility to return all StoreData for a Datastore Container identifier. Returns StoreData with this table identifier and where the class is the owner of the table.

Parameters:
tableIdentifier - Identifier for the table
Returns:
The StoreData for this table (if managed).

getDatastoreContainerObject

public DatastoreContainerObject getDatastoreContainerObject(AbstractMemberMetaData fmd)
Returns the datastore container (table) for the specified field. Returns 'null' if the field is not (yet) known to the store manager.

Parameters:
fmd - The metadata for the field.
Returns:
The corresponding datastore container, or 'null'.

addDatastoreContainer

public void addDatastoreContainer(DatastoreContainerObject table)
Method to add a datastore container to the managed datastore classes.

Parameters:
table - The datastore container

getDatastoreClass

public DatastoreClass getDatastoreClass(java.lang.String className,
                                        ClassLoaderResolver clr)
Returns the primary datastore table serving as backing for the given class. If the class is not yet known to the store manager, AbstractStoreManager.addClass(java.lang.String, org.datanucleus.ClassLoaderResolver)is called to add it. Classes which have inheritance strategy of "new-table" and "superclass-table" will return a table here, whereas "subclass-table" will return null since it doesn't have a table as such.

Parameters:
className - Name of the class whose table is be returned.
clr - The ClassLoaderResolver
Returns:
The corresponding class table.
Throws:
NoTableManagedException - If the given class has no table managed in the database.

getDatastoreClass

public DatastoreClass getDatastoreClass(DatastoreIdentifier name)
Returns the datastore table having the given SQL identifier. Returns 'null' if no such table is (yet) known to the store manager.

Parameters:
name - The identifier name of the table.
Returns:
The corresponding JDO table, or 'null'

getClassWithPrimaryKeyForClass

public AbstractClassMetaData getClassWithPrimaryKeyForClass(AbstractClassMetaData cmd,
                                                            ClassLoaderResolver clr)
Utility to navigate the inheritance hierarchy to find the base class that defines the primary keys for this tree. This will either go up to the next class in the hierarchy that has a table OR go up to the base class, whichever is first.

Parameters:
cmd - AbstractClassMetaData for this class
clr - The ClassLoaderResolver
Returns:
The AbstractClassMetaData for the class defining the primary keys

getClassesManagingTableForClass

public AbstractClassMetaData[] getClassesManagingTableForClass(AbstractClassMetaData cmd,
                                                               ClassLoaderResolver clr)
Method to return the class(es) that has a table managing the persistence of the fields of the supplied class. For the 3 inheritance strategies, the following occurs :-

Parameters:
cmd - The supplied class.
clr - ClassLoader resolver
Returns:
The ClassMetaData's managing the fields of the supplied class

isObjectInserted

public boolean isObjectInserted(StateManager sm,
                                int fieldNumber)
Accessor for whether the specified field of the object is inserted in the datastore yet.

Parameters:
sm - StateManager for the object
fieldNumber - (Absolute) field number for the object
Returns:
Whether it is persistent

isObjectInserted

public boolean isObjectInserted(StateManager sm,
                                java.lang.String className)
Returns whether this object is inserted in the datastore far enough to be considered to be the supplied type. For example if we have base class A, B extends A and this object is a B, and we pass in A here then this returns whether the A part of the object is now inserted.

Parameters:
sm - StateManager for the object
className - Name of class that we want to check the insertion level for.
Returns:
Whether the object is inserted in the datastore to this level

setObjectIsInsertedToLevel

public void setObjectIsInsertedToLevel(StateManager sm,
                                       DatastoreClass table)
Method to set that the specified object is inserted down to the defined datastore class. When the object is fully inserted (the table is the primary table for this object type) it is removed from the map of objects being inserted.

Parameters:
sm - StateManager for the object
table - Table to which it is now inserted

getBackingStoreForField

public Store getBackingStoreForField(ClassLoaderResolver clr,
                                     AbstractMemberMetaData fmd,
                                     java.lang.Class type)
Accessor for the backing store for the specified field.

Specified by:
getBackingStoreForField in interface StoreManager
Overrides:
getBackingStoreForField in class AbstractStoreManager
Parameters:
clr - The ClassLoaderResolver
fmd - the field to be persisted by this Store
type - instantiated type or prefered type
Returns:
The backing store

getFieldManagerForResultProcessing

public abstract FieldManager getFieldManagerForResultProcessing(StateManager sm,
                                                                java.lang.Object resultSet,
                                                                StatementClassMapping resultMappings)
Method to return a FieldManager for extracting information from the supplied results.

Parameters:
sm - StateManager for the object
resultSet - The results
resultMappings - Mappings of the results for this class
Returns:
FieldManager to use

getFieldManagerForStatementGeneration

public abstract FieldManager getFieldManagerForStatementGeneration(StateManager sm,
                                                                   java.lang.Object stmt,
                                                                   StatementClassMapping stmtMappings,
                                                                   boolean checkNonNullable)
Method to return a FieldManager for populating information in statements.

Parameters:
sm - The state manager for the object.
stmt - The input Statement to set values on.
stmtMappings - Mappings of the input parameters
checkNonNullable - Whether to check for nullability
Returns:
The FieldManager to use

getResultValueAtPosition

public abstract java.lang.Object getResultValueAtPosition(java.lang.Object resultSet,
                                                          JavaTypeMapping mapping,
                                                          int position)
Method to return the value from the results at the specified position.

Parameters:
resultSet - The results
mapping - The mapping
position - The position
Returns:
The value at that position

insertValuesOnInsert

public abstract boolean insertValuesOnInsert(DatastoreMapping datastoreMapping)
Accessor for whether this mapping requires values inserting on an INSERT.

Parameters:
datastoreMapping - The datastore mapping
Returns:
Whether values are to be inserted into this mapping on an INSERT

allowsBatching

public abstract boolean allowsBatching()
Convenience method to return if the datastore supports batching and the user wants batching.

Returns:
If batching of statements is permissible

newResultObjectFactory

public abstract ResultObjectFactory newResultObjectFactory(AbstractClassMetaData acmd,
                                                           StatementClassMapping mappingDefinition,
                                                           boolean ignoreCache,
                                                           FetchPlan fetchPlan,
                                                           java.lang.Class persistentClass)
Factory method for allocating a ResultObjectFactory of the appropriate concrete type.

Parameters:
acmd - MetaData for the class
mappingDefinition - Mapping of the class from the result set
ignoreCache - Whether to ignore the cache
fetchPlan - the Fetch Plan
persistentClass - Class that this factory will create instances of (or subclasses)

newFKArrayStore

protected abstract FKArrayStore newFKArrayStore(AbstractMemberMetaData clr,
                                                ClassLoaderResolver amd)

newFKListStore

protected abstract FKListStore newFKListStore(AbstractMemberMetaData clr,
                                              ClassLoaderResolver amd)

newFKSetStore

protected abstract FKSetStore newFKSetStore(AbstractMemberMetaData clr,
                                            ClassLoaderResolver mmd)

newFKMapStore

protected abstract FKMapStore newFKMapStore(AbstractMemberMetaData clr,
                                            ClassLoaderResolver amd)

newJoinArrayStore

protected abstract JoinArrayStore newJoinArrayStore(AbstractMemberMetaData amd,
                                                    ClassLoaderResolver clr,
                                                    DatastoreContainerObject arrayTable)

newJoinMapStore

protected abstract JoinMapStore newJoinMapStore(AbstractMemberMetaData amd,
                                                ClassLoaderResolver clr,
                                                DatastoreContainerObject mapTable)

newJoinListStore

protected abstract JoinListStore newJoinListStore(AbstractMemberMetaData amd,
                                                  ClassLoaderResolver clr,
                                                  DatastoreContainerObject listTable)

newJoinSetStore

protected abstract JoinSetStore newJoinSetStore(AbstractMemberMetaData amd,
                                                ClassLoaderResolver clr,
                                                DatastoreContainerObject setTable)


Copyright © 2010. All Rights Reserved.