© 2002 BEA Systems, Inc.


com.bea.p13n.util.jdbc
Class DatabaseFactory

java.lang.Object
  |
  +--com.bea.p13n.util.jdbc.DatabaseFactory

public class DatabaseFactory
extends java.lang.Object

The DatabaseFactory class provides a means for creating and returning specific Database instances relative to the database being used. This is necessary for CLOB column processing. There are many different ways JDBC driver vendors choose to implement CLOB handling, thus the need for driver-specific Database objects to handle CLOBs appropriately.

A java.sql.Connection object is passed in and the java.sql.DatabaseMetaData for that object is used to determine which database driver is responsible for creating the connection. A driver-specific Database instance will then be returned.

See Also:
Database

Constructor Summary
DatabaseFactory()
           
 
Method Summary
static void deregisterDatabase(Database instance)
          Remove Database instance from the list of registered instances
static java.sql.Connection getConnection(javax.sql.DataSource src, int retries)
          Get a connection from a DataSource with retry logic.
static java.sql.Connection getConnection(javax.sql.DataSource src, int retries, long waitTime)
          Get a connection from a DataSource with retry and timeout logic.
static Database getInstance(java.sql.Connection connection)
          Get the driver-specific Database instance
static void registerDatabase(Database instance)
          Add Database instance to the list of registered instances
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseFactory

public DatabaseFactory()
Method Detail

getInstance

public static Database getInstance(java.sql.Connection connection)
                            throws java.sql.SQLException
Get the driver-specific Database instance

Parameters:
connection - java.sql.Connection object
Returns:
Database The driver-specific Database instance
Throws:
java.sql.SQLException - Cannot create or cannot find Database instance for the connection.

getConnection

public static java.sql.Connection getConnection(javax.sql.DataSource src,
                                                int retries,
                                                long waitTime)
                                         throws java.sql.SQLException
Get a connection from a DataSource with retry and timeout logic.

This will retry upto maxRetries. Additionally, it will only retry for waitTime number of milliseconds (as best as possible -- it might be longer, but will not be less).

This will always try at least once to get a connection. Use retries=0 for only a single attempt.

This works with both transactional and non-transaction DataSources tied to WLS connection pools. In WLS, transactional DataSources always internally wait 5 seconds for a new connection; non-transaction DataSources don't wait at all.

NOTE: The connection pool referenced by the given DataSource needs to be configured with the testConnOnReserve property set to true. This is necessary to ensure that in the event a SQLException is thrown, the cause of the exception is the unavailability of a pooled connection.

The values for maxRetries and maxWaitTime default to -1 (meaning unlimited retries and infinite wait time). These can be configured via the System Properties max.retries and max.wait.

Parameters:
src - the data source.
retries - the maximum number of times to retry (cannot exceed maxRetries).
waitTime - the maximum number of milliseconds to try (cannot exceed maxWaitTime).
Returns:
a connection from the data source on success.
Throws:
java.sql.SQLException - thrown on an error getting a connection.

getConnection

public static java.sql.Connection getConnection(javax.sql.DataSource src,
                                                int retries)
                                         throws java.sql.SQLException
Get a connection from a DataSource with retry logic.

Parameters:
src - the data source.
retries - the maximum number of times to retry (cannot exceed maxRetries).
Returns:
a connection from the data source on success.
Throws:
java.sql.SQLException - thrown on an error getting a connection.

registerDatabase

public static void registerDatabase(Database instance)
Add Database instance to the list of registered instances

Parameters:
instance - The Database instance

deregisterDatabase

public static void deregisterDatabase(Database instance)
Remove Database instance from the list of registered instances

Parameters:
instance - The Database instance

© 2002 BEA Systems, Inc.

Copyright © 2002 BEA Systems, Inc. All Rights Reserved