This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 0b55117 Fixed not persist data-source-properties. (#14359)
0b55117 is described below
commit 0b55117d20e6865e5b616700e65fb0fe5536e6a0
Author: zhaojinchao <[email protected]>
AuthorDate: Tue Dec 28 20:43:43 2021 +0800
Fixed not persist data-source-properties. (#14359)
* Fixed not persist data-source-properties.
* update
* update
* add unit test
* adjust unit test.
* update
* final
* update code
* update
* change yaml
---
.../creator/impl/AbstractDataSourcePoolCreator.java | 7 ++++++-
.../creator/impl/HikariDataSourcePoolCreatorTest.java | 18 ++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/AbstractDataSourcePoolCreator.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/AbstractDataSourcePoolCreator.java
index 3c9e864..5fabb1b 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/AbstractDataSourcePoolCreator.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/AbstractDataSourcePoolCreator.java
@@ -35,6 +35,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Properties;
/**
* Abstract data source pool creator.
@@ -42,7 +43,7 @@ import java.util.Optional;
public abstract class AbstractDataSourcePoolCreator implements
DataSourcePoolCreator {
static {
- GENERAL_CLASS_TYPES = Sets.newHashSet(boolean.class, Boolean.class,
int.class, Integer.class, long.class, Long.class, String.class,
Collection.class, List.class);
+ GENERAL_CLASS_TYPES = Sets.newHashSet(boolean.class, Boolean.class,
int.class, Integer.class, long.class, Long.class, String.class,
Collection.class, List.class, Properties.class);
SKIPPED_PROPERTY_KEYS = Sets.newHashSet("loginTimeout");
}
@@ -144,6 +145,10 @@ public abstract class AbstractDataSourcePoolCreator
implements DataSourcePoolCre
method.invoke(target, Boolean.parseBoolean(value.toString()));
} else if (paramType == String.class) {
method.invoke(target, value.toString());
+ } else if (paramType == Properties.class) {
+ Properties props = new Properties();
+ props.putAll((Map) value);
+ method.invoke(target, props);
} else {
method.invoke(target, value);
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreatorTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreatorTest.java
index b62d23f..5888ed6 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreatorTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreatorTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
@@ -55,6 +56,7 @@ public final class HikariDataSourcePoolCreatorTest {
assertThat(configuration.getProps().get("password"), is("root"));
assertThat(configuration.getProps().get("maximumPoolSize"), is(10));
assertThat(configuration.getProps().get("minimumIdle"), is(1));
+ assertDataSourceProperties((Properties)
configuration.getProps().get("dataSourceProperties"));
}
@Test
@@ -70,6 +72,7 @@ public final class HikariDataSourcePoolCreatorTest {
assertThat(hikariDataSource.getPassword(), is("root"));
assertThat(hikariDataSource.getMaximumPoolSize(), is(10));
assertThat(hikariDataSource.getMinimumIdle(), is(1));
+ assertDataSourceProperties(hikariDataSource.getDataSourceProperties());
}
private DataSourceConfiguration createDataSourceConfiguration() {
@@ -81,8 +84,23 @@ public final class HikariDataSourcePoolCreatorTest {
props.put("password", "root");
props.put("maxPoolSize", 10);
props.put("minPoolSize", 1);
+ props.put("dataSourceProperties", getDataSourceProperties());
DataSourceConfiguration result = new
DataSourceConfiguration(String.valueOf(props.get("dataSourceClassName")));
result.getProps().putAll(props);
return result;
}
+
+ private Properties getDataSourceProperties() {
+ Properties result = new Properties();
+ result.put("prepStmtCacheSqlLimit", 1024);
+ result.put("cachePrepStmts", true);
+ result.put("prepStmtCacheSize", 1000);
+ return result;
+ }
+
+ private void assertDataSourceProperties(final Properties props) {
+ assertThat(props.get("prepStmtCacheSqlLimit"), is(1024));
+ assertThat(props.get("cachePrepStmts"), is(true));
+ assertThat(props.get("prepStmtCacheSize"), is(1000));
+ }
}