Class PooledDataSource
java.lang.Object
org.apache.ibatis.datasource.pooled.PooledDataSource
- All Implemented Interfaces:
Wrapper,CommonDataSource,DataSource
This is a simple, synchronous, thread-safe database connection pool.
- Author:
- Clinton Begin
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected intprotected intprotected intprotected booleanprotected Stringprotected int -
Constructor Summary
ConstructorsConstructorDescriptionPooledDataSource(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
Modifier and TypeMethodDescriptionprotected voidfinalize()voidCloses all active and idle connections in the pool.getConnection(String username, String password) Gets the default network timeout.intintintintintintintgetUrl()booleanbooleanbooleanisWrapperFor(Class<?> iface) protected booleanpingConnection(org.apache.ibatis.datasource.pooled.PooledConnection conn) Method to check to see if a connection is still usableprotected voidpushConnection(org.apache.ibatis.datasource.pooled.PooledConnection conn) voidsetDefaultAutoCommit(boolean defaultAutoCommit) voidsetDefaultNetworkTimeout(Integer milliseconds) Sets the default network timeout value to wait for the database operation to complete.voidsetDefaultTransactionIsolationLevel(Integer defaultTransactionIsolationLevel) voidvoidsetDriverProperties(Properties driverProps) voidsetLoginTimeout(int loginTimeout) voidsetLogWriter(PrintWriter logWriter) voidsetPassword(String password) voidsetPoolMaximumActiveConnections(int poolMaximumActiveConnections) The maximum number of active connections.voidsetPoolMaximumCheckoutTime(int poolMaximumCheckoutTime) The maximum time a connection can be used before it *may* be given away again.voidsetPoolMaximumIdleConnections(int poolMaximumIdleConnections) The maximum number of idle connections.voidsetPoolMaximumLocalBadConnectionTolerance(int poolMaximumLocalBadConnectionTolerance) The maximum number of tolerance for bad connection happens in one thread which are applying for newPooledConnection.voidsetPoolPingConnectionsNotUsedFor(int milliseconds) If a connection has not been used in this many milliseconds, ping the database to make sure the connection is still good.voidsetPoolPingEnabled(boolean poolPingEnabled) Determines if the ping query should be used.voidsetPoolPingQuery(String poolPingQuery) The query to be used to check a connection.voidsetPoolTimeToWait(int poolTimeToWait) The time to wait before retrying to get a connection.voidvoidsetUsername(String username) <T> Tstatic ConnectionunwrapConnection(Connection conn) Unwraps a pooled connection to get to the 'real' connectionMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Field Details
-
poolMaximumActiveConnections
protected int poolMaximumActiveConnections -
poolMaximumIdleConnections
protected int poolMaximumIdleConnections -
poolMaximumCheckoutTime
protected int poolMaximumCheckoutTime -
poolTimeToWait
protected int poolTimeToWait -
poolMaximumLocalBadConnectionTolerance
protected int poolMaximumLocalBadConnectionTolerance -
poolPingQuery
-
poolPingEnabled
protected boolean poolPingEnabled -
poolPingConnectionsNotUsedFor
protected int poolPingConnectionsNotUsedFor
-
-
Constructor Details
-
PooledDataSource
public PooledDataSource() -
PooledDataSource
-
PooledDataSource
-
PooledDataSource
-
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 Details
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
setLoginTimeout
public void setLoginTimeout(int loginTimeout) - Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource
-
getLoginTimeout
public int getLoginTimeout()- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource
-
setLogWriter
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource
-
getLogWriter
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource
-
setDriver
-
setUrl
-
setUsername
-
setPassword
-
setDefaultAutoCommit
public void setDefaultAutoCommit(boolean defaultAutoCommit) -
setDefaultTransactionIsolationLevel
-
setDriverProperties
-
setDefaultNetworkTimeout
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
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
-
getUrl
-
getUsername
-
getPassword
-
isAutoCommit
public boolean isAutoCommit() -
getDefaultTransactionIsolationLevel
-
getDriverProperties
-
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
-
isPoolPingEnabled
public boolean isPoolPingEnabled() -
getPoolPingConnectionsNotUsedFor
public int getPoolPingConnectionsNotUsedFor() -
forceCloseAll
public void forceCloseAll()Closes all active and idle connections in the pool. -
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
Unwraps a pooled connection to get to the 'real' connection- Parameters:
conn- - the pooled connection to unwrap- Returns:
- The 'real' connection
-
finalize
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource
-