connection
Property providing access to database connections from the HikariCP connection pool.
This property serves as the primary interface for obtaining database connections throughout the plugin system. It implements sophisticated connection management including automatic recovery, health checking, and re-initialization capabilities.
Connection Management Features:
Automatic health checking of the DataSource before providing connections
Self-healing capabilities that attempt re-initialization on connection failures
Thread-safe access to the underlying HikariCP connection pool
Comprehensive error handling with detailed logging for debugging
Automatic Recovery Logic: The property implements a multi-stage recovery process when connection issues are detected:
DataSource Health Check:
Verifies that the DataSource exists and is not closed
Logs warnings when connection pool issues are detected
Initialization State Verification:
Checks if the DatabaseManager was previously initialized successfully
Attempts full re-initialization if the manager was never properly set up
Connection Pool Recovery:
Re-establishes the HikariCP connection pool if it was closed unexpectedly
Preserves existing configuration settings during recovery
Failure Handling:
Marks the DatabaseManager as uninitialized if recovery fails
Throws detailed SQLExceptions with context about the failure
Usage Patterns: This property should be used with Kotlin's use{} blocks or try-with-resources patterns to ensure proper connection cleanup:
databaseManager.connection.use { conn ->
// Perform database operations
}Error Scenarios: The property handles several error conditions gracefully:
Null or closed DataSource: Attempts re-initialization
Failed initialization: Throws SQLException with detailed error information
Connection pool exhaustion: Relies on HikariCP's built-in waiting and timeout logic
Database connectivity issues: Propagates underlying connection exceptions
Thread Safety: This property is thread-safe through HikariCP's internal connection pool management. Multiple threads can safely request connections simultaneously without additional synchronization requirements.
Performance Considerations:
Connection acquisition is optimized through HikariCP's pooling mechanism
Health checks are performed efficiently to minimize overhead
Re-initialization attempts are logged to avoid silent failures
Return
A database Connection from the HikariCP pool
Since
1.0.0
See also
for the underlying connection acquisition
for the initialization process that this property may trigger
Throws
if the connection cannot be obtained due to:
DatabaseManager not being initialized and re-initialization failing
Connection pool being unavailable or exhausted
Underlying database connectivity issues
HikariCP DataSource being in an invalid state