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 2022/06/20 08:06:17 UTC

[shardingsphere] branch master updated: Handle jdbc url contains sessionVariables parameter (#18436)

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 93605415339 Handle jdbc url contains sessionVariables parameter (#18436)
93605415339 is described below

commit 93605415339bf946b187e73b6aff19a7291439fb
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Mon Jun 20 16:06:10 2022 +0800

    Handle jdbc url contains sessionVariables parameter (#18436)
    
    * Handle jdbc url contains sessionVariables parameter
    
    * Format it
---
 .../infra/database/metadata/url/StandardJdbcUrlParser.java          | 6 +++---
 .../infra/database/metadata/url/StandardJdbcUrlParserTest.java      | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParser.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParser.java
index 8d1823aaecf..7d515f19200 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParser.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParser.java
@@ -21,7 +21,6 @@ import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import org.apache.shardingsphere.infra.database.metadata.UnrecognizedDatabaseURLException;
 
-import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -88,8 +87,9 @@ public final class StandardJdbcUrlParser {
             return new Properties();
         }
         Properties result = new Properties();
-        for (Entry<String, String> entry : Splitter.on("&").withKeyValueSeparator("=").split(query).entrySet()) {
-            result.setProperty(entry.getKey(), entry.getValue());
+        for (String each : Splitter.on("&").split(query)) {
+            String[] property = each.split("=", 2);
+            result.setProperty(property[0], property[1]);
         }
         return result;
     }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParserTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParserTest.java
index c60fc8f8e64..7e76d6cad37 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParserTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParserTest.java
@@ -37,13 +37,14 @@ public final class StandardJdbcUrlParserTest {
     
     @Test
     public void assertParseMySQLJdbcUrl() {
-        JdbcUrl actual = new StandardJdbcUrlParser().parse("jdbc:mysql://127.0.0.1:3306/demo_ds?serverTimezone=UTC&useSSL=false");
+        JdbcUrl actual = new StandardJdbcUrlParser().parse("jdbc:mysql://127.0.0.1:3306/demo_ds?serverTimezone=UTC&useSSL=false&sessionVariables=group_concat_max_len=204800,SQL_SAFE_UPDATES=0");
         assertThat(actual.getHostname(), is("127.0.0.1"));
         assertThat(actual.getPort(), is(3306));
         assertThat(actual.getDatabase(), is("demo_ds"));
-        assertThat(actual.getQueryProperties().size(), is(2));
+        assertThat(actual.getQueryProperties().size(), is(3));
         assertThat(actual.getQueryProperties().get("serverTimezone"), is("UTC"));
         assertThat(actual.getQueryProperties().get("useSSL"), is(Boolean.FALSE.toString()));
+        assertThat(actual.getQueryProperties().get("sessionVariables"), is("group_concat_max_len=204800,SQL_SAFE_UPDATES=0"));
     }
     
     @Test