You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/12/28 14:39:56 UTC

(shardingsphere) branch master updated: Support modifying Hikari-CP configurations via props in standalone mode (#34185)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 0a1c8e53680 Support modifying Hikari-CP configurations via props in standalone mode (#34185)
0a1c8e53680 is described below

commit 0a1c8e53680f707b700bf5301d01f378eb0cfae3
Author: Joshua Chen <27...@qq.com>
AuthorDate: Sat Dec 28 22:39:50 2024 +0800

    Support modifying Hikari-CP configurations via props in standalone mode (#34185)
    
    * Support modifying Hikari-CP configurations via props in standalone mode
    
    * update release notes
    
    * Fix Spotless run failure
---
 RELEASE-NOTES.md                                   |  1 +
 .../repository/standalone/jdbc/JDBCRepository.java | 22 +++++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index aecb9693124..3217d36b5b3 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -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
 
diff --git a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
index 098b9e96572..25ddab133d1 100644
--- a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
+++ b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
@@ -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;
@@ -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()) {