You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/10/31 09:09:48 UTC

[shardingsphere] branch master updated: Move SQLStatementContextConverter to shardingsphere-infra-binder module (#7992)

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 4ebe65d  Move SQLStatementContextConverter to shardingsphere-infra-binder module (#7992)
4ebe65d is described below

commit 4ebe65d28e19cd39658ff1ba4993505e094a81ab
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Oct 31 17:09:34 2020 +0800

    Move SQLStatementContextConverter to shardingsphere-infra-binder module (#7992)
    
    * Update javadoc of SQLStatementContextConverter
    
    * Move SQLStatementContextConverter to shardingsphere-infra-binder module
    
    * Rename package name from convert to converter
---
 .../CreateShardingRuleStatementContextConverter.java        | 10 +++++-----
 .../CreateShardingRuleStatementContextConverterTest.java    |  2 +-
 .../binder/converter}/SQLStatementContextConverter.java     | 13 ++++++++-----
 .../proxy/backend/text/admin/RDLBackendHandler.java         |  4 ++--
 .../CreateDataSourcesStatementContextConverter.java         | 12 ++++++------
 .../CreateDataSourcesStatementContextConverterTest.java     |  2 +-
 6 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/convert/CreateShardingRuleStatementContextConverter.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/converter/CreateShardingRuleStatementContextConverter.java
similarity index 90%
rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/convert/CreateShardingRuleStatementContextConverter.java
rename to shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/converter/CreateShardingRuleStatementContextConverter.java
index 8e31f83..bd7b66c 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/convert/CreateShardingRuleStatementContextConverter.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/converter/CreateShardingRuleStatementContextConverter.java
@@ -15,12 +15,12 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.sharding.convert;
+package org.apache.shardingsphere.sharding.converter;
 
 import com.google.common.base.Joiner;
 import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.distsql.parser.binder.context.CreateShardingRuleStatementContext;
-import org.apache.shardingsphere.distsql.parser.binder.generator.SQLStatementContextConverter;
+import org.apache.shardingsphere.infra.binder.converter.SQLStatementContextConverter;
 import org.apache.shardingsphere.distsql.parser.statement.rdl.TableRuleSegment;
 import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
 import org.apache.shardingsphere.sharding.yaml.config.rule.YamlShardingAutoTableRuleConfiguration;
@@ -35,11 +35,11 @@ import java.util.Properties;
 public final class CreateShardingRuleStatementContextConverter implements SQLStatementContextConverter<CreateShardingRuleStatementContext, YamlShardingRuleConfiguration> {
     
     @Override
-    public YamlShardingRuleConfiguration convert(final CreateShardingRuleStatementContext context) {
+    public YamlShardingRuleConfiguration convert(final CreateShardingRuleStatementContext sqlStatementContext) {
         YamlShardingRuleConfiguration result = new YamlShardingRuleConfiguration();
-        for (TableRuleSegment each : context.getSqlStatement().getTables()) {
+        for (TableRuleSegment each : sqlStatementContext.getSqlStatement().getTables()) {
             result.getShardingAlgorithms().put(getAlgorithmName(each.getLogicTable(), each.getAlgorithmType()),
-                    createAlgorithmConfiguration(each, context.getAlgorithmProperties(each)));
+                    createAlgorithmConfiguration(each, sqlStatementContext.getAlgorithmProperties(each)));
             result.getAutoTables().put(each.getLogicTable(), createAutoTableRuleConfiguration(each));
         }
         return result;
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/convert/CreateShardingRuleStatementContextConverterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/converter/CreateShardingRuleStatementContextConverterTest.java
similarity index 98%
rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/convert/CreateShardingRuleStatementContextConverterTest.java
rename to shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/converter/CreateShardingRuleStatementContextConverterTest.java
index 5ca3261..938e208 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/convert/CreateShardingRuleStatementContextConverterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/converter/CreateShardingRuleStatementContextConverterTest.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.sharding.convert;
+package org.apache.shardingsphere.sharding.converter;
 
 import org.apache.shardingsphere.distsql.parser.binder.context.CreateShardingRuleStatementContext;
 import org.apache.shardingsphere.distsql.parser.statement.rdl.CreateShardingRuleStatement;
diff --git a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-binder/src/main/java/org/apache/shardingsphere/distsql/parser/binder/generator/SQLStatementContextConverter.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/converter/SQLStatementContextConverter.java
similarity index 76%
rename from shardingsphere-distsql-parser/shardingsphere-distsql-parser-binder/src/main/java/org/apache/shardingsphere/distsql/parser/binder/generator/SQLStatementContextConverter.java
rename to shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/converter/SQLStatementContextConverter.java
index 5dcde3b..6d6cf60 100644
--- a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-binder/src/main/java/org/apache/shardingsphere/distsql/parser/binder/generator/SQLStatementContextConverter.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/converter/SQLStatementContextConverter.java
@@ -15,20 +15,23 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.distsql.parser.binder.generator;
+package org.apache.shardingsphere.infra.binder.converter;
 
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 
 /**
  * SQL statement context converter.
+ * 
+ * @param <I> type of SQL statement context
+ * @param <O> type of output object 
  */
 public interface SQLStatementContextConverter<I extends SQLStatementContext<?>, O> {
     
     /**
-     * Convert sql statement.
+     * Convert SQL statement to desired object.
      *
-     * @param sqlStatement sql statement
-     * @return yaml configurations
+     * @param sqlStatementContext SQL statement context
+     * @return output object
      */
-    O convert(I sqlStatement);
+    O convert(I sqlStatementContext);
 }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandler.java
index 6ebed1c..3a853a7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandler.java
@@ -36,12 +36,12 @@ import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
 import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
 import org.apache.shardingsphere.proxy.config.util.DataSourceParameterConverter;
 import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
-import org.apache.shardingsphere.proxy.convert.CreateDataSourcesStatementContextConverter;
+import org.apache.shardingsphere.proxy.converter.CreateDataSourcesStatementContextConverter;
 import org.apache.shardingsphere.distsql.parser.binder.context.CreateDataSourcesStatementContext;
 import org.apache.shardingsphere.distsql.parser.binder.context.CreateShardingRuleStatementContext;
 import org.apache.shardingsphere.distsql.parser.statement.rdl.CreateDataSourcesStatement;
 import org.apache.shardingsphere.distsql.parser.statement.rdl.CreateShardingRuleStatement;
-import org.apache.shardingsphere.sharding.convert.CreateShardingRuleStatementContextConverter;
+import org.apache.shardingsphere.sharding.converter.CreateShardingRuleStatementContextConverter;
 import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.binder.statement.ddl.CreateDatabaseStatementContext;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverter.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverter.java
similarity index 84%
rename from shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverter.java
rename to shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverter.java
index aa76218..4deb912 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverter.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverter.java
@@ -15,12 +15,12 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.proxy.convert;
+package org.apache.shardingsphere.proxy.converter;
 
 import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
 import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
 import org.apache.shardingsphere.distsql.parser.binder.context.CreateDataSourcesStatementContext;
-import org.apache.shardingsphere.distsql.parser.binder.generator.SQLStatementContextConverter;
+import org.apache.shardingsphere.infra.binder.converter.SQLStatementContextConverter;
 import org.apache.shardingsphere.distsql.parser.statement.rdl.DataSourceConnectionSegment;
 
 import java.util.LinkedHashMap;
@@ -32,12 +32,12 @@ import java.util.Map;
 public final class CreateDataSourcesStatementContextConverter implements SQLStatementContextConverter<CreateDataSourcesStatementContext, Map<String, YamlDataSourceParameter>> {
     
     @Override
-    public Map<String, YamlDataSourceParameter> convert(final CreateDataSourcesStatementContext context) {
-        Map<String, YamlDataSourceParameter> result = new LinkedHashMap<>(context.getSqlStatement().getConnectionInfos().size(), 1);
-        for (DataSourceConnectionSegment each : context.getSqlStatement().getConnectionInfos()) {
+    public Map<String, YamlDataSourceParameter> convert(final CreateDataSourcesStatementContext sqlStatementContext) {
+        Map<String, YamlDataSourceParameter> result = new LinkedHashMap<>(sqlStatementContext.getSqlStatement().getConnectionInfos().size(), 1);
+        for (DataSourceConnectionSegment each : sqlStatementContext.getSqlStatement().getConnectionInfos()) {
             DataSourceParameter parameter = new DataSourceParameter();
             YamlDataSourceParameter dataSource = new YamlDataSourceParameter();
-            dataSource.setUrl(context.getUrl(each));
+            dataSource.setUrl(sqlStatementContext.getUrl(each));
             dataSource.setUsername(each.getUser());
             dataSource.setPassword(each.getPassword());
             dataSource.setMinPoolSize(parameter.getMinPoolSize());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverterTest.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverterTest.java
similarity index 98%
rename from shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverterTest.java
rename to shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverterTest.java
index 20bef9d..9834fb6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverterTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverterTest.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.proxy.convert;
+package org.apache.shardingsphere.proxy.converter;
 
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;