com.ibatis.common.jdbc

Class SimpleDataSource

public class SimpleDataSource extends Object implements DataSource

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

REQUIRED PROPERTIES ------------------- JDBC.Driver JDBC.ConnectionURL JDBC.Username JDBC.Password

Pool.MaximumActiveConnections Pool.MaximumIdleConnections Pool.MaximumCheckoutTime Pool.TimeToWait Pool.PingQuery Pool.PingEnabled Pool.PingConnectionsOlderThan Pool.PingConnectionsNotUsedFor Pool.QuietMode

Nested Class Summary
static classSimpleDataSource.SimplePooledConnection
--------------------------------------------------------------------------------------- SimplePooledConnection ---------------------------------------------------------------------------------------
Constructor Summary
SimpleDataSource(Map props)
Constructor to allow passing in a map of properties for configuration
Method Summary
protected voidfinalize()
voidforceCloseAll()
Closes all of the connections in the pool
longgetAverageCheckoutTime()
Getter for the average age of a connection checkout
longgetAverageOverdueCheckoutTime()
Getter for the average age of overdue connections
longgetAverageRequestTime()
Getter for the average time required to get a connection to the database
longgetAverageWaitTime()
Getter for the average time spent waiting for connections that were in use
longgetBadConnectionCount()
Getter for the number of invalid connections that were found in the pool
longgetClaimedOverdueConnectionCount()
Getter for the number of connections that were claimed before they were returned
ConnectiongetConnection()
ConnectiongetConnection(String username, String password)
longgetHadToWaitCount()
Getter for the number of requests that had to wait for connections that were in use
StringgetJdbcDriver()
Getter for the name of the JDBC driver class used
StringgetJdbcPassword()
Getter for the JDBC password used
StringgetJdbcUrl()
Getter of the JDBC URL used
StringgetJdbcUsername()
Getter for the JDBC user name used
intgetLoginTimeout()
PrintWritergetLogWriter()
intgetPoolMaximumActiveConnections()
Getter for the maximum number of active connections
intgetPoolMaximumCheckoutTime()
Getter for the maximum time a connection can be used before it *may* be given away again.
intgetPoolMaximumIdleConnections()
Getter for the maximum number of idle connections
intgetPoolPingConnectionsNotUsedFor()
If a connection has not been used in this many milliseconds, ping the database to make sure the connection is still good.
intgetPoolPingConnectionsOlderThan()
Getter for the age of connections that should be pinged before using
StringgetPoolPingQuery()
Getter for the query to be used to check a connection
intgetPoolTimeToWait()
Getter for the time to wait before retrying to get a connection
longgetRequestCount()
Getter for the number of connection requests made
StringgetStatus()
Returns the status of the connection pool
booleanisPoolPingEnabled()
Getter to tell if we should use the ping query
voidsetLoginTimeout(int loginTimeout)
voidsetLogWriter(PrintWriter logWriter)
static ConnectionunwrapConnection(Connection conn)
Unwraps a pooled connection to get to the 'real' connection

Constructor Detail

SimpleDataSource

public SimpleDataSource(Map props)
Constructor to allow passing in a map of properties for configuration

Parameters: props - the configuration parameters

Method Detail

finalize

protected void finalize()

forceCloseAll

public void forceCloseAll()
Closes all of the connections in the pool

getAverageCheckoutTime

public long getAverageCheckoutTime()
Getter for the average age of a connection checkout

Returns: The average age

getAverageOverdueCheckoutTime

public long getAverageOverdueCheckoutTime()
Getter for the average age of overdue connections

Returns: The average age

getAverageRequestTime

public long getAverageRequestTime()
Getter for the average time required to get a connection to the database

Returns: The average time

getAverageWaitTime

public long getAverageWaitTime()
Getter for the average time spent waiting for connections that were in use

Returns: The average time

getBadConnectionCount

public long getBadConnectionCount()
Getter for the number of invalid connections that were found in the pool

Returns: The number of invalid connections

getClaimedOverdueConnectionCount

public long getClaimedOverdueConnectionCount()
Getter for the number of connections that were claimed before they were returned

Returns: The number of connections

getConnection

public Connection getConnection()

See Also: javax.sql.DataSource#getConnection()

getConnection

public Connection getConnection(String username, String password)

See Also: javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)

getHadToWaitCount

public long getHadToWaitCount()
Getter for the number of requests that had to wait for connections that were in use

Returns: The number of requests that had to wait

getJdbcDriver

public String getJdbcDriver()
Getter for the name of the JDBC driver class used

Returns: The name of the class

getJdbcPassword

public String getJdbcPassword()
Getter for the JDBC password used

Returns: The password

getJdbcUrl

public String getJdbcUrl()
Getter of the JDBC URL used

Returns: The JDBC URL

getJdbcUsername

public String getJdbcUsername()
Getter for the JDBC user name used

Returns: The user name

getLoginTimeout

public int getLoginTimeout()

See Also: javax.sql.DataSource#getLoginTimeout()

getLogWriter

public PrintWriter getLogWriter()

See Also: javax.sql.DataSource#getLogWriter()

getPoolMaximumActiveConnections

public int getPoolMaximumActiveConnections()
Getter for the maximum number of active connections

Returns: The maximum number of active connections

getPoolMaximumCheckoutTime

public int getPoolMaximumCheckoutTime()
Getter for the maximum time a connection can be used before it *may* be given away again.

Returns: The maximum time

getPoolMaximumIdleConnections

public int getPoolMaximumIdleConnections()
Getter for the maximum number of idle connections

Returns: The maximum number of idle connections

getPoolPingConnectionsNotUsedFor

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

Returns: the number of milliseconds of inactivity that will trigger a ping

getPoolPingConnectionsOlderThan

public int getPoolPingConnectionsOlderThan()
Getter for the age of connections that should be pinged before using

Returns: The age

getPoolPingQuery

public String getPoolPingQuery()
Getter for the query to be used to check a connection

Returns: The query

getPoolTimeToWait

public int getPoolTimeToWait()
Getter for the time to wait before retrying to get a connection

Returns: The time to wait

getRequestCount

public long getRequestCount()
Getter for the number of connection requests made

Returns: The number of connection requests made

getStatus

public String getStatus()
Returns the status of the connection pool

Returns: The status

isPoolPingEnabled

public boolean isPoolPingEnabled()
Getter to tell if we should use the ping query

Returns: True if we need to check a connection before using it

setLoginTimeout

public void setLoginTimeout(int loginTimeout)

See Also: javax.sql.DataSource#setLoginTimeout(int)

setLogWriter

public void setLogWriter(PrintWriter logWriter)

See Also: javax.sql.DataSource#setLogWriter(java.io.PrintWriter)

unwrapConnection

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

Parameters: conn - the pooled connection to unwrap

Returns: The 'real' connection

Copyright © 2011. All Rights Reserved.