com.rhi.architecture.db
Class DataSourceFactory

java.lang.Object
  extended bycom.rhi.architecture.db.DataSourceFactory
All Implemented Interfaces:
Resource

public class DataSourceFactory
extends java.lang.Object
implements Resource

Factory for creating DataSources that pool database connections. Encapsulates creation of DataSource so that user deals w/ DataSource objects in an entirely standard way. The DataSource returned is a 100% compliant DataSource that pool DB connections for the user. In addition, the factory provides a static reference to the DataSources so that only 1 will be created per JVM. Multiple DBs can be connected to by providing different ResourceBundle filenames to the getBundle() method. The filename makes the bundle unique.

Since:
1.0
Author:
Pete McKinstry

Field Summary
static java.lang.String DB_URL_KEY
          the config key for the DB url.
static java.lang.String DEFAULT_DATA_SOURCE_NAME
          the default datasource name prefix.
static java.lang.String DRIVER_KEY
          the config key for the jdbc driver name.
static java.lang.String INIT_SIZE_KEY
          the initial size of the connection pool.
static java.lang.String INIT_SQL_KEY
          config key for optional sql string to be run upon new Connection checkout.
static java.lang.String KEY
          the configuration key used by the ResourceContext to look for & return the configured DataSourceFactory
static java.lang.String MAX_IDLE_KEY
          the max idle time for a connection in the pool before it is closed.
static java.lang.String MAX_SIZE_KEY
          the max size of the connection pool
static java.lang.String MAX_STMTS_KEY
          max number of Statements to be stored per connection.
static java.lang.String MAX_WAIT_KEY
          the max wait for a connection before timing out & throwing an exception
static java.lang.String PASSWORD_KEY
          the config key for the db password.
static java.lang.String USERNAME_KEY
          the config key for the db user name.
 
Constructor Summary
DataSourceFactory()
          Default Constructor
 
Method Summary
 void close()
          Cleanup the object pool that provides the connections.
 javax.sql.DataSource getDataSource()
          Retrieve the default datasource.
 javax.sql.DataSource getDataSource(java.lang.String dsName)
          retrieve a datsource by name.
 void init(java.util.Properties p)
          No initialization required.
 void setAction(byte action)
          Sets the action to be used when the pool is exhausted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY

public static final java.lang.String KEY
the configuration key used by the ResourceContext to look for & return the configured DataSourceFactory

See Also:
Constant Field Values

INIT_SQL_KEY

public static final java.lang.String INIT_SQL_KEY
config key for optional sql string to be run upon new Connection checkout.

See Also:
Constant Field Values

MAX_SIZE_KEY

public static final java.lang.String MAX_SIZE_KEY
the max size of the connection pool

See Also:
Constant Field Values

MAX_WAIT_KEY

public static final java.lang.String MAX_WAIT_KEY
the max wait for a connection before timing out & throwing an exception

See Also:
Constant Field Values

MAX_IDLE_KEY

public static final java.lang.String MAX_IDLE_KEY
the max idle time for a connection in the pool before it is closed.

See Also:
Constant Field Values

INIT_SIZE_KEY

public static final java.lang.String INIT_SIZE_KEY
the initial size of the connection pool. (# of connections checked out immediately)

See Also:
Constant Field Values

MAX_STMTS_KEY

public static final java.lang.String MAX_STMTS_KEY
max number of Statements to be stored per connection.

See Also:
Constant Field Values

DEFAULT_DATA_SOURCE_NAME

public static final java.lang.String DEFAULT_DATA_SOURCE_NAME
the default datasource name prefix.

See Also:
Constant Field Values

DB_URL_KEY

public static final java.lang.String DB_URL_KEY
the config key for the DB url.

See Also:
Constant Field Values

DRIVER_KEY

public static final java.lang.String DRIVER_KEY
the config key for the jdbc driver name.

See Also:
Constant Field Values

USERNAME_KEY

public static final java.lang.String USERNAME_KEY
the config key for the db user name.

See Also:
Constant Field Values

PASSWORD_KEY

public static final java.lang.String PASSWORD_KEY
the config key for the db password.

See Also:
Constant Field Values
Constructor Detail

DataSourceFactory

public DataSourceFactory()
Default Constructor

Since:
1.0
Method Detail

init

public void init(java.util.Properties p)
No initialization required.

Specified by:
init in interface Resource
Parameters:
p -

getDataSource

public javax.sql.DataSource getDataSource(java.lang.String dsName)
retrieve a datsource by name.

Parameters:
dsName -
Returns:
DataSource

getDataSource

public javax.sql.DataSource getDataSource()
Retrieve the default datasource. This is for backward compatibility, but the getDataSource(String name) version is preferred.

Returns:
DataSource.

close

public void close()
Cleanup the object pool that provides the connections.

Specified by:
close in interface Resource
Since:
1.0

setAction

public void setAction(byte action)
Sets the action to be used when the pool is exhausted. This method is mostly useful for testing where you may want to fail immediately if the pool is exhausted

Parameters:
action -


Copyright © 2002-2004 Robert Half International. All Rights Reserved.