This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 8cf9ff3 Refactor DataSourceProperties to PropertySynonyms and
CustomDataSourceProperties (#14874)
8cf9ff3 is described below
commit 8cf9ff3b4120dbadd2469b65b6ee6de1a1c8187a
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jan 19 07:12:14 2022 +0800
Refactor DataSourceProperties to PropertySynonyms and
CustomDataSourceProperties (#14874)
* Refactor DataSourceProperties
* Add ConnectionProperties
* Add PropertySynonyms
* Add CustomDataSourceProperties
* Refactor DataSourceProperties
* Refactor DataSourceProperties
* Fix test case
* Fix HikariDataSourcePoolMetaData
---
...hardingRuleAlteredJobConfigurationPreparer.java | 2 +-
.../pool/creator/DataSourcePoolCreator.java | 2 +-
.../impl/HikariDataSourcePoolMetaData.java | 1 +
.../datasource/props/DataSourceProperties.java | 76 +++++++------
.../props/custom/CustomDataSourceProperties.java | 41 +++++++
.../props/synonym/ConnectionPropertySynonyms.java | 43 ++++++++
.../props/synonym/PoolPropertySynonyms.java | 46 ++++++++
.../datasource/props/synonym/PropertySynonyms.java | 77 ++++++++++++++
.../YamlDataSourceConfigurationSwapper.java | 2 +-
.../datasource/props/DataSourcePropertiesTest.java | 118 ++++++++++-----------
.../custom/CustomDataSourcePropertiesTest.java | 51 +++++++++
.../synonym/ConnectionPropertySynonymsTest.java | 88 +++++++++++++++
.../props/synonym/PoolPropertySynonymsTest.java | 110 +++++++++++++++++++
.../YamlDataSourcePropertiesSwapperTest.java | 6 +-
.../jdbc/core/connection/ConnectionManager.java | 2 +-
...dingSpherePipelineDataSourcePropertiesTest.java | 4 +-
.../impl/DataSourceMetaDataPersistServiceTest.java | 8 +-
.../rql/resource/DataSourceQueryResultSet.java | 16 ++-
.../resource/ResourceSegmentsConverterTest.java | 4 +-
.../distsql/rql/DataSourceQueryResultSetTest.java | 7 +-
...oxyProxyResourceConfigurationConverterTest.java | 2 +-
21 files changed, 585 insertions(+), 121 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/schedule/ShardingRuleAlteredJobConfigurationPreparer.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/schedule/ShardingRuleAlteredJobConfigurationPreparer.java
index 3091587..62e60d2 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/schedule/ShardingRuleAlteredJobConfigurationPreparer.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/schedule/ShardingRuleAlteredJobConfigurationPreparer.java
@@ -139,7 +139,7 @@ public final class
ShardingRuleAlteredJobConfigurationPreparer implements RuleAl
tableMap.put(dataNode.getTableName(),
each.getLogicTableName());
}
}
- DumperConfiguration dumperConfig = createDumperConfig(dataSourceName,
dataSourcePropsMap.get(dataSourceName).getLocalProperties(), tableMap);
+ DumperConfiguration dumperConfig = createDumperConfig(dataSourceName,
dataSourcePropsMap.get(dataSourceName).getAllLocalProperties(), tableMap);
ImporterConfiguration importerConfig =
createImporterConfig(pipelineConfig, handleConfig, shardingColumnsMap);
TaskConfiguration taskConfig = new TaskConfiguration(handleConfig,
dumperConfig, importerConfig);
log.info("toTaskConfigs, dataSourceName={}, taskConfig={}",
dataSourceName, taskConfig);
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreator.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreator.java
index 8ea049c..2e39f13 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreator.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreator.java
@@ -74,7 +74,7 @@ public final class DataSourcePoolCreator {
}
private static void setConfiguredFields(final DataSourceProperties
dataSourceProps, final DataSourceReflection dataSourceReflection, final
DataSourcePoolMetaData poolMetaData) {
- for (Entry<String, Object> entry :
dataSourceProps.getLocalProperties().entrySet()) {
+ for (Entry<String, Object> entry :
dataSourceProps.getAllLocalProperties().entrySet()) {
String fieldName = entry.getKey();
Object fieldValue = entry.getValue();
if (isValidProperty(fieldName, fieldValue, poolMetaData)) {
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/metadata/impl/HikariDataSourcePoolMetaData.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/metadata/impl/HikariDataSourcePoolMetaData.java
index ba9bd19..0552a79 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/metadata/impl/HikariDataSourcePoolMetaData.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/metadata/impl/HikariDataSourcePoolMetaData.java
@@ -57,6 +57,7 @@ public final class HikariDataSourcePoolMetaData implements
DataSourcePoolMetaDat
}
private void buildPropertySynonyms() {
+ propertySynonyms.put("url", "jdbcUrl");
propertySynonyms.put("connectionTimeoutMilliseconds",
"connectionTimeout");
propertySynonyms.put("idleTimeoutMilliseconds", "idleTimeout");
propertySynonyms.put("maxLifetimeMilliseconds", "maxLifetime");
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/DataSourceProperties.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/DataSourceProperties.java
index 4d0a5da..b3fb06e 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/DataSourceProperties.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/DataSourceProperties.java
@@ -18,11 +18,15 @@
package org.apache.shardingsphere.infra.config.datasource.props;
import com.google.common.base.Objects;
-import lombok.AccessLevel;
import lombok.Getter;
import
org.apache.shardingsphere.infra.config.datasource.pool.metadata.DataSourcePoolMetaDataFactory;
+import
org.apache.shardingsphere.infra.config.datasource.props.custom.CustomDataSourceProperties;
+import
org.apache.shardingsphere.infra.config.datasource.props.synonym.ConnectionPropertySynonyms;
+import
org.apache.shardingsphere.infra.config.datasource.props.synonym.PoolPropertySynonyms;
+import java.util.Collection;
import java.util.LinkedHashMap;
+import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
@@ -34,43 +38,51 @@ public final class DataSourceProperties {
private final String dataSourceClassName;
- @Getter(AccessLevel.NONE)
- private final Map<String, String> propertySynonyms;
+ private final ConnectionPropertySynonyms connectionPropertySynonyms;
- private final Map<String, Object> standardProperties;
+ private final PoolPropertySynonyms poolPropertySynonyms;
- private final Map<String, Object> localProperties;
+ private final CustomDataSourceProperties customDataSourceProperties;
public DataSourceProperties(final String dataSourceClassName, final
Map<String, Object> props) {
+ Map<String, String> propertySynonyms =
DataSourcePoolMetaDataFactory.newInstance(dataSourceClassName).getPropertySynonyms();
this.dataSourceClassName = dataSourceClassName;
- propertySynonyms =
DataSourcePoolMetaDataFactory.newInstance(dataSourceClassName).getPropertySynonyms();
- standardProperties = buildStandardProperties(props);
- localProperties = buildLocalProperties(props);
+ connectionPropertySynonyms = new ConnectionPropertySynonyms(props,
propertySynonyms);
+ poolPropertySynonyms = new PoolPropertySynonyms(props,
propertySynonyms);
+ customDataSourceProperties = new CustomDataSourceProperties(props,
getStandardPropertyKeys(), propertySynonyms);
}
- private Map<String, Object> buildLocalProperties(final Map<String, Object>
props) {
- Map<String, Object> result = new LinkedHashMap<>(props);
- for (Entry<String, String> entry : propertySynonyms.entrySet()) {
- String standardPropertyName = entry.getKey();
- String synonymsPropertyName = entry.getValue();
- if (props.containsKey(standardPropertyName)) {
- result.put(synonymsPropertyName,
props.get(standardPropertyName));
- result.remove(standardPropertyName);
- }
- }
+ private Collection<String> getStandardPropertyKeys() {
+ Collection<String> result = new
LinkedList<>(connectionPropertySynonyms.getStandardPropertyKeys());
+ result.addAll(poolPropertySynonyms.getStandardPropertyKeys());
return result;
}
- private Map<String, Object> buildStandardProperties(final Map<String,
Object> props) {
- Map<String, Object> result = new LinkedHashMap<>(props);
- for (Entry<String, String> entry : propertySynonyms.entrySet()) {
- String standardPropertyName = entry.getKey();
- String synonymsPropertyName = entry.getValue();
- if (props.containsKey(synonymsPropertyName)) {
- result.put(standardPropertyName,
props.get(synonymsPropertyName));
- result.remove(synonymsPropertyName);
- }
- }
+ /**
+ * Get all standard properties.
+ *
+ * @return all standard properties
+ */
+ public Map<String, Object> getAllStandardProperties() {
+ Map<String, Object> result = new LinkedHashMap<>(
+ connectionPropertySynonyms.getStandardProperties().size() +
poolPropertySynonyms.getStandardProperties().size() +
customDataSourceProperties.getProperties().size(), 1);
+ result.putAll(connectionPropertySynonyms.getStandardProperties());
+ result.putAll(poolPropertySynonyms.getStandardProperties());
+ result.putAll(customDataSourceProperties.getProperties());
+ return result;
+ }
+
+ /**
+ * Get all local properties.
+ *
+ * @return all local properties
+ */
+ public Map<String, Object> getAllLocalProperties() {
+ Map<String, Object> result = new LinkedHashMap<>(
+ connectionPropertySynonyms.getLocalProperties().size() +
poolPropertySynonyms.getLocalProperties().size() +
customDataSourceProperties.getProperties().size(), 1);
+ result.putAll(connectionPropertySynonyms.getLocalProperties());
+ result.putAll(poolPropertySynonyms.getLocalProperties());
+ result.putAll(customDataSourceProperties.getProperties());
return result;
}
@@ -83,11 +95,11 @@ public final class DataSourceProperties {
if
(!dataSourceClassName.equals(dataSourceProperties.dataSourceClassName)) {
return false;
}
- for (Entry<String, Object> entry : localProperties.entrySet()) {
- if
(!dataSourceProperties.localProperties.containsKey(entry.getKey())) {
+ for (Entry<String, Object> entry : getAllLocalProperties().entrySet())
{
+ if
(!dataSourceProperties.getAllLocalProperties().containsKey(entry.getKey())) {
continue;
}
- if
(!String.valueOf(entry.getValue()).equals(String.valueOf(dataSourceProperties.localProperties.get(entry.getKey()))))
{
+ if
(!String.valueOf(entry.getValue()).equals(String.valueOf(dataSourceProperties.getAllLocalProperties().get(entry.getKey()))))
{
return false;
}
}
@@ -97,7 +109,7 @@ public final class DataSourceProperties {
@Override
public int hashCode() {
StringBuilder stringBuilder = new StringBuilder();
- for (Entry<String, Object> entry : localProperties.entrySet()) {
+ for (Entry<String, Object> entry : getAllLocalProperties().entrySet())
{
stringBuilder.append(entry.getKey()).append(entry.getValue());
}
return Objects.hashCode(dataSourceClassName, stringBuilder.toString());
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/custom/CustomDataSourceProperties.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/custom/CustomDataSourceProperties.java
new file mode 100644
index 0000000..2572197
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/custom/CustomDataSourceProperties.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.config.datasource.props.custom;
+
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Custom data source properties.
+ */
+@Getter
+@EqualsAndHashCode
+public final class CustomDataSourceProperties {
+
+ private final Map<String, Object> properties;
+
+ public CustomDataSourceProperties(final Map<String, Object> props, final
Collection<String> standardPropertyKeys, final Map<String, String>
propertySynonyms) {
+ properties = new LinkedHashMap<>(props);
+ standardPropertyKeys.forEach(properties::remove);
+ propertySynonyms.values().forEach(properties::remove);
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/ConnectionPropertySynonyms.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/ConnectionPropertySynonyms.java
new file mode 100644
index 0000000..bf83002
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/ConnectionPropertySynonyms.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.config.datasource.props.synonym;
+
+import lombok.EqualsAndHashCode;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Connection property synonyms.
+ */
+@EqualsAndHashCode(callSuper = true)
+public final class ConnectionPropertySynonyms extends PropertySynonyms {
+
+ private static final Collection<String> STANDARD_PROPERTY_KEYS = new
HashSet<>();
+
+ static {
+ STANDARD_PROPERTY_KEYS.add("url");
+ STANDARD_PROPERTY_KEYS.add("username");
+ STANDARD_PROPERTY_KEYS.add("password");
+ }
+
+ public ConnectionPropertySynonyms(final Map<String, Object> props, final
Map<String, String> propertySynonyms) {
+ super(props, STANDARD_PROPERTY_KEYS, propertySynonyms);
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/PoolPropertySynonyms.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/PoolPropertySynonyms.java
new file mode 100644
index 0000000..9bb0ca2
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/PoolPropertySynonyms.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.config.datasource.props.synonym;
+
+import lombok.EqualsAndHashCode;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * Pool property synonyms.
+ */
+@EqualsAndHashCode(callSuper = true)
+public final class PoolPropertySynonyms extends PropertySynonyms {
+
+ private static final Collection<String> STANDARD_PROPERTY_KEYS = new
HashSet<>();
+
+ static {
+ STANDARD_PROPERTY_KEYS.add("connectionTimeoutMilliseconds");
+ STANDARD_PROPERTY_KEYS.add("idleTimeoutMilliseconds");
+ STANDARD_PROPERTY_KEYS.add("maxLifetimeMilliseconds");
+ STANDARD_PROPERTY_KEYS.add("maxPoolSize");
+ STANDARD_PROPERTY_KEYS.add("minPoolSize");
+ STANDARD_PROPERTY_KEYS.add("readOnly");
+ }
+
+ public PoolPropertySynonyms(final Map<String, Object> props, final
Map<String, String> propertySynonyms) {
+ super(props, STANDARD_PROPERTY_KEYS, propertySynonyms);
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/PropertySynonyms.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/PropertySynonyms.java
new file mode 100644
index 0000000..ce36ea0
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/PropertySynonyms.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.config.datasource.props.synonym;
+
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Property synonyms.
+ */
+@Getter
+@EqualsAndHashCode
+public abstract class PropertySynonyms {
+
+ private final Collection<String> standardPropertyKeys;
+
+ private final Map<String, Object> standardProperties;
+
+ private final Map<String, Object> localProperties;
+
+ public PropertySynonyms(final Map<String, Object> props, final
Collection<String> standardPropertyKeys, final Map<String, String>
propertySynonyms) {
+ this.standardPropertyKeys = standardPropertyKeys;
+ standardProperties = buildStandardProperties(props,
standardPropertyKeys, propertySynonyms);
+ localProperties = buildLocalProperties(props, standardPropertyKeys,
propertySynonyms);
+ }
+
+ private Map<String, Object> buildStandardProperties(final Map<String,
Object> props, final Collection<String> standardPropertyKeys, final Map<String,
String> propertySynonyms) {
+ Map<String, Object> result = new
LinkedHashMap<>(standardPropertyKeys.size(), 1);
+ for (String each : standardPropertyKeys) {
+ if (props.containsKey(each)) {
+ result.put(each, props.get(each));
+ } else if (props.containsKey(propertySynonyms.get(each))) {
+ result.put(each, props.get(propertySynonyms.get(each)));
+ }
+ }
+ return result;
+ }
+
+ private Map<String, Object> buildLocalProperties(final Map<String, Object>
props, final Collection<String> standardPropertyKeys, final Map<String, String>
propertySynonyms) {
+ Map<String, Object> result = new
LinkedHashMap<>(standardPropertyKeys.size(), 1);
+ for (String each : getLocalPropertyKeys(standardPropertyKeys,
propertySynonyms)) {
+ if (props.containsKey(each)) {
+ result.put(each, props.get(each));
+ }
+ }
+ for (String each : standardPropertyKeys) {
+ if (props.containsKey(each)) {
+ result.put(propertySynonyms.getOrDefault(each, each),
props.get(each));
+ }
+ }
+ return result;
+ }
+
+ private Collection<String> getLocalPropertyKeys(final Collection<String>
standardPropertyKey, final Map<String, String> propertySynonyms) {
+ return
standardPropertyKey.stream().filter(propertySynonyms::containsKey).map(propertySynonyms::get).collect(Collectors.toSet());
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlDataSourceConfigurationSwapper.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlDataSourceConfigurationSwapper.java
index 0fa41e9..159bf65 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlDataSourceConfigurationSwapper.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlDataSourceConfigurationSwapper.java
@@ -90,7 +90,7 @@ public final class YamlDataSourceConfigurationSwapper {
* @return data source map
*/
public Map<String, Object> swapToMap(final DataSourceProperties
dataSourceProps) {
- Map<String, Object> result = new
HashMap<>(dataSourceProps.getStandardProperties());
+ Map<String, Object> result = new
HashMap<>(dataSourceProps.getAllStandardProperties());
result.put(DATA_SOURCE_CLASS_NAME_KEY,
dataSourceProps.getDataSourceClassName());
return result;
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/DataSourcePropertiesTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/DataSourcePropertiesTest.java
index 47c4492..64dd0b9 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/DataSourcePropertiesTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/DataSourcePropertiesTest.java
@@ -43,54 +43,7 @@ public final class DataSourcePropertiesTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void assertEquals() {
- assertThat(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("root")),
- is(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("root"))));
- }
-
- @Test
- public void assertNotEqualsWithNullValue() {
- assertFalse(new DataSourceProperties(MockedDataSource.class.getName(),
new HashMap<>()).equals(null));
- }
-
- @Test
- public void assertNotEqualsWithDifferentDataSourceClassName() {
- assertThat(new DataSourceProperties("FooDataSourceClass", new
HashMap<>()), not(new DataSourceProperties("BarDataSourceClass", new
HashMap<>())));
- }
-
- @Test
- public void assertNotEqualsWithDifferentProperties() {
- DataSourceProperties actual = new
DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("foo"));
- DataSourceProperties expected = new
DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("bar"));
- assertThat(actual, not(expected));
- }
-
- @Test
- public void assertSameHashCode() {
- assertThat(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("root")).hashCode(),
- is(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("root")).hashCode()));
- }
-
- @Test
- public void assertDifferentHashCodeWithDifferentDataSourceClassName() {
- assertThat(new DataSourceProperties("FooDataSourceClass",
createUserProperties("foo")).hashCode(),
- not(new DataSourceProperties("BarDataSourceClass",
createUserProperties("foo")).hashCode()));
- }
-
- @Test
- public void assertDifferentHashCodeWithDifferentProperties() {
- assertThat(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("foo")).hashCode(),
- not(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("bar")).hashCode()));
- }
-
- private Map<String, Object> createUserProperties(final String username) {
- Map<String, Object> result = new LinkedHashMap<>(1, 1);
- result.put("username", username);
- return result;
- }
-
+
@SuppressWarnings("unchecked")
@Test
public void assertGetDataSourceConfigurationWithConnectionInitSqls() {
@@ -102,21 +55,21 @@ public final class DataSourcePropertiesTest {
actualDataSource.setConnectionInitSqls(Arrays.asList("set names
utf8mb4;", "set names utf8;"));
DataSourceProperties actual =
DataSourcePropertiesCreator.create(actualDataSource);
assertThat(actual.getDataSourceClassName(),
is(BasicDataSource.class.getName()));
-
assertThat(actual.getLocalProperties().get("driverClassName").toString(),
is(MockedDataSource.class.getCanonicalName()));
- assertThat(actual.getLocalProperties().get("url").toString(),
is("jdbc:mock://127.0.0.1/foo_ds"));
- assertThat(actual.getLocalProperties().get("username").toString(),
is("root"));
- assertThat(actual.getLocalProperties().get("password").toString(),
is("root"));
- assertNull(actual.getLocalProperties().get("loginTimeout"));
- assertThat(actual.getLocalProperties().get("connectionInitSqls"),
instanceOf(List.class));
- List<String> actualConnectionInitSql = (List<String>)
actual.getLocalProperties().get("connectionInitSqls");
+
assertThat(actual.getAllLocalProperties().get("driverClassName").toString(),
is(MockedDataSource.class.getCanonicalName()));
+ assertThat(actual.getAllLocalProperties().get("url").toString(),
is("jdbc:mock://127.0.0.1/foo_ds"));
+ assertThat(actual.getAllLocalProperties().get("username").toString(),
is("root"));
+ assertThat(actual.getAllLocalProperties().get("password").toString(),
is("root"));
+ assertNull(actual.getAllLocalProperties().get("loginTimeout"));
+ assertThat(actual.getAllLocalProperties().get("connectionInitSqls"),
instanceOf(List.class));
+ List<String> actualConnectionInitSql = (List<String>)
actual.getAllLocalProperties().get("connectionInitSqls");
assertThat(actualConnectionInitSql, hasItem("set names utf8mb4;"));
assertThat(actualConnectionInitSql, hasItem("set names utf8;"));
}
-
+
@Test
- public void assertGetLocalProperties() {
+ public void assertgetAllLocalProperties() {
DataSourceProperties originalDataSourceProps = new
DataSourceProperties(MockedDataSource.class.getName(), getProperties());
- Map<String, Object> actualAllProperties =
originalDataSourceProps.getLocalProperties();
+ Map<String, Object> actualAllProperties =
originalDataSourceProps.getAllLocalProperties();
assertNotNull(actualAllProperties);
assertThat(actualAllProperties.size(), is(7));
assertTrue(actualAllProperties.containsKey("driverClassName"));
@@ -134,7 +87,7 @@ public final class DataSourcePropertiesTest {
assertTrue(actualAllProperties.containsKey("idleTimeout"));
assertTrue(actualAllProperties.containsValue("30000"));
}
-
+
private Map<String, Object> getProperties() {
Map<String, Object> result = new HashMap<>(7, 1);
result.put("driverClassName",
MockedDataSource.class.getCanonicalName());
@@ -146,4 +99,51 @@ public final class DataSourcePropertiesTest {
result.put("idleTimeout", "30000");
return result;
}
+
+ @Test
+ public void assertEquals() {
+ assertThat(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("root")),
+ is(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("root"))));
+ }
+
+ @Test
+ public void assertNotEqualsWithNullValue() {
+ assertFalse(new DataSourceProperties(MockedDataSource.class.getName(),
new HashMap<>()).equals(null));
+ }
+
+ @Test
+ public void assertNotEqualsWithDifferentDataSourceClassName() {
+ assertThat(new DataSourceProperties("FooDataSourceClass", new
HashMap<>()), not(new DataSourceProperties("BarDataSourceClass", new
HashMap<>())));
+ }
+
+ @Test
+ public void assertNotEqualsWithDifferentProperties() {
+ DataSourceProperties actual = new
DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("foo"));
+ DataSourceProperties expected = new
DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("bar"));
+ assertThat(actual, not(expected));
+ }
+
+ @Test
+ public void assertSameHashCode() {
+ assertThat(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("root")).hashCode(),
+ is(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("root")).hashCode()));
+ }
+
+ @Test
+ public void assertDifferentHashCodeWithDifferentDataSourceClassName() {
+ assertThat(new DataSourceProperties("FooDataSourceClass",
createUserProperties("foo")).hashCode(),
+ not(new DataSourceProperties("BarDataSourceClass",
createUserProperties("foo")).hashCode()));
+ }
+
+ @Test
+ public void assertDifferentHashCodeWithDifferentProperties() {
+ assertThat(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("foo")).hashCode(),
+ not(new DataSourceProperties(MockedDataSource.class.getName(),
createUserProperties("bar")).hashCode()));
+ }
+
+ private Map<String, Object> createUserProperties(final String username) {
+ Map<String, Object> result = new LinkedHashMap<>(1, 1);
+ result.put("username", username);
+ return result;
+ }
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/custom/CustomDataSourcePropertiesTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/custom/CustomDataSourcePropertiesTest.java
new file mode 100644
index 0000000..e369e8b
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/custom/CustomDataSourcePropertiesTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.config.datasource.props.custom;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class CustomDataSourcePropertiesTest {
+
+ @Test
+ public void assertGetProperties() {
+ Map<String, Object> actual = new
CustomDataSourceProperties(createProperties(), Arrays.asList("username",
"password"), createPropertySynonyms()).getProperties();
+ assertThat(actual.size(), is(1));
+ assertThat(actual.get("foo"), is("bar"));
+ }
+
+ private Map<String, Object> createProperties() {
+ Map<String, Object> result = new LinkedHashMap<>(3, 1);
+ result.put("user", "root");
+ result.put("password", "root");
+ result.put("foo", "bar");
+ return result;
+ }
+
+ private Map<String, String> createPropertySynonyms() {
+ Map<String, String> result = new LinkedHashMap<>(1, 1);
+ result.put("username", "user");
+ return result;
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/ConnectionPropertySynonymsTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/ConnectionPropertySynonymsTest.java
new file mode 100644
index 0000000..eba7bff
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/ConnectionPropertySynonymsTest.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.config.datasource.props.synonym;
+
+import org.junit.Test;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class ConnectionPropertySynonymsTest {
+
+ @Test
+ public void assertGetStandardPropertiesWithStandardProperties() {
+ ConnectionPropertySynonyms actual = new
ConnectionPropertySynonyms(createStandardProperties(),
createPropertySynonyms());
+ assertThat(actual.getStandardProperties().size(), is(3));
+ assertThat(actual.getStandardProperties().get("url"),
is("jdbc:mock://127.0.0.1/foo_ds"));
+ assertThat(actual.getStandardProperties().get("username"), is("root"));
+ assertThat(actual.getStandardProperties().get("password"), is("root"));
+ }
+
+ @Test
+ public void assertGetStandardPropertiesWithLocalProperties() {
+ ConnectionPropertySynonyms actual = new
ConnectionPropertySynonyms(createLocalProperties(), createPropertySynonyms());
+ assertThat(actual.getStandardProperties().size(), is(3));
+ assertThat(actual.getStandardProperties().get("url"),
is("jdbc:mock://127.0.0.1/foo_ds"));
+ assertThat(actual.getStandardProperties().get("username"), is("root"));
+ assertThat(actual.getStandardProperties().get("password"), is("root"));
+ }
+
+ @Test
+ public void assertGetLocalPropertiesWithStandardProperties() {
+ ConnectionPropertySynonyms actual = new
ConnectionPropertySynonyms(createStandardProperties(),
createPropertySynonyms());
+ assertThat(actual.getLocalProperties().size(), is(3));
+ assertThat(actual.getLocalProperties().get("jdbcUrl"),
is("jdbc:mock://127.0.0.1/foo_ds"));
+ assertThat(actual.getLocalProperties().get("user"), is("root"));
+ assertThat(actual.getLocalProperties().get("password"), is("root"));
+ }
+
+ @Test
+ public void assertGetLocalPropertiesWithLocalProperties() {
+ ConnectionPropertySynonyms actual = new
ConnectionPropertySynonyms(createLocalProperties(), createPropertySynonyms());
+ assertThat(actual.getLocalProperties().size(), is(3));
+ assertThat(actual.getLocalProperties().get("jdbcUrl"),
is("jdbc:mock://127.0.0.1/foo_ds"));
+ assertThat(actual.getLocalProperties().get("user"), is("root"));
+ assertThat(actual.getLocalProperties().get("password"), is("root"));
+ }
+
+ private Map<String, Object> createStandardProperties() {
+ Map<String, Object> result = new LinkedHashMap<>(3, 1);
+ result.put("url", "jdbc:mock://127.0.0.1/foo_ds");
+ result.put("username", "root");
+ result.put("password", "root");
+ return result;
+ }
+
+ private Map<String, Object> createLocalProperties() {
+ Map<String, Object> result = new LinkedHashMap<>(3, 1);
+ result.put("jdbcUrl", "jdbc:mock://127.0.0.1/foo_ds");
+ result.put("user", "root");
+ result.put("password", "root");
+ return result;
+ }
+
+ private Map<String, String> createPropertySynonyms() {
+ Map<String, String> result = new LinkedHashMap<>(2, 1);
+ result.put("url", "jdbcUrl");
+ result.put("username", "user");
+ return result;
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/PoolPropertySynonymsTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/PoolPropertySynonymsTest.java
new file mode 100644
index 0000000..5b41821
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/props/synonym/PoolPropertySynonymsTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.config.datasource.props.synonym;
+
+import org.junit.Test;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+
+public final class PoolPropertySynonymsTest {
+
+ @Test
+ public void assertGetStandardPropertiesWithStandardProperties() {
+ PoolPropertySynonyms actual = new
PoolPropertySynonyms(createStandardProperties(), createPropertySynonyms());
+ assertThat(actual.getStandardProperties().size(), is(6));
+
assertThat(actual.getStandardProperties().get("connectionTimeoutMilliseconds"),
is(30000));
+
assertThat(actual.getStandardProperties().get("idleTimeoutMilliseconds"),
is(180000));
+
assertThat(actual.getStandardProperties().get("maxLifetimeMilliseconds"),
is(180000));
+ assertThat(actual.getStandardProperties().get("maxPoolSize"), is(30));
+ assertThat(actual.getStandardProperties().get("minPoolSize"), is(10));
+ assertFalse((Boolean) actual.getStandardProperties().get("readOnly"));
+ }
+
+ @Test
+ public void assertGetStandardPropertiesWithLocalProperties() {
+ PoolPropertySynonyms actual = new
PoolPropertySynonyms(createLocalProperties(), createPropertySynonyms());
+ assertThat(actual.getStandardProperties().size(), is(6));
+
assertThat(actual.getStandardProperties().get("connectionTimeoutMilliseconds"),
is(30000));
+
assertThat(actual.getStandardProperties().get("idleTimeoutMilliseconds"),
is(180000));
+
assertThat(actual.getStandardProperties().get("maxLifetimeMilliseconds"),
is(180000));
+ assertThat(actual.getStandardProperties().get("maxPoolSize"), is(30));
+ assertThat(actual.getStandardProperties().get("minPoolSize"), is(10));
+ assertFalse((Boolean) actual.getStandardProperties().get("readOnly"));
+ }
+
+ @Test
+ public void assertGetLocalPropertiesWithStandardProperties() {
+ PoolPropertySynonyms actual = new
PoolPropertySynonyms(createStandardProperties(), createPropertySynonyms());
+ assertThat(actual.getLocalProperties().size(), is(6));
+ assertThat(actual.getLocalProperties().get("connectionTimeout"),
is(30000));
+ assertThat(actual.getLocalProperties().get("idleTimeout"), is(180000));
+ assertThat(actual.getLocalProperties().get("maxLifetime"), is(180000));
+ assertThat(actual.getLocalProperties().get("maximumPoolSize"), is(30));
+ assertThat(actual.getLocalProperties().get("minimumIdle"), is(10));
+ assertFalse((Boolean) actual.getLocalProperties().get("readOnly"));
+ }
+
+ @Test
+ public void assertGetLocalPropertiesWithLocalProperties() {
+ PoolPropertySynonyms actual = new
PoolPropertySynonyms(createLocalProperties(), createPropertySynonyms());
+ assertThat(actual.getLocalProperties().size(), is(6));
+ assertThat(actual.getLocalProperties().get("connectionTimeout"),
is(30000));
+ assertThat(actual.getLocalProperties().get("idleTimeout"), is(180000));
+ assertThat(actual.getLocalProperties().get("maxLifetime"), is(180000));
+ assertThat(actual.getLocalProperties().get("maximumPoolSize"), is(30));
+ assertThat(actual.getLocalProperties().get("minimumIdle"), is(10));
+ assertFalse((Boolean) actual.getLocalProperties().get("readOnly"));
+ }
+
+ private Map<String, Object> createStandardProperties() {
+ Map<String, Object> result = new LinkedHashMap<>(6, 1);
+ result.put("connectionTimeoutMilliseconds", 30000);
+ result.put("idleTimeoutMilliseconds", 180000);
+ result.put("maxLifetimeMilliseconds", 180000);
+ result.put("maxPoolSize", 30);
+ result.put("minPoolSize", 10);
+ result.put("readOnly", false);
+ return result;
+ }
+
+ private Map<String, Object> createLocalProperties() {
+ Map<String, Object> result = new LinkedHashMap<>(6, 1);
+ result.put("connectionTimeout", 30000);
+ result.put("idleTimeout", 180000);
+ result.put("maxLifetime", 180000);
+ result.put("maximumPoolSize", 30);
+ result.put("minimumIdle", 10);
+ result.put("readOnly", false);
+ return result;
+ }
+
+ private Map<String, String> createPropertySynonyms() {
+ Map<String, String> result = new LinkedHashMap<>(5, 1);
+ result.put("connectionTimeoutMilliseconds", "connectionTimeout");
+ result.put("idleTimeoutMilliseconds", "idleTimeout");
+ result.put("maxLifetimeMilliseconds", "maxLifetime");
+ result.put("maxPoolSize", "maximumPoolSize");
+ result.put("minPoolSize", "minimumIdle");
+ return result;
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlDataSourcePropertiesSwapperTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlDataSourcePropertiesSwapperTest.java
index 8db0194..277f764 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlDataSourcePropertiesSwapperTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/YamlDataSourcePropertiesSwapperTest.java
@@ -58,9 +58,9 @@ public final class YamlDataSourcePropertiesSwapperTest {
yamlConfig.put("username", "root");
DataSourceProperties actual =
swapper.swapToDataSourceProperties(yamlConfig);
assertThat(actual.getDataSourceClassName(),
is(MockedDataSource.class.getCanonicalName()));
- assertThat(actual.getLocalProperties().size(), is(2));
- assertThat(actual.getLocalProperties().get("url").toString(),
is("xx:xxx"));
- assertThat(actual.getLocalProperties().get("username").toString(),
is("root"));
+ assertThat(actual.getAllLocalProperties().size(), is(2));
+ assertThat(actual.getAllLocalProperties().get("url").toString(),
is("xx:xxx"));
+ assertThat(actual.getAllLocalProperties().get("username").toString(),
is("root"));
}
@Test
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
index 64befc7..6f328e1 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
@@ -124,7 +124,7 @@ public final class ConnectionManager implements
ExecutorJDBCManager, AutoCloseab
private DataSourceProperties createDataSourceProperties(final
ComputeNodeInstance instance, final Collection<ShardingSphereUser> users,
final
DataSourceProperties dataSourcePropsSample, final String schema) {
- Map<String, Object> props = dataSourcePropsSample.getLocalProperties();
+ Map<String, Object> props =
dataSourcePropsSample.getAllLocalProperties();
props.put("jdbcUrl", createJdbcUrl(instance, schema, props));
ShardingSphereUser user = users.iterator().next();
props.put("username", user.getGrantee().getUsername());
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/infra/config/datasource/config/impl/ShardingSpherePipelineDataSourcePropertiesTest.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/infra/config/datasource/config/impl/ShardingSpherePipelineDataSourcePropertiesTest.java
index bc44647..baa0012 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/infra/config/datasource/config/impl/ShardingSpherePipelineDataSourcePropertiesTest.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/infra/config/datasource/config/impl/ShardingSpherePipelineDataSourcePropertiesTest.java
@@ -40,8 +40,8 @@ public final class
ShardingSpherePipelineDataSourcePropertiesTest {
queryProps.setProperty("rewriteBatchedStatements",
Boolean.TRUE.toString());
dataSourceConfig.appendJDBCQueryProperties(queryProps);
List<DataSourceProperties> actual = new
ArrayList<>(getDataSourcePropertiesMap(dataSourceConfig.getRootConfig().getDataSources()).values());
- assertThat(actual.get(0).getLocalProperties().get("url"),
is("jdbc:mysql://192.168.0.2:3306/scaling?serverTimezone=UTC&useSSL=false&rewriteBatchedStatements=true"));
- assertThat(actual.get(1).getLocalProperties().get("url"),
is("jdbc:mysql://192.168.0.1:3306/scaling?serverTimezone=UTC&useSSL=false&rewriteBatchedStatements=true"));
+ assertThat(actual.get(0).getAllLocalProperties().get("url"),
is("jdbc:mysql://192.168.0.2:3306/scaling?serverTimezone=UTC&useSSL=false&rewriteBatchedStatements=true"));
+ assertThat(actual.get(1).getAllLocalProperties().get("url"),
is("jdbc:mysql://192.168.0.1:3306/scaling?serverTimezone=UTC&useSSL=false&rewriteBatchedStatements=true"));
}
private String getDataSourceYaml() {
diff --git
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/impl/DataSourceMetaDataPersistServiceTest.java
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/impl/DataSourceMetaDataPersistServiceTest.java
index e59c492..9f38c4c 100644
---
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/impl/DataSourceMetaDataPersistServiceTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/impl/DataSourceMetaDataPersistServiceTest.java
@@ -67,10 +67,10 @@ public final class DataSourceMetaDataPersistServiceTest {
private void assertDataSourceProperties(final DataSourceProperties actual,
final DataSourceProperties expected) {
assertThat(actual.getDataSourceClassName(),
is(expected.getDataSourceClassName()));
- assertThat(actual.getLocalProperties().get("url"),
is(expected.getLocalProperties().get("url")));
- assertThat(actual.getLocalProperties().get("username"),
is(expected.getLocalProperties().get("username")));
- assertThat(actual.getLocalProperties().get("password"),
is(expected.getLocalProperties().get("password")));
- assertThat(actual.getLocalProperties().get("connectionInitSqls"),
is(expected.getLocalProperties().get("connectionInitSqls")));
+ assertThat(actual.getAllLocalProperties().get("url"),
is(expected.getAllLocalProperties().get("url")));
+ assertThat(actual.getAllLocalProperties().get("username"),
is(expected.getAllLocalProperties().get("username")));
+ assertThat(actual.getAllLocalProperties().get("password"),
is(expected.getAllLocalProperties().get("password")));
+ assertThat(actual.getAllLocalProperties().get("connectionInitSqls"),
is(expected.getAllLocalProperties().get("connectionInitSqls")));
}
@Test
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/resource/DataSourceQueryResultSet.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/resource/DataSourceQueryResultSet.java
index 70e4136..167d550 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/resource/DataSourceQueryResultSet.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/resource/DataSourceQueryResultSet.java
@@ -74,22 +74,18 @@ public final class DataSourceQueryResultSet implements
DistSQLResultSet {
String dataSourceName = dataSourceNames.next();
DataSourceMetaData metaData =
resource.getDataSourcesMetaData().getDataSourceMetaData(dataSourceName);
return Arrays.asList(dataSourceName,
resource.getDatabaseType().getName(), metaData.getHostname(),
metaData.getPort(), metaData.getCatalog(),
- new
Gson().toJson(getFilteredUndisplayedProperties(dataSourcePropsMap.get(dataSourceName).getStandardProperties())));
+ new
Gson().toJson(getFilteredUndisplayedProperties(dataSourcePropsMap.get(dataSourceName))));
}
- // TODO to be configured
- private Map<String, Object> getFilteredUndisplayedProperties(final
Map<String, Object> standardProps) {
- Map<String, Object> result = new HashMap<>(standardProps);
- result.remove("url");
- result.remove("jdbcUrl");
- result.remove("user");
- result.remove("username");
- result.remove("password");
+ private Map<String, Object> getFilteredUndisplayedProperties(final
DataSourceProperties dataSourceProperties) {
+ Map<String, Object> result = new
HashMap<>(dataSourceProperties.getPoolPropertySynonyms().getStandardProperties());
+
result.putAll(dataSourceProperties.getCustomDataSourceProperties().getProperties());
+ // TODO to be configured
result.remove("running");
result.remove("poolName");
result.remove("registerMbeans");
result.remove("closed");
- for (Entry<String, Object> entry : standardProps.entrySet()) {
+ for (Entry<String, Object> entry :
dataSourceProperties.getCustomDataSourceProperties().getProperties().entrySet())
{
if (entry.getValue() instanceof Collection || entry.getValue()
instanceof Map) {
result.remove(entry.getKey());
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverterTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverterTest.java
index 00f1004..cd3722c 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverterTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverterTest.java
@@ -39,8 +39,8 @@ public final class ResourceSegmentsConverterTest {
Map<String, DataSourceProperties> actual =
ResourceSegmentsConverter.convert(new MySQLDatabaseType(),
createDataSourceSegments());
assertThat(actual.size(), is(2));
assertTrue(actual.keySet().containsAll(Arrays.asList("ds0", "ds1")));
-
assertThat(actual.values().iterator().next().getLocalProperties().get("username"),
is("root0"));
-
assertThat(actual.values().iterator().next().getStandardProperties().get("maxPoolSize"),
is("30"));
+
assertThat(actual.values().iterator().next().getAllLocalProperties().get("username"),
is("root0"));
+
assertThat(actual.values().iterator().next().getAllStandardProperties().get("maxPoolSize"),
is("30"));
}
private Collection<DataSourceSegment> createDataSourceSegments() {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/DataSourceQueryResultSetTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/DataSourceQueryResultSetTest.java
index c9332f0..de27711 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/DataSourceQueryResultSetTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/DataSourceQueryResultSetTest.java
@@ -124,15 +124,14 @@ public final class DataSourceQueryResultSetTest {
private Map<String, DataSourceProperties> createDataSourcePropertiesMap() {
Map<String, DataSourceProperties> result = new HashMap<>();
- DataSourceProperties ds0 = new DataSourceProperties("ds_0",
createProperties());
- ds0.getStandardProperties().put("test", "test");
- result.put("ds_0", ds0);
+ result.put("ds_0", new DataSourceProperties("ds_0",
createProperties()));
return result;
}
private Map<String, Object> createProperties() {
- Map<String, Object> result = new LinkedHashMap<>(1, 1);
+ Map<String, Object> result = new LinkedHashMap<>(2, 1);
result.put("readOnly", true);
+ result.put("test", "test");
return result;
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/config/resource/ProxyProxyResourceConfigurationConverterTest.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/config/resource/ProxyProxyResourceConfigurationConverterTest.java
index 2300651..21eaa6e 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/config/resource/ProxyProxyResourceConfigurationConverterTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/config/resource/ProxyProxyResourceConfigurationConverterTest.java
@@ -49,7 +49,7 @@ public final class
ProxyProxyResourceConfigurationConverterTest {
}
private void assertParameter(final DataSourceProperties actual) {
- Map<String, Object> props = actual.getLocalProperties();
+ Map<String, Object> props = actual.getAllLocalProperties();
assertThat(props.size(), is(9));
assertThat(props.get("jdbcUrl"),
is("jdbc:mysql://localhost:3306/demo_ds"));
assertThat(props.get("username"), is("root"));