From 21b951de0e0814f4e53b4d056becadda9bd8a974 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 28 Dec 2024 22:51:55 +0800 Subject: [PATCH] Revise JDBCRepository (#34192) --- .../standalone/jdbc/JDBCRepository.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) 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 25ddab133d17e..42686f9f1a818 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 @@ -60,21 +60,7 @@ public final class JDBCRepository implements StandalonePersistRepository { public void init(final Properties props) { JDBCRepositoryProperties jdbcRepositoryProps = new JDBCRepositoryProperties(props); repositorySQL = JDBCRepositorySQLLoader.load(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.PROVIDER)); - - 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); - + dataSource = new HikariDataSource(createHikariConfig(props, jdbcRepositoryProps)); try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -90,6 +76,24 @@ public void init(final Properties props) { } } + private HikariConfig createHikariConfig(final Properties props, final JDBCRepositoryProperties jdbcRepositoryProps) { + HikariConfig result = new HikariConfig(copyProperties(props)); + result.setDriverClassName(repositorySQL.getDriverClassName()); + result.setJdbcUrl(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.JDBC_URL)); + result.setUsername(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.USERNAME)); + result.setPassword(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.PASSWORD)); + return result; + } + + private Properties copyProperties(final Properties props) { + Properties result = PropertyElf.copyProperties(props); + result.remove(JDBCRepositoryPropertyKey.PROVIDER.getKey()); + result.remove(JDBCRepositoryPropertyKey.JDBC_URL.getKey()); + result.remove(JDBCRepositoryPropertyKey.USERNAME.getKey()); + result.remove(JDBCRepositoryPropertyKey.PASSWORD.getKey()); + return result; + } + @Override public String query(final String key) { try (