Package com.tbg.wms.db
Class DbConnectionPool
java.lang.Object
com.tbg.wms.db.DbConnectionPool
- All Implemented Interfaces:
AutoCloseable
Manages the Oracle database connection pool using HikariCP.
This service is responsible for:
- Creating and configuring the HikariCP connection pool
- Validating connectivity with detailed error diagnostics
- Mapping raw SQL exceptions to
WmsDbConnectivityExceptionwith remediation hints - Providing connection lifecycle management (open/close)
Usage:
AppConfig config = new AppConfig();
DbConnectionPool pool = new DbConnectionPool(config);
pool.testConnectivity(); // throws WmsDbConnectivityException on failure
// Later, obtain connections via DataSource
DataSource ds = pool.getDataSource();
try (Connection c = ds.getConnection()) {
// use connection
}
// Finally, close pool at shutdown
pool.close();
-
Constructor Summary
ConstructorsConstructorDescriptionDbConnectionPool(AppConfig config) Creates a new connection pool with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionReturns the JDBC URL that successfully created the pool.voidclose()Closes the connection pool and releases all resources.Returns the underlying DataSource.Tests connectivity to the database and returns detailed diagnostics.
-
Constructor Details
-
DbConnectionPool
Creates a new connection pool with the given configuration.The pool is created immediately but not validated. Call
testConnectivity()to verify the database is reachable.- Parameters:
config- the application configuration containing Oracle connection details- Throws:
WmsDbConnectivityException- if pool creation fails
-
-
Method Details
-
getDataSource
Returns the underlying DataSource.- Returns:
- the HikariDataSource for obtaining connections
-
testConnectivity
Tests connectivity to the database and returns detailed diagnostics.This method executes a simple query (SELECT 1 FROM dual) to verify:
- Host is reachable (DNS, network, firewall)
- Port is open
- Service/SID exists
- Credentials are valid
- Connection pool can create connections
- Returns:
- diagnostic information (pool stats, driver version, etc.)
- Throws:
WmsDbConnectivityException- if connectivity test fails
-
close
public void close()Closes the connection pool and releases all resources. Should be called on application shutdown.- Specified by:
closein interfaceAutoCloseable
-
activeJdbcUrl
Returns the JDBC URL that successfully created the pool.- Returns:
- active JDBC URL
-