Class DatabaseConnectionImpl
java.lang.Object
fr.codinbox.connector.commons.database.DatabaseConnectionImpl
- All Implemented Interfaces:
DatabaseConnection
Implementation of
DatabaseConnection that uses HikariCP for connection pooling.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a JDBC connection from the underlying HikariCP pool.voidinit()Initializes the connection pool by loading HikariCP configuration.booleanReturns whether this connection is configured to cause server shutdown on initialization failure.voidshutdown()Shuts down the HikariCP connection pool and releases all associated resources.
-
Constructor Details
-
DatabaseConnectionImpl
public DatabaseConnectionImpl(@NotNull @NotNull Logger logger, @NotNull @NotNull String id, @NotNull @NotNull String configFilePath) Creates a new database connection instance.- Parameters:
logger- the logger for diagnostic messagesid- the connection identifierconfigFilePath- the path to the HikariCP.propertiesconfiguration file
-
-
Method Details
-
init
Description copied from interface:DatabaseConnectionInitializes the connection pool by loading HikariCP configuration.- Specified by:
initin interfaceDatabaseConnection- Throws:
ConnectionInitException- if the configuration is invalid or the pool cannot be created
-
shutdown
public void shutdown()Description copied from interface:DatabaseConnectionShuts down the HikariCP connection pool and releases all associated resources.- Specified by:
shutdownin interfaceDatabaseConnection
-
getConnection
Description copied from interface:DatabaseConnectionReturns a JDBC connection from the underlying HikariCP pool.- Specified by:
getConnectionin interfaceDatabaseConnection- Returns:
- a
Connectionfrom the pool
-
isExitOnFailure
public boolean isExitOnFailure()Description copied from interface:DatabaseConnectionReturns whether this connection is configured to cause server shutdown on initialization failure.- Specified by:
isExitOnFailurein interfaceDatabaseConnection- Returns:
trueif the server should exit when this connection fails to initialize
-