org.xorm.datastore.sql
Class PooledDataSource

java.lang.Object
  |
  +--org.xorm.datastore.sql.PooledDataSource
All Implemented Interfaces:
DataSource

public class PooledDataSource
extends Object
implements DataSource

Wraps a JDBC driver manager and provides a pooling of connections.

Version:
$Revision: 1.7 $
Author:
Scott Bendar

Field Summary
protected  LinkedList availableConnections
           
protected  int connCount
           
protected  Driver driver
           
protected  Properties props
           
 
Constructor Summary
PooledDataSource()
          Initializes a new pooled data source
 
Method Summary
 void close()
          Releases all available connections.
protected  void dropConnection(org.xorm.datastore.sql.PooledConnection conn)
          remove a connection from the pool
 boolean getCheckReturnedConnection()
          If set, instructs the connection to verify its valid when the caller is done with the connection (calls close).
 Connection getConnection()
          Gets a DB connection, actually a wrapper that allows the connection to be pooled.
 Connection getConnection(String userName, String password)
          This function is currently not implemented as it doesn't allow us to use the connections in the pool.
 String getConnectionUrl()
           
 String getDriverName()
           
 long getIdleCheck()
          Gets the amount of time in milliseconds a connection has been idle before the pool tests the connection to see if its still valid
 String getIdleCheckSQL()
          Gets a sql statement to be used to check a connection.
 Integer getIsolationLevel()
           
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
          The PooledDataSource class uses JDK 1.4 logging and ignores the log writer.
 int getMaxPool()
          The maximum number of connections created by the data source.
 int getMinPool()
          The minimum number of connections in the pool.
 String getUser()
           
protected  void makeAvailable(org.xorm.datastore.sql.PooledConnection conn)
          Makes the connection available again.
 void setCheckReturnedConnection(boolean value)
          If set, instructs the connection to verify its valid when the caller is done with the connection (calls close).
 void setConnectionUrl(String s)
          Set the URL used to connect to the DB
 void setDriverName(String s)
          Set the name of the driver to load when connecting to the DB
 void setIdleCheck(long idle)
          Sets the amount of time in milliseconds a connection has been idle before the pool tests the connection to see if its still valid
 void setIdleCheckSQL(String sql)
          Sets a sql statement to be used to check a connection.
 void setIsolationLevel(Integer isolationLevel)
          Sets the transaction isolation level.
 void setLoginTimeout(int timeout)
          Sets the maximum time to wait in seconds for a connection before throwing an exception.
 void setLogWriter(PrintWriter logger)
           
 void setMaxPool(int i)
           
 void setMinPool(int i)
           
 void setPassword(String s)
          Sets the password to use when creating a db connection.
 void setUser(String s)
          Sets the user name to pass when making a db connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

props

protected Properties props

connCount

protected int connCount

driver

protected Driver driver

availableConnections

protected LinkedList availableConnections
Constructor Detail

PooledDataSource

public PooledDataSource()
Initializes a new pooled data source

Method Detail

setUser

public void setUser(String s)
Sets the user name to pass when making a db connection


getUser

public String getUser()

setPassword

public void setPassword(String s)
Sets the password to use when creating a db connection. For security reasons, there is no way to get the password.


setConnectionUrl

public void setConnectionUrl(String s)
Set the URL used to connect to the DB


getConnectionUrl

public String getConnectionUrl()

setDriverName

public void setDriverName(String s)
Set the name of the driver to load when connecting to the DB


getDriverName

public String getDriverName()

getMaxPool

public int getMaxPool()
The maximum number of connections created by the data source. Once the max is exceeded callers must wait for a connection to become available.


setMaxPool

public void setMaxPool(int i)

getMinPool

public int getMinPool()
The minimum number of connections in the pool. It will create this number of connections when the pool is first initialized and the pool will never shrink below this many connections.


setMinPool

public void setMinPool(int i)

getLoginTimeout

public int getLoginTimeout()
Specified by:
getLoginTimeout in interface DataSource

setLoginTimeout

public void setLoginTimeout(int timeout)
Sets the maximum time to wait in seconds for a connection before throwing an exception.

Specified by:
setLoginTimeout in interface DataSource

getCheckReturnedConnection

public boolean getCheckReturnedConnection()
If set, instructs the connection to verify its valid when the caller is done with the connection (calls close). This is used for debugging purposes only to help catch folks to return closed connections to the pool.


setCheckReturnedConnection

public void setCheckReturnedConnection(boolean value)
If set, instructs the connection to verify its valid when the caller is done with the connection (calls close). This is used for debugging purposes only to help catch folks to return closed connections to the pool.


getIdleCheck

public long getIdleCheck()
Gets the amount of time in milliseconds a connection has been idle before the pool tests the connection to see if its still valid. -1: Never check 0: Always check


setIdleCheck

public void setIdleCheck(long idle)
Sets the amount of time in milliseconds a connection has been idle before the pool tests the connection to see if its still valid. -1: Never check 0: Always check


getIdleCheckSQL

public String getIdleCheckSQL()
Gets a sql statement to be used to check a connection. If not specified, isConnectionClosed() is called instead.


setIdleCheckSQL

public void setIdleCheckSQL(String sql)
Sets a sql statement to be used to check a connection. If not specified, isConnectionClosed() is called instead.


setIsolationLevel

public void setIsolationLevel(Integer isolationLevel)
Sets the transaction isolation level. If null, no specific setting is made on a Connection instance; otherwise, the wrapped value is used.


getIsolationLevel

public Integer getIsolationLevel()

getConnection

public Connection getConnection()
                         throws SQLException
Gets a DB connection, actually a wrapper that allows the connection to be pooled. The method first allocates a connection from the available pool, if there are none available it creates a new connection unless that would put it over the max pool size, in which case it forces the caller to wait. If the data source was configured with a loginTimeout value greater than 0, it will wait for loginTimeout seconds for a connection.

Specified by:
getConnection in interface DataSource
SQLException

getConnection

public Connection getConnection(String userName,
                                String password)
                         throws SQLException
This function is currently not implemented as it doesn't allow us to use the connections in the pool. The workaround is to create a new data source with a different user and password. Should this just pass back an unpooled real connection?

Specified by:
getConnection in interface DataSource
SQLException

getLogWriter

public PrintWriter getLogWriter()
The PooledDataSource class uses JDK 1.4 logging and ignores the log writer.

Specified by:
getLogWriter in interface DataSource

setLogWriter

public void setLogWriter(PrintWriter logger)
Specified by:
setLogWriter in interface DataSource

makeAvailable

protected void makeAvailable(org.xorm.datastore.sql.PooledConnection conn)
Makes the connection available again. This is called by the PooledConnection class when the user chooses to close a connection.


close

public void close()
Releases all available connections.


dropConnection

protected void dropConnection(org.xorm.datastore.sql.PooledConnection conn)
remove a connection from the pool



$Header: /cvsroot/xorm/xorm/docs/api/org/xorm/datastore/sql/PooledDataSource.html,v 1.7 2004/05/30 08:55:06 wbiggs Exp $