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
- 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
DataSourceResource
on 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.
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionPoolingDataSource(IResourceHandle rh, String name)
PoolingDataSource(IResourceHandle rh, String name, DataSource ds)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
getConnection(String arg0, String arg1)
int
boolean
isWrapperFor(Class<?> arg0)
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.void
setConnectionMaxUse(int connectionMaxUse)
Change the number of times a connection from this pool may be used before it will be dumpedvoid
setDriverClass(String driverClass)
void
setLoginTimeout(int arg0)
void
setLogWriter(PrintWriter out)
void
setMaxInUseConnections(int mc)
Change the number of connections to be provided by this pool at most.void
setMaxSpareConnections(int mc)
Change the number of spare connections to be held open by this pool.void
setPassword(String password)
void
setTransactionIsolation(int transactionIsolation)
void
void
<T> T
Methods inherited from class java.lang.Object
clone, equals, finalize, 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
-
PoolingDataSource
-
PoolingDataSource
-
-
Method Details
-
destroy
public void destroy() -
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getLogWriter
- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Throws:
SQLException
-
getLoginTimeout
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Throws:
SQLException
-
setLogWriter
- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Throws:
SQLException
-
setLoginTimeout
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
setUrl
-
setUser
-
setTransactionIsolation
public void setTransactionIsolation(int transactionIsolation) -
setPassword
-
setDriverClass
-
getParentLogger
- Specified by:
getParentLogger
in 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
-
-