This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 fa1ef901643 Refactor ShardingSphereURL.parameters to queryProps
(#30150)
fa1ef901643 is described below
commit fa1ef901643ed83705f2ce4a2ab08b039499e5f7
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Feb 17 14:02:00 2024 +0800
Refactor ShardingSphereURL.parameters to queryProps (#30150)
* Refactor ShardingSphereURL.parameters to props
* Refactor ShardingSphereURL.parameters to queryProps
---
.../shardingsphere/infra/url/ShardingSphereURL.java | 16 +++++++---------
.../infra/url/ShardingSphereURLLoadEngine.java | 4 ++--
.../infra/url/arg/URLArgumentPlaceholderTypeFactory.java | 11 ++++-------
.../shardingsphere/infra/url/ShardingSphereURLTest.java | 4 ++--
.../infra/url/ShardingSphereURLLoader.java | 6 +++---
.../url/type/absolutepath/AbsolutePathURLLoader.java | 4 ++--
.../url/type/absolutepath/AbsolutePathURLLoaderTest.java | 4 ++--
.../infra/url/type/classpath/ClassPathURLLoader.java | 4 ++--
.../infra/url/type/classpath/ClassPathURLLoaderTest.java | 4 ++--
9 files changed, 26 insertions(+), 31 deletions(-)
diff --git
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURL.java
b/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURL.java
index 0d61deb973c..40405328f62 100644
---
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURL.java
+++
b/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURL.java
@@ -25,9 +25,7 @@ import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.url.exception.URLProviderNotFoundException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Properties;
/**
* ShardingSphere URL.
@@ -40,7 +38,7 @@ public final class ShardingSphereURL {
private final String configurationSubject;
- private final Map<String, String> parameters;
+ private final Properties queryProps;
/**
* Parse ShardingSphere URL.
@@ -51,7 +49,7 @@ public final class ShardingSphereURL {
public static ShardingSphereURL parse(final String url) {
ShardingSpherePreconditions.checkNotNull(url, () -> new
URLProviderNotFoundException(url));
String sourceType = parseSourceType(url);
- return new ShardingSphereURL(sourceType,
parseConfigurationSubject(url.substring(sourceType.length())),
parseParameters(url));
+ return new ShardingSphereURL(sourceType,
parseConfigurationSubject(url.substring(sourceType.length())),
parseProperties(url));
}
private static String parseSourceType(final String url) {
@@ -64,16 +62,16 @@ public final class ShardingSphereURL {
return result;
}
- private static Map<String, String> parseParameters(final String url) {
+ private static Properties parseProperties(final String url) {
if (!url.contains("?")) {
- return Collections.emptyMap();
+ return new Properties();
}
String queryProps = url.substring(url.indexOf('?') + 1);
if (Strings.isNullOrEmpty(queryProps)) {
- return Collections.emptyMap();
+ return new Properties();
}
String[] pairs = queryProps.split("&");
- Map<String, String> result = new HashMap<>(pairs.length, 1F);
+ Properties result = new Properties();
for (String each : pairs) {
int index = each.indexOf("=");
if (index > 0) {
diff --git
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURLLoadEngine.java
b/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURLLoadEngine.java
index 3e7db68ce25..92226b68c1e 100644
---
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURLLoadEngine.java
+++
b/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURLLoadEngine.java
@@ -44,7 +44,7 @@ public final class ShardingSphereURLLoadEngine {
* @return loaded content
*/
public byte[] loadContent() {
- Collection<String> lines =
Arrays.asList(urlLoader.load(url.getConfigurationSubject(),
url.getParameters()).split(System.lineSeparator()));
- return URLArgumentLineRender.render(lines,
URLArgumentPlaceholderTypeFactory.valueOf(url.getParameters()));
+ Collection<String> lines =
Arrays.asList(urlLoader.load(url.getConfigurationSubject(),
url.getQueryProps()).split(System.lineSeparator()));
+ return URLArgumentLineRender.render(lines,
URLArgumentPlaceholderTypeFactory.valueOf(url.getQueryProps()));
}
}
diff --git
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/arg/URLArgumentPlaceholderTypeFactory.java
b/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/arg/URLArgumentPlaceholderTypeFactory.java
index d8c3d5ea9c3..ae4db2f62bd 100644
---
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/arg/URLArgumentPlaceholderTypeFactory.java
+++
b/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/arg/URLArgumentPlaceholderTypeFactory.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.infra.url.arg;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import java.util.Map;
+import java.util.Properties;
/**
* URL argument placeholder type factory.
@@ -33,15 +33,12 @@ public final class URLArgumentPlaceholderTypeFactory {
/**
* Get value of placeholder type.
*
- * @param params parameters
+ * @param queryProps query properties
* @return placeholder type
*/
- public static URLArgumentPlaceholderType valueOf(final Map<String, String>
params) {
- if (!params.containsKey(KEY)) {
- return URLArgumentPlaceholderType.NONE;
- }
+ public static URLArgumentPlaceholderType valueOf(final Properties
queryProps) {
try {
- return
URLArgumentPlaceholderType.valueOf(params.get(KEY).toUpperCase());
+ return
URLArgumentPlaceholderType.valueOf(queryProps.getProperty(KEY,
URLArgumentPlaceholderType.NONE.name()).toUpperCase());
} catch (final IllegalArgumentException ex) {
return URLArgumentPlaceholderType.NONE;
}
diff --git
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/ShardingSphereURLTest.java
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/ShardingSphereURLTest.java
index cf9996d18a2..fcfbbae52fb 100644
---
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/ShardingSphereURLTest.java
+++
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/ShardingSphereURLTest.java
@@ -35,11 +35,11 @@ class ShardingSphereURLTest {
@ParameterizedTest(name = "{0}")
@ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertParse(final String url, final String expectedSourceType, final
String expectedConfigurationSubject, final Map<String, String>
expectedParameters) {
+ void assertParse(final String url, final String expectedSourceType, final
String expectedConfigurationSubject, final Map<String, String> expectedProps) {
ShardingSphereURL actual = ShardingSphereURL.parse(url);
assertThat(actual.getSourceType(), is(expectedSourceType));
assertThat(actual.getConfigurationSubject(),
is(expectedConfigurationSubject));
- assertThat(actual.getParameters(), is(expectedParameters));
+ assertThat(actual.getQueryProps(), is(expectedProps));
}
private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
diff --git
a/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURLLoader.java
b/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURLLoader.java
index f2dcb958b5c..d3aeadda3bb 100644
---
a/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURLLoader.java
+++
b/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/ShardingSphereURLLoader.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.infra.url;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
-import java.util.Map;
+import java.util.Properties;
/**
* ShardingSphere URL loader.
@@ -32,8 +32,8 @@ public interface ShardingSphereURLLoader extends TypedSPI {
* Load configuration content.
*
* @param configurationSubject configuration subject
- * @param parameters parameters
+ * @param queryProps query properties
* @return loaded content
*/
- String load(String configurationSubject, Map<String, String> parameters);
+ String load(String configurationSubject, Properties queryProps);
}
diff --git
a/infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/type/absolutepath/AbsolutePathURLLoader.java
b/infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/type/absolutepath/AbsolutePathURLLoader.java
index 8aa733c86ff..e1427a4af4a 100644
---
a/infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/type/absolutepath/AbsolutePathURLLoader.java
+++
b/infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/type/absolutepath/AbsolutePathURLLoader.java
@@ -24,7 +24,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.util.Map;
+import java.util.Properties;
import java.util.stream.Collectors;
/**
@@ -34,7 +34,7 @@ public final class AbsolutePathURLLoader implements
ShardingSphereURLLoader {
@Override
@SneakyThrows(IOException.class)
- public String load(final String configurationSubject, final Map<String,
String> parameters) {
+ public String load(final String configurationSubject, final Properties
queryProps) {
return
Files.readAllLines(getAbsoluteFile(configurationSubject).toPath(),
StandardCharsets.UTF_8).stream().collect(Collectors.joining(System.lineSeparator()));
}
diff --git
a/infra/url/type/absolutepath/src/test/java/org/apache/shardingsphere/infra/url/type/absolutepath/AbsolutePathURLLoaderTest.java
b/infra/url/type/absolutepath/src/test/java/org/apache/shardingsphere/infra/url/type/absolutepath/AbsolutePathURLLoaderTest.java
index 705548198ce..21f9b8ce52e 100644
---
a/infra/url/type/absolutepath/src/test/java/org/apache/shardingsphere/infra/url/type/absolutepath/AbsolutePathURLLoaderTest.java
+++
b/infra/url/type/absolutepath/src/test/java/org/apache/shardingsphere/infra/url/type/absolutepath/AbsolutePathURLLoaderTest.java
@@ -21,8 +21,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
-import java.util.Collections;
import java.util.Objects;
+import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -43,7 +43,7 @@ class AbsolutePathURLLoaderTest {
private void assertGetContent(final int expectedLength) {
String actual = new AbsolutePathURLLoader().load(
-
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("config/absolutepath/fixture.yaml")).getPath(),
Collections.emptyMap());
+
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("config/absolutepath/fixture.yaml")).getPath(),
new Properties());
assertThat(actual.length(), is(expectedLength));
}
}
diff --git
a/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/type/classpath/ClassPathURLLoader.java
b/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/type/classpath/ClassPathURLLoader.java
index 658c9dd8731..892d236c54d 100644
---
a/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/type/classpath/ClassPathURLLoader.java
+++
b/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/type/classpath/ClassPathURLLoader.java
@@ -24,8 +24,8 @@ import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
-import java.util.Map;
import java.util.Objects;
+import java.util.Properties;
import java.util.stream.Collectors;
/**
@@ -35,7 +35,7 @@ public final class ClassPathURLLoader implements
ShardingSphereURLLoader {
@Override
@SneakyThrows(IOException.class)
- public String load(final String configurationSubject, final Map<String,
String> parameters) {
+ public String load(final String configurationSubject, final Properties
queryProps) {
return
Files.readAllLines(getResourceFile(configurationSubject).toPath()).stream().collect(Collectors.joining(System.lineSeparator()));
}
diff --git
a/infra/url/type/classpath/src/test/java/org/apache/shardingsphere/infra/url/type/classpath/ClassPathURLLoaderTest.java
b/infra/url/type/classpath/src/test/java/org/apache/shardingsphere/infra/url/type/classpath/ClassPathURLLoaderTest.java
index 8cc4503aaf2..167d9cdccff 100644
---
a/infra/url/type/classpath/src/test/java/org/apache/shardingsphere/infra/url/type/classpath/ClassPathURLLoaderTest.java
+++
b/infra/url/type/classpath/src/test/java/org/apache/shardingsphere/infra/url/type/classpath/ClassPathURLLoaderTest.java
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
-import java.util.Collections;
+import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -41,6 +41,6 @@ class ClassPathURLLoaderTest {
}
private void assertGetContent(final int expectedLength) {
- assertThat(new
ClassPathURLLoader().load("config/classpath/fixture.yaml",
Collections.emptyMap()).length(), is(expectedLength));
+ assertThat(new
ClassPathURLLoader().load("config/classpath/fixture.yaml", new
Properties()).length(), is(expectedLength));
}
}