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 c64833b0310 Refactor H2ConnectionProperties (#36396)
c64833b0310 is described below
commit c64833b031050933f6d6a097b57f01de35df982d
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Aug 23 21:24:43 2025 +0800
Refactor H2ConnectionProperties (#36396)
---
.../h2/jdbcurl/H2ConnectionProperties.java | 9 +++++---
.../h2/jdbcurl/H2ConnectionPropertiesParser.java | 26 +++++++++++-----------
2 files changed, 19 insertions(+), 16 deletions(-)
diff --git
a/database/connector/dialect/h2/src/main/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionProperties.java
b/database/connector/dialect/h2/src/main/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionProperties.java
index 77ba9b3ab9d..171e2839c7a 100644
---
a/database/connector/dialect/h2/src/main/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionProperties.java
+++
b/database/connector/dialect/h2/src/main/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionProperties.java
@@ -17,9 +17,11 @@
package org.apache.shardingsphere.database.connector.h2.jdbcurl;
+import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.database.connector.core.jdbcurl.parser.ConnectionProperties;
+import
org.apache.shardingsphere.database.connector.core.jdbcurl.parser.StandardConnectionProperties;
import java.util.Properties;
@@ -38,12 +40,13 @@ public final class H2ConnectionProperties implements
ConnectionProperties {
private final String hostname;
- private final String model;
-
private final int port;
private final String catalog;
+ @Getter(AccessLevel.NONE)
+ private final String model;
+
@Override
public String getSchema() {
return null;
@@ -67,7 +70,7 @@ public final class H2ConnectionProperties implements
ConnectionProperties {
if (!isSameModel(model, ((H2ConnectionProperties)
connectionProps).model)) {
return false;
}
- return hostname.equals(connectionProps.getHostname()) && port ==
connectionProps.getPort();
+ return new StandardConnectionProperties(hostname, port, catalog,
null).isInSameDatabaseInstance(connectionProps);
}
private boolean isSameModel(final String model1, final String model2) {
diff --git
a/database/connector/dialect/h2/src/main/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionPropertiesParser.java
b/database/connector/dialect/h2/src/main/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionPropertiesParser.java
index e478e1de8c5..0e2db760a8d 100644
---
a/database/connector/dialect/h2/src/main/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionPropertiesParser.java
+++
b/database/connector/dialect/h2/src/main/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionPropertiesParser.java
@@ -43,7 +43,7 @@ public final class H2ConnectionPropertiesParser implements
ConnectionPropertiesP
public ConnectionProperties parse(final String url, final String username,
final String catalog) {
Matcher matcher = URL_PATTERN.matcher(url);
ShardingSpherePreconditions.checkState(matcher.find(), () -> new
UnrecognizedDatabaseURLException(url, URL_PATTERN.pattern()));
- return new H2ConnectionProperties(getHostname(matcher),
getModel(matcher), getPort(matcher), getCatalog(matcher));
+ return new H2ConnectionProperties(getHostname(matcher),
getPort(matcher), getCatalog(matcher), getModel(matcher));
}
private String getHostname(final Matcher matcher) {
@@ -51,18 +51,6 @@ public final class H2ConnectionPropertiesParser implements
ConnectionPropertiesP
return null == hostname ? DEFAULT_HOST_NAME : hostname;
}
- private static String getModel(final Matcher matcher) {
- String modelMem = matcher.group("modelMem");
- if (null != modelMem) {
- return modelMem;
- }
- String modelSslOrTcp = matcher.group("modelSslOrTcp");
- if (null != modelSslOrTcp) {
- return modelSslOrTcp;
- }
- return matcher.group("modelFile");
- }
-
private int getPort(final Matcher matcher) {
String port = matcher.group("port");
return Strings.isNullOrEmpty(port) ? DEFAULT_PORT :
Integer.parseInt(port);
@@ -80,6 +68,18 @@ public final class H2ConnectionPropertiesParser implements
ConnectionPropertiesP
return matcher.group("catalog");
}
+ private static String getModel(final Matcher matcher) {
+ String modelMem = matcher.group("modelMem");
+ if (null != modelMem) {
+ return modelMem;
+ }
+ String modelSslOrTcp = matcher.group("modelSslOrTcp");
+ if (null != modelSslOrTcp) {
+ return modelSslOrTcp;
+ }
+ return matcher.group("modelFile");
+ }
+
@Override
public String getDatabaseType() {
return "H2";