org.exolab.castor.jdo
Class JDO2

java.lang.Object
  extended byorg.exolab.castor.jdo.JDO2
All Implemented Interfaces:
DataObjects, javax.naming.spi.ObjectFactory, javax.naming.Referenceable, java.io.Serializable

public class JDO2
extends java.lang.Object
implements DataObjects, javax.naming.Referenceable, javax.naming.spi.ObjectFactory, java.io.Serializable

Implementation of the JDO engine used for obtaining database connection. After successful instantiation, getDatabase() is used to obtain a new database connection. Any number of database connections can be obtained from the same JDO object.

Please note that this clas is provided on an experimental base, and might still undergo minor changes.

An instance of this class is contructed with a two-step approach:

Example:


 . . .

 JDO jdo;
 Database db;
 
 try {
 
    // load the JDO configuration file 
    JDO.loadConfiguration ("jdo-config.xml");
 
    // Construct a new JDO for the database 'mydb'
    jdo = JDO.createInstance ("mydb");
 
    // Open a connection to the database
    db = jdo.getDatabase();
 
 }
 catch (MappingException e) {
    ...
 }
 catch (DatabaseNotFoundException) {
    ...
 }
 
 

Version:
$Revision: 1.3 $ $Date: 2004/11/03 09:36:43 $
Author:
Assaf Arkin, Bruce Snyder, Werner Guttmann
See Also:
Serialized Form

Field Summary
static java.lang.String DEFAULT_DESCRIPTION
          Default description.
static int DEFAULT_LOCK_TIMEOUT
          The default lock timeout (specified in seconds).
 
Method Summary
static JDO2 createInstance(java.lang.String databaseName)
          Factory method for creating a JDOOld instance for one of the databases configured in the JDOOld config file.
 java.lang.ClassLoader getClassLoader()
          Returns the application classloader.
 org.xml.sax.InputSource getConfiguration()
          Return the URL of the database configuration file.
 Database getDatabase()
          Opens and returns a connection to the database.
 java.lang.String getDatabaseName()
          Returns the name of this database.
 boolean getDatabasePooling()
          Indicates if jdo 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.
 int getLockTimeout()
          Returns the lock timeout for this database.
 LogInterceptor getLogInterceptor()
          Deprecated. There is no need for this method due to the implementation of Log4J which is controlled via the log4j.properties file.
 java.lang.Object getObjectInstance(java.lang.Object refObj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable env)
           
 javax.naming.Reference getReference()
           
 boolean isAutoStore()
          Return if the next Database instance will be set to autoStore.
static void loadConfiguration(org.xml.sax.InputSource source, org.xml.sax.EntityResolver resolver, java.lang.ClassLoader loader)
          Load the JDO configuration from the specified input source using a custom class loader.
static void loadConfiguration(java.lang.String url)
          Load the JDO configuration from the specified location.
static void loadConfiguration(java.lang.String url, java.lang.ClassLoader loader)
          Load the JDO configuration from the specified location 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 setConfiguration(org.xml.sax.InputSource source)
          Sets the URL of the database configuration file.
 void setDatabasePooling(boolean pool)
          Enable/disable jdo 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 data object when it is needed during loading.
 void setLockTimeout(int seconds)
          Sets the lock timeout for this database.
 void setLogInterceptor(LogInterceptor logInterceptor)
          Deprecated. There is no need for this method due to the implementation of Log4J which is controlled via the log4j.properties file.
 void setLogWriter(java.io.PrintWriter logWriter)
          Deprecated. There is no need for this method due to the implementation of Log4J which is controlled via the log4j.properties file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOCK_TIMEOUT

public static final int DEFAULT_LOCK_TIMEOUT
The default lock timeout (specified in seconds).

See Also:
Constant Field Values

DEFAULT_DESCRIPTION

public static final java.lang.String DEFAULT_DESCRIPTION
Default description.

See Also:
Constant Field Values
Method Detail

createInstance

public static JDO2 createInstance(java.lang.String databaseName)
                           throws MappingException
Factory method for creating a JDOOld instance for one of the databases configured in the JDOOld config file. Please make sure that you call loadConfiguration() first.

Parameters:
databaseName - Database name as configured in the JDOOld config file.
Returns:
A JDOOld instance.
Throws:
MappingException - The mapping file is invalid, or any error occured trying to load the JDO configuration/mapping

setLogWriter

public void setLogWriter(java.io.PrintWriter logWriter)
Deprecated. There is no need for this method due to the implementation of Log4J which is controlled via the log4j.properties file.

Returns the log writer for this database source.

The log writer is a character output stream to which all logging and tracing messages will be printed.

Parameters:
logWriter - A PrintWriter instance.

setLogInterceptor

public void setLogInterceptor(LogInterceptor logInterceptor)
Deprecated. There is no need for this method due to the implementation of Log4J which is controlled via the log4j.properties file.

Sets the log interceptor for this database source.

The interceptor is a callback to to which all logging and tracing messages are sent.

Parameters:
logInterceptor - The log interceptor, null if disabled

setCallbackInterceptor

public void setCallbackInterceptor(CallbackInterceptor callback)
Overrides the default callback interceptor by a custom interceptor for this database source.

The interceptor is a callback that notifies data objects on persistent state events.

If callback interceptor is not overrided, events will be sent to data object that implements the org.exolab.castor.jdo.Persistent interface.

Parameters:
callback - The callback interceptor, null if disabled

setInstanceFactory

public void setInstanceFactory(InstanceFactory factory)
Overrides the default instance factory by a custom one to be used by Castor to obtaining an instance of data object when it is needed during loading.

If instance factory is not overrided, and if class loader is not set, Class.forName( className ).newInstance() will be used; if instance factory is not override, and class loader is set, loader.loadClass( className ).newInstance() will be used to create a new instance.

Parameters:
factory - The instance factory, null to use the default

getLogInterceptor

public LogInterceptor getLogInterceptor()
Deprecated. There is no need for this method due to the implementation of Log4J which is controlled via the log4j.properties file.

Returns the log interceptor for this database source.

Returns:
The log interceptor, null if disabled

getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the application classloader.

Returns:
The currently used ClassLoader.

getEntityResolver

public org.xml.sax.EntityResolver getEntityResolver()
Returns the entity resolver.

Returns:
The EntityResolver currently in use.

setDescription

public void setDescription(java.lang.String description)
Sets the description of this database.

The standard name for this property is description.

Specified by:
setDescription in interface DataObjects
Parameters:
description - The description of this database

getDescription

public java.lang.String getDescription()
Returns the description of this database.

The standard name for this property is description.

Specified by:
getDescription in interface DataObjects
Returns:
The description of this database

getDatabaseName

public java.lang.String getDatabaseName()
Returns the name of this database.

The standard name for this property is databaseName.

Specified by:
getDatabaseName in interface DataObjects
Returns:
The name of this database

setLockTimeout

public void setLockTimeout(int seconds)
Sets the lock timeout for this database. Use zero for immediate timeout, an infinite value for no timeout. The timeout is specified in seconds.

The standard name for this property is lockTimeout.

Parameters:
seconds - The lock timeout, specified in seconds

getLockTimeout

public int getLockTimeout()
Returns the lock timeout for this database.

The standard name for this property is lockTimeout.

Returns:
The lock timeout, specified in seconds

setConfiguration

public void setConfiguration(org.xml.sax.InputSource source)
Sets the URL of the database configuration file. If the URL is specified, the first attempt to load a database of this type will use the specified configuration file. If the URL is not specified, use one of the loadConfiguration(String) methods instead.

The standard name for this property is configuration.

Parameters:
source - The URL of the database configuration file as an InputSource.

getConfiguration

public org.xml.sax.InputSource getConfiguration()
Return the URL of the database configuration file.

The standard name for this property is configuration.

Returns:
The URL of the database configuration file as an InoutSource.

setDatabasePooling

public void setDatabasePooling(boolean pool)
Enable/disable jdo Database pooling. This option only affects JDO if transactionManager is set and a transaction is associated with the thread that call getDatabase(). If jdo Database pooling is enabled, JDO 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 the invocation of getDatabase().

Experimental maybe removed in the future releases

Parameters:
pool - true to enable database pooling

getDatabasePooling

public boolean getDatabasePooling()
Indicates if jdo Database pooling is enable or not.

Experimental maybe removed in the further release

Returns:
True if pooling is enabled for this Database instance.
See Also:
setDatabasePooling(boolean)

setAutoStore

public void setAutoStore(boolean autoStore)
Sets autoStore mode.

Parameters:
autoStore - True if user prefer all reachable object to be stored automatically; False if user want only dependent object to be stored. See also, setAutoStore(boolean)

isAutoStore

public boolean isAutoStore()
Return if the next Database instance will be set to autoStore.

Returns:
True if autoStore is enabled.

getDatabase

public Database getDatabase()
                     throws DatabaseNotFoundException,
                            PersistenceException
Opens and returns a connection to the database. Throws an DatabaseNotFoundException if no database configuration exists for the named database.

Specified by:
getDatabase in interface DataObjects
Returns:
An open connection to the database
Throws:
DatabaseNotFoundException - Attempted to open a database that does not exist
PersistenceException - Database access failed

loadConfiguration

public static void loadConfiguration(org.xml.sax.InputSource source,
                                     org.xml.sax.EntityResolver resolver,
                                     java.lang.ClassLoader loader)
                              throws MappingException
Load the JDO configuration from the specified input source using a custom class loader. In addition, a custom entity resolver can be provided.

Parameters:
source - The JDO 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 default
Throws:
MappingException - The mapping file is invalid, or any error occured trying to load the JDO configuration/mapping

loadConfiguration

public static void loadConfiguration(java.lang.String url,
                                     java.lang.ClassLoader loader)
                              throws MappingException
Load the JDO configuration from the specified location using a custom class loader.

Parameters:
url - The location from which to load the JDOOld config file.
loader - The custom class loader to use, null for the default.
Throws:
MappingException - The mapping file is invalid, or any error occured trying to load the JDO configuration/mapping

loadConfiguration

public static void loadConfiguration(java.lang.String url)
                              throws MappingException
Load the JDO configuration from the specified location.

Parameters:
url - The location from which to load the JDOOld config file.
Throws:
MappingException - The mapping file is invalid, or any error occured trying to load the JDO configuration/mapping

getReference

public javax.naming.Reference getReference()
Specified by:
getReference in interface javax.naming.Referenceable

getObjectInstance

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
Specified by:
getObjectInstance in interface javax.naming.spi.ObjectFactory
Throws:
javax.naming.NamingException


Intalio Inc. (C) 1999-2004. All rights reserved http://www.intalio.com