org.apache.ibatis.datasource.pooled
Class PooledDataSource

java.lang.Object
  extended by org.apache.ibatis.datasource.pooled.PooledDataSource
All Implemented Interfaces:
java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource

public class PooledDataSource
extends java.lang.Object
implements javax.sql.DataSource

This is a simple, synchronous, thread-safe database connection pool.


Field Summary
protected  int poolMaximumActiveConnections
           
protected  int poolMaximumCheckoutTime
           
protected  int poolMaximumIdleConnections
           
protected  int poolPingConnectionsNotUsedFor
           
protected  boolean poolPingEnabled
           
protected  java.lang.String poolPingQuery
           
protected  int poolTimeToWait
           
 
Constructor Summary
PooledDataSource()
           
PooledDataSource(java.lang.ClassLoader driverClassLoader, java.lang.String driver, java.lang.String url, java.util.Properties driverProperties)
           
PooledDataSource(java.lang.ClassLoader driverClassLoader, java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)
           
PooledDataSource(java.lang.String driver, java.lang.String url, java.util.Properties driverProperties)
           
PooledDataSource(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)
           
 
Method Summary
protected  void finalize()
           
 void forceCloseAll()
          Closes all active and idle connections in the pool
 java.sql.Connection getConnection()
           
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
           
 java.lang.Integer getDefaultTransactionIsolationLevel()
           
 java.lang.String getDriver()
           
 java.util.Properties getDriverProperties()
           
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
           
 java.lang.String getPassword()
           
 int getPoolMaximumActiveConnections()
           
 int getPoolMaximumCheckoutTime()
           
 int getPoolMaximumIdleConnections()
           
 int getPoolPingConnectionsNotUsedFor()
           
 java.lang.String getPoolPingQuery()
           
 PoolState getPoolState()
           
 int getPoolTimeToWait()
           
 java.lang.String getUrl()
           
 java.lang.String getUsername()
           
 boolean isAutoCommit()
           
 boolean isPoolPingEnabled()
           
 boolean isWrapperFor(java.lang.Class<?> iface)
           
protected  boolean pingConnection(org.apache.ibatis.datasource.pooled.PooledConnection conn)
          Method to check to see if a connection is still usable
protected  void pushConnection(org.apache.ibatis.datasource.pooled.PooledConnection conn)
           
 void setDefaultAutoCommit(boolean defaultAutoCommit)
           
 void setDefaultTransactionIsolationLevel(java.lang.Integer defaultTransactionIsolationLevel)
           
 void setDriver(java.lang.String driver)
           
 void setDriverProperties(java.util.Properties driverProps)
           
 void setLoginTimeout(int loginTimeout)
           
 void setLogWriter(java.io.PrintWriter logWriter)
           
 void setPassword(java.lang.String password)
           
 void setPoolMaximumActiveConnections(int poolMaximumActiveConnections)
          The maximum number of active connections
 void setPoolMaximumCheckoutTime(int poolMaximumCheckoutTime)
          The maximum time a connection can be used before it *may* be given away again.
 void setPoolMaximumIdleConnections(int poolMaximumIdleConnections)
          The maximum number of idle connections
 void setPoolPingConnectionsNotUsedFor(int milliseconds)
          If a connection has not been used in this many milliseconds, ping the database to make sure the connection is still good.
 void setPoolPingEnabled(boolean poolPingEnabled)
          Determines if the ping query should be used.
 void setPoolPingQuery(java.lang.String poolPingQuery)
          The query to be used to check a connection
 void setPoolTimeToWait(int poolTimeToWait)
          The time to wait before retrying to get a connection
 void setUrl(java.lang.String url)
           
 void setUsername(java.lang.String username)
           
<T> T
unwrap(java.lang.Class<T> iface)
           
static java.sql.Connection unwrapConnection(java.sql.Connection conn)
          Unwraps a pooled connection to get to the 'real' connection
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

poolMaximumActiveConnections

protected int poolMaximumActiveConnections

poolMaximumIdleConnections

protected int poolMaximumIdleConnections

poolMaximumCheckoutTime

protected int poolMaximumCheckoutTime

poolTimeToWait

protected int poolTimeToWait

poolPingQuery

protected java.lang.String poolPingQuery

poolPingEnabled

protected boolean poolPingEnabled

poolPingConnectionsNotUsedFor

protected int poolPingConnectionsNotUsedFor
Constructor Detail

PooledDataSource

public PooledDataSource()

PooledDataSource

public PooledDataSource(java.lang.String driver,
                        java.lang.String url,
                        java.lang.String username,
                        java.lang.String password)

PooledDataSource

public PooledDataSource(java.lang.String driver,
                        java.lang.String url,
                        java.util.Properties driverProperties)

PooledDataSource

public PooledDataSource(java.lang.ClassLoader driverClassLoader,
                        java.lang.String driver,
                        java.lang.String url,
                        java.lang.String username,
                        java.lang.String password)

PooledDataSource

public PooledDataSource(java.lang.ClassLoader driverClassLoader,
                        java.lang.String driver,
                        java.lang.String url,
                        java.util.Properties driverProperties)
Method Detail

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 username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

setLoginTimeout

public void setLoginTimeout(int loginTimeout)
                     throws java.sql.SQLException
Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLogWriter

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

getLogWriter

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

setDriver

public void setDriver(java.lang.String driver)

setUrl

public void setUrl(java.lang.String url)

setUsername

public void setUsername(java.lang.String username)

setPassword

public void setPassword(java.lang.String password)

setDefaultAutoCommit

public void setDefaultAutoCommit(boolean defaultAutoCommit)

setDefaultTransactionIsolationLevel

public void setDefaultTransactionIsolationLevel(java.lang.Integer defaultTransactionIsolationLevel)

setDriverProperties

public void setDriverProperties(java.util.Properties driverProps)

setPoolMaximumActiveConnections

public void setPoolMaximumActiveConnections(int poolMaximumActiveConnections)
The maximum number of active connections

Parameters:
poolMaximumActiveConnections - The maximum number of active connections

setPoolMaximumIdleConnections

public void setPoolMaximumIdleConnections(int poolMaximumIdleConnections)
The maximum number of idle connections

Parameters:
poolMaximumIdleConnections - The maximum number of idle connections

setPoolMaximumCheckoutTime

public void setPoolMaximumCheckoutTime(int poolMaximumCheckoutTime)
The maximum time a connection can be used before it *may* be given away again.

Parameters:
poolMaximumCheckoutTime - The maximum time

setPoolTimeToWait

public void setPoolTimeToWait(int poolTimeToWait)
The time to wait before retrying to get a connection

Parameters:
poolTimeToWait - The time to wait

setPoolPingQuery

public void setPoolPingQuery(java.lang.String poolPingQuery)
The query to be used to check a connection

Parameters:
poolPingQuery - The query

setPoolPingEnabled

public void setPoolPingEnabled(boolean poolPingEnabled)
Determines if the ping query should be used.

Parameters:
poolPingEnabled - True if we need to check a connection before using it

setPoolPingConnectionsNotUsedFor

public void setPoolPingConnectionsNotUsedFor(int milliseconds)
If a connection has not been used in this many milliseconds, ping the database to make sure the connection is still good.

Parameters:
milliseconds - the number of milliseconds of inactivity that will trigger a ping

getDriver

public java.lang.String getDriver()

getUrl

public java.lang.String getUrl()

getUsername

public java.lang.String getUsername()

getPassword

public java.lang.String getPassword()

isAutoCommit

public boolean isAutoCommit()

getDefaultTransactionIsolationLevel

public java.lang.Integer getDefaultTransactionIsolationLevel()

getDriverProperties

public java.util.Properties getDriverProperties()

getPoolMaximumActiveConnections

public int getPoolMaximumActiveConnections()

getPoolMaximumIdleConnections

public int getPoolMaximumIdleConnections()

getPoolMaximumCheckoutTime

public int getPoolMaximumCheckoutTime()

getPoolTimeToWait

public int getPoolTimeToWait()

getPoolPingQuery

public java.lang.String getPoolPingQuery()

isPoolPingEnabled

public boolean isPoolPingEnabled()

getPoolPingConnectionsNotUsedFor

public int getPoolPingConnectionsNotUsedFor()

forceCloseAll

public void forceCloseAll()
Closes all active and idle connections in the pool


getPoolState

public PoolState getPoolState()

pushConnection

protected void pushConnection(org.apache.ibatis.datasource.pooled.PooledConnection conn)
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

pingConnection

protected boolean pingConnection(org.apache.ibatis.datasource.pooled.PooledConnection conn)
Method to check to see if a connection is still usable

Parameters:
conn - - the connection to check
Returns:
True if the connection is still usable

unwrapConnection

public static java.sql.Connection unwrapConnection(java.sql.Connection conn)
Unwraps a pooled connection to get to the 'real' connection

Parameters:
conn - - the pooled connection to unwrap
Returns:
The 'real' connection

finalize

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

unwrap

public <T> T unwrap(java.lang.Class<T> iface)
         throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> iface)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException


Copyright © 2010 MyBatis.org. All Rights Reserved.