| java.lang.Object com.triactive.jdo.store.StoreManager
StoreManager | public class StoreManager implements SchemaManager(Code) | | 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:
- Creating and/or validating database tables according to the persistent
classes being accessed by the application.
- Serving as the primary intermediary between StateManagers and the
database (implements insert(), fetch(), update(), delete()).
- Managing TJDO's schema table (JDO_TABLE).
- Serving as the base Extent and Query factory.
- Providing cached access to JDBC database metadata.
- Resolving SQL identifier macros to actual SQL identifiers.
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 version: $Revision: 1.18 $ |
Constructor Summary | |
| StoreManager(PersistenceManagerFactoryImpl pmf, String userName, String password) Constructs a new StoreManager.
On successful return the new StoreManager 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.
To avoid creating unnecessary redundant StoreManagers, new StoreManagers
should always be obtained from the
StoreManagerFactory , rather
than constructed directly.
Parameters: pmf - The corresponding PersistenceManagerFactory. |
Method Summary | |
public void | addClasses(Class[] classes) Adds the given persistence-capable classes to the store manager's set
of active classes ready for persistence. | public void | delete(StateManager sm) Deletes a persistent object from the database. | public void | dropAllTables() | public void | dropTablesFor(Class[] classes) | public void | fetch(StateManager sm, int fieldNumbers) Fetches a persistent object from the database. | public ClassBaseTable | getClassBaseTable(Class c) Returns the primary table serving as backing for the given class.
If the class is not yet known to the store manager,
StoreManager.addClasses is called to add it.
This method is functionally equivalent to
StoreManager.getTable(Class) except that it will only return base tables (not views).
Parameters: c - The class whose table is be returned. | List | getColumnInfo(SQLIdentifier tableName, Connection conn) Returns the column info for a database table. | public DatabaseAdapter | getDatabaseAdapter() Returns the database adapter used by this store manager. | DeleteRequest | getDeleteRequest(ClassBaseTable cbt) Returns a request object that will delete a row from the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table from which to delete. | public Extent | getExtent(PersistenceManager pm, Class c, boolean subclasses) | FetchRequest | getFetchRequest(ClassBaseTable cbt, int[] fieldNumbers) Returns a request object that will fetch a row from the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table from which to fetch. Parameters: fieldNumbers - The field numbers corresponding to the columns to befetched. | List | getForeignKeyInfo(SQLIdentifier tableName, Connection conn) Returns the foreign key info for a database table. | InsertRequest | getInsertRequest(ClassBaseTable cbt) Returns a request object that will insert a row in the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table into which to insert. | public String | getJavaName(int tableID) Returns the Java name of the JDO table having the given table ID.
Returns null if no such table exists in the schema.
If the table is not (yet) known to the store manager, this method does
not initialize it.
Parameters: tableID - The table ID of the table to be returned. | LookupRequest | getLookupRequest(ClassBaseTable cbt) Returns a request object that will lookup a row in the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table in which to lookup. | int | getNextOIDHiValue(int classID) Returns the next OID high-order value for IDs of the given class.
Parameters: classID - The class ID number of the class. | public Query | getQuery(PersistenceManager pm, Object query) | public Query | getQuery(String language, PersistenceManager pm, Object query) | public String | getSchemaName() | public synchronized JDOTable | getTable(SQLIdentifier name) Returns the JDO 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. | public synchronized JDOTable | getTable(int tableID) Returns the JDO 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. | synchronized JDOTable | getTable(MetaData md) Returns the JDO 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. | public ClassTable | getTable(Class c) Returns the primary table serving as backing for the given class.
If the class is not yet known to the store manager,
StoreManager.addClasses is called to add it.
Parameters: c - The class whose table is be returned. | public int | getTableType(SQLIdentifier tableName, Connection conn) Returns the type of a database table.
Parameters: tableName - The name of the table (or view). Parameters: conn - A JDBC connection to the database. | UpdateRequest | getUpdateRequest(ClassBaseTable cbt, int[] fieldNumbers) Returns a request object that will update a row in the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table in which to update. Parameters: fieldNumbers - The field numbers corresponding to the columns to beupdated. | public void | insert(StateManager sm) Inserts a persistent object into the database. | public void | logSQLWarnings(SQLWarning warning) Logs SQL warnings to the common log. | public void | logSQLWarnings(Connection conn) | public void | logSQLWarnings(Statement stmt) | public void | logSQLWarnings(ResultSet rs) | public void | lookup(StateManager sm) Confirms that a persistent object exists in the database. | synchronized MapTable | newMapTable(ClassBaseTable cbt, FieldMetaData fmd) Called by Mapping objects in the midst of StoreManager.addClasses()
to request the creation of a map table. | public Object | newObjectID(Class c) Returns a new, unique ID for an object of the given class.
Parameters: c - The class of the object. | synchronized SetTable | newSetTable(ClassBaseTable cbt, FieldMetaData fmd) Called by Mapping objects in the midst of StoreManager.addClasses()
to request the creation of a set table. | public synchronized void | reset() Clears all knowledge of tables, cached requests, metadata, etc and resets
the store manager to its initial state. | public void | resolveIdentifierMacro(MacroString.IdentifierMacro im) Resolves an identifier macro. | public boolean | tableExists(SQLIdentifier tableName, Connection conn) Tests if a database table exists.
Parameters: tableName - The name of the table (or view). Parameters: conn - A JDBC connection to the database. | public void | update(StateManager sm, int fieldNumbers) Updates a persistent object in the database. |
StoreManager | StoreManager(PersistenceManagerFactoryImpl pmf, String userName, String password)(Code) | | Constructs a new StoreManager.
On successful return the new StoreManager 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.
To avoid creating unnecessary redundant StoreManagers, new StoreManagers
should always be obtained from the
StoreManagerFactory , rather
than constructed directly.
Parameters: pmf - The corresponding PersistenceManagerFactory. This factory'snon-transactional data source will be used to get databaseconnections as needed to perform management functions. Parameters: userName - The database user name. Parameters: password - The database user's password. exception: JDODataStoreException - If the database could not be accessed or the name of the schemacould not be determined. See Also: StoreManagerFactory |
addClasses | public void addClasses(Class[] classes)(Code) | | Adds the given persistence-capable classes to the store manager's set
of active classes ready for persistence.
The act of adding a class to the store manager causes any necessary
database objects (tables, views, constraints, indexes, etc.) to be
created.
Other StoreManager methods may cause classes to be added as a side
effect.
Parameters: classes - The class(es) to be added. |
delete | public void delete(StateManager sm)(Code) | | Deletes a persistent object from the database.
Parameters: sm - The state manager of the object to be deleted. |
dropAllTables | public void dropAllTables()(Code) | | |
dropTablesFor | public void dropTablesFor(Class[] classes)(Code) | | |
fetch | public void fetch(StateManager sm, int fieldNumbers)(Code) | | Fetches a persistent object from the database.
Parameters: sm - The state manager of the object to be fetched. Parameters: fieldNumbers - The numbers of the fields to be fetched. |
getClassBaseTable | public ClassBaseTable getClassBaseTable(Class c)(Code) | | Returns the primary table serving as backing for the given class.
If the class is not yet known to the store manager,
StoreManager.addClasses is called to add it.
This method is functionally equivalent to
StoreManager.getTable(Class) except that it will only return base tables (not views).
Parameters: c - The class whose table is be returned. The corresponding class table. exception: NoExtentException - If the given class is not persistence-capable. exception: ViewNotSupportedException - If the given class is backed by a view. |
getColumnInfo | List getColumnInfo(SQLIdentifier tableName, Connection conn) throws SQLException(Code) | | Returns the column info for a database table. This should be used
instead of making direct calls to DatabaseMetaData.getColumns().
Where possible, this method loads and caches column info for more than
just the table being requested, improving performance by reducing the
overall number of calls made to DatabaseMetaData.getColumns() (each of
which usually results in one or more database queries).
Parameters: tableName - The name of the table (or view). Parameters: conn - A JDBC connection to the database. A list of ColumnInfo objects describing the columns of thetable. The list is in the same order as was supplied bygetColumns(). If no column info is found for the given table,an empty list is returned. See Also: ColumnInfo |
getDatabaseAdapter | public DatabaseAdapter getDatabaseAdapter()(Code) | | Returns the database adapter used by this store manager.
The database adapter used by this store manager. |
getDeleteRequest | DeleteRequest getDeleteRequest(ClassBaseTable cbt)(Code) | | Returns a request object that will delete a row from the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table from which to delete. A deletion request object. |
getFetchRequest | FetchRequest getFetchRequest(ClassBaseTable cbt, int[] fieldNumbers)(Code) | | Returns a request object that will fetch a row from the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table from which to fetch. Parameters: fieldNumbers - The field numbers corresponding to the columns to befetched. Field numbers whose columns exist insupertables will be ignored. A fetch request object. |
getForeignKeyInfo | List getForeignKeyInfo(SQLIdentifier tableName, Connection conn) throws SQLException(Code) | | Returns the foreign key info for a database table.
This should be used instead of making direct calls to
DatabaseMetaData.getImportedKeys() or DatabaseMetaData.getExportedKeys().
Parameters: tableName - The name of the table (or view). Parameters: conn - A JDBC connection to the database.A list of ForeignKeyInfo objects describing the columns of thetable's foreign keys.The list is in the same order as was supplied by get??portedKeys().If no column info is found for the given table, an empty list isreturned. See Also: ForeignKeyInfo |
getInsertRequest | InsertRequest getInsertRequest(ClassBaseTable cbt)(Code) | | Returns a request object that will insert a row in the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table into which to insert. An insertion request object. |
getJavaName | public String getJavaName(int tableID)(Code) | | Returns the Java name of the JDO table having the given table ID.
Returns null if no such table exists in the schema.
If the table is not (yet) known to the store manager, this method does
not initialize it.
Parameters: tableID - The table ID of the table to be returned. The corresponding Java name, or null . |
getLookupRequest | LookupRequest getLookupRequest(ClassBaseTable cbt)(Code) | | Returns a request object that will lookup a row in the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table in which to lookup. A lookup request object. |
getNextOIDHiValue | int getNextOIDHiValue(int classID)(Code) | | Returns the next OID high-order value for IDs of the given class.
Parameters: classID - The class ID number of the class. The next high-order OID value. exception: JDODataStoreException - If an error occurs in accessing or updating the schema table. |
getTable | public synchronized JDOTable getTable(SQLIdentifier name)(Code) | | Returns the JDO 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. The corresponding JDO table, or null . |
getTable | public synchronized JDOTable getTable(int tableID)(Code) | | Returns the JDO 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. The corresponding JDO table, or null . |
getTable | synchronized JDOTable getTable(MetaData md)(Code) | | Returns the JDO 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. The corresponding JDO table, or null . |
getTable | public ClassTable getTable(Class c)(Code) | | Returns the primary table serving as backing for the given class.
If the class is not yet known to the store manager,
StoreManager.addClasses is called to add it.
Parameters: c - The class whose table is be returned. The corresponding class table. exception: NoExtentException - If the given class is not persistence-capable. |
getTableType | public int getTableType(SQLIdentifier tableName, Connection conn) throws SQLException(Code) | | Returns the type of a database table.
Parameters: tableName - The name of the table (or view). Parameters: conn - A JDBC connection to the database. one of the TABLE_TYPE_* values from Table. See Also: Table |
getUpdateRequest | UpdateRequest getUpdateRequest(ClassBaseTable cbt, int[] fieldNumbers)(Code) | | Returns a request object that will update a row in the given table.
The store manager will cache the request object for re-use by subsequent
requests to the same table.
Parameters: cbt - The table in which to update. Parameters: fieldNumbers - The field numbers corresponding to the columns to beupdated. Field numbers whose columns exist insupertables will be ignored. An update request object. |
insert | public void insert(StateManager sm)(Code) | | Inserts a persistent object into the database.
Parameters: sm - The state manager of the object to be inserted. |
logSQLWarnings | public void logSQLWarnings(SQLWarning warning)(Code) | | Logs SQL warnings to the common log. Should be called after any
operation on a JDBC Statement or ResultSet
object as:
storeMgr.logSQLWarnings(obj.getWarnings());
If any warnings were generated, the entire list of them are logged
to System.err.
Parameters: warning - the value returned from getWarnings(). |
lookup | public void lookup(StateManager sm)(Code) | | Confirms that a persistent object exists in the database.
Parameters: sm - The state manager of the object to be fetched. |
newMapTable | synchronized MapTable newMapTable(ClassBaseTable cbt, FieldMetaData fmd)(Code) | | Called by Mapping objects in the midst of StoreManager.addClasses()
to request the creation of a map table.
Parameters: cbt - The base table for the class containing the map. Parameters: fmd - The field metadata describing the map field. |
newObjectID | public Object newObjectID(Class c)(Code) | | Returns a new, unique ID for an object of the given class.
Parameters: c - The class of the object. A new object ID. |
newSetTable | synchronized SetTable newSetTable(ClassBaseTable cbt, FieldMetaData fmd)(Code) | | Called by Mapping objects in the midst of StoreManager.addClasses()
to request the creation of a set table.
Parameters: cbt - The base table for the class containing the set. Parameters: fmd - The field metadata describing the set field. |
reset | public synchronized void reset()(Code) | | Clears all knowledge of tables, cached requests, metadata, etc and resets
the store manager to its initial state.
|
resolveIdentifierMacro | public void resolveIdentifierMacro(MacroString.IdentifierMacro im)(Code) | | 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. |
tableExists | public boolean tableExists(SQLIdentifier tableName, Connection conn) throws SQLException(Code) | | Tests if a database table exists.
Parameters: tableName - The name of the table (or view). Parameters: conn - A JDBC connection to the database. true if the table exists in the database,false otherwise. |
update | public void update(StateManager sm, int fieldNumbers)(Code) | | Updates a persistent object in the database.
Parameters: sm - The state manager of the object to be updated. Parameters: fieldNumbers - The numbers of the fields to be updated. |
|
|