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
CHECK_OUT_TIMEOUT, IDLE_TIMEOUT, MAXIMUM_POOL_SIZE, MINIMUM_POOL_SIZE, VALIDATE_CONNECTIONS_ON_CHECKOUT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractConnectionPoolWrapper(ConnectionFactory connectionFactory, User user, DataSource dataSource, Function<DataSource, T> poolFactory) Instantiates a new AbstractConnectionPool instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract intprotected final voidCleans up statistics collection resources to prevent resource leaks.final Connectionconnection(User user) Fetches a connection from the pool.protected final Tprotected abstract ConnectionFetches a connection from the underlying pool.protected abstract intinUse()final booleanReturns true if connection check out times are being collected.final booleanReturns true if snapshot statistics are being collected.final voidResets the collected usage statisticsfinal voidsetCollectCheckOutTimes(boolean collectCheckOutTimes) Specifies whether to collect connection check out times.final voidsetCollectSnapshotStatistics(boolean collectSnapshotStatistics) Specifies whether to collect usage statistics for a snapshot.final ConnectionPoolStatisticsstatistics(long since) Retrieves usage statistics for the connection pool since timesince.final Useruser()protected abstract intwaiting()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface is.codion.common.db.pool.ConnectionPoolWrapper
close, getCleanupInterval, getIdleTimeout, getMaximumCheckOutTime, getMaximumPoolSize, getMinimumPoolSize, setCleanupInterval, setIdleTimeout, 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:
userin interfaceConnectionPoolWrapper- Returns:
- the user this connection pool is based on.
-
connection
Description copied from interface:ConnectionPoolWrapperFetches a connection from the pool. Close the connection to return it to the pool.- Specified by:
connectionin interfaceConnectionPoolWrapper- Parameters:
user- the user credentials- Returns:
- a database connection retrieved from the pool
- See Also:
-
resetStatistics
public final void resetStatistics()Description copied from interface:ConnectionPoolWrapperResets the collected usage statistics- Specified by:
resetStatisticsin interfaceConnectionPoolWrapper
-
isCollectSnapshotStatistics
public final boolean isCollectSnapshotStatistics()Description copied from interface:ConnectionPoolWrapperReturns true if snapshot statistics are being collected.- Specified by:
isCollectSnapshotStatisticsin 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:ConnectionPoolWrapperSpecifies whether to collect usage statistics for a snapshot.- Specified by:
setCollectSnapshotStatisticsin interfaceConnectionPoolWrapper- Parameters:
collectSnapshotStatistics- the value- See Also:
-
isCollectCheckOutTimes
public final boolean isCollectCheckOutTimes()Description copied from interface:ConnectionPoolWrapperReturns true if connection check out times are being collected.- Specified by:
isCollectCheckOutTimesin interfaceConnectionPoolWrapper- Returns:
- true if connection check out times should be collected
- See Also:
-
setCollectCheckOutTimes
public final void setCollectCheckOutTimes(boolean collectCheckOutTimes) Description copied from interface:ConnectionPoolWrapperSpecifies whether to collect connection check out times.- Specified by:
setCollectCheckOutTimesin interfaceConnectionPoolWrapper- Parameters:
collectCheckOutTimes- the value- See Also:
-
statistics
Description copied from interface:ConnectionPoolWrapperRetrieves usage statistics for the connection pool since timesince.- Specified by:
statisticsin 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
-
closeStatisticsCollection
protected final void closeStatisticsCollection()Cleans up statistics collection resources to prevent resource leaks. This method should be called by concrete implementations in their close() methods before shutting down the actual connection pool.
-