Package com.zfabrik.impl.db.data
Class PoolingDataSource
java.lang.Object
com.zfabrik.impl.db.data.PoolingDataSource
- All Implemented Interfaces:
Wrapper,CommonDataSource,DataSource
A simple but effective data base connection pool. This pool manages a number of spare and a number of maximum connections.
Connections that have errors will be closed. Connections will be forcibly closed after some expiration period (no stale connections)
Configuration properties:
- maxInUseConnection
- Maximum number of connections provided by this pool
- maxSpareConnection
- Maximum number of spare connections
- exhaustWarningDelay
- Delay to pass until warning for pool exhaustion (again)
- connectionExpiration
- Connections expire after this many milli-seconds
- connectionMaxUse
- Connections expire after they have been checked out this many times
- transactionIsolation
- If set, all connections provided will be set to this isolation level. Use the transaction isolation constants on
Connection. - driverClass
- Set this, if you want the pool to use a driver class rather than using connections from a data source. The latter is
is recommended. See
DataSourceResourceon how to specify a data source class. - user
- If configuring the pool via a driver class, this user name will be used to request new connections.
- password
- If configuring the pool via a driver class, this password will be used to request new connections.
- password
- If configuring the pool via a driver class, this password will be used to request new connections.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionPoolingDataSource(IResourceHandle rh, String name) PoolingDataSource(IResourceHandle rh, String name, DataSource ds) -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()getConnection(String arg0, String arg1) intbooleanisWrapperFor(Class<?> arg0) voidsetConnectionExpiration(int ex) Change the number of milliseconds a connection will be kept open at least before it will be considered stale by the pool and closed at the next opportunity.voidsetConnectionMaxUse(int connectionMaxUse) Change the number of times a connection from this pool may be used before it will be dumpedvoidsetDriverClass(String driverClass) voidsetExhaustWarningDelay(int exhaustWarningDelay) Delay for exhaust warnings before warning again.voidsetLoginTimeout(int arg0) voidsetLogWriter(PrintWriter out) voidsetMaxInUseConnections(int mc) Change the number of connections to be provided by this pool at most.voidsetMaxSpareConnections(int mc) Change the number of spare connections to be held open by this pool.voidsetPassword(String password) voidsetTransactionIsolation(int transactionIsolation) voidvoid<T> TMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Constructor Details
-
PoolingDataSource
-
PoolingDataSource
-
-
Method Details
-
destroy
public void destroy() -
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getLogWriter
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException
-
getLoginTimeout
- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
setLogWriter
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException
-
setLoginTimeout
- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
setUrl
-
setUser
-
setTransactionIsolation
public void setTransactionIsolation(int transactionIsolation) -
setPassword
-
setDriverClass
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
setMaxInUseConnections
public void setMaxInUseConnections(int mc) Change the number of connections to be provided by this pool at most. Request that would exceed this number have to wait for connections to return. This setting can be changed at runtime.- Parameters:
mc-
-
setMaxSpareConnections
public void setMaxSpareConnections(int mc) Change the number of spare connections to be held open by this pool. Can be changed at runtime and the pool will adapt to the new setting- Parameters:
mc-
-
setConnectionMaxUse
public void setConnectionMaxUse(int connectionMaxUse) Change the number of times a connection from this pool may be used before it will be dumped -
setConnectionExpiration
public void setConnectionExpiration(int ex) Change the number of milliseconds a connection will be kept open at least before it will be considered stale by the pool and closed at the next opportunity.- Parameters:
mc-
-
setExhaustWarningDelay
public void setExhaustWarningDelay(int exhaustWarningDelay) Delay for exhaust warnings before warning again. Set to <=0 to never warn
-