You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/09/07 09:51:56 UTC

[GitHub] [shardingsphere] menghaoranss opened a new pull request #12268: Refactor DataSourceConfiguration

menghaoranss opened a new pull request #12268:
URL: https://github.com/apache/shardingsphere/pull/12268


   Fixes #11921.
   
   Changes proposed in this pull request:
   - Add DataSourceCreator SPI 
   - Add HikariDataSourceCreator to skip invalid properties
   - Move `createDataSource` and `createDataSourceConfiguration` from DataSourceConfiguration to DataSourceCreator
   - Add `getDataSource` and `getDataSourceConfiguration` in DataSourceConverter
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter commented on pull request #12268: Refactor DataSourceConfiguration

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #12268:
URL: https://github.com/apache/shardingsphere/pull/12268#issuecomment-914246428


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12268?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#12268](https://codecov.io/gh/apache/shardingsphere/pull/12268?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (42dd921) into [master](https://codecov.io/gh/apache/shardingsphere/commit/b7574e827d5bcd1f309b9adf92398303c8fc6864?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b7574e8) will **increase** coverage by `0.03%`.
   > The diff coverage is `73.68%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/12268/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/12268?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #12268      +/-   ##
   ============================================
   + Coverage     63.74%   63.77%   +0.03%     
   - Complexity     1261     1265       +4     
   ============================================
     Files          2351     2361      +10     
     Lines         35746    35815      +69     
     Branches       6210     6219       +9     
   ============================================
   + Hits          22785    22841      +56     
   - Misses        11135    11138       +3     
   - Partials       1826     1836      +10     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/12268?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [.../manager/cluster/ClusterContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtY2x1c3Rlci1tb2RlL3NoYXJkaW5nc3BoZXJlLWNsdXN0ZXItbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvY2x1c3Rlci9DbHVzdGVyQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `73.64% <0.00%> (+1.40%)` | :arrow_up: |
   | [...er/standalone/StandaloneContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtc3RhbmRhbG9uZS1tb2RlL3NoYXJkaW5nc3BoZXJlLXN0YW5kYWxvbmUtbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvc3RhbmRhbG9uZS9TdGFuZGFsb25lQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...sphere/proxy/initializer/BootstrapInitializer.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYm9vdHN0cmFwL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9wcm94eS9pbml0aWFsaXplci9Cb290c3RyYXBJbml0aWFsaXplci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...asource/creator/impl/DefaultDataSourceCreator.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9jb25maWcvZGF0YXNvdXJjZS9jcmVhdG9yL2ltcGwvRGVmYXVsdERhdGFTb3VyY2VDcmVhdG9yLmphdmE=) | `22.22% <22.22%> (ø)` | |
   | [...g/datasource/creator/DataSourceCreatorFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9jb25maWcvZGF0YXNvdXJjZS9jcmVhdG9yL0RhdGFTb3VyY2VDcmVhdG9yRmFjdG9yeS5qYXZh) | `75.00% <75.00%> (ø)` | |
   | [...tasource/creator/impl/HikariDataSourceCreator.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9jb25maWcvZGF0YXNvdXJjZS9jcmVhdG9yL2ltcGwvSGlrYXJpRGF0YVNvdXJjZUNyZWF0b3IuamF2YQ==) | `76.47% <76.47%> (ø)` | |
   | [...source/creator/impl/AbstractDataSourceCreator.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9jb25maWcvZGF0YXNvdXJjZS9jcmVhdG9yL2ltcGwvQWJzdHJhY3REYXRhU291cmNlQ3JlYXRvci5qYXZh) | `80.00% <80.00%> (ø)` | |
   | [...fra/config/datasource/DataSourceConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9jb25maWcvZGF0YXNvdXJjZS9EYXRhU291cmNlQ29uZmlndXJhdGlvbi5qYXZh) | `65.21% <100.00%> (-10.13%)` | :arrow_down: |
   | [...e/infra/config/datasource/DataSourceConverter.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9jb25maWcvZGF0YXNvdXJjZS9EYXRhU291cmNlQ29udmVydGVyLmphdmE=) | `100.00% <100.00%> (ø)` | |
   | [...e/infra/config/datasource/DataSourceValidator.java](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9jb25maWcvZGF0YXNvdXJjZS9EYXRhU291cmNlVmFsaWRhdG9yLmphdmE=) | `57.14% <100.00%> (ø)` | |
   | ... and [15 more](https://codecov.io/gh/apache/shardingsphere/pull/12268/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12268?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/12268?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [b7574e8...42dd921](https://codecov.io/gh/apache/shardingsphere/pull/12268?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #12268: Refactor DataSourceConfiguration

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #12268:
URL: https://github.com/apache/shardingsphere/pull/12268#discussion_r703469010



##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/creator/impl/HikariDataSourceCreator.java
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.creator.impl;
+
+import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
+
+import javax.sql.DataSource;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Hikari data source creator.
+ */
+public final class HikariDataSourceCreator extends AbstractDataSourceCreator {
+    
+    private final Map<String, Object> skippedProperties = new HashMap<>();
+    
+    public HikariDataSourceCreator() {
+        skippedProperties.put("minimumIdle", -1);
+        skippedProperties.put("maximumPoolSize", -1);
+    }
+    
+    @Override
+    public DataSource createDataSource(final DataSourceConfiguration dataSourceConfiguration) {
+        DataSource result = buildDataSource(dataSourceConfiguration.getDataSourceClassName());
+        Method[] methods = result.getClass().getMethods();
+        for (Map.Entry<String, Object> entry : dataSourceConfiguration.getAllProps().entrySet()) {
+            if (isInvalidProperty(entry.getKey(), entry.getValue())) {
+                continue;
+            }
+            setField(result, methods, entry.getKey(), entry.getValue());
+        }
+        return result;
+    }
+    
+    private boolean isInvalidProperty(final String property, final Object value) {
+        return skippedProperties.containsKey(property) && null != value 
+                && value.equals(skippedProperties.get(property));

Review comment:
       Please keep one line if not exceed 200

##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/creator/impl/HikariDataSourceCreator.java
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.creator.impl;
+
+import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
+
+import javax.sql.DataSource;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Hikari data source creator.
+ */
+public final class HikariDataSourceCreator extends AbstractDataSourceCreator {
+    
+    private final Map<String, Object> skippedProperties = new HashMap<>();
+    
+    public HikariDataSourceCreator() {
+        skippedProperties.put("minimumIdle", -1);
+        skippedProperties.put("maximumPoolSize", -1);
+    }
+    
+    @Override
+    public DataSource createDataSource(final DataSourceConfiguration dataSourceConfiguration) {
+        DataSource result = buildDataSource(dataSourceConfiguration.getDataSourceClassName());
+        Method[] methods = result.getClass().getMethods();
+        for (Map.Entry<String, Object> entry : dataSourceConfiguration.getAllProps().entrySet()) {

Review comment:
       Please use import for `Map.Entry`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu merged pull request #12268: Refactor DataSourceConfiguration

Posted by GitBox <gi...@apache.org>.
terrymanu merged pull request #12268:
URL: https://github.com/apache/shardingsphere/pull/12268


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org