feat(okapi-exposed): ExposedConnectionProvider support for multiple databases - #97
Conversation
There was a problem hiding this comment.
🟢 Ready to approve
The behavior change is narrowly scoped, aligned with existing module patterns, and is covered by targeted regression tests plus a documented breaking-change entry.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR fixes a multi-database correctness issue in okapi-exposed by scoping ExposedConnectionProvider to a specific Exposed Database, aligning it with the existing ExposedTransactionRunner/ExposedTransactionContextValidator behavior and preventing accidental use of another database’s active transaction.
Changes:
- Make
ExposedConnectionProviderrequire adatabase: Databaseconstructor param and usedatabase.transactionManager.currentOrNull()instead of the globalTransactionManager.currentOrNull(). - Expand unit tests to cover multi-database scenarios (wrong-db active transaction throws; nested cross-db transactions still resolve correctly).
- Document the breaking change under
[Unreleased]inCHANGELOG.md.
File summaries
| File | Description |
|---|---|
| okapi-exposed/src/main/kotlin/com/softwaremill/okapi/exposed/ExposedConnectionProvider.kt | Scope connection lookup to a specific Database and update KDoc + error message accordingly. |
| okapi-exposed/src/test/kotlin/com/softwaremill/okapi/exposed/ExposedConnectionProviderTest.kt | Update tests for new constructor signature and add multi-database regression coverage. |
| CHANGELOG.md | Add a breaking-change entry describing the new required constructor parameter and behavior change. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
There was a problem hiding this comment.
🟡 Not ready to approve
The added nested multi-database regression test currently doesn’t exercise the key “outbox transaction outer, other DB transaction inner” case, so a reversion to global transaction resolution could go undetected.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (1)
okapi-exposed/src/test/kotlin/com/softwaremill/okapi/exposed/ExposedConnectionProviderTest.kt:57
- The nested-transaction test currently nests
transaction(otherDb) { transaction(outboxDb) { ... } }, which would still pass even ifwithConnectionincorrectly used the globalTransactionManager.currentOrNull()(because the outbox transaction is innermost in that scenario). To actually guard the multi-DB nesting behavior, invert the nesting (outboxDbouter,otherDbinner) and assert the connection belongs to the outbox DB (e.g., by checking the JDBC URL), not just that it’s open.
test("resolves the outbox Database's transaction even when nested inside a transaction on another Database") {
val connectionWasOpen: Boolean = transaction(otherDb) {
transaction(outboxDb) {
provider.withConnection { conn -> !conn.isClosed }
}
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
There was a problem hiding this comment.
🟢 Ready to approve
The change aligns ExposedConnectionProvider with existing per-database patterns, and the added tests meaningfully validate the regression scenario and expected behavior.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Fix (ExposedConnectionProvider.kt): added a required database: Database constructor param; withConnection now reads database.transactionManager.currentOrNull() (per-database transaction manager) instead of the global TransactionManager.currentOrNull(), matching the existing pattern in ExposedTransactionRunner/ExposedTransactionContextValidator. KDoc updated to explain the multi-database scoping and the breaking change.
Tests: updated ExposedConnectionProviderTest.kt to pass a Database, plus two new regression tests — one confirming it throws when only a different database's transaction is active, one confirming it still resolves correctly when nested inside a transaction on another database.
Verified the fix guards a real regression two ways:
CHANGELOG.md: added an ### Changed (BREAKING) entry under [Unreleased] documenting the constructor change and linking issue #96, per this project's post-1.0.0 semver discipline.
ktlintCheck and the full okapi-exposed test suite (11 tests) pass clean.