com.triactive.jdo.store
Class StoreManager

java.lang.Object
  extended bycom.triactive.jdo.store.StoreManager

public class StoreManager
extends java.lang.Object

Manages the contents of a data store (aka database schema) on behalf of a particular PersistenceManagerFactory and all its persistent instances.

The store manager's responsibilities include:

A store manager's knowledge of its schema's contents is not necessarily complete. It is aware of only those tables whose classes have somehow been accessed, directly or indirectly, by the application during the life of the store manager object.

Author:
Mike Martin

Nested Class Summary
 class StoreManager.MgmtTransaction
          An abstract base class for StoreManager transactions that perform some management function on the database.
 
Method Summary
 void delete(StateManager sm)
          Deletes a persistent object from the database.
 void fetch(StateManager sm, int[] fieldNumbers)
          Fetches a persistent object from the database.
 java.lang.String getCatalogName()
           
 ClassBaseTable getClassBaseTable(java.lang.Class c)
          Returns the primary table serving as backing for the given class.
 ClassFinder getClassFinder()
          Returns the class finder to be used for all lookup of classes associated with this store manager.
 int getClassId(java.lang.Class c)
          Returns the class ID for the given class.
 ClassTable getClassTable(int classId, java.lang.Class contextClass)
          Returns the class table having the given class ID.
 DatabaseAdapter getDatabaseAdapter()
          Returns the database adapter used by this store manager.
 java.lang.String getDatabaseUrl()
           
 javax.jdo.Extent getExtent(PersistenceManager pm, java.lang.Class c, boolean subclasses)
           
static StoreManager getInstance(PersistenceManagerFactoryImpl pmf, java.lang.String userName, java.lang.String password)
          Obtains a store manager instance.
 InitializedConnectionFactory getNontransactionalConnectionFactory()
          Returns the connection factory to be used for non-transactional access.
 OIDGenerator getOIDGenerator(java.lang.Class c)
          Returns the OID generator for the specified class.
 SchemaManagementOptions getOptions()
          Returns the current schema management options for the calling thread.
 java.lang.String getSchemaName()
           
 ClassTable getTable(java.lang.Class c)
          Returns the primary table serving as backing for the given class.
 Table getTable(int tableId)
          Returns the table having the given table ID.
 Table getTable(MetaData md)
          Returns the table having the given metadata, if any.
 Table getTable(TableName name)
          Returns the table having the given SQL name, if any.
 InitializedConnectionFactory getTransactionalConnectionFactory()
          Returns the connection factory to be used for transactional access.
 void insert(StateManager sm)
          Inserts a persistent object into the database.
 void lookup(StateManager sm)
          Confirms that a persistent object exists in the database.
 java.lang.Object newObjectID(java.lang.Class c)
          Returns a new, unique ID for an object of the given class.
 SchemaManager newSchemaManager()
          Returns a new schema manager.
 void reset()
          Clears all knowledge of tables, cached requests, metadata, etc and resets the store manager to its initial state.
 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
 

Method Detail

getInstance

public static StoreManager getInstance(PersistenceManagerFactoryImpl pmf,
                                       java.lang.String userName,
                                       java.lang.String password)
Obtains a store manager instance. Returns a cached instance if one exists that refers to the exact same storage with the exact same management options. Having redundant store managers would be prohibitively expensive, wasting memory and much initialization time.

Caching is implemented such that a store manager becomes eligible for garbage collection when all of the PersistenceManagerFactorys that used it also become eligible.

A newly-created store manager will have successfully connected to the database with the given credentials and determined the schema name, but will not have inspected the schema contents any further. The contents (tables, views, etc.) will be subsequently created and/or validated on-demand as the application accesses persistent classes.

Parameters:
pmf - A PersistenceManagerFactory. The 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.
Throws:
javax.jdo.JDODataStoreException - If the database could not be accessed or the name of the schema could not be determined.

reset

public void reset()
Clears all knowledge of tables, cached requests, metadata, etc and resets the store manager to its initial state.


getOptions

public SchemaManagementOptions getOptions()
Returns the current schema management options for the calling thread.


getClassFinder

public ClassFinder getClassFinder()
Returns the class finder to be used for all lookup of classes associated with this store manager.


getTransactionalConnectionFactory

public InitializedConnectionFactory getTransactionalConnectionFactory()
Returns the connection factory to be used for transactional access.


getNontransactionalConnectionFactory

public InitializedConnectionFactory getNontransactionalConnectionFactory()
Returns the connection factory to be used for non-transactional access.


getDatabaseAdapter

public DatabaseAdapter getDatabaseAdapter()
Returns the database adapter used by this store manager.

Returns:
The database adapter used by this store manager.

getDatabaseUrl

public java.lang.String getDatabaseUrl()

getCatalogName

public java.lang.String getCatalogName()

getSchemaName

public java.lang.String getSchemaName()

newSchemaManager

public SchemaManager newSchemaManager()
Returns a new schema manager. The initial management options are the defaults for this store manager.


getTable

public Table getTable(TableName name)
Returns the table having the given SQL name, if any. Returns null if no such table is (yet) known to the store manager.

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

getTable

public Table getTable(int tableId)
Returns the table having the given table ID. Returns null if no such table is (yet) known to the store manager.

Parameters:
tableId - The table ID of the table to be returned.
Returns:
The corresponding table, or null.

getClassTable

public ClassTable getClassTable(int classId,
                                java.lang.Class contextClass)
Returns the class table having the given class ID. If the class is not yet known to the store manager it is added.

Parameters:
classId - The class ID of the table to be returned.
contextClass - A class used to establish the class loader context in case the corresponding class needs to be loaded.
Throws:
javax.jdo.JDOUserException - if the specified class ID is unknown, not associated with a class table, or associated with a class table whose class cannot be loaded.

getTable

public Table getTable(MetaData md)
Returns the table having the given metadata, if any. Returns null if no such table is (yet) known to the store manager.

Parameters:
md - The metadata for the table.
Returns:
The corresponding table, or null.

getTable

public ClassTable getTable(java.lang.Class c)
Returns the primary table serving as backing for the given class. If the class is not yet known to the store manager, addClasses() is called to add it.

Parameters:
c - The class whose table is be returned.
Returns:
The corresponding class table.
Throws:
NoExtentException - If the given class is not persistence-capable.

getClassBaseTable

public ClassBaseTable getClassBaseTable(java.lang.Class c)
Returns the primary table serving as backing for the given class. If the class is not yet known to the store manager, addClasses() is called to add it.

This method is functionally equivalent to getTable(Class) except that it will only return base tables (not views).

Parameters:
c - The class whose table is be returned.
Returns:
The corresponding class table.
Throws:
NoExtentException - If the given class is not persistence-capable.
ViewNotSupportedException - If the given class is backed by a view.

getClassId

public int getClassId(java.lang.Class c)
Returns the class ID for the given class. If the class is not yet known to the store manager, addClasses() is called to add it.

Parameters:
c - The class whose ID is be returned.
Throws:
NoExtentException - If the given class is not persistence-capable.

getExtent

public javax.jdo.Extent getExtent(PersistenceManager pm,
                                  java.lang.Class c,
                                  boolean subclasses)

newObjectID

public java.lang.Object newObjectID(java.lang.Class c)
Returns a new, unique ID for an object of the given class. If the class is not yet known to the store manager, addClasses() is called to add it.

Parameters:
c - The class of the object.
Returns:
A new object ID.

getOIDGenerator

public OIDGenerator getOIDGenerator(java.lang.Class c)
Returns the OID generator for the specified class. If the class is not yet known to the store manager, addClasses() is called to add it.

Parameters:
c - the class
Returns:
the class's OID generator

insert

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

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

lookup

public void lookup(StateManager sm)
Confirms that a persistent object exists in the database.

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

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.


Copyright 2001-2007 The TJDO Project All Rights Reserved.