java.io.Serializable
, javax.naming.Referenceable
, javax.naming.spi.ObjectFactory
, DataObjects
public final class JDOManager extends java.lang.Object implements DataObjects, javax.naming.Referenceable, javax.naming.spi.ObjectFactory, java.io.Serializable
getDatabase()
is used
to obtain a new database connection. Any number of database connections can
be obtained from the same JDOManager object.
An instance of this class is contructed with a two-step approach:
... JDOManager jdo; Database db; try { // load the JDOManager configuration file JDOManager.loadConfiguration("jdo-config.xml"); // construct a new JDOManager for 'mydb' jdo = JDOManager.createInstance("mydb"); // open a connection to the database db = jdo.getDatabase(); } catch (MappingException ex) { ... } catch (DatabaseNotFoundException ex) { ... }
Modifier and Type | Field | Description |
---|---|---|
static java.lang.String |
DEFAULT_DESCRIPTION |
Default description.
|
static int |
DEFAULT_LOCK_TIMEOUT |
The default lock timeout (specified in seconds).
|
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
Lyfe-cycle methods to close JDOManager instance and initiate resource cleanup.
|
static JDOManager |
createInstance(java.lang.String databaseName) |
Factory method for creating a JDOManager instance for one of the
databases configured in the JDOManager configuration file.
|
static void |
disposeInstance(java.lang.String databaseName) |
Method to dispose a JDOManager instance.
|
CallbackInterceptor |
getCallbackInterceptor() |
Returns the callback interceptor.
|
java.lang.ClassLoader |
getClassLoader() |
Returns the application classloader.
|
org.xml.sax.InputSource |
getConfiguration() |
Return the URL of the database configuration file.
|
ConnectionFactory |
getConnectionFactory() |
Returns the ConnectionFactory for this JDOManager instance.
|
Database |
getDatabase() |
Opens and returns a connection to the database.
|
java.lang.String |
getDatabaseName() |
Returns the name of this database.
|
boolean |
getDatabasePooling() |
Indicates if database pooling is enable or not.
|
java.lang.String |
getDescription() |
Returns the description of this database.
|
org.xml.sax.EntityResolver |
getEntityResolver() |
Returns the entity resolver.
|
InstanceFactory |
getInstanceFactory() |
Returns the instance factory.
|
int |
getLockTimeout() |
Returns the lock timeout for this database.
|
java.lang.Object |
getObjectInstance(java.lang.Object refObj,
javax.naming.Name name,
javax.naming.Context nameCtx,
java.util.Hashtable<?,?> env) |
|
javax.naming.Reference |
getReference() |
Constructs a new reference to JDOManager being its own factory.
|
boolean |
isAutoStore() |
Return if the next database instance will be set to autoStore.
|
static void |
loadConfiguration(java.lang.String url) |
Load the JDOManager configuration from the specified location.
|
static void |
loadConfiguration(java.lang.String url,
java.lang.ClassLoader loader) |
Load the JDOManager configuration from the specified location using a
custom class loader.
|
static void |
loadConfiguration(java.lang.String url,
java.lang.ClassLoader loader,
JDOClassDescriptorResolver classDescriptorResolver) |
Load the JDOManager configuration from the specified location using a
custom class loader.
|
static void |
loadConfiguration(java.lang.String name,
java.lang.String engine,
javax.sql.DataSource datasource,
Mapping mapping,
javax.transaction.TransactionManager txManager) |
Initialize the JDOManager configuration with given name, engine, datasource,
transaction demarcation and mapping.
|
static void |
loadConfiguration(JdoConf jdoConf,
java.lang.ClassLoader loader,
java.lang.String baseURI) |
Load the JDOManager configuration from the specified in-memory JdoConf.
|
static void |
loadConfiguration(JdoConf jdoConf,
java.lang.String baseURI) |
Load the JDOManager configuration from the specified in-memory JdoConf.
|
static void |
loadConfiguration(JdoConf jdoConf,
org.xml.sax.EntityResolver resolver,
java.lang.ClassLoader loader,
java.lang.String baseURI) |
Load the JDOManager configuration from the specified in-memory JdoConf.
|
static void |
loadConfiguration(org.xml.sax.InputSource source,
org.xml.sax.EntityResolver resolver,
java.lang.ClassLoader loader) |
Load the JDOManager configuration from the specified input source using
a custom class loader.
|
static void |
loadConfiguration(org.xml.sax.InputSource source,
org.xml.sax.EntityResolver resolver,
java.lang.ClassLoader loader,
JDOClassDescriptorResolver classDescriptorResolver) |
Load the JDOManager configuration from the specified input source using
a custom class loader.
|
void |
setAutoStore(boolean autoStore) |
Sets autoStore mode.
|
void |
setCallbackInterceptor(CallbackInterceptor callback) |
Overrides the default callback interceptor by a custom interceptor
for this database source.
|
void |
setDatabasePooling(boolean pool) |
Enable/disable database pooling.
|
void |
setDescription(java.lang.String description) |
Sets the description of this database.
|
void |
setInstanceFactory(InstanceFactory factory) |
Overrides the default instance factory by a custom one to be used by
Castor to obtaining an instance of a data object when it is needed during
loading.
|
void |
setLockTimeout(int seconds) |
Sets the lock timeout for this database.
|
public static final int DEFAULT_LOCK_TIMEOUT
public static final java.lang.String DEFAULT_DESCRIPTION
public static JDOManager createInstance(java.lang.String databaseName) throws MappingException
databaseName
- Database name as configured in the JDOManager
configuration file.MappingException
- The mapping file is invalid, or any error
occurred trying to load the mapping from JDOManager configuration
file.public static void disposeInstance(java.lang.String databaseName)
databaseName
- Database name as configured in the JDOManager
configuration file.public static void loadConfiguration(java.lang.String name, java.lang.String engine, javax.sql.DataSource datasource, Mapping mapping, javax.transaction.TransactionManager txManager) throws MappingException
name
- The Name of the database configuration.engine
- The Name of the persistence factory to use.datasource
- The preconfigured datasource to use for creating connections.mapping
- The previously loaded mapping.txManager
- The transaction manager to use.MappingException
- If LockEngine could not be initialized.public static void loadConfiguration(JdoConf jdoConf, org.xml.sax.EntityResolver resolver, java.lang.ClassLoader loader, java.lang.String baseURI) throws MappingException
jdoConf
- the in-memory JdoConf.resolver
- An (optional) entity resolver to resolve cached
entities, e.g. for external mapping documents.loader
- The class loader to use, null for the defaultbaseURI
- The base URL for the mappingMappingException
- The mapping file is invalid, or any error
occured trying to load the JDO configuration/mappingpublic static void loadConfiguration(JdoConf jdoConf, java.lang.ClassLoader loader, java.lang.String baseURI) throws MappingException
jdoConf
- the in-memory JdoConf.loader
- The class loader to use, null for the defaultbaseURI
- The base URL for the mappingMappingException
- The mapping file is invalid, or any error
occured trying to load the JDO configuration/mappingpublic static void loadConfiguration(JdoConf jdoConf, java.lang.String baseURI) throws MappingException
jdoConf
- the in-memory JdoConf.baseURI
- The base URL for the mappingMappingException
- The mapping file is invalid, or any error
occured trying to load the JDO configuration/mappingpublic static void loadConfiguration(org.xml.sax.InputSource source, org.xml.sax.EntityResolver resolver, java.lang.ClassLoader loader) throws MappingException
source
- The JDOManager configuration file describing the
databases, connection factory and mappings.resolver
- An (optional) entity resolver to resolve cached
entities, e.g. for external mapping documents.loader
- The class loader to use, null for the defaultMappingException
- The mapping file is invalid, or any error
occured trying to load the JDO configuration/mappingpublic static void loadConfiguration(org.xml.sax.InputSource source, org.xml.sax.EntityResolver resolver, java.lang.ClassLoader loader, JDOClassDescriptorResolver classDescriptorResolver) throws MappingException
source
- The JDOManager configuration file describing the
databases, connection factory and mappings.resolver
- An (optional) entity resolver to resolve cached
entities, e.g. for external mapping documents.loader
- The class loader to use, null for the defaultclassDescriptorResolver
- ClassDescriptorResolver
used for class to class
descriptor resolution.MappingException
- The mapping file is invalid, or any error
occurred trying to load the JDO configuration/mappingpublic static void loadConfiguration(java.lang.String url, java.lang.ClassLoader loader) throws MappingException
url
- The location from which to load the configuration file.loader
- The custom class loader to use, null for the default.MappingException
- The mapping file is invalid, or any error
occured trying to load the JDOManager configuration/mapping.public static void loadConfiguration(java.lang.String url, java.lang.ClassLoader loader, JDOClassDescriptorResolver classDescriptorResolver) throws MappingException
url
- The location from which to load the configuration file.loader
- The custom class loader to use, null for the default. *classDescriptorResolver
- ClassDescriptorResolver
used for class to class
descriptor resolution.MappingException
- The mapping file is invalid, or any error occurred trying
to load the JDOManager configuration/mapping.public static void loadConfiguration(java.lang.String url) throws MappingException
url
- The location from which to load the configuration file.MappingException
- The mapping file is invalid, or any error
occured trying to load the JDOManager configuration/mapping.public java.lang.ClassLoader getClassLoader()
public org.xml.sax.EntityResolver getEntityResolver()
public org.xml.sax.InputSource getConfiguration()
public void setCallbackInterceptor(CallbackInterceptor callback)
callback
- The callback interceptor, null if disabledpublic CallbackInterceptor getCallbackInterceptor()
public void setInstanceFactory(InstanceFactory factory)
factory
- The instance factory, null to use the defaultpublic InstanceFactory getInstanceFactory()
public void setLockTimeout(int seconds)
seconds
- The lock timeout, specified in secondspublic int getLockTimeout()
public void setDescription(java.lang.String description)
setDescription
in interface DataObjects
description
- The description of this databasepublic java.lang.String getDescription()
getDescription
in interface DataObjects
public void setDatabasePooling(boolean pool)
getDatabase()
. If database pooling is enabled, JDOManager
will first search in the pool to see if there is already a database for the
current transaction. If found, it returns the database; if not, it create a
new one, associates it will the transaction and return the newly created
database.
This method should be called before getDatabase()
.pool
- true to enable database poolingpublic boolean getDatabasePooling()
setDatabasePooling(boolean)
public void setAutoStore(boolean autoStore)
autoStore
- True if user prefer all reachable object to be stored
automatically; False if user want only dependent object to be
stored.public boolean isAutoStore()
public java.lang.String getDatabaseName()
getDatabaseName
in interface DataObjects
public ConnectionFactory getConnectionFactory() throws MappingException
MappingException
- If database can not be instantiated or is not configured.public Database getDatabase() throws PersistenceException
DatabaseNotFoundException
is thrown.getDatabase
in interface DataObjects
PersistenceException
- Database access failed.public javax.naming.Reference getReference()
getReference
in interface javax.naming.Referenceable
Reference
,
ObjectFactory
public java.lang.Object getObjectInstance(java.lang.Object refObj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable<?,?> env) throws javax.naming.NamingException
getObjectInstance
in interface javax.naming.spi.ObjectFactory
javax.naming.NamingException
public void close()
Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com