org.jpox.store
Class StoreManager

java.lang.Object
  extended byorg.jpox.store.StoreManager
Direct Known Subclasses:
RDBMSManager

public abstract class StoreManager
extends java.lang.Object

An abstract representation of a Store Manager. Manages the persistence of objects to the store. Will be implemented for the type of datastore (RDBMS, ODBMS, OLAP) in question. The store manager's responsibilities include:

A store manager's knowledge of its contents is typically not complete. It knows about the classes that it has encountered in its lifetime. The PersistenceManager can make the StoreManager aware of a class, and can check if the StoreManager knows about a particular class. The Auto-Start mechanism provides a way of inheriting knowledge from the last time the store was used.

Version:
$Revision: 1.56 $

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  boolean checkExistTablesOrViews
          Whether to check if table/view exists
protected  DatastoreAdapter dba
          Adapter for the datastore being used.
protected  java.lang.String defaultPoidGeneratorClass
          The default id generator class name for the store manager.
protected  Dictionary dictionary
          Dictionary to use for identifiers etc.
protected  javax.sql.DataSource[] ds
          Datasource
protected  javax.sql.DataSource[] dsNonTx
          Non transactional Datasource
protected  boolean fixedSchema
          Whether this datastore schema is fixed (no mods to table definitions allowed).
protected  IdentifierFactory identifierFactory
          Factory for identifiers for this datastore.
protected static Localiser LOCALISER
           
protected  java.lang.String password
          Password for the datastore being used.
protected  PMFContext pmfContext
          PMF context.
protected  PoidManager poidManager
          Manager for identity generation.
protected  boolean readOnlySchema
          Whether this datastore schema is read only.
protected  AutoStartMechanism starter
          Auto-Start mechanism to use.
protected  boolean starterInitialised
          Whether the AutoStart mechanism is initialised
protected  MultiMap storeDataByAppIdClass
          Map of all managed store data using Application Identity, keyed by the app id PK class
protected  java.util.Map storeDataByClass
          Map of all managed store data, keyed by the class/field name.
protected  java.lang.String userName
          Username for the datastore being used.
protected  boolean validateColumns
          Whether to validate any columns
protected  boolean validateConstraints
          Whether to validate any constraints
protected  boolean validateTables
          Whether to validate any tables
 
Constructor Summary
protected StoreManager(ClassLoaderResolver clr, AbstractPersistenceManagerFactory pmf, java.lang.String userName, java.lang.String password)
          Constructor for a new StoreManager.
 
Method Summary
abstract  void addClass(java.lang.String className, ClassLoaderResolver clr)
          Method to add a class to the managed list for this datastore manager.
abstract  void addClasses(java.lang.String[] classes, ClassLoaderResolver clr)
          Add classes to the persistence model for the datastore.
protected  void clearAutoStarter()
          Method to clear the Auto-Starter status.
 void close()
          Release of resources
 void delete(StateManager sm)
          Deletes a persistent object from the database.
 void deleteDependent(StateManager sm, int[] fieldNumbers)
          Delete dependent objects of a persistent object.
protected  void deregisterAllStoreData()
          Method to deregister all existing store data so that we are managing nothing.
 void fetch(StateManager sm, int[] fieldNumbers)
          Fetches a persistent object from the database.
abstract  ArrayStore getBackingStoreForArray(AbstractPropertyMetaData fmd, DatastoreObject datastoreTable, ClassLoaderResolver clr)
          Method to return a backing store for an array, consistent with this store and the instantiated type.
abstract  CollectionStore getBackingStoreForCollection(java.lang.Class instantiatedType, AbstractPropertyMetaData fmd, DatastoreObject datastoreTable, ClassLoaderResolver clr)
          Method to return a backing store for a Collection, consistent with this store and the instantiated type.
abstract  MapStore getBackingStoreForMap(AbstractPropertyMetaData fmd, DatastoreObject datastoreTable, ClassLoaderResolver clr)
          Method to return a backing store for a Map, consistent with this store and the instantiated type.
 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.
abstract  java.lang.String getClassNameForObjectID(java.lang.Object id, ClassLoaderResolver clr, PersistenceManager pm)
          Returns the class corresponding to the given object JDO ID.
 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 JDO table having the given SQL identifier.
 DatastoreClass getDatastoreClass(java.lang.String className, ClassLoaderResolver clr)
          Returns the primary datastore container serving as backing for the given class.
 DatastoreContainerObject getDatastoreContainerObject(AbstractPropertyMetaData fmd)
          Returns the datastore container (table) for the specified field.
abstract  javax.jdo.Extent getExtent(PersistenceManager pm, java.lang.Class c, boolean subclasses)
          Interface to getting an Extent for a class.
abstract  FetchStatement getFetchStatement(DatastoreContainerObject table)
          Method to create a new fetch statement for the passed table.
 IdentifierFactory getIdentifierFactory()
          Accessor for the identifier factory.
 MappingManager getMappingManager()
          Gets the MappingManager to use for this store.
 MetaDataManager getMetaDataManager()
          Gets the MetaDataManager to use for this store.
 PMFContext getPMFContext()
          Accessor for the context in which this RDBMSManager is running
 StoreData[] getStoreDataForTable(DatastoreIdentifier tableIdentifier)
          Utility to return all StoreData for a table identifier.
abstract  java.lang.Object getStrategyValue(PersistenceManager pm, DatastoreClass table, AbstractClassMetaData cmd, int absoluteFieldNumber, IdentityStrategy strategy, java.lang.String sequence, ExtensionMetaData[] extensions)
          Method to retrieve the value for a strategy for a particular field.
 java.util.HashSet getSubClassesForClass(java.lang.String className, boolean includeDescendents, ClassLoaderResolver clr)
          Utility to return the names of the classes that are known subclasses of the provided class.
protected  void initialiseAutoStart(ClassLoaderResolver clr)
          Method to initialise the auto-start mechanism, loading up the classes from its store into memory so that we start from where we got to last time.
 void insert(StateManager sm)
          Inserts a persistent object into the database.
 boolean isStrategyDatastoreAttributed(IdentityStrategy identityStrategy)
          Check if the strategy is attributed by the database when the PersistenceCapable object is inserted into the database
 void locate(StateManager sm)
          Locates this object in the datastore.
 java.lang.String manageClassForIdentity(OID id, ClassLoaderResolver clr)
          Convenience method to ensure that the class defined by the passed OID is managed by this store.
 java.lang.String manageClassForIdentity(javax.jdo.identity.SingleFieldIdentity id, ClassLoaderResolver clr)
          Convenience method to ensure that the class defined by the passed SingleFieldIdentity is managed by this store.
 boolean managesClass(java.lang.String className)
          Accessor for whether the specified class is managed currently
abstract  DatastoreContainerObject newJoinDatastoreContainerObject(AbstractPropertyMetaData fmd, ClassLoaderResolver clr)
          Called by Mapping objects to request the creation of a DatastoreObject (table).
abstract  java.lang.Object newObjectID(PersistenceManager pm, java.lang.String className, javax.jdo.spi.PersistenceCapable pc)
          Returns a new, unique ID for an object of the given class.
abstract  javax.jdo.Query newQuery(java.lang.String language, PersistenceManager pm, java.lang.Object query)
          Method to generate a new query using the passed query.
protected  void registerStoreData(StoreData data)
          Method to register some data with the store.
abstract  void removeAllClasses(ClassLoaderResolver clr)
          Drops all tables in the schema.
abstract  void resolveIdentifierMacro(MacroString.IdentifierMacro im, ClassLoaderResolver clr)
          Resolves an identifier macro.
abstract  boolean supportsQueryLanguage(java.lang.String language)
          Accessor for the query languages supported by this store
 void update(StateManager sm, int[] fieldNumbers)
          Updates a persistent object in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER

ds

protected final javax.sql.DataSource[] ds
Datasource


dsNonTx

protected final javax.sql.DataSource[] dsNonTx
Non transactional Datasource


dba

protected DatastoreAdapter dba
Adapter for the datastore being used.


userName

protected final java.lang.String userName
Username for the datastore being used.


password

protected final java.lang.String password
Password for the datastore being used.


readOnlySchema

protected final boolean readOnlySchema
Whether this datastore schema is read only.


fixedSchema

protected final boolean fixedSchema
Whether this datastore schema is fixed (no mods to table definitions allowed).


starter

protected AutoStartMechanism starter
Auto-Start mechanism to use.


starterInitialised

protected boolean starterInitialised
Whether the AutoStart mechanism is initialised


dictionary

protected final Dictionary dictionary
Dictionary to use for identifiers etc.


pmfContext

protected final PMFContext pmfContext
PMF context.


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


checkExistTablesOrViews

protected final boolean checkExistTablesOrViews
Whether to check if table/view exists


defaultPoidGeneratorClass

protected final java.lang.String defaultPoidGeneratorClass
The default id generator class name for the store manager. Each class can have it's own Id generator defined in the meta-data file.

See Also:
PoidGenerator

poidManager

protected final PoidManager poidManager
Manager for identity generation.


identifierFactory

protected IdentifierFactory identifierFactory
Factory for identifiers for this datastore.


storeDataByClass

protected java.util.Map storeDataByClass
Map of all managed store data, keyed by the class/field name.


storeDataByAppIdClass

protected MultiMap storeDataByAppIdClass
Map of all managed store data using Application Identity, keyed by the app id PK class

Constructor Detail

StoreManager

protected StoreManager(ClassLoaderResolver clr,
                       AbstractPersistenceManagerFactory pmf,
                       java.lang.String userName,
                       java.lang.String password)
Constructor for a new StoreManager. Stores the basic information required for the datastore management.

Parameters:
clr - the ClassLoaderResolver
pmf - The corresponding PersistenceManagerFactory. This factory's non-transactional data source will be used to get database connections as needed to perform management functions.
userName - The database user name.
password - The database user's password.
See Also:
StoreManagerFactory
Method Detail

close

public void close()
Release of resources


registerStoreData

protected void registerStoreData(StoreData data)
Method to register some data with the store. This will also register the data with the starter process.

Parameters:
data - The StoreData to add

deregisterAllStoreData

protected void deregisterAllStoreData()
Method to deregister all existing store data so that we are managing nothing.


getStoreDataForTable

public StoreData[] getStoreDataForTable(DatastoreIdentifier tableIdentifier)
Utility to return all StoreData for a table 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).

initialiseAutoStart

protected void initialiseAutoStart(ClassLoaderResolver clr)
                            throws DatastoreInitialisationException
Method to initialise the auto-start mechanism, loading up the classes from its store into memory so that we start from where we got to last time.

Parameters:
clr - The ClassLoaderResolver
Throws:
DatastoreInitialisationException

clearAutoStarter

protected void clearAutoStarter()
Method to clear the Auto-Starter status.


managesClass

public boolean managesClass(java.lang.String className)
Accessor for whether the specified class is managed currently

Parameters:
className - The name of the class
Returns:
Whether it is managed

addClass

public abstract void addClass(java.lang.String className,
                              ClassLoaderResolver clr)
Method to add a class to the managed list for this datastore manager.

Parameters:
className - Name of the class
clr - The ClassLoaderResolver

addClasses

public abstract void addClasses(java.lang.String[] classes,
                                ClassLoaderResolver clr)
Add classes to the persistence model for the datastore. In the case of an RDBMS, this will map these classes to RDBMS tables. In the case of XML, this will map these classes to XML datafiles.

This method is primarily useful for applications that wish to perform all of their datastore initialization up front, rather than wait for the JPOX runtime to do it on-demand.

Parameters:
classes - The class(es) to be added.
clr - The ClassLoaderResolver
Throws:
SchemaValidationException - If there is some mismatch between the current schema contents and those necessary to enable persistence of the given classes.

removeAllClasses

public abstract void removeAllClasses(ClassLoaderResolver clr)
Drops all tables in the schema. This empties the schema of all database objects managed by JPOX. All objects not managed by JPOX are left untouched.

Parameters:
clr - The ClassLoaderResolver

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

manageClassForIdentity

public java.lang.String manageClassForIdentity(OID id,
                                               ClassLoaderResolver clr)
Convenience method to ensure that the class defined by the passed OID is managed by this store.

Parameters:
id - OID
clr - ClassLoader resolver
Returns:
The class name of the class associated to this identity

manageClassForIdentity

public java.lang.String manageClassForIdentity(javax.jdo.identity.SingleFieldIdentity id,
                                               ClassLoaderResolver clr)
Convenience method to ensure that the class defined by the passed SingleFieldIdentity is managed by this store.

Parameters:
id - Single Field Identity
clr - ClassLoader resolver
Returns:
The class name of the class associated to this identity

getExtent

public abstract javax.jdo.Extent getExtent(PersistenceManager pm,
                                           java.lang.Class c,
                                           boolean subclasses)
Interface to getting an Extent for a class.

Parameters:
pm - The Persistence Manager
c - The class requiring the Extent
subclasses - Whether to include subclasses of 'c'
Returns:
The Extent.

supportsQueryLanguage

public abstract boolean supportsQueryLanguage(java.lang.String language)
Accessor for the query languages supported by this store

Parameters:
language - The language name
Returns:
Whether it is supported.

newQuery

public abstract javax.jdo.Query newQuery(java.lang.String language,
                                         PersistenceManager pm,
                                         java.lang.Object query)
Method to generate a new query using the passed query.

Parameters:
language - The query language
pm - The PM
query - Either the query filter (String) or an existing Query
Returns:
The Query

getClassNameForObjectID

public abstract java.lang.String getClassNameForObjectID(java.lang.Object id,
                                                         ClassLoaderResolver clr,
                                                         PersistenceManager pm)
Returns the class corresponding to the given object JDO ID. If the object is an OID, return the PersistenceCapable class. If the object is a SCOID, return the SCO class. If the object is a PersistenceCapable class, return the class. If the object is an AppID PK, return the PersistenceCapable class.

Parameters:
id - The JDO identity of some object.
clr - ClassLoader resolver
pm - Persistence Manager
Returns:
For datastore identity, return the class of the corresponding object. For application identity, return the class of the corresponding object or null if object does not exist.
Throws:
java.lang.ClassCastException - If the type of ID is not recognized (OID or SCOID).

isStrategyDatastoreAttributed

public boolean isStrategyDatastoreAttributed(IdentityStrategy identityStrategy)
Check if the strategy is attributed by the database when the PersistenceCapable object is inserted into the database

Parameters:
identityStrategy - the identityStrategy
Returns:
if the object for the strategy is attributed by the database

getStrategyValue

public abstract java.lang.Object getStrategyValue(PersistenceManager pm,
                                                  DatastoreClass table,
                                                  AbstractClassMetaData cmd,
                                                  int absoluteFieldNumber,
                                                  IdentityStrategy strategy,
                                                  java.lang.String sequence,
                                                  ExtensionMetaData[] extensions)
Method to retrieve the value for a strategy for a particular field.

Parameters:
pm - The Persistence Manager
table - The datastore table
cmd - AbstractClassMetaData for the class
absoluteFieldNumber - The field number
strategy - The strategy
sequence - The sequence name if strategy is sequence-based
extensions - Any extensions to control the value generation process
Returns:
The value

newObjectID

public abstract java.lang.Object newObjectID(PersistenceManager pm,
                                             java.lang.String className,
                                             javax.jdo.spi.PersistenceCapable pc)
Returns a new, unique ID for an object of the given class.

Parameters:
pm - The PersistenceManager
className - Name of the class of the object.
pc - The persistenceCapable object. Useful for AppID
Returns:
A new object ID.

insert

public void insert(StateManager sm)
Inserts a persistent object into the database.

Parameters:
sm - The state manager of the object to be inserted.

fetch

public void fetch(StateManager sm,
                  int[] fieldNumbers)
Fetches a persistent object from the database.

Parameters:
sm - The state manager of the object to be fetched.
fieldNumbers - The numbers of the fields to be fetched.

update

public void update(StateManager sm,
                   int[] fieldNumbers)
Updates a persistent object in the database.

Parameters:
sm - The state manager of the object to be updated.
fieldNumbers - The numbers of the fields to be updated.

delete

public void delete(StateManager sm)
Deletes a persistent object from the database.

Parameters:
sm - The state manager of the object to be deleted.

locate

public void locate(StateManager sm)
Locates this object in the datastore.

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,
                            int[] fieldNumbers)
Delete dependent objects of a persistent object.

Parameters:
sm - StateManager for the object being deleted.
fieldNumbers - the fields to delete.
Since:
1.1

newJoinDatastoreContainerObject

public abstract DatastoreContainerObject newJoinDatastoreContainerObject(AbstractPropertyMetaData 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

getSubClassesForClass

public java.util.HashSet getSubClassesForClass(java.lang.String className,
                                               boolean includeDescendents,
                                               ClassLoaderResolver clr)
Utility to return the names of the classes that are known subclasses of the provided class. Actually uses the MetaDataManager for determining what is a subclass since the MetaData is often registered before being needed by the Store.

Parameters:
className - Class for which we search for subclasses.
includeDescendents - Whether to include subclasses of subclasses etc
clr - The ClassLoaderResolver
Returns:
Set of classes that are subclasses of the input class.

getIdentifierFactory

public IdentifierFactory getIdentifierFactory()
Accessor for the identifier factory.

Returns:
Returns the identifier factory.

getPMFContext

public PMFContext getPMFContext()
Accessor for the context in which this RDBMSManager is running

Returns:
Returns the pmfContext.

getMetaDataManager

public MetaDataManager getMetaDataManager()
Gets the MetaDataManager to use for this store.

Returns:
Returns the MetaDataManager.

getMappingManager

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

Returns:
Returns the MappingManager.

getDatastoreAdapter

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

Returns:
Returns the DatastoreAdapter

getDatastoreClass

public DatastoreClass getDatastoreClass(java.lang.String className,
                                        ClassLoaderResolver clr)
Returns the primary datastore container serving as backing for the given class. If the class is not yet known to the store manager, addClass(java.lang.String, org.jpox.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.

getDatastoreContainerObject

public DatastoreContainerObject getDatastoreContainerObject(AbstractPropertyMetaData 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'.

getDatastoreClass

public DatastoreClass getDatastoreClass(DatastoreIdentifier name)
Returns the JDO 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

resolveIdentifierMacro

public abstract void resolveIdentifierMacro(MacroString.IdentifierMacro im,
                                            ClassLoaderResolver clr)
Resolves an identifier macro. The public fields clazz , fieldName , and subfieldName of the given macro are taken as inputs, and the public value field is set to the SQL identifier of the corresponding database table or column.

Parameters:
im - The macro to resolve.
clr - The ClassLoaderResolver

getFetchStatement

public abstract FetchStatement getFetchStatement(DatastoreContainerObject table)
Method to create a new fetch statement for the passed table.

Parameters:
table - The table to fetch from
Returns:
The fetch statement

getBackingStoreForCollection

public abstract CollectionStore getBackingStoreForCollection(java.lang.Class instantiatedType,
                                                             AbstractPropertyMetaData fmd,
                                                             DatastoreObject datastoreTable,
                                                             ClassLoaderResolver clr)
Method to return a backing store for a Collection, consistent with this store and the instantiated type.

Parameters:
instantiatedType - Type of the instantiated collection
fmd - MetaData for the field that has this collection
datastoreTable - The datastore object
clr - ClassLoader resolver
Returns:
The Backing store for this collection in this store

getBackingStoreForMap

public abstract MapStore getBackingStoreForMap(AbstractPropertyMetaData fmd,
                                               DatastoreObject datastoreTable,
                                               ClassLoaderResolver clr)
Method to return a backing store for a Map, consistent with this store and the instantiated type.

Parameters:
fmd - MetaData for the field that has this map
datastoreTable - The datastore object
clr - ClassLoader resolver
Returns:
The Backing store for this map in this store

getBackingStoreForArray

public abstract ArrayStore getBackingStoreForArray(AbstractPropertyMetaData fmd,
                                                   DatastoreObject datastoreTable,
                                                   ClassLoaderResolver clr)
Method to return a backing store for an array, consistent with this store and the instantiated type.

Parameters:
fmd - MetaData for the field that has this array
datastoreTable - The datastore object
clr - ClassLoader resolver
Returns:
The Backing store for this array in this store


Copyright © -2007 . All Rights Reserved.