java.lang.Object
is.codion.common.db.pool.AbstractConnectionPoolWrapper<T>
- Type Parameters:
T
- the type representing the actual pool object
- All Implemented Interfaces:
ConnectionPoolWrapper
public abstract class AbstractConnectionPoolWrapper<T>
extends Object
implements ConnectionPoolWrapper
A default base implementation of the ConnectionPool wrapper, handling the collection of statistics
-
Field Summary
Fields inherited from interface is.codion.common.db.pool.ConnectionPoolWrapper
DEFAULT_IDLE_TIMEOUT, DEFAULT_MAXIMUM_POOL_SIZE, DEFAULT_MINIMUM_POOL_SIZE
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractConnectionPoolWrapper
(ConnectionFactory connectionFactory, User user, DataSource dataSource, Function<DataSource, T> poolFactory) Instantiates a new AbstractConnectionPool instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int
final Connection
connection
(User user) Fetches a connection from the pool.protected final T
protected abstract Connection
Fetches a connection from the underlying pool.protected abstract int
inUse()
final boolean
final boolean
final void
Resets the collected usage statisticsfinal void
setCollectCheckOutTimes
(boolean collectCheckOutTimes) Specifies whether to collect connection check out times.final void
setCollectSnapshotStatistics
(boolean collectSnapshotStatistics) Specifies whether to collect usage statistics for a snapshot.final ConnectionPoolStatistics
statistics
(long since) Retrives usage statistics for the connection pool since timesince
.final User
user()
protected abstract int
waiting()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface is.codion.common.db.pool.ConnectionPoolWrapper
close, getCleanupInterval, getIdleConnectionTimeout, getMaximumCheckOutTime, getMaximumPoolSize, getMinimumPoolSize, setCleanupInterval, setIdleConnectionTimeout, setMaximumCheckOutTime, setMaximumPoolSize, setMinimumPoolSize
-
Constructor Details
-
AbstractConnectionPoolWrapper
protected AbstractConnectionPoolWrapper(ConnectionFactory connectionFactory, User user, DataSource dataSource, Function<DataSource, T> poolFactory) Instantiates a new AbstractConnectionPool instance.- Parameters:
connectionFactory
- the connection factoryuser
- the connection pool userdataSource
- the data sourcepoolFactory
- creates the actual connection pool based on the given data source
-
-
Method Details
-
user
- Specified by:
user
in interfaceConnectionPoolWrapper
- Returns:
- the user this connection pool is based on.
-
connection
Description copied from interface:ConnectionPoolWrapper
Fetches a connection from the pool. Close the connection to return it to the pool.- Specified by:
connection
in interfaceConnectionPoolWrapper
- Parameters:
user
- the user credentials- Returns:
- a database connection retrieved from the pool
- Throws:
DatabaseException
- in case of an exception while fetching the connection- See Also:
-
resetStatistics
public final void resetStatistics()Description copied from interface:ConnectionPoolWrapper
Resets the collected usage statistics- Specified by:
resetStatistics
in interfaceConnectionPoolWrapper
-
isCollectSnapshotStatistics
public final boolean isCollectSnapshotStatistics()- Specified by:
isCollectSnapshotStatistics
in interfaceConnectionPoolWrapper
- Returns:
- true if pool usage statistics for a snapshot should be collected.
- See Also:
-
setCollectSnapshotStatistics
public final void setCollectSnapshotStatistics(boolean collectSnapshotStatistics) Description copied from interface:ConnectionPoolWrapper
Specifies whether to collect usage statistics for a snapshot.- Specified by:
setCollectSnapshotStatistics
in interfaceConnectionPoolWrapper
- Parameters:
collectSnapshotStatistics
- the value- See Also:
-
isCollectCheckOutTimes
public final boolean isCollectCheckOutTimes()- Specified by:
isCollectCheckOutTimes
in interfaceConnectionPoolWrapper
- Returns:
- true if connection check out times should be collected.
- See Also:
-
setCollectCheckOutTimes
public final void setCollectCheckOutTimes(boolean collectCheckOutTimes) Description copied from interface:ConnectionPoolWrapper
Specifies whether to collect connection check out times.- Specified by:
setCollectCheckOutTimes
in interfaceConnectionPoolWrapper
- Parameters:
collectCheckOutTimes
- the value- See Also:
-
statistics
Description copied from interface:ConnectionPoolWrapper
Retrives usage statistics for the connection pool since timesince
.- Specified by:
statistics
in interfaceConnectionPoolWrapper
- Parameters:
since
- the time from which statistics should be retrieved- Returns:
- connection pool usage statistics
-
fetchConnection
Fetches a connection from the underlying pool.- Returns:
- a connection from the underlying pool
- Throws:
SQLException
- in case of an exception.
-
connectionPool
- Returns:
- the underlying connection pool instance
-
available
protected abstract int available()- Returns:
- the number of available connections in this pool
-
inUse
protected abstract int inUse()- Returns:
- the number of connections in active use
-
waiting
protected abstract int waiting()- Returns:
- the number of waiting connection requests
-