Skip to content

Commit

Permalink
Support modifying Hikari-CP configurations via props in standalone mo…
Browse files Browse the repository at this point in the history
…de (#34185)

* Support modifying Hikari-CP configurations via props in standalone mode

* update release notes

* Fix Spotless run failure
  • Loading branch information
JoshuaChen authored Dec 28, 2024
1 parent 97bf345 commit 0a1c8e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
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

0 comments on commit 0a1c8e5

Please sign in to comment.