org.jpox.store.rdbms
Class RDBMSManager

java.lang.Object
  extended byorg.jpox.store.StoreManager
      extended byorg.jpox.store.rdbms.RDBMSManager

public class RDBMSManager
extends StoreManager

Manages the contents of a database schema on behalf of a particular PersistenceManagerFactory and all of its persistent instances.

The RDBMS manager's responsibilities extend those for Storemanager to add :

Version:
$Revision: 1.177 $

Field Summary
protected static Localiser LOCALISER_RDBMS
          Localiser for messages.
 
Fields inherited from class org.jpox.store.StoreManager
autoCreateColumns, autoCreateConstraints, autoCreateTables, autoCreateWarnOnError, checkExistTablesOrViews, dba, defaultPoidGeneratorClass, dictionary, ds, dsNonTx, fixedSchema, identifierFactory, LOCALISER, password, pmfContext, poidManager, readOnlySchema, starter, starterInitialised, storeDataByAppIdClass, storeDataByClass, userName, validateColumns, validateConstraints, validateTables
 
Constructor Summary
RDBMSManager(ClassLoaderResolver clr, AbstractPersistenceManagerFactory pmf, java.lang.String userName, java.lang.String password)
          Constructs a new RDBMSManager.
 
Method Summary
 void addClass(java.lang.String className, ClassLoaderResolver clr)
          Method to add a (PersistenceCapable) class to the store manager's set of supported classes.
 void addClasses(java.lang.String[] classNames, ClassLoaderResolver clr)
          Method to add several (PersistenceCapable) classes to the store manager's set of supported classes.
 void close()
          Release of resources
 void closeConnection(java.sql.Connection conn)
          Utility to close a Connection for the Datastore.
 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.
 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.
 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.
 java.lang.String getCatalogName()
          Accessor for the RDBMS catalog name.
 java.lang.String getClassNameForObjectID(java.lang.Object id, ClassLoaderResolver clr, PersistenceManager pm)
          Returns the class corresponding to the given object JDO ID.
 java.util.List getColumnInfo(java.lang.String schemaNamePattern, java.lang.String tableNamePattern)
          Returns the column info for a database schema.
 ColumnInfo getColumnInfoForColumnName(Table table, java.sql.Connection conn, DatastoreIdentifier column)
          Returns the column info for a column name.
 java.util.List getColumnInfoForTable(Table table, java.sql.Connection conn)
          Returns the column info for a database table.
 java.sql.Connection getConnection(int isolation_level)
          Utility to return a Connection not associated to the current transaction.
 DeleteRequest getDeleteRequest(DatastoreClass table, java.lang.Class cls, ClassLoaderResolver clr)
          Returns a request object that will delete a row from the given table.
 javax.jdo.Extent getExtent(PersistenceManager pm, java.lang.Class c, boolean subclasses)
          Accessor for an Extent for a class, and its subclasses.
 FetchRequest getFetchRequest(DatastoreClass table, AbstractPropertyMetaData[] fieldMetaData, java.lang.Class cls, ClassLoaderResolver clr)
          Returns a request object that will fetch a row from the given table.
 FetchStatement getFetchStatement(DatastoreContainerObject table)
          Method to create a new fetch statement for the passed table.
 InsertRequest getInsertRequest(DatastoreClass table, java.lang.Class cls, ClassLoaderResolver clr)
          Returns a request object that will insert a row in the given table.
 LocateRequest getLocateRequest(DatastoreClass table, java.lang.String className)
          Returns a request object that will locate a row from the given table.
 java.lang.String getSchemaName()
          Accessor for the RDBMS schema name.
 java.sql.PreparedStatement getStatement(java.sql.Connection conn, java.lang.String stmtText, boolean applyTimeout)
          Convenience method to create a new PreparedStatement.
 java.sql.PreparedStatement getStatement(java.sql.Connection conn, java.lang.String stmtText, boolean applyTimeout, java.lang.String resultSetType, java.lang.String resultSetConcurrency)
          Convenience method to create a new PreparedStatement.
 java.lang.Object getStrategyValue(PersistenceManager pm, DatastoreClass table, AbstractClassMetaData cmd, int absoluteFieldNumber, IdentityStrategy strategy, java.lang.String sequence, ExtensionMetaData[] extensions)
          Method to return the value for the specified strategy.
 java.util.List getTableInfo()
          Returns the table info for a database schema.
 java.util.List getTableInfo(java.lang.String schemaNamePattern)
          Returns the table info for a database schema.
 UpdateRequest getUpdateRequest(DatastoreClass table, AbstractPropertyMetaData[] fieldMetaData, java.lang.Class cls, ClassLoaderResolver clr)
          Returns a request object that will update a row in the given table.
 void invalidateColumnInfoForTable(Table table)
          Method to invalidate the cached column info for a table.
 DatastoreContainerObject newJoinDatastoreContainerObject(AbstractPropertyMetaData fmd, ClassLoaderResolver clr)
          Called by (container) Mapping objects to request the creation of a DatastoreObject (table).
 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.
 javax.jdo.Query newQuery(java.lang.String language, PersistenceManager pm, java.lang.Object query)
          Method to generate a new query using the passed query as basis.
 void removeAllClasses(ClassLoaderResolver clr)
          Utility to remove all classes that we are managing.
 void resolveIdentifierMacro(MacroString.IdentifierMacro im, ClassLoaderResolver clr)
          Resolves an identifier macro.
 boolean supportsQueryLanguage(java.lang.String language)
          Accessor for whether this query language is supported.
 
Methods inherited from class org.jpox.store.StoreManager
clearAutoStarter, delete, deleteDependent, deregisterAllStoreData, fetch, getClassesManagingTableForClass, getClassWithPrimaryKeyForClass, getDatastoreAdapter, getDatastoreClass, getDatastoreClass, getDatastoreContainerObject, getIdentifierFactory, getMappingManager, getMetaDataManager, getPMFContext, getStoreDataForTable, getSubClassesForClass, initialiseAutoStart, insert, isStrategyDatastoreAttributed, locate, manageClassForIdentity, manageClassForIdentity, managesClass, registerStoreData, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER_RDBMS

protected static final Localiser LOCALISER_RDBMS
Localiser for messages.

Constructor Detail

RDBMSManager

public RDBMSManager(ClassLoaderResolver clr,
                    AbstractPersistenceManagerFactory pmf,
                    java.lang.String userName,
                    java.lang.String password)
Constructs a new RDBMSManager. On successful return the new RDBMSManager 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 RDBMSManagers, new RDBMSManagers should always be obtained from the StoreManagerFactory, rather than constructed directly.

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.
Throws:
javax.jdo.JDODataStoreException - If the database could not be accessed or the name of the schema could not be determined.
See Also:
StoreManagerFactory
Method Detail

close

public void close()
Release of resources

Overrides:
close in class StoreManager

getConnection

public java.sql.Connection getConnection(int isolation_level)
                                  throws java.sql.SQLException
Utility to return a Connection not associated to the current transaction. Is simply a wrapper to the DatabaseAdapter getConnection method. It will return a connection from a secondary DataSource (e.g. javax.jdo.option.connectionFactory2Name), if it is given. However, if a secondary DataSource is not configured, the connection is obtained from the default DataSource.

Parameters:
isolation_level - The transaction isolation scheme to use e.g Connection.TRANSACTION_NONE
Returns:
The Connection to the datastore
Throws:
java.sql.SQLException

closeConnection

public void closeConnection(java.sql.Connection conn)
                     throws java.sql.SQLException
Utility to close a Connection for the Datastore. Is simply a wrapper to the DatabaseAdapter closeConnection method.

Parameters:
conn - The Connection to the datastore
Throws:
java.sql.SQLException

getStatement

public java.sql.PreparedStatement getStatement(java.sql.Connection conn,
                                               java.lang.String stmtText,
                                               boolean applyTimeout)
                                        throws java.sql.SQLException
Convenience method to create a new PreparedStatement. Provided here so that we have a single place to apply control such as timeouts to the statement before returning it. TODO Could also be used as a way of applying cached PreparedStatements.

Parameters:
conn - The Connection to use for the statement
stmtText - Statement text
applyTimeout - Whether this query will apply any timeout (where specified)
Returns:
The PreparedStatement
Throws:
java.sql.SQLException - thrown if an error occurs creating the statement

getStatement

public java.sql.PreparedStatement getStatement(java.sql.Connection conn,
                                               java.lang.String stmtText,
                                               boolean applyTimeout,
                                               java.lang.String resultSetType,
                                               java.lang.String resultSetConcurrency)
                                        throws java.sql.SQLException
Convenience method to create a new PreparedStatement. Provided here so that we have a single place to apply control such as timeouts, result set types etc to the statement before returning it. TODO Could also be used as a way of applying cached PreparedStatements.

Parameters:
conn - The Connection to use for the statement
stmtText - Statement text
applyTimeout - Whether this query will apply any timeout (where specified)
resultSetType - Type of result set
resultSetConcurrency - Concurrency for the result set
Returns:
The PreparedStatement
Throws:
java.sql.SQLException - thrown if an error occurs creating the statement

getCatalogName

public java.lang.String getCatalogName()
Accessor for the RDBMS catalog name.

Returns:
The catalog name.

getSchemaName

public java.lang.String getSchemaName()
Accessor for the RDBMS schema name.

Returns:
The schema name.

addClasses

public void addClasses(java.lang.String[] classNames,
                       ClassLoaderResolver clr)
Method to add several (PersistenceCapable) classes to the store manager's set of supported classes. This will create any necessary database objects (tables, views, constraints, indexes etc). This will cause the addition of any related classes.

Specified by:
addClasses in class StoreManager
Parameters:
classNames - Name of the class(es) to be added.
clr - The ClassLoaderResolver

addClass

public void addClass(java.lang.String className,
                     ClassLoaderResolver clr)
Method to add a (PersistenceCapable) class to the store manager's set of supported classes. This will create any necessary database objects. This will cause the addition of any related classes.

Specified by:
addClass in class StoreManager
Parameters:
className - Name of the class to be added.
clr - The ClassLoaderResolver

removeAllClasses

public void removeAllClasses(ClassLoaderResolver clr)
Utility to remove all classes that we are managing.

Specified by:
removeAllClasses in class StoreManager
Parameters:
clr - The ClassLoaderResolver

getFetchStatement

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

Specified by:
getFetchStatement in class StoreManager
Parameters:
table - The table to fetch from
Returns:
The fetch statement

newJoinDatastoreContainerObject

public DatastoreContainerObject newJoinDatastoreContainerObject(AbstractPropertyMetaData fmd,
                                                                ClassLoaderResolver clr)
Called by (container) Mapping objects to request the creation of a DatastoreObject (table). If the specified field doesn't require a join table then this returns null. If the join table already exists, then this returns it.

Specified by:
newJoinDatastoreContainerObject in class StoreManager
Parameters:
fmd - The field metadata describing the field.
clr - The ClassLoaderResolver
Returns:
The container object (SetTable/ListTable/MapTable/ArrayTable)

getBackingStoreForCollection

public 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.

Specified by:
getBackingStoreForCollection in class StoreManager
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 of this collection in this store

getBackingStoreForMap

public 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.

Specified by:
getBackingStoreForMap in class StoreManager
Parameters:
fmd - MetaData for the field that has this map
datastoreTable - The datastore object
clr - ClassLoader resolver
Returns:
The backing store of this map in this store

getBackingStoreForArray

public 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.

Specified by:
getBackingStoreForArray in class StoreManager
Parameters:
fmd - MetaData for the field that has this array
datastoreTable - The datastore object
clr - ClassLoader resolver
Returns:
The backing store of this array in this store

getClassNameForObjectID

public 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 an AppID PK, return the PersistenceCapable class that the id relates to. If SingleFieldIdentity return the associated PC class. If the object id is an application id and the user supplies the "pm" argument then a check can be performed in the datastore where necessary.

Specified by:
getClassNameForObjectID in class StoreManager
Parameters:
id - The JDO identity of some object.
clr - ClassLoader resolver
pm - Persistence Manager (optional - to allow check in the datastore)
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 ( OIDor SCOID).

getExtent

public javax.jdo.Extent getExtent(PersistenceManager pm,
                                  java.lang.Class c,
                                  boolean subclasses)
Accessor for an Extent for a class, and its subclasses.

Specified by:
getExtent in class StoreManager
Parameters:
pm - The Persistence Manager
c - The (candidate) class to use for the Extent
subclasses - Whether to include subclasses of 'c'
Returns:
The Extent
Throws:
NoExtentException - if an extent is not managed for the specified class

supportsQueryLanguage

public boolean supportsQueryLanguage(java.lang.String language)
Accessor for whether this query language is supported.

Specified by:
supportsQueryLanguage in class StoreManager
Parameters:
language - The language
Returns:
Whether it is supported.
See Also:
StoreManager.supportsQueryLanguage(java.lang.String)

newQuery

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

Specified by:
newQuery in class StoreManager
Parameters:
language - The query language
pm - The PM
query - The query filter (String) or a previous Query
Returns:
The Query

newObjectID

public 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.

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

getStrategyValue

public java.lang.Object getStrategyValue(PersistenceManager pm,
                                         DatastoreClass table,
                                         AbstractClassMetaData cmd,
                                         int absoluteFieldNumber,
                                         IdentityStrategy strategy,
                                         java.lang.String sequence,
                                         ExtensionMetaData[] extensions)
Method to return the value for the specified strategy. Supports the non-datastore strategies of JDO2. That is, does not support "autoassign" and "identity" which are done elsewhere. This method is synchronised so that several threads dont come in and update the PoidManager connection details while another thread is allocating the POID and change the connection that it should release after its work!

Specified by:
getStrategyValue in class StoreManager
Parameters:
pm - the PersistenceManager requesting an ID for the object
table - The datastore table
cmd - AbstractClassMetaData for the class containing this field
absoluteFieldNumber - Absolute number of the field (-1 means datastore identity field)
strategy - The strategy to use for defining the value
sequence - Name of a sequence if the strategy is sequence
extensions - Any extensions to control the value generation process. For value-strategy tags this is in the field extension. For datastore-identity tags this is in the datastore-identity extension.
Returns:
The value for this strategy
Throws:
javax.jdo.JDODataStoreException - Thrown if an error occurs getting the value

getInsertRequest

public InsertRequest getInsertRequest(DatastoreClass table,
                                      java.lang.Class cls,
                                      ClassLoaderResolver clr)
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:
table - The table into which to insert.
cls - class of the object of the request
clr - ClassLoader resolver
Returns:
An insertion request object.

getFetchRequest

public FetchRequest getFetchRequest(DatastoreClass table,
                                    AbstractPropertyMetaData[] fieldMetaData,
                                    java.lang.Class cls,
                                    ClassLoaderResolver clr)
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:
table - The table from which to fetch.
fieldMetaData - MetaData for the fields corresponding to the columns to be fetched.
cls - class of the object of the request
clr - ClassLoader resolver
Returns:
A fetch request object.

getUpdateRequest

public UpdateRequest getUpdateRequest(DatastoreClass table,
                                      AbstractPropertyMetaData[] fieldMetaData,
                                      java.lang.Class cls,
                                      ClassLoaderResolver clr)
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:
table - The table in which to update.
fieldMetaData - The AbstractPropertyMetaData corresponding to the columns to be updated. FieldMetaData whose columns exist in supertables will be ignored.
cls - class of the object of the request
clr - ClassLoader resolver
Returns:
An update request object.

getLocateRequest

public LocateRequest getLocateRequest(DatastoreClass table,
                                      java.lang.String className)
Returns a request object that will locate 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:
table - The table from which to locate.
className - the class name of the object of the request
Returns:
A locate request object.

getDeleteRequest

public DeleteRequest getDeleteRequest(DatastoreClass table,
                                      java.lang.Class cls,
                                      ClassLoaderResolver clr)
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:
table - The table from which to delete.
cls - class of the object of the request
clr - ClassLoader resolver
Returns:
A deletion request object.

getColumnInfoForColumnName

public ColumnInfo getColumnInfoForColumnName(Table table,
                                             java.sql.Connection conn,
                                             DatastoreIdentifier column)
                                      throws java.sql.SQLException
Returns the column info for a column name. 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:
table - The table/view
conn - JDBC connection to the database.
column - the column
Returns:
The ColumnInfo objects describing the column.
Throws:
java.sql.SQLException
See Also:
ColumnInfo

getColumnInfoForTable

public java.util.List getColumnInfoForTable(Table table,
                                            java.sql.Connection conn)
                                     throws java.sql.SQLException
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:
table - The table/view
conn - JDBC connection to the database.
Returns:
A list of ColumnInfo objects describing the columns of the table. The list is in the same order as was supplied by getColumns(). If no column info is found for the given table, an empty list is returned.
Throws:
java.sql.SQLException
See Also:
ColumnInfo

getTableInfo

public java.util.List getTableInfo()
                            throws java.sql.SQLException
Returns the table info for a database schema. This should be used instead of making direct calls to DatabaseMetaData.getTables().

Where possible, this method loads and caches table info for more than just the table being requested, improving performance by reducing the overall number of calls made to DatabaseMetaData.getTables() (each of which usually results in one or more database queries).

Returns:
A list of TableInfo objects describing the tables. The list is in the same order as was supplied by getTables(). If no table info, an empty list is returned.
Throws:
java.sql.SQLException
See Also:
TableInfo

getTableInfo

public java.util.List getTableInfo(java.lang.String schemaNamePattern)
                            throws java.sql.SQLException
Returns the table info for a database schema. This should be used instead of making direct calls to DatabaseMetaData.getTables(). The tables are searched using the default schema name for this RDBMSManager

Where possible, this method loads and caches table info for more than just the table being requested, improving performance by reducing the overall number of calls made to DatabaseMetaData.getTables() (each of which usually results in one or more database queries).

Parameters:
schemaNamePattern - the schema name pattern
Returns:
A list of TableInfo objects describing the tables. The list is in the same order as was supplied by getTables(). If no table info, an empty list is returned.
Throws:
java.sql.SQLException
See Also:
TableInfo

getColumnInfo

public java.util.List getColumnInfo(java.lang.String schemaNamePattern,
                                    java.lang.String tableNamePattern)
                             throws java.sql.SQLException
Returns the column info for a database schema. This should be used instead of making direct calls to DatabaseMetaData.getColumns().

Where possible, this method loads and caches table 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:
schemaNamePattern - the schema name pattern
tableNamePattern - the table name pattern
Returns:
A list of ColumnInfo objects describing the columns. The list is in the same order as was supplied by getColumns(). If no column info, an empty list is returned.
Throws:
java.sql.SQLException
See Also:
ColumnInfo

invalidateColumnInfoForTable

public void invalidateColumnInfoForTable(Table table)
Method to invalidate the cached column info for a table. This is called when we have just added columns to the table in the schema has the effect of a reload of the tables information the next time it is needed.

Parameters:
table - The table

resolveIdentifierMacro

public void resolveIdentifierMacro(MacroString.IdentifierMacro im,
                                   ClassLoaderResolver clr)
Resolves an identifier macro. The public fields className, 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.

Specified by:
resolveIdentifierMacro in class StoreManager
Parameters:
im - The macro to resolve.
clr - The ClassLoaderResolver


Copyright © -2007 . All Rights Reserved.