Class PooledDataSource
- java.lang.Object
-
- org.apache.ibatis.datasource.pooled.PooledDataSource
-
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,DataSource
public class PooledDataSource extends Object implements DataSource
This is a simple, synchronous, thread-safe database connection pool.- Author:
- Clinton Begin
-
-
Field Summary
Fields Modifier and Type Field Description protected int
poolMaximumActiveConnections
protected int
poolMaximumCheckoutTime
protected int
poolMaximumIdleConnections
protected int
poolMaximumLocalBadConnectionTolerance
protected int
poolPingConnectionsNotUsedFor
protected boolean
poolPingEnabled
protected String
poolPingQuery
protected int
poolTimeToWait
-
Constructor Summary
Constructors Constructor Description PooledDataSource()
PooledDataSource(ClassLoader driverClassLoader, String driver, String url, String username, String password)
PooledDataSource(ClassLoader driverClassLoader, String driver, String url, Properties driverProperties)
PooledDataSource(String driver, String url, String username, String password)
PooledDataSource(String driver, String url, Properties driverProperties)
PooledDataSource(UnpooledDataSource dataSource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
finalize()
void
forceCloseAll()
Closes all active and idle connections in the pool.Connection
getConnection()
Connection
getConnection(String username, String password)
Integer
getDefaultNetworkTimeout()
Gets the default network timeout.Integer
getDefaultTransactionIsolationLevel()
String
getDriver()
Properties
getDriverProperties()
int
getLoginTimeout()
PrintWriter
getLogWriter()
Logger
getParentLogger()
String
getPassword()
int
getPoolMaximumActiveConnections()
int
getPoolMaximumCheckoutTime()
int
getPoolMaximumIdleConnections()
int
getPoolMaximumLocalBadConnectionTolerance()
int
getPoolPingConnectionsNotUsedFor()
String
getPoolPingQuery()
PoolState
getPoolState()
int
getPoolTimeToWait()
String
getUrl()
String
getUsername()
boolean
isAutoCommit()
boolean
isPoolPingEnabled()
boolean
isWrapperFor(Class<?> iface)
protected boolean
pingConnection(org.apache.ibatis.datasource.pooled.PooledConnection conn)
Method to check to see if a connection is still usableprotected void
pushConnection(org.apache.ibatis.datasource.pooled.PooledConnection conn)
void
setDefaultAutoCommit(boolean defaultAutoCommit)
void
setDefaultNetworkTimeout(Integer milliseconds)
Sets the default network timeout value to wait for the database operation to complete.void
setDefaultTransactionIsolationLevel(Integer defaultTransactionIsolationLevel)
void
setDriver(String driver)
void
setDriverProperties(Properties driverProps)
void
setLoginTimeout(int loginTimeout)
void
setLogWriter(PrintWriter logWriter)
void
setPassword(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
setPoolMaximumLocalBadConnectionTolerance(int poolMaximumLocalBadConnectionTolerance)
The maximum number of tolerance for bad connection happens in one thread which are applying for newPooledConnection
.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(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(String url)
void
setUsername(String username)
<T> T
unwrap(Class<T> iface)
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
-
-
-
-
Field Detail
-
poolMaximumActiveConnections
protected int poolMaximumActiveConnections
-
poolMaximumIdleConnections
protected int poolMaximumIdleConnections
-
poolMaximumCheckoutTime
protected int poolMaximumCheckoutTime
-
poolTimeToWait
protected int poolTimeToWait
-
poolMaximumLocalBadConnectionTolerance
protected int poolMaximumLocalBadConnectionTolerance
-
poolPingQuery
protected String poolPingQuery
-
poolPingEnabled
protected boolean poolPingEnabled
-
poolPingConnectionsNotUsedFor
protected int poolPingConnectionsNotUsedFor
-
-
Constructor Detail
-
PooledDataSource
public PooledDataSource()
-
PooledDataSource
public PooledDataSource(UnpooledDataSource dataSource)
-
PooledDataSource
public PooledDataSource(String driver, String url, String username, String password)
-
PooledDataSource
public PooledDataSource(String driver, String url, Properties driverProperties)
-
PooledDataSource
public PooledDataSource(ClassLoader driverClassLoader, String driver, String url, String username, String password)
-
PooledDataSource
public PooledDataSource(ClassLoader driverClassLoader, String driver, String url, Properties driverProperties)
-
-
Method Detail
-
getConnection
public Connection getConnection() throws SQLException
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getConnection
public Connection getConnection(String username, String password) throws SQLException
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
setLoginTimeout
public void setLoginTimeout(int loginTimeout)
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
-
getLoginTimeout
public int getLoginTimeout()
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
-
setLogWriter
public void setLogWriter(PrintWriter logWriter)
- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
-
getLogWriter
public PrintWriter getLogWriter()
- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
-
setDriver
public void setDriver(String driver)
-
setUrl
public void setUrl(String url)
-
setUsername
public void setUsername(String username)
-
setPassword
public void setPassword(String password)
-
setDefaultAutoCommit
public void setDefaultAutoCommit(boolean defaultAutoCommit)
-
setDefaultTransactionIsolationLevel
public void setDefaultTransactionIsolationLevel(Integer defaultTransactionIsolationLevel)
-
setDriverProperties
public void setDriverProperties(Properties driverProps)
-
setDefaultNetworkTimeout
public void setDefaultNetworkTimeout(Integer milliseconds)
Sets the default network timeout value to wait for the database operation to complete. SeeConnection.setNetworkTimeout(java.util.concurrent.Executor, int)
- Parameters:
milliseconds
- The time in milliseconds to wait for the database operation to complete.- Since:
- 3.5.2
-
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
-
setPoolMaximumLocalBadConnectionTolerance
public void setPoolMaximumLocalBadConnectionTolerance(int poolMaximumLocalBadConnectionTolerance)
The maximum number of tolerance for bad connection happens in one thread which are applying for newPooledConnection
.- Parameters:
poolMaximumLocalBadConnectionTolerance
- max tolerance for bad connection happens in one thread- Since:
- 3.4.5
-
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(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 String getDriver()
-
getUrl
public String getUrl()
-
getUsername
public String getUsername()
-
getPassword
public String getPassword()
-
isAutoCommit
public boolean isAutoCommit()
-
getDefaultTransactionIsolationLevel
public Integer getDefaultTransactionIsolationLevel()
-
getDriverProperties
public Properties getDriverProperties()
-
getDefaultNetworkTimeout
public Integer getDefaultNetworkTimeout()
Gets the default network timeout.- Returns:
- the default network timeout
- Since:
- 3.5.2
-
getPoolMaximumActiveConnections
public int getPoolMaximumActiveConnections()
-
getPoolMaximumIdleConnections
public int getPoolMaximumIdleConnections()
-
getPoolMaximumLocalBadConnectionTolerance
public int getPoolMaximumLocalBadConnectionTolerance()
-
getPoolMaximumCheckoutTime
public int getPoolMaximumCheckoutTime()
-
getPoolTimeToWait
public int getPoolTimeToWait()
-
getPoolPingQuery
public 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 SQLException
- Throws:
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 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
-
finalize
protected void finalize() throws Throwable
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface)
- Specified by:
isWrapperFor
in interfaceWrapper
-
getParentLogger
public Logger getParentLogger()
- Specified by:
getParentLogger
in interfaceCommonDataSource
-
-