com.ibatis.common.jdbc
Class SimpleDataSource

java.lang.Object
  extended by com.ibatis.common.jdbc.SimpleDataSource
All Implemented Interfaces:
java.sql.Wrapper, javax.sql.CommonDataSource, 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
static class SimpleDataSource.SimplePooledConnection
          --------------------------------------------------------------------------------------- SimplePooledConnection ---------------------------------------------------------------------------------------
 
Constructor Summary
SimpleDataSource(java.util.Map props)
          Constructor to allow passing in a map of properties for configuration
 
Method Summary
protected  void finalize()
           
 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)
           
 long getHadToWaitCount()
          Getter for the number of requests that had to wait for connections that were in use
 int getHoldability()
           
 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()
           
 java.io.Reader getNCharacterStream(int columnIndex)
           
 java.io.Reader getNCharacterStream(java.lang.String columnLabel)
           
 java.sql.NClob getNClob(int columnIndex)
           
 java.sql.NClob getNClob(java.lang.String columnLabel)
           
 java.lang.String getNString(int columnIndex)
           
 java.lang.String getNString(java.lang.String columnLabel)
           
 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()
          If a connection has not been used in this many milliseconds, ping the database to make sure the connection is still good.
 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.sql.RowId getRowId(int columnIndex)
           
 java.sql.RowId getRowId(java.lang.String columnLabel)
           
 java.sql.SQLXML getSQLXML(int columnIndex)
           
 java.sql.SQLXML getSQLXML(java.lang.String columnLabel)
           
 java.lang.String getStatus()
          Returns the status of the connection pool
 boolean isClosed()
           
 boolean isPoolPingEnabled()
          Getter to tell if we should use the ping query
 boolean isWrapperFor(java.lang.Class arg0)
           
 void setLoginTimeout(int loginTimeout)
           
 void setLogWriter(java.io.PrintWriter logWriter)
           
 java.lang.Object unwrap(java.lang.Class arg0)
           
static java.sql.Connection unwrapConnection(java.sql.Connection conn)
          Unwraps a pooled connection to get to the 'real' connection
 void updateAsciiStream(int columnIndex, java.io.InputStream x)
           
 void updateAsciiStream(int columnIndex, java.io.InputStream x, long length)
           
 void updateAsciiStream(java.lang.String columnLabel, java.io.InputStream x)
           
 void updateAsciiStream(java.lang.String columnLabel, java.io.InputStream x, long length)
           
 void updateBinaryStream(int columnIndex, java.io.InputStream x)
           
 void updateBinaryStream(int columnIndex, java.io.InputStream x, long length)
           
 void updateBinaryStream(java.lang.String columnLabel, java.io.InputStream x)
           
 void updateBinaryStream(java.lang.String columnLabel, java.io.InputStream x, long length)
           
 void updateBlob(int columnIndex, java.io.InputStream inputStream)
           
 void updateBlob(int columnIndex, java.io.InputStream inputStream, long length)
           
 void updateBlob(java.lang.String columnLabel, java.io.InputStream inputStream)
           
 void updateBlob(java.lang.String columnLabel, java.io.InputStream inputStream, long length)
           
 void updateCharacterStream(int columnIndex, java.io.Reader x)
           
 void updateCharacterStream(int columnIndex, java.io.Reader x, long length)
           
 void updateCharacterStream(java.lang.String columnLabel, java.io.Reader reader)
           
 void updateCharacterStream(java.lang.String columnLabel, java.io.Reader reader, long length)
           
 void updateClob(int columnIndex, java.io.Reader reader)
           
 void updateClob(int columnIndex, java.io.Reader reader, long length)
           
 void updateClob(java.lang.String columnLabel, java.io.Reader reader)
           
 void updateClob(java.lang.String columnLabel, java.io.Reader reader, long length)
           
 void updateNCharacterStream(int columnIndex, java.io.Reader x)
           
 void updateNCharacterStream(int columnIndex, java.io.Reader x, long length)
           
 void updateNCharacterStream(java.lang.String columnLabel, java.io.Reader reader)
           
 void updateNCharacterStream(java.lang.String columnLabel, java.io.Reader reader, long length)
           
 void updateNClob(int columnIndex, java.sql.NClob clob)
           
 void updateNClob(int columnIndex, java.io.Reader reader)
           
 void updateNClob(int columnIndex, java.io.Reader reader, long length)
           
 void updateNClob(java.lang.String columnLabel, java.sql.NClob clob)
           
 void updateNClob(java.lang.String columnLabel, java.io.Reader reader)
           
 void updateNClob(java.lang.String columnLabel, java.io.Reader reader, long length)
           
 void updateNString(int columnIndex, java.lang.String string)
           
 void updateNString(java.lang.String columnLabel, java.lang.String string)
           
 void updateRowId(int columnIndex, java.sql.RowId x)
           
 void updateRowId(java.lang.String columnLabel, java.sql.RowId x)
           
 void updateSQLXML(int columnIndex, java.sql.SQLXML xmlObject)
           
 void updateSQLXML(java.lang.String columnLabel, java.sql.SQLXML xmlObject)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleDataSource

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

Parameters:
props - - the configuration parameters
Method Detail

getConnection

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

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
See Also:
DataSource.getConnection(java.lang.String, java.lang.String)

setLoginTimeout

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

getLoginTimeout

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

setLogWriter

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

getLogWriter

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

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

getJdbcDriver

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

Returns:
The name of the class

getJdbcUrl

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

Returns:
The JDBC URL

getJdbcUsername

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

Returns:
The user name

getJdbcPassword

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

Returns:
The password

getPoolMaximumActiveConnections

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

Returns:
The maximum number of active connections

getPoolMaximumIdleConnections

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

Returns:
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.

Returns:
The maximum time

getPoolTimeToWait

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

Returns:
The time to wait

getPoolPingQuery

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

Returns:
The query

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

getPoolPingConnectionsOlderThan

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

Returns:
The age

getRequestCount

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

Returns:
The number of connection requests made

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

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

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

getAverageOverdueCheckoutTime

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

Returns:
The average age

getAverageCheckoutTime

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

Returns:
The average age

getStatus

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

Returns:
The status

forceCloseAll

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


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

getHoldability

public int getHoldability()
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getNCharacterStream

public java.io.Reader getNCharacterStream(int columnIndex)
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getNCharacterStream

public java.io.Reader getNCharacterStream(java.lang.String columnLabel)
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getNClob

public java.sql.NClob getNClob(int columnIndex)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

getNClob

public java.sql.NClob getNClob(java.lang.String columnLabel)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

getNString

public java.lang.String getNString(int columnIndex)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

getNString

public java.lang.String getNString(java.lang.String columnLabel)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

getRowId

public java.sql.RowId getRowId(int columnIndex)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

getRowId

public java.sql.RowId getRowId(java.lang.String columnLabel)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

getSQLXML

public java.sql.SQLXML getSQLXML(int columnIndex)
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

getSQLXML

public java.sql.SQLXML getSQLXML(java.lang.String columnLabel)
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

updateAsciiStream

public void updateAsciiStream(int columnIndex,
                              java.io.InputStream x,
                              long length)
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

updateAsciiStream

public void updateAsciiStream(int columnIndex,
                              java.io.InputStream x)
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

updateAsciiStream

public void updateAsciiStream(java.lang.String columnLabel,
                              java.io.InputStream x,
                              long length)
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

updateAsciiStream

public void updateAsciiStream(java.lang.String columnLabel,
                              java.io.InputStream x)
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

updateBinaryStream

public void updateBinaryStream(int columnIndex,
                               java.io.InputStream x,
                               long length)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

updateBinaryStream

public void updateBinaryStream(int columnIndex,
                               java.io.InputStream x)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

updateBinaryStream

public void updateBinaryStream(java.lang.String columnLabel,
                               java.io.InputStream x,
                               long length)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

updateBinaryStream

public void updateBinaryStream(java.lang.String columnLabel,
                               java.io.InputStream x)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

updateBlob

public void updateBlob(int columnIndex,
                       java.io.InputStream inputStream,
                       long length)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

updateBlob

public void updateBlob(int columnIndex,
                       java.io.InputStream inputStream)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

updateBlob

public void updateBlob(java.lang.String columnLabel,
                       java.io.InputStream inputStream,
                       long length)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

updateBlob

public void updateBlob(java.lang.String columnLabel,
                       java.io.InputStream inputStream)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

updateCharacterStream

public void updateCharacterStream(int columnIndex,
                                  java.io.Reader x,
                                  long length)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

updateCharacterStream

public void updateCharacterStream(int columnIndex,
                                  java.io.Reader x)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

updateCharacterStream

public void updateCharacterStream(java.lang.String columnLabel,
                                  java.io.Reader reader,
                                  long length)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

updateCharacterStream

public void updateCharacterStream(java.lang.String columnLabel,
                                  java.io.Reader reader)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

updateClob

public void updateClob(int columnIndex,
                       java.io.Reader reader,
                       long length)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

updateClob

public void updateClob(int columnIndex,
                       java.io.Reader reader)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

updateClob

public void updateClob(java.lang.String columnLabel,
                       java.io.Reader reader,
                       long length)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

updateClob

public void updateClob(java.lang.String columnLabel,
                       java.io.Reader reader)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNCharacterStream

public void updateNCharacterStream(int columnIndex,
                                   java.io.Reader x,
                                   long length)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNCharacterStream

public void updateNCharacterStream(int columnIndex,
                                   java.io.Reader x)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNCharacterStream

public void updateNCharacterStream(java.lang.String columnLabel,
                                   java.io.Reader reader,
                                   long length)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNCharacterStream

public void updateNCharacterStream(java.lang.String columnLabel,
                                   java.io.Reader reader)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNClob

public void updateNClob(int columnIndex,
                        java.sql.NClob clob)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNClob

public void updateNClob(int columnIndex,
                        java.io.Reader reader,
                        long length)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNClob

public void updateNClob(int columnIndex,
                        java.io.Reader reader)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNClob

public void updateNClob(java.lang.String columnLabel,
                        java.sql.NClob clob)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNClob

public void updateNClob(java.lang.String columnLabel,
                        java.io.Reader reader,
                        long length)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNClob

public void updateNClob(java.lang.String columnLabel,
                        java.io.Reader reader)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNString

public void updateNString(int columnIndex,
                          java.lang.String string)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNString

public void updateNString(java.lang.String columnLabel,
                          java.lang.String string)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

updateRowId

public void updateRowId(int columnIndex,
                        java.sql.RowId x)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

updateRowId

public void updateRowId(java.lang.String columnLabel,
                        java.sql.RowId x)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

updateSQLXML

public void updateSQLXML(int columnIndex,
                         java.sql.SQLXML xmlObject)
                  throws java.sql.SQLException
Throws:
java.sql.SQLException

updateSQLXML

public void updateSQLXML(java.lang.String columnLabel,
                         java.sql.SQLXML xmlObject)
                  throws java.sql.SQLException
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class arg0)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException

unwrap

public java.lang.Object unwrap(java.lang.Class arg0)
                        throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException