Skip to content

#752 Remove 'driver' from JDBC options, and try current thread context class loader for dynamically loaded JDBC drivers.#753

Merged
yruslan merged 2 commits into
mainfrom
bugfix/752-remove-driver-property
May 20, 2026
Merged

#752 Remove 'driver' from JDBC options, and try current thread context class loader for dynamically loaded JDBC drivers.#753
yruslan merged 2 commits into
mainfrom
bugfix/752-remove-driver-property

Conversation

@yruslan
Copy link
Copy Markdown
Collaborator

@yruslan yruslan commented May 20, 2026

Summary by CodeRabbit

  • Refactor
    • Improved JDBC connection initialization with deferred driver loading. The system now loads the database driver at connection time rather than during initialization, with an intelligent fallback mechanism to handle different class loader contexts. This change enhances compatibility and flexibility across various deployment scenarios.

Review Change Stack

…t class loader for dynamically loaded JDBC drivers.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Warning

Rate limit exceeded

@yruslan has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 52 minutes and 59 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cc21eb1f-b595-44fa-9ea5-07a524960cef

📥 Commits

Reviewing files that changed from the base of the PR and between b220f08 and e1b8ae2.

📒 Files selected for processing (1)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/JdbcNativeUtils.scala

Walkthrough

This pull request defers JDBC driver loading from initialization to connection time and adds fallback logic. The driver property is removed from connection properties, and driver loading is wrapped in a try/catch that retries using the thread context class loader if the default loader fails.

Changes

JDBC Driver Loading Deferral

Layer / File(s) Summary
Remove driver from connection properties
pramen/core/src/main/scala/za/co/absa/pramen/core/reader/JdbcUrlSelectorImpl.scala
Driver property is no longer added to the Properties object; user, password, database, and extraOptions remain unchanged.
Deferred driver loading with context class loader fallback
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/JdbcNativeUtils.scala
JDBC driver loading is deferred from initialization to connection time. The default class loader attempt is wrapped in try/catch; on ClassNotFoundException, the thread context class loader loads, instantiates, and registers the driver before opening the connection.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A driver hops along the path,
No longer loaded in a flash—
When connection time draws near,
Thread context loaders appear!
Fallback magic, smooth and swift,
ClassLoaders raise the JDBC gift. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes both main changes: removing the 'driver' property from JDBC options and implementing fallback to current thread context class loader for driver loading.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/752-remove-driver-property

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Unit Test Coverage

Overall Project 76.94% -0.06% 🍏
Files changed 12.33%

Module Coverage
pramen:core Jacoco Report 77.94% -0.07%
Files
Module File Coverage
pramen:core Jacoco Report JdbcUrlSelectorImpl.scala 76.1% 🍏
JdbcNativeUtils.scala 62.29% -13.33%

@yruslan
Copy link
Copy Markdown
Collaborator Author

yruslan commented May 20, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/JdbcNativeUtils.scala (1)

213-214: ⚡ Quick win

Redundant class loading.

Class.forName(jdbcConfig.driver, true, loader) already loads and initializes the class, but its return value is discarded. The subsequent loader.loadClass(jdbcConfig.driver) call loads the same class again.

♻️ Proposed fix to use the return value directly
-        Class.forName(jdbcConfig.driver, true, loader)
-        val driverClass = loader.loadClass(jdbcConfig.driver)
+        val driverClass = Class.forName(jdbcConfig.driver, true, loader)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@pramen/core/src/main/scala/za/co/absa/pramen/core/utils/JdbcNativeUtils.scala`
around lines 213 - 214, The code redundantly loads the JDBC driver twice; remove
the extra loader.loadClass call and use the Class.forName return instead:
replace the two lines so that Class.forName(jdbcConfig.driver, true, loader) is
assigned to driverClass (or otherwise use its returned Class object) and then
proceed with existing logic that uses driverClass; update references to
driverClass accordingly and keep jdbcConfig.driver and loader as the identifying
symbols.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@pramen/core/src/main/scala/za/co/absa/pramen/core/utils/JdbcNativeUtils.scala`:
- Line 217: In JdbcNativeUtils (look for the driver.connect(url, properties)
call), add a null-check after Driver.connect to handle the case where the driver
declines the URL: if the returned connection is null, throw a clear
IllegalStateException (or SQLException) with a message mentioning the URL and
driver class instead of proceeding to use the null `connection` (which leads to
an NPE at connection.setAutoCommit); this ensures code paths in methods that use
the `connection` variable (e.g., wherever `autoCommit` is set) either get a
valid Connection or a descriptive error.

---

Nitpick comments:
In
`@pramen/core/src/main/scala/za/co/absa/pramen/core/utils/JdbcNativeUtils.scala`:
- Around line 213-214: The code redundantly loads the JDBC driver twice; remove
the extra loader.loadClass call and use the Class.forName return instead:
replace the two lines so that Class.forName(jdbcConfig.driver, true, loader) is
assigned to driverClass (or otherwise use its returned Class object) and then
proceed with existing logic that uses driverClass; update references to
driverClass accordingly and keep jdbcConfig.driver and loader as the identifying
symbols.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 338c801e-154a-48a9-b4ba-f42d02a7abdc

📥 Commits

Reviewing files that changed from the base of the PR and between 98c77eb and b220f08.

📒 Files selected for processing (2)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/reader/JdbcUrlSelectorImpl.scala
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/JdbcNativeUtils.scala
💤 Files with no reviewable changes (1)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/reader/JdbcUrlSelectorImpl.scala

Comment thread pramen/core/src/main/scala/za/co/absa/pramen/core/utils/JdbcNativeUtils.scala Outdated
@yruslan yruslan merged commit 54ff738 into main May 20, 2026
7 checks passed
@yruslan yruslan deleted the bugfix/752-remove-driver-property branch May 20, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant