Skip to content

Support Runtime JDBC Driver Loading and Dynamic Datasource Creation#4984

Draft
flyrain wants to merge 3 commits into
apache:mainfrom
flyrain:poc-jdbc-managed-datasource
Draft

Support Runtime JDBC Driver Loading and Dynamic Datasource Creation#4984
flyrain wants to merge 3 commits into
apache:mainfrom
flyrain:poc-jdbc-managed-datasource

Conversation

@flyrain

@flyrain flyrain commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This PR is intended to support two related requirements:

  1. Runtime JDBC driver loading. Polaris should be able to load a JDBC driver from a runtime provided jar, instead of requiring every supported driver to be built into the Polaris distribution. One concrete use case is MySQL, where deployments may want to provide the MySQL JDBC driver at runtime.
  2. Dynamic datasource creation. Polaris should be able to create JDBC datasources dynamically from configuration, rather than relying only on the static Quarkus datasource. This is useful for future multi realm support, where we may want to create and manage one datasource per realm.

You can find the test cases for these two requirements in file JdbcDataSourceFactoryTest.java

Checklist

  • 🛡️ Don't disclose security issues! (contact security@apache.org)
  • 🔗 Clearly explained why the changes are needed, or linked related issues: Fixes #
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Updated CHANGELOG.md (if needed)
  • 📚 Updated documentation in site/content/in-dev/unreleased (if needed)

Allow the relational JDBC backend to create and own a Hikari datasource from polaris.persistence.relational.jdbc.* settings when jdbc-url is provided, while preserving the existing Quarkus datasource fallback when it is absent.

Cover the new path with unit and integration tests for managed datasource creation, independent datasource creation from separate configs, CockroachDB configuration, production-readiness checks, and loading a JDBC driver from a runtime-provided jar.

Document the managed datasource properties and update distribution license metadata for the added runtime dependencies.
@github-project-automation github-project-automation Bot moved this to PRs In Progress in Basic Kanban Board Jul 6, 2026
@flyrain flyrain changed the title Add Polaris-managed JDBC datasource configuration Support Runtime JDBC Driver Loading and Dynamic Datasource Creation Jul 6, 2026
DatasourceOperations(
DataSource datasource,
RelationalJdbcConfiguration relationalJdbcConfiguration,
boolean closeDataSourceOnClose) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

closeDataSourceOnClose is awkward to read. How about assumeDataSourceOwnership?

}

@Override
public void close() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When is this close() method called?


We have 2 options for configuring the persistence backend:
Polaris can use either a Quarkus-managed datasource or a Polaris-managed JDBC connection pool. When
`polaris.persistence.relational.jdbc.jdbc-url` is set, Polaris creates the JDBC pool directly;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The only advantage of doing this, that I can see, realizes when Polaris is able to load the JDBC driver dynamically. However, I could not find any provisions for dynamic loading in this PR. Did I miss that? 🤔

If repackaging at the binary level is assumed, a Quakus build can be performed at that stage to make the DataSource available via Quarkus-backed CDI.

@Override
public void init(Map<String, String> initArgs) {
initScript = initArgs.get(INIT_SCRIPT);
polarisManagedDatasource = Boolean.parseBoolean(initArgs.get(POLARIS_MANAGED_DATASOURCE));

@dimas-b dimas-b Jul 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Who controls the value of this variable?

flyrain added 2 commits July 6, 2026 18:19
Support loading third-party JDBC driver jars from a configured driver directory when Polaris creates the relational JDBC datasource directly.

For binary distributions, include visible server and admin jdbc-drivers directories and document the drop-in workflow.

Add tests for explicit driver-directory loading and the default quarkus-run.jar sibling directory layout.
Move Polaris-managed JDBC datasource property descriptions into the Quarkus config mapping so generated config docs stay current.

Regenerate the relational JDBC config section with copyConfigSectionsToSite.
boolean success = false;
try {
Thread.currentThread().setContextClassLoader(driverClassLoader);
HikariDataSource dataSource =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't you want to override closeto call closeDriverClassLoader to avoid to leak the driver JarFile?

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.

3 participants