Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.ibatis.common.jdbc
Class SimpleDataSource  view SimpleDataSource download SimpleDataSource.java

java.lang.Object
  extended bycom.ibatis.common.jdbc.SimpleDataSource
All Implemented Interfaces:
javax.sql.DataSource

public class SimpleDataSource
extends java.lang.Object
implements javax.sql.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
private static class SimpleDataSource.SimplePooledConnection
          --------------------------------------------------------------------------------------- SimplePooledConnection ---------------------------------------------------------------------------------------
 
Field Summary
private  long accumulatedCheckoutTime
           
private  long accumulatedCheckoutTimeOfOverdueConnections
           
private  long accumulatedRequestTime
           
private  long accumulatedWaitTime
           
private  java.util.List activeConnections
           
private static java.lang.String ADD_DRIVER_PROPS_PREFIX
           
private static int ADD_DRIVER_PROPS_PREFIX_LENGTH
           
private  long badConnectionCount
           
private  long claimedOverdueConnectionCount
           
private  java.util.Properties driverProps
           
private  int expectedConnectionTypeCode
           
private  long hadToWaitCount
           
private  java.util.List idleConnections
           
private  boolean jdbcDefaultAutoCommit
           
private  java.lang.String jdbcDriver
           
private  java.lang.String jdbcPassword
           
private  java.lang.String jdbcUrl
           
private  java.lang.String jdbcUsername
           
private static org.apache.commons.logging.Log log
           
private  java.lang.Object POOL_LOCK
           
private  int poolMaximumActiveConnections
           
private  int poolMaximumCheckoutTime
           
private  int poolMaximumIdleConnections
           
private  int poolPingConnectionsNotUsedFor
           
private  int poolPingConnectionsOlderThan
           
private  boolean poolPingEnabled
           
private  java.lang.String poolPingQuery
           
private  int poolTimeToWait
           
private static java.lang.String PROP_JDBC_DEFAULT_AUTOCOMMIT
           
private static java.lang.String PROP_JDBC_DRIVER
           
private static java.lang.String PROP_JDBC_PASSWORD
           
private static java.lang.String PROP_JDBC_URL
           
private static java.lang.String PROP_JDBC_USERNAME
           
private static java.lang.String PROP_POOL_MAX_ACTIVE_CONN
           
private static java.lang.String PROP_POOL_MAX_CHECKOUT_TIME
           
private static java.lang.String PROP_POOL_MAX_IDLE_CONN
           
private static java.lang.String PROP_POOL_PING_CONN_NOT_USED_FOR
           
private static java.lang.String PROP_POOL_PING_CONN_OLDER_THAN
           
private static java.lang.String PROP_POOL_PING_ENABLED
           
private static java.lang.String PROP_POOL_PING_QUERY
           
private static java.lang.String PROP_POOL_TIME_TO_WAIT
           
private  long requestCount
           
private  boolean useDriverProps
           
 
Constructor Summary
SimpleDataSource(java.util.Map props)
          Constructor to allow passing in a map of properties for configuration
 
Method Summary
private  int assembleConnectionTypeCode(java.lang.String url, java.lang.String username, java.lang.String password)
           
protected  void finalize()
          Called on an object by the Virtual Machine at most once, at some point after the Object is determined unreachable but before it is destroyed.
 void forceCloseAll()
          Closes all of the connections in the pool
 long getAverageCheckoutTime()
          Getter for the average age of a connection checkout
 long getAverageOverdueCheckoutTime()
          Getter for the average age of overdue connections
 long getAverageRequestTime()
          Getter for the average time required to get a connection to the database
 long getAverageWaitTime()
          Getter for the average time spent waiting for connections that were in use
 long getBadConnectionCount()
          Getter for the number of invalid connections that were found in the pool
 long getClaimedOverdueConnectionCount()
          Getter for the number of connections that were claimed before they were returned
 java.sql.Connection getConnection()
           
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
           
private  int getExpectedConnectionTypeCode()
           
 long getHadToWaitCount()
          Getter for the number of requests that had to wait for connections that were in use
 java.lang.String getJdbcDriver()
          Getter for the name of the JDBC driver class used
 java.lang.String getJdbcPassword()
          Getter for the JDBC password used
 java.lang.String getJdbcUrl()
          Getter of the JDBC URL used
 java.lang.String getJdbcUsername()
          Getter for the JDBC user name used
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
           
 int getPoolMaximumActiveConnections()
          Getter for the maximum number of active connections
 int getPoolMaximumCheckoutTime()
          Getter for the maximum time a connection can be used before it *may* be given away again.
 int getPoolMaximumIdleConnections()
          Getter for the maximum number of idle connections
 int getPoolPingConnectionsNotUsedFor()
          No idea what this is used for...
 int getPoolPingConnectionsOlderThan()
          Getter for the age of connections that should be pinged before using
 java.lang.String getPoolPingQuery()
          Getter for the query to be used to check a connection
 int getPoolTimeToWait()
          Getter for the time to wait before retrying to get a connection
 long getRequestCount()
          Getter for the number of connection requests made
 java.lang.String getStatus()
          Returns the status of the connection pool
private  void initialize(java.util.Map props)
           
 boolean isPoolPingEnabled()
          Getter to tell if we should use the ping query
private  boolean pingConnection(SimpleDataSource.SimplePooledConnection conn)
          Method to check to see if a connection is still usable
private  SimpleDataSource.SimplePooledConnection popConnection(java.lang.String username, java.lang.String password)
           
private  void pushConnection(SimpleDataSource.SimplePooledConnection conn)
           
 void setLoginTimeout(int loginTimeout)
           
 void setLogWriter(java.io.PrintWriter logWriter)
           
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

log

private static final org.apache.commons.logging.Log log

PROP_JDBC_DRIVER

private static final java.lang.String PROP_JDBC_DRIVER
See Also:
Constant Field Values

PROP_JDBC_URL

private static final java.lang.String PROP_JDBC_URL
See Also:
Constant Field Values

PROP_JDBC_USERNAME

private static final java.lang.String PROP_JDBC_USERNAME
See Also:
Constant Field Values

PROP_JDBC_PASSWORD

private static final java.lang.String PROP_JDBC_PASSWORD
See Also:
Constant Field Values

PROP_JDBC_DEFAULT_AUTOCOMMIT

private static final java.lang.String PROP_JDBC_DEFAULT_AUTOCOMMIT
See Also:
Constant Field Values

PROP_POOL_MAX_ACTIVE_CONN

private static final java.lang.String PROP_POOL_MAX_ACTIVE_CONN
See Also:
Constant Field Values

PROP_POOL_MAX_IDLE_CONN

private static final java.lang.String PROP_POOL_MAX_IDLE_CONN
See Also:
Constant Field Values

PROP_POOL_MAX_CHECKOUT_TIME

private static final java.lang.String PROP_POOL_MAX_CHECKOUT_TIME
See Also:
Constant Field Values

PROP_POOL_TIME_TO_WAIT

private static final java.lang.String PROP_POOL_TIME_TO_WAIT
See Also:
Constant Field Values

PROP_POOL_PING_QUERY

private static final java.lang.String PROP_POOL_PING_QUERY
See Also:
Constant Field Values

PROP_POOL_PING_CONN_OLDER_THAN

private static final java.lang.String PROP_POOL_PING_CONN_OLDER_THAN
See Also:
Constant Field Values

PROP_POOL_PING_ENABLED

private static final java.lang.String PROP_POOL_PING_ENABLED
See Also:
Constant Field Values

PROP_POOL_PING_CONN_NOT_USED_FOR

private static final java.lang.String PROP_POOL_PING_CONN_NOT_USED_FOR
See Also:
Constant Field Values

expectedConnectionTypeCode

private int expectedConnectionTypeCode

ADD_DRIVER_PROPS_PREFIX

private static final java.lang.String ADD_DRIVER_PROPS_PREFIX
See Also:
Constant Field Values

ADD_DRIVER_PROPS_PREFIX_LENGTH

private static final int ADD_DRIVER_PROPS_PREFIX_LENGTH

POOL_LOCK

private final java.lang.Object POOL_LOCK

idleConnections

private java.util.List idleConnections

activeConnections

private java.util.List activeConnections

requestCount

private long requestCount

accumulatedRequestTime

private long accumulatedRequestTime

accumulatedCheckoutTime

private long accumulatedCheckoutTime

claimedOverdueConnectionCount

private long claimedOverdueConnectionCount

accumulatedCheckoutTimeOfOverdueConnections

private long accumulatedCheckoutTimeOfOverdueConnections

accumulatedWaitTime

private long accumulatedWaitTime

hadToWaitCount

private long hadToWaitCount

badConnectionCount

private long badConnectionCount

jdbcDriver

private java.lang.String jdbcDriver

jdbcUrl

private java.lang.String jdbcUrl

jdbcUsername

private java.lang.String jdbcUsername

jdbcPassword

private java.lang.String jdbcPassword

jdbcDefaultAutoCommit

private boolean jdbcDefaultAutoCommit

driverProps

private java.util.Properties driverProps

useDriverProps

private boolean useDriverProps

poolMaximumActiveConnections

private int poolMaximumActiveConnections

poolMaximumIdleConnections

private int poolMaximumIdleConnections

poolMaximumCheckoutTime

private int poolMaximumCheckoutTime

poolTimeToWait

private int poolTimeToWait

poolPingQuery

private java.lang.String poolPingQuery

poolPingEnabled

private boolean poolPingEnabled

poolPingConnectionsOlderThan

private int poolPingConnectionsOlderThan

poolPingConnectionsNotUsedFor

private int poolPingConnectionsNotUsedFor
Constructor Detail

SimpleDataSource

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

Method Detail

initialize

private void initialize(java.util.Map props)

assembleConnectionTypeCode

private int assembleConnectionTypeCode(java.lang.String url,
                                       java.lang.String username,
                                       java.lang.String password)

getConnection

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

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

setLoginTimeout

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

getLoginTimeout

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

setLogWriter

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

getLogWriter

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

getPoolPingConnectionsNotUsedFor

public int getPoolPingConnectionsNotUsedFor()
No idea what this is used for...


getJdbcDriver

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


getJdbcUrl

public java.lang.String getJdbcUrl()
Getter of the JDBC URL used


getJdbcUsername

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


getJdbcPassword

public java.lang.String getJdbcPassword()
Getter for the JDBC password used


getPoolMaximumActiveConnections

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


getPoolMaximumIdleConnections

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


getPoolMaximumCheckoutTime

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


getPoolTimeToWait

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


getPoolPingQuery

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


isPoolPingEnabled

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


getPoolPingConnectionsOlderThan

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


getExpectedConnectionTypeCode

private int getExpectedConnectionTypeCode()

getRequestCount

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


getAverageRequestTime

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


getAverageWaitTime

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


getHadToWaitCount

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


getBadConnectionCount

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


getClaimedOverdueConnectionCount

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


getAverageOverdueCheckoutTime

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


getAverageCheckoutTime

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


getStatus

public java.lang.String getStatus()
Returns the status of the connection pool


forceCloseAll

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


pushConnection

private void pushConnection(SimpleDataSource.SimplePooledConnection conn)
                     throws java.sql.SQLException

popConnection

private SimpleDataSource.SimplePooledConnection popConnection(java.lang.String username,
                                                              java.lang.String password)
                                                       throws java.sql.SQLException

pingConnection

private boolean pingConnection(SimpleDataSource.SimplePooledConnection conn)
Method to check to see if a 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


finalize

protected void finalize()
                 throws java.lang.Throwable
Description copied from class: java.lang.Object
Called on an object by the Virtual Machine at most once, at some point after the Object is determined unreachable but before it is destroyed. You would think that this means it eventually is called on every Object, but this is not necessarily the case. If execution terminates abnormally, garbage collection does not always happen. Thus you cannot rely on this method to always work. For finer control over garbage collection, use references from the java.lang.ref package.

Virtual Machines are free to not call this method if they can determine that it does nothing important; for example, if your class extends Object and overrides finalize to do simply super.finalize().

finalize() will be called by a java.lang.Thread that has no locks on any Objects, and may be called concurrently. There are no guarantees on the order in which multiple objects are finalized. This means that finalize() is usually unsuited for performing actions that must be thread-safe, and that your implementation must be use defensive programming if it is to always work.

If an Exception is thrown from finalize() during garbage collection, it will be patently ignored and the Object will still be destroyed.

It is allowed, although not typical, for user code to call finalize() directly. User invocation does not affect whether automatic invocation will occur. It is also permitted, although not recommended, for a finalize() method to "revive" an object by making it reachable from normal code again.

Unlike constructors, finalize() does not get called for an object's superclass unless the implementation specifically calls super.finalize().

The default implementation does nothing.