com.jfw.database
Class ConnectionBroker

java.lang.Object
  extended by com.jfw.database.ConnectionBroker
All Implemented Interfaces:
java.util.Observer

public final class ConnectionBroker
extends java.lang.Object
implements java.util.Observer

Distribute database connections.
The connections are get from connection pools, datasource and specific connection management, as defined in jfw.properties.
The method get(java.lang.String) is used to get a connection and the method release(java.lang.String, java.sql.Connection) for release the connection.
Is a singleton, the instance is returned from method getInstance().
Is an observer of UpdateObservable.


Field Summary
static java.lang.String DATA_SOURCE
          Indicates a data source.
static java.lang.String FREE
          Indicates a proprietary connection management.
static java.lang.String POOL
          Indicates a connection pool.
 
Method Summary
 java.sql.Connection get(java.lang.String resource)
          Return an java.sql.Connection object.
static ConnectionBroker getInstance()
          Return the unique instance.
 void release(java.lang.String resource, java.sql.Connection connection)
          Release a connection.
 void update(java.util.Observable observable, java.lang.Object obj)
          Call method initialize().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_SOURCE

public static final java.lang.String DATA_SOURCE
Indicates a data source. This is a possible value of key db_resources_types in file jfw.properties.

See Also:
Constant Field Values

POOL

public static final java.lang.String POOL
Indicates a connection pool. This is a possible value of key db_resources_types in file jfw.properties.

See Also:
Constant Field Values

FREE

public static final java.lang.String FREE
Indicates a proprietary connection management. This is a possible value of key db_resources_types in file jfw.properties.

See Also:
Constant Field Values
Method Detail

getInstance

public static ConnectionBroker getInstance()
Return the unique instance.

Returns:
the unique instance.

get

public java.sql.Connection get(java.lang.String resource)
                        throws java.lang.Exception
Return an java.sql.Connection object.

Parameters:
resource - the resource name (connection pool or data source) that manage the connection.
Returns:
an java.sql.Connection object.
Throws:
java.lang.Exception

release

public void release(java.lang.String resource,
                    java.sql.Connection connection)
             throws java.lang.Exception
Release a connection.

Parameters:
resource - the resource name (connection pool or data source) that manage the connection.
connection - the connection returned by method get(java.lang.String).
Throws:
java.lang.Exception

update

public void update(java.util.Observable observable,
                   java.lang.Object obj)
Call method initialize(). The method is called asynchronously by UpdateObservable.

Specified by:
update in interface java.util.Observer