Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support modifying Hikari-CP configurations via props in standalone mode #34185

Merged
merged 3 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
1. SQL Binder: Support load data and load xml sql bind and add test case - [#34177](https://github.com/apache/shardingsphere/pull/34177)
1. Transaction: Support savepoint/release savepoint TCL statements in jdbc adapter -[#34173](https://github.com/apache/shardingsphere/pull/34173)
1. Kernel: Add WithAvailable interface and encrypt with, combine, insert select support checker - [#34175](https://github.com/apache/shardingsphere/pull/34175)
1. Mode: Support modifying Hikari-CP configurations via props in standalone mode [#34185](https://github.com/apache/shardingsphere/pull/34185)

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package org.apache.shardingsphere.mode.repository.standalone.jdbc;

import com.google.common.base.Strings;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.util.PropertyElf;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository;
Expand Down Expand Up @@ -58,11 +60,21 @@ public final class JDBCRepository implements StandalonePersistRepository {
public void init(final Properties props) {
JDBCRepositoryProperties jdbcRepositoryProps = new JDBCRepositoryProperties(props);
repositorySQL = JDBCRepositorySQLLoader.load(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.PROVIDER));
dataSource = new HikariDataSource();
dataSource.setDriverClassName(repositorySQL.getDriverClassName());
dataSource.setJdbcUrl(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.JDBC_URL));
dataSource.setUsername(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.USERNAME));
dataSource.setPassword(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.PASSWORD));

Properties hikariProperties = PropertyElf.copyProperties(props);
hikariProperties.remove(JDBCRepositoryPropertyKey.PROVIDER.getKey());
hikariProperties.remove(JDBCRepositoryPropertyKey.JDBC_URL.getKey());
hikariProperties.remove(JDBCRepositoryPropertyKey.USERNAME.getKey());
hikariProperties.remove(JDBCRepositoryPropertyKey.PASSWORD.getKey());

HikariConfig hikariConfig = new HikariConfig(hikariProperties);
hikariConfig.setDriverClassName(repositorySQL.getDriverClassName());
hikariConfig.setJdbcUrl(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.JDBC_URL));
hikariConfig.setUsername(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.USERNAME));
hikariConfig.setPassword(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.PASSWORD));

dataSource = new HikariDataSource(hikariConfig);

try (
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
Expand Down
Loading