feat: introduce ConnectionProvider for thread-scoped DB manager lifecycle#106
Draft
lanarimarco wants to merge 6 commits intodevelopfrom
Draft
feat: introduce ConnectionProvider for thread-scoped DB manager lifecycle#106lanarimarco wants to merge 6 commits intodevelopfrom
lanarimarco wants to merge 6 commits intodevelopfrom
Conversation
…ecycle Adds a thread-local ConnectionProvider singleton that manages DBMManager instances per thread using withScope() for automatic lifecycle management. - base: add ConnectionProvider, PoolConfig, and move ConnectionConfigResolver (findConnectionConfigFor + ConnectionConfigComparator) out of DBFileFactory - base: add poolConfig field to ConnectionConfig (@jvmoverloads constructor) - manager: DBFileFactory now delegates to ConnectionProvider.currentManagerOrNull() when a scope is active, falling back to its own manager pool - manager: add ConnectionProviderExtensions to wire manager-module factory - sql: add SQLConnectionPool, SQLPooledDBMManager, ThreadScopedDataSource, ConnectionProviderSqlExtensions, DBMManagerSqlExtensions, and HikariCP dep
…eprecation shim - ThreadScopedDataSource now returns a NonCloseableConnection so callers following the standard JDBC close-every-connection idiom cannot accidentally terminate the shared scope connection - Update test assertion to unwrap the delegate before comparing identity - Add deprecated findConnectionConfigFor shim in manager package pointing to the new location in com.smeup.dbnative
`ConnectionConfig.poolConfig` is now nullable (default null). `configureWithPool` skips pooling for configs without an explicit `PoolConfig` and falls back to a plain `SQLDBMManager`, so callers can mix pooled and non-pooled connections in one config. `SQLConnectionPool` guards against a null poolConfig with a clear `requireNotNull`.
Some JDBC drivers (e.g. AS400) do not implement `Connection.isValid()`, causing HikariCP health checks to fail. The new optional `connectionTestQuery` field is forwarded to `HikariConfig.setConnectionTestQuery()` when set, enabling a fallback SQL query for connection validation.
Log pool creation/shutdown, connection open/close with lifetime, and pooled borrow/return with acquire timing; add ConnectionLoggingTest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Allow any class on the same thread to obtain the same
javax.sql.DataSource(and therefore the samejava.sql.Connection) within a logical unit of work, without passing the connection explicitly through the call stack.reloadcreates and owns connections — via HikariCP pool (production) orDriverManager(tests)reloadnever reads YAML or external configConnectionProvider.withScope(() -> {})— a thread-scoped scope; no connection name is required at call timewithScope(), any class retrieves the appropriate manager orDataSourceby file name viaConnectionProvider.currentManager(fileName)/requireDataSource(fileName)DBFileFactorytransparently participates in the active scope — jariko and Java service code share the sameConnectionon the same thread with no changes to jariko itselfcurrentManagerOrNull()returnsnullandDBFileFactoryfalls back to its own manager — no behavioural regressionSummary
ConnectionProvidersingleton (base module) with thread-localwithScope()lifecycle management forDBMManagerinstancesPoolConfigdata class for connection pool tuning andpoolConfigfield onConnectionConfigfindConnectionConfigFor+ConnectionConfigComparatorfromDBFileFactoryinto the base module (ConnectionConfigResolver.kt)DBFileFactorynow delegates toConnectionProvider.currentManagerOrNull()when a scope is active, falling back to its own manager pool — guarantees connection sharing with Java service code on the same threadSQLConnectionPool,SQLPooledDBMManager,ThreadScopedDataSource,ConnectionProviderSqlExtensions,DBMManagerSqlExtensions, and HikariCP dependencyThree-layer design
reload:baseConnectionProvider— works for anyDBMManagerreload:managerreload:sqlThreadScopedDataSource+ type-discovery extensions + HikariCP poolreload:jt400toAS400Connection(): AS400?reload:nosqltoMongoDatabase(): MongoDatabase?Test plan
ConnectionProviderTest— unit tests for scope lifecycle, manager reuse, and null-safe fallbackDBFileFactoryConnectionSharingTest— verifiesDBFileFactoryreuses the scoped manager whenwithScope()is activeSQLConnectionPoolTest— pool acquire/release behaviourSQLPooledDBMManagerTest— pooled manager integrationConnectionProviderSqlExtensionsTest— SQL-specific provider wiring