This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 5957e6c Unify spring boot data source properties setter with
DataSourcePoolCreator (#15270)
5957e6c is described below
commit 5957e6c84616ff58d3b42ebc816d05f7418d8d2e
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Feb 7 01:35:46 2022 +0800
Unify spring boot data source properties setter with DataSourcePoolCreator
(#15270)
* Add more test cases
* Process sub prop in CustomDataSourceProperties
* Remove DataSourcePropertiesSetter
---
.../props/custom/CustomDataSourceProperties.java | 24 ++++++++-
.../custom/CustomDataSourcePropertiesTest.java | 13 ++++-
.../boot/datasource/DataSourceMapSetter.java | 6 +--
.../prop/DataSourcePropertiesSetter.java | 46 ----------------
.../AbstractDbcp2DataSourcePropertiesSetter.java | 54 -------------------
.../CommonDbcp2DataSourcePropertiesSetter.java | 29 ----------
.../impl/DataSourcePropertiesSetterHolder.java | 49 -----------------
.../impl/HikariDataSourcePropertiesSetter.java | 51 ------------------
.../TomcatDbcp2DataSourcePropertiesSetter.java | 29 ----------
...boot.datasource.prop.DataSourcePropertiesSetter | 20 -------
.../boot/datasource/DataSourceMapSetterTest.java | 3 +-
.../DataSourcePropertiesSetterHolderTest.java | 40 --------------
.../Dbcp2DataSourcePropertiesSetterTest.java | 62 ----------------------
.../HikariDataSourcePropertiesSetterTest.java | 59 --------------------
14 files changed, 38 insertions(+), 447 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/props/custom/CustomDataSourceProperties.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/props/custom/CustomDataSourceProperties.java
index 4e21722..f0c2f04 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/props/custom/CustomDataSourceProperties.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/props/custom/CustomDataSourceProperties.java
@@ -23,6 +23,8 @@ import lombok.Getter;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
/**
* Custom data source properties.
@@ -35,9 +37,29 @@ public final class CustomDataSourceProperties {
public CustomDataSourceProperties(final Map<String, Object> props,
final Collection<String>
standardPropertyKeys, final Collection<String> transientFieldNames, final
Map<String, String> propertySynonyms) {
- properties = new LinkedHashMap<>(props);
+ properties = getProperties(props);
standardPropertyKeys.forEach(properties::remove);
transientFieldNames.forEach(properties::remove);
propertySynonyms.values().forEach(properties::remove);
}
+
+ private Map<String, Object> getProperties(final Map<String, Object> props)
{
+ Map<String, Object> result = new LinkedHashMap<>(props.size(), 1);
+ for (Entry<String, Object> entry : props.entrySet()) {
+ if (!entry.getKey().contains(".")) {
+ result.put(entry.getKey(), entry.getValue());
+ continue;
+ }
+ String[] complexKeys = entry.getKey().split("\\.");
+ if (2 != complexKeys.length) {
+ result.put(entry.getKey(), entry.getValue());
+ continue;
+ }
+ if (!result.containsKey(complexKeys[0])) {
+ result.put(complexKeys[0], new Properties());
+ }
+ ((Properties)
result.get(complexKeys[0])).setProperty(complexKeys[1],
entry.getValue().toString());
+ }
+ return result;
+ }
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/props/custom/CustomDataSourcePropertiesTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/props/custom/CustomDataSourcePropertiesTest.java
index 54292db..5cc4368 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/props/custom/CustomDataSourcePropertiesTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/props/custom/CustomDataSourcePropertiesTest.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -33,8 +34,14 @@ public final class CustomDataSourcePropertiesTest {
public void assertGetProperties() {
Map<String, Object> actual = new CustomDataSourceProperties(
createProperties(), Arrays.asList("username", "password",
"closed"), Collections.singletonList("closed"),
createPropertySynonyms()).getProperties();
- assertThat(actual.size(), is(1));
+ assertThat(actual.size(), is(3));
assertThat(actual.get("foo"), is("bar"));
+ assertThat(((Properties) actual.get("fooProperties")).size(), is(2));
+ assertThat(((Properties)
actual.get("fooProperties")).getProperty("foo1"), is("fooValue1"));
+ assertThat(((Properties)
actual.get("fooProperties")).getProperty("foo2"), is("fooValue2"));
+ assertThat(((Properties) actual.get("barProperties")).size(), is(2));
+ assertThat(((Properties)
actual.get("barProperties")).getProperty("bar1"), is("barValue1"));
+ assertThat(((Properties)
actual.get("barProperties")).getProperty("bar2"), is("barValue2"));
}
private Map<String, Object> createProperties() {
@@ -43,6 +50,10 @@ public final class CustomDataSourcePropertiesTest {
result.put("password", "root");
result.put("closed", false);
result.put("foo", "bar");
+ result.put("fooProperties.foo1", "fooValue1");
+ result.put("fooProperties.foo2", "fooValue2");
+ result.put("barProperties.bar1", "barValue1");
+ result.put("barProperties.bar2", "barValue2");
return result;
}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetter.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetter.java
index 683a95d..f5930f2 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetter.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetter.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCre
import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.sharding.support.InlineExpressionParser;
-import
org.apache.shardingsphere.spring.boot.datasource.prop.impl.DataSourcePropertiesSetterHolder;
import org.apache.shardingsphere.spring.boot.util.PropertyUtil;
import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
@@ -90,10 +89,7 @@ public final class DataSourceMapSetter {
if (dataSourceProps.containsKey(JNDI_NAME)) {
return
getJNDIDataSource(dataSourceProps.get(JNDI_NAME).toString());
}
- String dataSourceType =
dataSourceProps.get(DATA_SOURCE_TYPE).toString();
- DataSource result = DataSourcePoolCreator.create(new
DataSourceProperties(dataSourceType,
PropertyUtil.getCamelCaseKeys(dataSourceProps)));
-
DataSourcePropertiesSetterHolder.getDataSourcePropertiesSetterByType(dataSourceType).ifPresent(optional
-> optional.propertiesSet(environment, PREFIX, dataSourceName, result));
- return result;
+ return DataSourcePoolCreator.create(new
DataSourceProperties(dataSourceProps.get(DATA_SOURCE_TYPE).toString(),
PropertyUtil.getCamelCaseKeys(dataSourceProps)));
}
private static DataSource getJNDIDataSource(final String jndiName) throws
NamingException {
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/DataSourcePropertiesSetter.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/DataSourcePropertiesSetter.java
deleted file mode 100644
index 30d6bd9..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/DataSourcePropertiesSetter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.spring.boot.datasource.prop;
-
-import org.apache.shardingsphere.spi.singleton.SingletonSPI;
-import org.springframework.core.env.Environment;
-
-import javax.sql.DataSource;
-
-/**
- * Different datasource properties setter.
- */
-public interface DataSourcePropertiesSetter extends SingletonSPI {
-
- /**
- * Set datasource custom properties.
- *
- * @param environment environment variable
- * @param prefix properties prefix
- * @param dataSourceName current database name
- * @param dataSource dataSource instance
- */
- void propertiesSet(Environment environment, String prefix, String
dataSourceName, DataSource dataSource);
-
- /**
- * Get type name of data source.
- *
- * @return type name of data source.
- */
- String getType();
-}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/AbstractDbcp2DataSourcePropertiesSetter.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/AbstractDbcp2DataSourcePropertiesSe
[...]
deleted file mode 100644
index b3919ea..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/AbstractDbcp2DataSourcePropertiesSetter.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.spring.boot.datasource.prop.impl;
-
-import lombok.SneakyThrows;
-import
org.apache.shardingsphere.spring.boot.datasource.prop.DataSourcePropertiesSetter;
-import org.apache.shardingsphere.spring.boot.util.PropertyUtil;
-import org.springframework.core.env.Environment;
-
-import javax.sql.DataSource;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * DBCP datasource properties setter.
- */
-public abstract class AbstractDbcp2DataSourcePropertiesSetter implements
DataSourcePropertiesSetter {
-
- /**
- * Common DBCP2 add custom connection properties.
- *
- * @param environment environment variable
- * @param prefix properties prefix
- * @param dataSourceName current database name
- * @param dataSource dataSource instance
- */
- @SneakyThrows(ReflectiveOperationException.class)
- public void propertiesSet(final Environment environment, final String
prefix, final String dataSourceName, final DataSource dataSource) {
- String datasourcePropPrefix = prefix + dataSourceName.trim() +
".connection-properties";
- if (PropertyUtil.containPropertyPrefix(environment,
datasourcePropPrefix)) {
- Map<?, ?> datasourceProperties = PropertyUtil.handle(environment,
datasourcePropPrefix, Map.class);
- Method method =
dataSource.getClass().getMethod("addConnectionProperty", String.class,
String.class);
- for (Entry<?, ?> entry : datasourceProperties.entrySet()) {
- method.invoke(dataSource, entry.getKey(), entry.getValue());
- }
- }
- }
-}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/CommonDbcp2DataSourcePropertiesSetter.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/CommonDbcp2DataSourcePropertiesSetter.java
deleted file mode 100644
index fac3e68..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/CommonDbcp2DataSourcePropertiesSetter.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.spring.boot.datasource.prop.impl;
-
-/**
- * DBCP2 datasource properties setter.
- */
-public final class CommonDbcp2DataSourcePropertiesSetter extends
AbstractDbcp2DataSourcePropertiesSetter {
-
- @Override
- public String getType() {
- return "org.apache.commons.dbcp2.BasicDataSource";
- }
-}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/DataSourcePropertiesSetterHolder.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/DataSourcePropertiesSetterHolder.java
deleted file mode 100644
index eb550aa..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/DataSourcePropertiesSetterHolder.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.spring.boot.datasource.prop.impl;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.spi.singleton.SingletonSPIRegistry;
-import
org.apache.shardingsphere.spring.boot.datasource.prop.DataSourcePropertiesSetter;
-
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * Datasource properties setter holder.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DataSourcePropertiesSetterHolder {
-
- private static final Map<String, DataSourcePropertiesSetter>
DATA_SOURCE_PROPERTIES_SETTER_MAP;
-
- static {
- DATA_SOURCE_PROPERTIES_SETTER_MAP =
SingletonSPIRegistry.getSingletonInstancesMap(DataSourcePropertiesSetter.class,
DataSourcePropertiesSetter::getType);
- }
-
- /**
- * Get data source properties setter by type.
- *
- * @param type data source type
- * @return data source properties setter
- */
- public static Optional<DataSourcePropertiesSetter>
getDataSourcePropertiesSetterByType(final String type) {
- return DATA_SOURCE_PROPERTIES_SETTER_MAP.containsKey(type) ?
Optional.of(DATA_SOURCE_PROPERTIES_SETTER_MAP.get(type)) : Optional.empty();
- }
-}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/HikariDataSourcePropertiesSetter.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/HikariDataSourcePropertiesSetter.java
deleted file mode 100644
index af894c6..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/HikariDataSourcePropertiesSetter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.spring.boot.datasource.prop.impl;
-
-import lombok.SneakyThrows;
-import
org.apache.shardingsphere.spring.boot.datasource.prop.DataSourcePropertiesSetter;
-import org.apache.shardingsphere.spring.boot.util.PropertyUtil;
-import org.springframework.core.env.Environment;
-
-import javax.sql.DataSource;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * Hikari datasource properties setter.
- */
-public final class HikariDataSourcePropertiesSetter implements
DataSourcePropertiesSetter {
-
- @Override
- @SneakyThrows(ReflectiveOperationException.class)
- public void propertiesSet(final Environment environment, final String
prefix, final String dataSourceName, final DataSource dataSource) {
- Properties props = new Properties();
- String dataSourcePropKey = prefix + dataSourceName.trim() +
".data-source-properties";
- if (PropertyUtil.containPropertyPrefix(environment,
dataSourcePropKey)) {
- props.putAll(PropertyUtil.handle(environment, dataSourcePropKey,
Map.class));
- Method method =
dataSource.getClass().getMethod("setDataSourceProperties", Properties.class);
- method.invoke(dataSource, props);
- }
- }
-
- @Override
- public String getType() {
- return "com.zaxxer.hikari.HikariDataSource";
- }
-}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/TomcatDbcp2DataSourcePropertiesSetter.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/TomcatDbcp2DataSourcePropertiesSetter.java
deleted file mode 100644
index d3fec3a..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/prop/impl/TomcatDbcp2DataSourcePropertiesSetter.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.spring.boot.datasource.prop.impl;
-
-/**
- * Tomcat DBCP2 datasource properties setter.
- */
-public final class TomcatDbcp2DataSourcePropertiesSetter extends
AbstractDbcp2DataSourcePropertiesSetter {
-
- @Override
- public String getType() {
- return "org.apache.tomcat.dbcp.dbcp2.BasicDataSource";
- }
-}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/resources/META-INF/services/org.apache.shardingsphere.spring.boot.datasource.prop.DataSourcePropertiesSetter
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/resources/META-INF/services/org.apache.shardingsphere.spring.boot.datasource.prop.DataSourcePropert
[...]
deleted file mode 100644
index dd64b9c..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/resources/META-INF/services/org.apache.shardingsphere.spring.boot.datasource.prop.DataSourcePropertiesSetter
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# 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.
-#
-
-org.apache.shardingsphere.spring.boot.datasource.prop.impl.HikariDataSourcePropertiesSetter
-org.apache.shardingsphere.spring.boot.datasource.prop.impl.CommonDbcp2DataSourcePropertiesSetter
-org.apache.shardingsphere.spring.boot.datasource.prop.impl.TomcatDbcp2DataSourcePropertiesSetter
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetterTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetterTest.java
index ecc39f7..8fdba02 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetterTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetterTest.java
@@ -39,11 +39,13 @@ public final class DataSourceMapSetterTest {
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds0.username",
"sa");
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds0.max-total",
"50");
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds0.password",
"");
+
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds0.connection-properties.useServerPrepStmts",
Boolean.TRUE.toString());
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds1.url",
"jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL");
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds1.type",
"org.apache.commons.dbcp2.BasicDataSource");
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds1.username",
"sa");
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds1.max-total",
"150");
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds1.password",
"");
+
mockEnvironment.setProperty("spring.shardingsphere.datasource.ds1.connection-properties.useServerPrepStmts",
Boolean.TRUE.toString());
StandardEnvironment standardEnvironment = new StandardEnvironment();
standardEnvironment.merge(mockEnvironment);
Map<String, DataSource> dataSourceMap =
DataSourceMapSetter.getDataSourceMap(standardEnvironment);
@@ -52,4 +54,3 @@ public final class DataSourceMapSetterTest {
assertThat(dataSourceMap.get("ds1").getConnection().getMetaData().getUserName(),
is("SA"));
}
}
-
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourcePropertiesSetterHolderTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourcePropertiesSetterHolderTest.java
deleted file mode 100644
index 919ef7b..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/DataSourcePropertiesSetterHolderTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.spring.boot.datasource;
-
-import com.zaxxer.hikari.HikariDataSource;
-import
org.apache.shardingsphere.spring.boot.datasource.prop.DataSourcePropertiesSetter;
-import
org.apache.shardingsphere.spring.boot.datasource.prop.impl.DataSourcePropertiesSetterHolder;
-import
org.apache.shardingsphere.spring.boot.datasource.prop.impl.HikariDataSourcePropertiesSetter;
-import org.junit.Test;
-
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class DataSourcePropertiesSetterHolderTest {
-
- @Test
- public void assertGetDataSourcePropertiesSetterByType() {
- Optional<DataSourcePropertiesSetter> actual =
DataSourcePropertiesSetterHolder.getDataSourcePropertiesSetterByType(HikariDataSource.class.getName());
- assertTrue(actual.isPresent());
- assertThat(actual.get(),
instanceOf(HikariDataSourcePropertiesSetter.class));
- }
-}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/Dbcp2DataSourcePropertiesSetterTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/Dbcp2DataSourcePropertiesSetterTest.java
deleted file mode 100644
index be62026..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/Dbcp2DataSourcePropertiesSetterTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.spring.boot.datasource;
-
-import org.apache.commons.dbcp2.BasicDataSource;
-import
org.apache.shardingsphere.spring.boot.datasource.prop.impl.CommonDbcp2DataSourcePropertiesSetter;
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.core.env.Environment;
-import org.springframework.mock.env.MockEnvironment;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class Dbcp2DataSourcePropertiesSetterTest {
-
- private final CommonDbcp2DataSourcePropertiesSetter
dbcp2DataSourcePropertiesSetter = new CommonDbcp2DataSourcePropertiesSetter();
-
- private final BasicDataSource dataSource = new BasicDataSource();
-
- private Environment environment;
-
- @Before
- public void setUp() {
- MockEnvironment mockEnvironment = new MockEnvironment();
-
mockEnvironment.setProperty("spring.shardingsphere.datasource.primary_ds.type",
"org.apache.commons.dbcp2.BasicDataSource");
-
mockEnvironment.setProperty("spring.shardingsphere.datasource.primary_ds.connection-properties.test",
"test");
-
mockEnvironment.setProperty("spring.shardingsphere.datasource.primary_ds.connection-properties.xxx",
"yyy");
- environment = mockEnvironment;
- }
-
- @Test
- public void assertPropertiesSet() {
- dbcp2DataSourcePropertiesSetter.propertiesSet(environment,
"spring.shardingsphere.datasource.", "primary_ds", dataSource);
- Properties connectionProperties = (Properties)
ReflectionTestUtils.getField(dataSource, "connectionProperties");
- assertThat(connectionProperties.getProperty("test"), is("test"));
- assertThat(connectionProperties.getProperty("xxx"), is("yyy"));
- }
-
- @Test
- public void assertGetType() {
- assertThat(dbcp2DataSourcePropertiesSetter.getType(),
is("org.apache.commons.dbcp2.BasicDataSource"));
- }
-}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/HikariDataSourcePropertiesSetterTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/HikariDataSourcePropertiesSetterTest.java
deleted file mode 100644
index 7dbdc42..0000000
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/datasource/HikariDataSourcePropertiesSetterTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.spring.boot.datasource;
-
-import com.zaxxer.hikari.HikariDataSource;
-import
org.apache.shardingsphere.spring.boot.datasource.prop.impl.HikariDataSourcePropertiesSetter;
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.core.env.Environment;
-import org.springframework.mock.env.MockEnvironment;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class HikariDataSourcePropertiesSetterTest {
-
- private final HikariDataSourcePropertiesSetter
dbcpDataSourcePropertiesSetter = new HikariDataSourcePropertiesSetter();
-
- private final HikariDataSource dataSource = new HikariDataSource();
-
- private Environment environment;
-
- @Before
- public void setUp() {
- MockEnvironment mockEnvironment = new MockEnvironment();
-
mockEnvironment.setProperty("spring.shardingsphere.datasource.primary_ds.type",
"com.zaxxer.hikari.HikariDataSource");
-
mockEnvironment.setProperty("spring.shardingsphere.datasource.primary_ds.data-source-properties.cachePrepStmts",
"true");
-
mockEnvironment.setProperty("spring.shardingsphere.datasource.primary_ds.data-source-properties.prepStmtCacheSize",
"250");
- environment = mockEnvironment;
- }
-
- @Test
- public void assertPropertiesSet() {
- dbcpDataSourcePropertiesSetter.propertiesSet(environment,
"spring.shardingsphere.datasource.", "primary_ds", dataSource);
-
assertThat(dataSource.getDataSourceProperties().getProperty("cachePrepStmts"),
is("true"));
-
assertThat(dataSource.getDataSourceProperties().getProperty("prepStmtCacheSize"),
is("250"));
- }
-
- @Test
- public void assertGetType() {
- assertThat(dbcpDataSourcePropertiesSetter.getType(),
is("com.zaxxer.hikari.HikariDataSource"));
- }
-
-}