Package com.ibatis.common.jdbc
Class SimpleDataSource
java.lang.Object
com.ibatis.common.jdbc.SimpleDataSource
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,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
Nested ClassesModifier and TypeClassDescriptionstatic class
--------------------------------------------------------------------------------------- SimplePooledConnection ---------------------------------------------------------------------------------------. -
Constructor Summary
ConstructorsConstructorDescriptionSimpleDataSource
(Map props) Constructor to allow passing in a map of properties for configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
finalize()
void
Closes all of the connections in the pool.long
Getter for the average age of a connection checkout.long
Getter for the average age of overdue connections.long
Getter for the average time required to get a connection to the database.long
Getter for the average time spent waiting for connections that were in use.long
Getter for the number of invalid connections that were found in the pool.long
Getter for the number of connections that were claimed before they were returned.getConnection
(String username, String password) long
Getter for the number of requests that had to wait for connections that were in use.Getter for the name of the JDBC driver class used.Getter for the JDBC password used.Getter of the JDBC URL used.Getter for the JDBC user name used.int
int
Getter for the maximum number of active connections.int
Getter for the maximum time a connection can be used before it *may* be given away again.int
Getter for the maximum number of idle connections.int
If a connection has not been used in this many milliseconds, ping the database to make sure the connection is still good.int
Getter for the age of connections that should be pinged before using.Getter for the query to be used to check a connection.int
Getter for the time to wait before retrying to get a connection.long
Getter for the number of connection requests made.Returns the status of the connection pool.boolean
Getter to tell if we should use the ping query.boolean
isWrapperFor
(Class<?> iface) void
setLoginTimeout
(int loginTimeout) void
setLogWriter
(PrintWriter logWriter) <T> T
static Connection
unwrapConnection
(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
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Constructor Details
-
SimpleDataSource
Constructor to allow passing in a map of properties for configuration.- Parameters:
props
- - the configuration parameters
-
-
Method Details
-
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
setLoginTimeout
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getLoginTimeout
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
setLogWriter
- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getLogWriter
- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
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
Getter for the name of the JDBC driver class used.- Returns:
- The name of the class
-
getJdbcUrl
-
getJdbcUsername
-
getJdbcPassword
-
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
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
-
forceCloseAll
public void forceCloseAll()Closes all of the connections in the pool. -
unwrapConnection
Unwraps a pooled connection to get to the 'real' connection.- Parameters:
conn
- - the pooled connection to unwrap- Returns:
- The 'real' connection
-
finalize
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-