未验证 提交 4ebe65d2 编写于 作者: L Liang Zhang 提交者: GitHub

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
上级 8711298b
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.shardingsphere.sharding.convert; package org.apache.shardingsphere.sharding.converter;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration; 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.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.distsql.parser.statement.rdl.TableRuleSegment;
import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration; import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.rule.YamlShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.yaml.config.rule.YamlShardingAutoTableRuleConfiguration;
...@@ -35,11 +35,11 @@ import java.util.Properties; ...@@ -35,11 +35,11 @@ import java.util.Properties;
public final class CreateShardingRuleStatementContextConverter implements SQLStatementContextConverter<CreateShardingRuleStatementContext, YamlShardingRuleConfiguration> { public final class CreateShardingRuleStatementContextConverter implements SQLStatementContextConverter<CreateShardingRuleStatementContext, YamlShardingRuleConfiguration> {
@Override @Override
public YamlShardingRuleConfiguration convert(final CreateShardingRuleStatementContext context) { public YamlShardingRuleConfiguration convert(final CreateShardingRuleStatementContext sqlStatementContext) {
YamlShardingRuleConfiguration result = new YamlShardingRuleConfiguration(); YamlShardingRuleConfiguration result = new YamlShardingRuleConfiguration();
for (TableRuleSegment each : context.getSqlStatement().getTables()) { for (TableRuleSegment each : sqlStatementContext.getSqlStatement().getTables()) {
result.getShardingAlgorithms().put(getAlgorithmName(each.getLogicTable(), each.getAlgorithmType()), 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)); result.getAutoTables().put(each.getLogicTable(), createAutoTableRuleConfiguration(each));
} }
return result; return result;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* limitations under the License. * 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.binder.context.CreateShardingRuleStatementContext;
import org.apache.shardingsphere.distsql.parser.statement.rdl.CreateShardingRuleStatement; import org.apache.shardingsphere.distsql.parser.statement.rdl.CreateShardingRuleStatement;
......
...@@ -15,20 +15,23 @@ ...@@ -15,20 +15,23 @@
* limitations under the License. * 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; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
/** /**
* SQL statement context converter. * SQL statement context converter.
*
* @param <I> type of SQL statement context
* @param <O> type of output object
*/ */
public interface SQLStatementContextConverter<I extends SQLStatementContext<?>, O> { public interface SQLStatementContextConverter<I extends SQLStatementContext<?>, O> {
/** /**
* Convert sql statement. * Convert SQL statement to desired object.
* *
* @param sqlStatement sql statement * @param sqlStatementContext SQL statement context
* @return yaml configurations * @return output object
*/ */
O convert(I sqlStatement); O convert(I sqlStatementContext);
} }
...@@ -36,12 +36,12 @@ import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse; ...@@ -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.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.config.util.DataSourceParameterConverter; import org.apache.shardingsphere.proxy.config.util.DataSourceParameterConverter;
import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter; 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.CreateDataSourcesStatementContext;
import org.apache.shardingsphere.distsql.parser.binder.context.CreateShardingRuleStatementContext; 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.CreateDataSourcesStatement;
import org.apache.shardingsphere.distsql.parser.statement.rdl.CreateShardingRuleStatement; 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.sharding.yaml.config.YamlShardingRuleConfiguration;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.ddl.CreateDatabaseStatementContext; import org.apache.shardingsphere.infra.binder.statement.ddl.CreateDatabaseStatementContext;
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
* limitations under the License. * 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.infra.config.datasource.DataSourceParameter;
import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter; import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
import org.apache.shardingsphere.distsql.parser.binder.context.CreateDataSourcesStatementContext; 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 org.apache.shardingsphere.distsql.parser.statement.rdl.DataSourceConnectionSegment;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
...@@ -32,12 +32,12 @@ import java.util.Map; ...@@ -32,12 +32,12 @@ import java.util.Map;
public final class CreateDataSourcesStatementContextConverter implements SQLStatementContextConverter<CreateDataSourcesStatementContext, Map<String, YamlDataSourceParameter>> { public final class CreateDataSourcesStatementContextConverter implements SQLStatementContextConverter<CreateDataSourcesStatementContext, Map<String, YamlDataSourceParameter>> {
@Override @Override
public Map<String, YamlDataSourceParameter> convert(final CreateDataSourcesStatementContext context) { public Map<String, YamlDataSourceParameter> convert(final CreateDataSourcesStatementContext sqlStatementContext) {
Map<String, YamlDataSourceParameter> result = new LinkedHashMap<>(context.getSqlStatement().getConnectionInfos().size(), 1); Map<String, YamlDataSourceParameter> result = new LinkedHashMap<>(sqlStatementContext.getSqlStatement().getConnectionInfos().size(), 1);
for (DataSourceConnectionSegment each : context.getSqlStatement().getConnectionInfos()) { for (DataSourceConnectionSegment each : sqlStatementContext.getSqlStatement().getConnectionInfos()) {
DataSourceParameter parameter = new DataSourceParameter(); DataSourceParameter parameter = new DataSourceParameter();
YamlDataSourceParameter dataSource = new YamlDataSourceParameter(); YamlDataSourceParameter dataSource = new YamlDataSourceParameter();
dataSource.setUrl(context.getUrl(each)); dataSource.setUrl(sqlStatementContext.getUrl(each));
dataSource.setUsername(each.getUser()); dataSource.setUsername(each.getUser());
dataSource.setPassword(each.getPassword()); dataSource.setPassword(each.getPassword());
dataSource.setMinPoolSize(parameter.getMinPoolSize()); dataSource.setMinPoolSize(parameter.getMinPoolSize());
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* limitations under the License. * 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.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter; import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册