biz.hammurapi.sql
Class ConnectionPerThreadDataSource

java.lang.Object
  extended by biz.hammurapi.sql.ConnectionPerThreadDataSource
All Implemented Interfaces:
Component, javax.sql.DataSource
Direct Known Subclasses:
HsqldbDataSource

public class ConnectionPerThreadDataSource
extends java.lang.Object
implements javax.sql.DataSource, Component

Maintains one connection per thread. Connection is allocated on first getConnection() call. Every next call increments use counter. Connection closes when it is not used (counter==0) and connectionCloseTimeout passed.

Version:
$Revision: 1.7 $
Author:
Pavel Vlasov

Constructor Summary
ConnectionPerThreadDataSource(java.lang.ClassLoader classLoader, java.lang.String driverClass, java.lang.String dbURL, java.lang.String user, java.lang.String password, Transaction initConnectionTransaction)
          Constructor
ConnectionPerThreadDataSource(java.lang.String driverClass, java.lang.String dbURL, java.lang.String user, java.lang.String password, Transaction initConnectionTransaction)
          Constructor
 
Method Summary
protected  void finalize()
           
 java.sql.Connection getConnection()
           
 java.sql.Connection getConnection(java.lang.String user, java.lang.String password)
           
 Transaction getInitConnectionTransaction()
           
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
           
 void setLoginTimeout(int seconds)
           
 void setLogWriter(java.io.PrintWriter out)
           
 void setOwner(java.lang.Object owner)
          Plugs the component into container and naming bus.
 void shutdown()
          Closes all pooled (unused) connections and instructs connections being used to close immeidatly once they are released.
 void start()
          Invoked by container before the first use.
 void stop()
          Invoked by container when component is not needed anymore.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPerThreadDataSource

public ConnectionPerThreadDataSource(java.lang.String driverClass,
                                     java.lang.String dbURL,
                                     java.lang.String user,
                                     java.lang.String password,
                                     Transaction initConnectionTransaction)
                              throws java.lang.ClassNotFoundException
Constructor

Parameters:
driverClass -
dbURL -
user -
password -
Throws:
java.lang.ClassNotFoundException

ConnectionPerThreadDataSource

public ConnectionPerThreadDataSource(java.lang.ClassLoader classLoader,
                                     java.lang.String driverClass,
                                     java.lang.String dbURL,
                                     java.lang.String user,
                                     java.lang.String password,
                                     Transaction initConnectionTransaction)
                              throws java.sql.SQLException,
                                     java.lang.InstantiationException,
                                     java.lang.IllegalAccessException,
                                     java.lang.ClassNotFoundException
Constructor

Parameters:
driverClass -
dbURL -
user -
password -
Throws:
java.sql.SQLException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
Method Detail

getLoginTimeout

public int getLoginTimeout()
Specified by:
getLoginTimeout in interface javax.sql.DataSource

setLoginTimeout

public void setLoginTimeout(int seconds)
Specified by:
setLoginTimeout in interface javax.sql.DataSource

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Specified by:
getLogWriter in interface javax.sql.DataSource
Throws:
java.sql.SQLException

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Specified by:
setLogWriter in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String user,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

shutdown

public void shutdown()
Closes all pooled (unused) connections and instructs connections being used to close immeidatly once they are released.

Throws:
java.sql.SQLException

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getInitConnectionTransaction

public Transaction getInitConnectionTransaction()
Returns:
connection initialization transaction

setOwner

public void setOwner(java.lang.Object owner)
Description copied from interface: Component
Plugs the component into container and naming bus.

Specified by:
setOwner in interface Component

start

public void start()
           throws ConfigurationException
Description copied from interface: Component
Invoked by container before the first use. Component shall perform initialization in this method.

Specified by:
start in interface Component
Throws:
ConfigurationException

stop

public void stop()
          throws ConfigurationException
Description copied from interface: Component
Invoked by container when component is not needed anymore. Component shall perform cleanup in this method.

Specified by:
stop in interface Component
Throws:
ConfigurationException


Copyright © 2003 Hammurapi Group. All Rights Reserved.