This is an automated email from the ASF dual-hosted git repository.
panjuan 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 656e7bb Use DataSourcePoolCreationMetaData to decouple
DataSourcePoolCreator (#14473)
656e7bb is described below
commit 656e7bbe8ad8a638c07e8bcbdc845b9cf90b6fc1
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jan 1 17:01:25 2022 +0800
Use DataSourcePoolCreationMetaData to decouple DataSourcePoolCreator
(#14473)
---
.../config/datasource/DataSourceConverter.java | 6 +-
...or.java => DataSourcePoolCreationMetaData.java} | 43 +++++++---
.../pool/creator/DataSourcePoolCreator.java | 78 ++++++++++++++++--
.../pool/creator/DataSourcePoolCreatorFactory.java | 44 ----------
.../impl/AbstractDataSourcePoolCreator.java | 96 ----------------------
... => DefaultDataSourcePoolCreationMetaData.java} | 14 ++--
...a => HikariDataSourcePoolCreationMetaData.java} | 9 +-
.../creator/reflection}/ConnectionURLParser.java | 2 +-
.../creator/reflection}/DataSourceReflection.java | 2 +-
...ce.pool.creator.DataSourcePoolCreationMetaData} | 4 +-
.../creator/DataSourcePoolCreatorFactoryTest.java | 39 ---------
.../DefaultDataSourcePoolCreatorTest.java | 22 ++---
.../impl/HikariDataSourcePoolCreatorTest.java | 6 +-
.../reflection}/ConnectionURLParserTest.java | 2 +-
14 files changed, 138 insertions(+), 229 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConverter.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConverter.java
index fd182a5..4969a78 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConverter.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConverter.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.infra.config.datasource;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreatorFactory;
+import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreator;
import javax.sql.DataSource;
import java.util.LinkedHashMap;
@@ -40,7 +40,7 @@ public final class DataSourceConverter {
* @return data source
*/
public static DataSource getDataSource(final DataSourceConfiguration
dataSourceConfig) {
- return
DataSourcePoolCreatorFactory.getInstance(dataSourceConfig.getDataSourceClassName()).createDataSource(dataSourceConfig);
+ return new
DataSourcePoolCreator(dataSourceConfig.getDataSourceClassName()).createDataSource(dataSourceConfig);
}
/**
@@ -50,7 +50,7 @@ public final class DataSourceConverter {
* @return data source configuration
*/
public static DataSourceConfiguration getDataSourceConfiguration(final
DataSource dataSource) {
- return
DataSourcePoolCreatorFactory.getInstance(dataSource.getClass().getName()).createDataSourceConfiguration(dataSource);
+ return new
DataSourcePoolCreator(dataSource.getClass().getCanonicalName()).createDataSourceConfiguration(dataSource);
}
/**
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/DataSourcePoolCreationMetaData.java
similarity index 55%
copy from
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreator.java
copy to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreationMetaData.java
index cc6ab97..ce18698 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/DataSourcePoolCreationMetaData.java
@@ -17,30 +17,49 @@
package org.apache.shardingsphere.infra.config.datasource.pool.creator;
-import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
import org.apache.shardingsphere.spi.required.RequiredSPI;
import org.apache.shardingsphere.spi.typed.TypedSPI;
-import javax.sql.DataSource;
+import java.util.Map;
+import java.util.Properties;
/**
- * Data source pool creator.
+ * Data source pool creation meta data.
*/
-public interface DataSourcePoolCreator extends TypedSPI, RequiredSPI {
+public interface DataSourcePoolCreationMetaData extends TypedSPI, RequiredSPI {
/**
- * Create data source configuration by data source.
+ * Get invalid properties.
*
- * @param dataSource data source
- * @return data source configuration
+ * @return invalid properties
*/
- DataSourceConfiguration createDataSourceConfiguration(DataSource
dataSource);
+ Map<String, Object> getInvalidProperties();
/**
- * Create data source.
+ * Get property synonyms.
*
- * @param dataSourceConfig data source configuration
- * @return data source
+ * @return property synonyms
*/
- DataSource createDataSource(DataSourceConfiguration dataSourceConfig);
+ Map<String, String> getPropertySynonyms();
+
+ /**
+ * Get data source properties field name.
+ *
+ * @return data source properties field name
+ */
+ String getDataSourcePropertiesFieldName();
+
+ /**
+ * Get JDBC URL field name.
+ *
+ * @return JDBC URL field name
+ */
+ String getJdbcUrlFieldName();
+
+ /**
+ * Get default data source properties.
+ *
+ * @return default data source properties
+ */
+ Properties getDefaultDataSourceProperties();
}
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 cc6ab97..2f45d5c 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
@@ -17,24 +17,57 @@
package org.apache.shardingsphere.infra.config.datasource.pool.creator;
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
-import org.apache.shardingsphere.spi.required.RequiredSPI;
-import org.apache.shardingsphere.spi.typed.TypedSPI;
+import
org.apache.shardingsphere.infra.config.datasource.pool.creator.reflection.DataSourceReflection;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.required.RequiredSPIRegistry;
+import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
import javax.sql.DataSource;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
/**
* Data source pool creator.
*/
-public interface DataSourcePoolCreator extends TypedSPI, RequiredSPI {
+@RequiredArgsConstructor
+public final class DataSourcePoolCreator {
+
+ static {
+
ShardingSphereServiceLoader.register(DataSourcePoolCreationMetaData.class);
+ }
+
+ private final DataSourcePoolCreationMetaData creationMetaData;
+
+ public DataSourcePoolCreator(final String dataSourceClassName) {
+ creationMetaData =
TypedSPIRegistry.findRegisteredService(DataSourcePoolCreationMetaData.class,
dataSourceClassName, new Properties())
+
.orElse(RequiredSPIRegistry.getRegisteredService(DataSourcePoolCreationMetaData.class));
+ }
/**
- * Create data source configuration by data source.
+ * Create data source configuration.
*
* @param dataSource data source
* @return data source configuration
*/
- DataSourceConfiguration createDataSourceConfiguration(DataSource
dataSource);
+ public DataSourceConfiguration createDataSourceConfiguration(final
DataSource dataSource) {
+ DataSourceConfiguration result = new
DataSourceConfiguration(dataSource.getClass().getName());
+ filterInvalidProperties(result, new
DataSourceReflection(dataSource).convertToProperties());
+ return result;
+ }
+
+ private void filterInvalidProperties(final DataSourceConfiguration
dataSourceConfig, final Map<String, Object> reflectionProps) {
+ for (Entry<String, Object> entry : reflectionProps.entrySet()) {
+ String propertyName = entry.getKey();
+ Object propertyValue = entry.getValue();
+ if (isValidProperty(propertyName, propertyValue)) {
+ dataSourceConfig.getProps().put(propertyName, propertyValue);
+ }
+ }
+ }
/**
* Create data source.
@@ -42,5 +75,38 @@ public interface DataSourcePoolCreator extends TypedSPI,
RequiredSPI {
* @param dataSourceConfig data source configuration
* @return data source
*/
- DataSource createDataSource(DataSourceConfiguration dataSourceConfig);
+ public DataSource createDataSource(final DataSourceConfiguration
dataSourceConfig) {
+ DataSource result =
buildDataSource(dataSourceConfig.getDataSourceClassName());
+ addPropertySynonym(dataSourceConfig);
+ DataSourceReflection dataSourceReflection = new
DataSourceReflection(result);
+ setConfiguredFields(dataSourceConfig, dataSourceReflection);
+ dataSourceReflection.addDefaultDataSourceProperties(
+ creationMetaData.getDataSourcePropertiesFieldName(),
creationMetaData.getJdbcUrlFieldName(),
creationMetaData.getDefaultDataSourceProperties());
+ return result;
+ }
+
+ @SneakyThrows(ReflectiveOperationException.class)
+ private DataSource buildDataSource(final String dataSourceClassName) {
+ return (DataSource)
Class.forName(dataSourceClassName).getConstructor().newInstance();
+ }
+
+ private void addPropertySynonym(final DataSourceConfiguration
dataSourceConfig) {
+ for (Entry<String, String> entry :
creationMetaData.getPropertySynonyms().entrySet()) {
+ dataSourceConfig.addPropertySynonym(entry.getKey(),
entry.getValue());
+ }
+ }
+
+ private void setConfiguredFields(final DataSourceConfiguration
dataSourceConfig, final DataSourceReflection dataSourceReflection) {
+ for (Entry<String, Object> entry :
dataSourceConfig.getAllProperties().entrySet()) {
+ String fieldName = entry.getKey();
+ Object fieldValue = entry.getValue();
+ if (isValidProperty(fieldName, fieldValue)) {
+ dataSourceReflection.setField(fieldName, fieldValue);
+ }
+ }
+ }
+
+ private boolean isValidProperty(final String key, final Object value) {
+ return !creationMetaData.getInvalidProperties().containsKey(key) ||
null == value ||
!value.equals(creationMetaData.getInvalidProperties().get(key));
+ }
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreatorFactory.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreatorFactory.java
deleted file mode 100644
index d0a0f14..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreatorFactory.java
+++ /dev/null
@@ -1,44 +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.infra.config.datasource.pool.creator;
-
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.required.RequiredSPIRegistry;
-import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
-
-import java.util.Properties;
-
-/**
- * Data source pool creator factory.
- */
-public final class DataSourcePoolCreatorFactory {
-
- static {
- ShardingSphereServiceLoader.register(DataSourcePoolCreator.class);
- }
-
- /**
- * Get data source pool creator instance.
- *
- * @param dataSourceClassName data source class name
- * @return data source pool creator instance
- */
- public static DataSourcePoolCreator getInstance(final String
dataSourceClassName) {
- return
TypedSPIRegistry.findRegisteredService(DataSourcePoolCreator.class,
dataSourceClassName, new
Properties()).orElse(RequiredSPIRegistry.getRegisteredService(DataSourcePoolCreator.class));
- }
-}
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
deleted file mode 100644
index 050abde..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/AbstractDataSourcePoolCreator.java
+++ /dev/null
@@ -1,96 +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.infra.config.datasource.pool.creator.impl;
-
-import lombok.SneakyThrows;
-import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
-import org.apache.shardingsphere.infra.config.datasource.DataSourceReflection;
-import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreator;
-
-import javax.sql.DataSource;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-
-/**
- * Abstract data source pool creator.
- */
-public abstract class AbstractDataSourcePoolCreator implements
DataSourcePoolCreator {
-
- @Override
- public final DataSourceConfiguration createDataSourceConfiguration(final
DataSource dataSource) {
- DataSourceConfiguration result = new
DataSourceConfiguration(dataSource.getClass().getName());
- filterInvalidProperties(result, new
DataSourceReflection(dataSource).convertToProperties());
- return result;
- }
-
- private void filterInvalidProperties(final DataSourceConfiguration
dataSourceConfig, final Map<String, Object> reflectionProps) {
- for (Entry<String, Object> entry : reflectionProps.entrySet()) {
- String propertyName = entry.getKey();
- Object propertyValue = entry.getValue();
- if (isValidProperty(propertyName, propertyValue)) {
- dataSourceConfig.getProps().put(propertyName, propertyValue);
- }
- }
- }
-
- @Override
- public final DataSource createDataSource(final DataSourceConfiguration
dataSourceConfig) {
- DataSource result =
buildDataSource(dataSourceConfig.getDataSourceClassName());
- addPropertySynonym(dataSourceConfig);
- DataSourceReflection dataSourceReflection = new
DataSourceReflection(result);
- setConfiguredFields(dataSourceConfig, dataSourceReflection);
-
dataSourceReflection.addDefaultDataSourceProperties(getDataSourcePropertiesFieldName(),
getJdbcUrlFieldName(), getDefaultDataSourceProperties());
- return result;
- }
-
- @SneakyThrows(ReflectiveOperationException.class)
- protected final DataSource buildDataSource(final String
dataSourceClassName) {
- return (DataSource)
Class.forName(dataSourceClassName).getConstructor().newInstance();
- }
-
- private void addPropertySynonym(final DataSourceConfiguration
dataSourceConfig) {
- for (Entry<String, String> entry : getPropertySynonyms().entrySet()) {
- dataSourceConfig.addPropertySynonym(entry.getKey(),
entry.getValue());
- }
- }
-
- private void setConfiguredFields(final DataSourceConfiguration
dataSourceConfig, final DataSourceReflection dataSourceReflection) {
- for (Entry<String, Object> entry :
dataSourceConfig.getAllProperties().entrySet()) {
- String fieldName = entry.getKey();
- Object fieldValue = entry.getValue();
- if (isValidProperty(fieldName, fieldValue)) {
- dataSourceReflection.setField(fieldName, fieldValue);
- }
- }
- }
-
- private boolean isValidProperty(final String key, final Object value) {
- return !getInvalidProperties().containsKey(key) || null == value ||
!value.equals(getInvalidProperties().get(key));
- }
-
- protected abstract Map<String, Object> getInvalidProperties();
-
- protected abstract Map<String, String> getPropertySynonyms();
-
- protected abstract String getDataSourcePropertiesFieldName();
-
- protected abstract String getJdbcUrlFieldName();
-
- protected abstract Properties getDefaultDataSourceProperties();
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/DefaultDataSourcePoolCreator.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/DefaultDataSourcePoolCreationMetaData.java
similarity index 75%
rename from
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/DefaultDataSourcePoolCreator.java
rename to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/DefaultDataSourcePoolCreationMetaData.java
index 3fbe124..079531c 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/DefaultDataSourcePoolCreator.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/DefaultDataSourcePoolCreationMetaData.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.infra.config.datasource.pool.creator.impl;
+import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreationMetaData;
+
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
@@ -24,30 +26,30 @@ import java.util.Properties;
/**
* Default data source pool creator.
*/
-public final class DefaultDataSourcePoolCreator extends
AbstractDataSourcePoolCreator {
+public final class DefaultDataSourcePoolCreationMetaData implements
DataSourcePoolCreationMetaData {
@Override
- protected Map<String, Object> getInvalidProperties() {
+ public Map<String, Object> getInvalidProperties() {
return Collections.emptyMap();
}
@Override
- protected Map<String, String> getPropertySynonyms() {
+ public Map<String, String> getPropertySynonyms() {
return Collections.emptyMap();
}
@Override
- protected String getDataSourcePropertiesFieldName() {
+ public String getDataSourcePropertiesFieldName() {
return null;
}
@Override
- protected String getJdbcUrlFieldName() {
+ public String getJdbcUrlFieldName() {
return null;
}
@Override
- protected Properties getDefaultDataSourceProperties() {
+ public Properties getDefaultDataSourceProperties() {
return new Properties();
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreator.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreationMetaData.java
similarity index 90%
rename from
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreator.java
rename to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreationMetaData.java
index 9e687a8..6ac9c96 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreator.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/HikariDataSourcePoolCreationMetaData.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.infra.config.datasource.pool.creator.impl;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;
+import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreationMetaData;
import java.util.HashMap;
import java.util.Map;
@@ -28,7 +29,7 @@ import java.util.Properties;
* Hikari data source pool creator.
*/
@Getter
-public final class HikariDataSourcePoolCreator extends
AbstractDataSourcePoolCreator {
+public final class HikariDataSourcePoolCreationMetaData implements
DataSourcePoolCreationMetaData {
private final Map<String, Object> invalidProperties = new HashMap<>(2, 1);
@@ -36,7 +37,7 @@ public final class HikariDataSourcePoolCreator extends
AbstractDataSourcePoolCre
private final Properties defaultDataSourceProperties = new Properties();
- public HikariDataSourcePoolCreator() {
+ public HikariDataSourcePoolCreationMetaData() {
buildInvalidProperties();
buildPropertySynonyms();
buildDefaultDataSourceProperties();
@@ -70,12 +71,12 @@ public final class HikariDataSourcePoolCreator extends
AbstractDataSourcePoolCre
}
@Override
- protected String getDataSourcePropertiesFieldName() {
+ public String getDataSourcePropertiesFieldName() {
return "dataSourceProperties";
}
@Override
- protected String getJdbcUrlFieldName() {
+ public String getJdbcUrlFieldName() {
return "jdbcUrl";
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/ConnectionURLParser.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/reflection/ConnectionURLParser.java
similarity index 96%
rename from
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/ConnectionURLParser.java
rename to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/reflection/ConnectionURLParser.java
index 3c0cff7..f6be8ea 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/ConnectionURLParser.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/reflection/ConnectionURLParser.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.config.datasource;
+package
org.apache.shardingsphere.infra.config.datasource.pool.creator.reflection;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceReflection.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/reflection/DataSourceReflection.java
similarity index 98%
rename from
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceReflection.java
rename to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/reflection/DataSourceReflection.java
index 6ae442c..eaad0d0 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceReflection.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/reflection/DataSourceReflection.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.config.datasource;
+package
org.apache.shardingsphere.infra.config.datasource.pool.creator.reflection;
import com.google.common.base.CaseFormat;
import com.google.common.collect.Sets;
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreator
b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreationMetaData
similarity index 91%
rename from
shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreator
rename to
shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreationMetaData
index 7719026..34ce923 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreator
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreationMetaData
@@ -15,5 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.infra.config.datasource.pool.creator.impl.HikariDataSourcePoolCreator
-org.apache.shardingsphere.infra.config.datasource.pool.creator.impl.DefaultDataSourcePoolCreator
+org.apache.shardingsphere.infra.config.datasource.pool.creator.impl.HikariDataSourcePoolCreationMetaData
+org.apache.shardingsphere.infra.config.datasource.pool.creator.impl.DefaultDataSourcePoolCreationMetaData
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreatorFactoryTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreatorFactoryTest.java
deleted file mode 100644
index cbcd747..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DataSourcePoolCreatorFactoryTest.java
+++ /dev/null
@@ -1,39 +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.infra.config.datasource.pool.creator;
-
-import com.zaxxer.hikari.HikariDataSource;
-import
org.apache.shardingsphere.infra.config.datasource.pool.creator.impl.DefaultDataSourcePoolCreator;
-import
org.apache.shardingsphere.infra.config.datasource.pool.creator.impl.HikariDataSourcePoolCreator;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertThat;
-
-public final class DataSourcePoolCreatorFactoryTest {
-
- @Test
- public void assertGetInstanceWhenDataSourcePoolCreatorExisted() {
-
assertThat(DataSourcePoolCreatorFactory.getInstance(HikariDataSource.class.getName()),
instanceOf(HikariDataSourcePoolCreator.class));
- }
-
- @Test
- public void assertGetInstanceWhenDataSourcePoolCreatorNotExisted() {
-
assertThat(DataSourcePoolCreatorFactory.getInstance("NOT_EXISTED_DATA_SOURCE"),
instanceOf(DefaultDataSourcePoolCreator.class));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DefaultDataSourcePoolCreatorTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/DefaultDataSourcePoolCreatorTest.java
similarity index 71%
rename from
shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DefaultDataSourcePoolCreatorTest.java
rename to
shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/DefaultDataSourcePoolCreatorTest.java
index af4c813..81caaca 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/DefaultDataSourcePoolCreatorTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/impl/DefaultDataSourcePoolCreatorTest.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.config.datasource.pool.creator;
+package org.apache.shardingsphere.infra.config.datasource.pool.creator.impl;
-import com.zaxxer.hikari.HikariDataSource;
import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
-import
org.apache.shardingsphere.infra.config.datasource.pool.creator.impl.DefaultDataSourcePoolCreator;
+import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreator;
+import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.Test;
import javax.sql.DataSource;
@@ -31,13 +31,13 @@ public final class DefaultDataSourcePoolCreatorTest {
@Test
public void assertCreateDataSourceConfiguration() {
- assertThat(new
DefaultDataSourcePoolCreator().createDataSourceConfiguration(createDataSource()),
is(createDataSourceConfiguration()));
+ assertThat(new
DataSourcePoolCreator("Default").createDataSourceConfiguration(createDataSource()),
is(createDataSourceConfiguration()));
}
private DataSource createDataSource() {
- HikariDataSource result = new HikariDataSource();
+ MockedDataSource result = new MockedDataSource();
result.setDriverClassName("org.h2.Driver");
-
result.setJdbcUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
+
result.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
result.setUsername("root");
result.setPassword("root");
return result;
@@ -45,17 +45,17 @@ public final class DefaultDataSourcePoolCreatorTest {
@Test
public void assertCreateDataSource() {
- HikariDataSource actual = (HikariDataSource) new
DefaultDataSourcePoolCreator().createDataSource(createDataSourceConfiguration());
+ MockedDataSource actual = (MockedDataSource) new
DataSourcePoolCreator("Default").createDataSource(createDataSourceConfiguration());
+ assertThat(actual.getDriverClassName(), is("org.h2.Driver"));
+ assertThat(actual.getUrl(),
is("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
assertThat(actual.getUsername(), is("root"));
assertThat(actual.getPassword(), is("root"));
- assertThat(actual.getDriverClassName(), is("org.h2.Driver"));
- assertThat(actual.getJdbcUrl(),
is("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
}
private DataSourceConfiguration createDataSourceConfiguration() {
- DataSourceConfiguration result = new
DataSourceConfiguration(HikariDataSource.class.getName());
- result.getProps().put("jdbcUrl",
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
+ DataSourceConfiguration result = new
DataSourceConfiguration(MockedDataSource.class.getCanonicalName());
result.getProps().put("driverClassName", "org.h2.Driver");
+ result.getProps().put("url",
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
result.getProps().put("username", "root");
result.getProps().put("password", "root");
return result;
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 eeb0783..32e041e 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
@@ -40,14 +40,14 @@ public final class HikariDataSourcePoolCreatorTest {
dataSource.setJdbcUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
dataSource.setUsername("root");
dataSource.setPassword("root");
- DataSourceConfiguration dataSourceConfiguration = new
DefaultDataSourcePoolCreator().createDataSourceConfiguration(dataSource);
+ DataSourceConfiguration dataSourceConfiguration = new
DataSourcePoolCreator(HikariDataSource.class.getCanonicalName()).createDataSourceConfiguration(dataSource);
Map<String, Object> props = dataSourceConfiguration.getProps();
assertFalse(props.containsKey("driverClassName") && null ==
props.get("driverClassName"));
}
@Test
public void assertCreateDataSourceConfiguration() {
- DataSourcePoolCreator dataSourcePoolCreator = new
HikariDataSourcePoolCreator();
+ DataSourcePoolCreator dataSourcePoolCreator = new
DataSourcePoolCreator(HikariDataSource.class.getCanonicalName());
DataSourceConfiguration configuration =
dataSourcePoolCreator.createDataSourceConfiguration(dataSourcePoolCreator.createDataSource(createDataSourceConfiguration()));
assertThat(configuration.getDataSourceClassName(),
is("com.zaxxer.hikari.HikariDataSource"));
assertThat(configuration.getProps().get("jdbcUrl"),
is("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
@@ -61,7 +61,7 @@ public final class HikariDataSourcePoolCreatorTest {
@Test
public void assertCreateDataSource() {
- DataSourcePoolCreator dataSourcePoolCreator = new
HikariDataSourcePoolCreator();
+ DataSourcePoolCreator dataSourcePoolCreator = new
DataSourcePoolCreator(HikariDataSource.class.getCanonicalName());
DataSource dataSource =
dataSourcePoolCreator.createDataSource(createDataSourceConfiguration());
assertThat(dataSource, instanceOf(HikariDataSource.class));
HikariDataSource hikariDataSource = (HikariDataSource) dataSource;
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/ConnectionURLParserTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/reflection/ConnectionURLParserTest.java
similarity index 97%
rename from
shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/ConnectionURLParserTest.java
rename to
shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/reflection/ConnectionURLParserTest.java
index b08168a..cf89a96 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/ConnectionURLParserTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/pool/creator/reflection/ConnectionURLParserTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.config.datasource;
+package
org.apache.shardingsphere.infra.config.datasource.pool.creator.reflection;
import org.junit.Test;