This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 cad7aff7fbc Support underscore property name for storage units (#35098)
cad7aff7fbc is described below
commit cad7aff7fbcbf12db70cda0976340369df0a4777
Author: Raigor <[email protected]>
AuthorDate: Fri Mar 28 14:09:02 2025 +0800
Support underscore property name for storage units (#35098)
---
.../pool/props/domain/DataSourcePoolProperties.java | 18 +++++++++++++++---
.../converter/DataSourceSegmentsConverterTest.java | 3 ++-
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git
a/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/domain/DataSourcePoolProperties.java
b/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/domain/DataSourcePoolProperties.java
index 7a1fd34d784..940be09f84e 100644
---
a/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/domain/DataSourcePoolProperties.java
+++
b/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/domain/DataSourcePoolProperties.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.datasource.pool.props.domain;
+import com.google.common.base.CaseFormat;
import com.google.common.base.Objects;
import lombok.Getter;
import
org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
@@ -39,6 +40,8 @@ import java.util.Optional;
@Getter
public final class DataSourcePoolProperties {
+ private static final String UNDERSCORE = "_";
+
private final String poolClassName;
private final ConnectionPropertySynonyms connectionPropertySynonyms;
@@ -51,10 +54,19 @@ public final class DataSourcePoolProperties {
Optional<DataSourcePoolMetaData> metaData =
TypedSPILoader.findService(DataSourcePoolMetaData.class, poolClassName);
this.poolClassName = metaData.map(optional ->
optional.getType().toString()).orElse(poolClassName);
Map<String, String> propertySynonyms =
metaData.map(DataSourcePoolMetaData::getPropertySynonyms).orElse(Collections.emptyMap());
- connectionPropertySynonyms = new ConnectionPropertySynonyms(props,
propertySynonyms);
- poolPropertySynonyms = new PoolPropertySynonyms(props,
propertySynonyms);
+ Map<String, Object> effectiveProps = convertToCamelKeys(props);
+ connectionPropertySynonyms = new
ConnectionPropertySynonyms(effectiveProps, propertySynonyms);
+ poolPropertySynonyms = new PoolPropertySynonyms(effectiveProps,
propertySynonyms);
Collection<String> transientFieldNames =
metaData.map(DataSourcePoolMetaData::getTransientFieldNames).orElse(Collections.emptyList());
- customProperties = new CustomDataSourcePoolProperties(props,
getStandardPropertyKeys(), transientFieldNames, propertySynonyms);
+ customProperties = new CustomDataSourcePoolProperties(effectiveProps,
getStandardPropertyKeys(), transientFieldNames, propertySynonyms);
+ }
+
+ private Map<String, Object> convertToCamelKeys(final Map<String, Object>
props) {
+ Map<String, Object> result = new LinkedHashMap<>(props.size(), 1F);
+ for (Entry<String, Object> entry : props.entrySet()) {
+ result.put(entry.getKey().contains(UNDERSCORE) ?
CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, entry.getKey()) :
entry.getKey(), entry.getValue());
+ }
+ return result;
}
private Collection<String> getStandardPropertyKeys() {
diff --git
a/parser/distsql/statement/src/test/java/org/apache/shardingsphere/distsql/segment/converter/DataSourceSegmentsConverterTest.java
b/parser/distsql/statement/src/test/java/org/apache/shardingsphere/distsql/segment/converter/DataSourceSegmentsConverterTest.java
index 794bdb36d4e..73dcafb71d5 100644
---
a/parser/distsql/statement/src/test/java/org/apache/shardingsphere/distsql/segment/converter/DataSourceSegmentsConverterTest.java
+++
b/parser/distsql/statement/src/test/java/org/apache/shardingsphere/distsql/segment/converter/DataSourceSegmentsConverterTest.java
@@ -46,11 +46,12 @@ class DataSourceSegmentsConverterTest {
assertTrue(actual.keySet().containsAll(Arrays.asList("ds0", "ds1")));
assertThat(actual.values().iterator().next().getAllLocalProperties().get("username"),
is("root0"));
assertThat(actual.values().iterator().next().getAllStandardProperties().get("maxPoolSize"),
is("30"));
+
assertThat(actual.values().iterator().next().getAllStandardProperties().get("minPoolSize"),
is("10"));
}
private Collection<DataSourceSegment> createDataSourceSegments() {
Collection<DataSourceSegment> result = new LinkedList<>();
- Properties customPoolProps = PropertiesBuilder.build(new
Property("maxPoolSize", "30"));
+ Properties customPoolProps = PropertiesBuilder.build(new
Property("maxPoolSize", "30"), new Property("min_pool_size", "10"));
result.add(new HostnameAndPortBasedDataSourceSegment("ds0",
"127.0.0.1", "3306", "demo_ds_0", "root0", "root0", customPoolProps));
result.add(new URLBasedDataSourceSegment("ds1",
"jdbc:mysql://127.0.0.1:3306/demo_ds_1?useSSL=false", "root1", "root1",
customPoolProps));
return result;