Class PooledDataSource
- java.lang.Object
- 
- org.apache.ibatis.datasource.pooled.PooledDataSource
 
- 
- All Implemented Interfaces:
- java.sql.Wrapper,- javax.sql.CommonDataSource,- javax.sql.DataSource
 
 public class PooledDataSource extends java.lang.Object implements javax.sql.DataSourceThis is a simple, synchronous, thread-safe database connection pool.- Author:
- Clinton Begin
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected intpoolMaximumActiveConnectionsprotected intpoolMaximumCheckoutTimeprotected intpoolMaximumIdleConnectionsprotected intpoolMaximumLocalBadConnectionToleranceprotected intpoolPingConnectionsNotUsedForprotected booleanpoolPingEnabledprotected java.lang.StringpoolPingQueryprotected intpoolTimeToWait
 - 
Constructor SummaryConstructors Constructor Description PooledDataSource()PooledDataSource(java.lang.ClassLoader driverClassLoader, java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)PooledDataSource(java.lang.ClassLoader driverClassLoader, java.lang.String driver, java.lang.String url, java.util.Properties driverProperties)PooledDataSource(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)PooledDataSource(java.lang.String driver, java.lang.String url, java.util.Properties driverProperties)PooledDataSource(UnpooledDataSource dataSource)
 - 
Method SummaryModifier and Type Method Description protected voidfinalize()voidforceCloseAll()Closes all active and idle connections in the pool.java.sql.ConnectiongetConnection()java.sql.ConnectiongetConnection(java.lang.String username, java.lang.String password)java.lang.IntegergetDefaultNetworkTimeout()java.lang.IntegergetDefaultTransactionIsolationLevel()java.lang.StringgetDriver()java.util.PropertiesgetDriverProperties()intgetLoginTimeout()java.io.PrintWritergetLogWriter()java.util.logging.LoggergetParentLogger()java.lang.StringgetPassword()intgetPoolMaximumActiveConnections()intgetPoolMaximumCheckoutTime()intgetPoolMaximumIdleConnections()intgetPoolMaximumLocalBadConnectionTolerance()intgetPoolPingConnectionsNotUsedFor()java.lang.StringgetPoolPingQuery()PoolStategetPoolState()intgetPoolTimeToWait()java.lang.StringgetUrl()java.lang.StringgetUsername()booleanisAutoCommit()booleanisPoolPingEnabled()booleanisWrapperFor(java.lang.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(java.lang.Integer milliseconds)Sets the default network timeout value to wait for the database operation to complete.voidsetDefaultTransactionIsolationLevel(java.lang.Integer defaultTransactionIsolationLevel)voidsetDriver(java.lang.String driver)voidsetDriverProperties(java.util.Properties driverProps)voidsetLoginTimeout(int loginTimeout)voidsetLogWriter(java.io.PrintWriter logWriter)voidsetPassword(java.lang.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(java.lang.String poolPingQuery)The query to be used to check a connection.voidsetPoolTimeToWait(int poolTimeToWait)The time to wait before retrying to get a connection.voidsetUrl(java.lang.String url)voidsetUsername(java.lang.String username)<T> Tunwrap(java.lang.Class<T> iface)static java.sql.ConnectionunwrapConnection(java.sql.Connection conn)Unwraps a pooled connection to get to the 'real' connection
 
- 
- 
- 
Field Detail- 
poolMaximumActiveConnectionsprotected int poolMaximumActiveConnections 
 - 
poolMaximumIdleConnectionsprotected int poolMaximumIdleConnections 
 - 
poolMaximumCheckoutTimeprotected int poolMaximumCheckoutTime 
 - 
poolTimeToWaitprotected int poolTimeToWait 
 - 
poolMaximumLocalBadConnectionToleranceprotected int poolMaximumLocalBadConnectionTolerance 
 - 
poolPingQueryprotected java.lang.String poolPingQuery 
 - 
poolPingEnabledprotected boolean poolPingEnabled 
 - 
poolPingConnectionsNotUsedForprotected int poolPingConnectionsNotUsedFor 
 
- 
 - 
Constructor Detail- 
PooledDataSourcepublic PooledDataSource() 
 - 
PooledDataSourcepublic PooledDataSource(UnpooledDataSource dataSource) 
 - 
PooledDataSourcepublic PooledDataSource(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)
 - 
PooledDataSourcepublic PooledDataSource(java.lang.String driver, java.lang.String url, java.util.Properties driverProperties)
 - 
PooledDataSourcepublic PooledDataSource(java.lang.ClassLoader driverClassLoader, java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)
 - 
PooledDataSourcepublic PooledDataSource(java.lang.ClassLoader driverClassLoader, java.lang.String driver, java.lang.String url, java.util.Properties driverProperties)
 
- 
 - 
Method Detail- 
getConnectionpublic java.sql.Connection getConnection() throws java.sql.SQLException- Specified by:
- getConnectionin interface- javax.sql.DataSource
- Throws:
- java.sql.SQLException
 
 - 
getConnectionpublic java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException- Specified by:
- getConnectionin interface- javax.sql.DataSource
- Throws:
- java.sql.SQLException
 
 - 
setLoginTimeoutpublic void setLoginTimeout(int loginTimeout) - Specified by:
- setLoginTimeoutin interface- javax.sql.CommonDataSource
- Specified by:
- setLoginTimeoutin interface- javax.sql.DataSource
 
 - 
getLoginTimeoutpublic int getLoginTimeout() - Specified by:
- getLoginTimeoutin interface- javax.sql.CommonDataSource
- Specified by:
- getLoginTimeoutin interface- javax.sql.DataSource
 
 - 
setLogWriterpublic void setLogWriter(java.io.PrintWriter logWriter) - Specified by:
- setLogWriterin interface- javax.sql.CommonDataSource
- Specified by:
- setLogWriterin interface- javax.sql.DataSource
 
 - 
getLogWriterpublic java.io.PrintWriter getLogWriter() - Specified by:
- getLogWriterin interface- javax.sql.CommonDataSource
- Specified by:
- getLogWriterin interface- javax.sql.DataSource
 
 - 
setDriverpublic void setDriver(java.lang.String driver) 
 - 
setUrlpublic void setUrl(java.lang.String url) 
 - 
setUsernamepublic void setUsername(java.lang.String username) 
 - 
setPasswordpublic void setPassword(java.lang.String password) 
 - 
setDefaultAutoCommitpublic void setDefaultAutoCommit(boolean defaultAutoCommit) 
 - 
setDefaultTransactionIsolationLevelpublic void setDefaultTransactionIsolationLevel(java.lang.Integer defaultTransactionIsolationLevel) 
 - 
setDriverPropertiespublic void setDriverProperties(java.util.Properties driverProps) 
 - 
setDefaultNetworkTimeoutpublic void setDefaultNetworkTimeout(java.lang.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
 
 - 
setPoolMaximumActiveConnectionspublic void setPoolMaximumActiveConnections(int poolMaximumActiveConnections) The maximum number of active connections.- Parameters:
- poolMaximumActiveConnections- The maximum number of active connections
 
 - 
setPoolMaximumIdleConnectionspublic void setPoolMaximumIdleConnections(int poolMaximumIdleConnections) The maximum number of idle connections.- Parameters:
- poolMaximumIdleConnections- The maximum number of idle connections
 
 - 
setPoolMaximumLocalBadConnectionTolerancepublic 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
 
 - 
setPoolMaximumCheckoutTimepublic void setPoolMaximumCheckoutTime(int poolMaximumCheckoutTime) The maximum time a connection can be used before it *may* be given away again.- Parameters:
- poolMaximumCheckoutTime- The maximum time
 
 - 
setPoolTimeToWaitpublic void setPoolTimeToWait(int poolTimeToWait) The time to wait before retrying to get a connection.- Parameters:
- poolTimeToWait- The time to wait
 
 - 
setPoolPingQuerypublic void setPoolPingQuery(java.lang.String poolPingQuery) The query to be used to check a connection.- Parameters:
- poolPingQuery- The query
 
 - 
setPoolPingEnabledpublic 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
 
 - 
setPoolPingConnectionsNotUsedForpublic 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
 
 - 
getDriverpublic java.lang.String getDriver() 
 - 
getUrlpublic java.lang.String getUrl() 
 - 
getUsernamepublic java.lang.String getUsername() 
 - 
getPasswordpublic java.lang.String getPassword() 
 - 
isAutoCommitpublic boolean isAutoCommit() 
 - 
getDefaultTransactionIsolationLevelpublic java.lang.Integer getDefaultTransactionIsolationLevel() 
 - 
getDriverPropertiespublic java.util.Properties getDriverProperties() 
 - 
getDefaultNetworkTimeoutpublic java.lang.Integer getDefaultNetworkTimeout() - Since:
- 3.5.2
 
 - 
getPoolMaximumActiveConnectionspublic int getPoolMaximumActiveConnections() 
 - 
getPoolMaximumIdleConnectionspublic int getPoolMaximumIdleConnections() 
 - 
getPoolMaximumLocalBadConnectionTolerancepublic int getPoolMaximumLocalBadConnectionTolerance() 
 - 
getPoolMaximumCheckoutTimepublic int getPoolMaximumCheckoutTime() 
 - 
getPoolTimeToWaitpublic int getPoolTimeToWait() 
 - 
getPoolPingQuerypublic java.lang.String getPoolPingQuery() 
 - 
isPoolPingEnabledpublic boolean isPoolPingEnabled() 
 - 
getPoolPingConnectionsNotUsedForpublic int getPoolPingConnectionsNotUsedFor() 
 - 
forceCloseAllpublic void forceCloseAll() Closes all active and idle connections in the pool.
 - 
getPoolStatepublic PoolState getPoolState() 
 - 
pushConnectionprotected void pushConnection(org.apache.ibatis.datasource.pooled.PooledConnection conn) throws java.sql.SQLException- Throws:
- java.sql.SQLException
 
 - 
pingConnectionprotected 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
 
 - 
unwrapConnectionpublic 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
 
 - 
finalizeprotected void finalize() throws java.lang.Throwable- Overrides:
- finalizein class- java.lang.Object
- Throws:
- java.lang.Throwable
 
 - 
unwrappublic <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException- Specified by:
- unwrapin interface- java.sql.Wrapper
- Throws:
- java.sql.SQLException
 
 - 
isWrapperForpublic boolean isWrapperFor(java.lang.Class<?> iface) - Specified by:
- isWrapperForin interface- java.sql.Wrapper
 
 - 
getParentLoggerpublic java.util.logging.Logger getParentLogger() - Specified by:
- getParentLoggerin interface- javax.sql.CommonDataSource
 
 
- 
 
-