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

Adjust ShardingSphereRule (#5415)

* rename BaseRule to ShardingSphereRule

* replace LINE_SEPARATOR to System.lineSeparator()

* rename TablesAggregationRule to DataNodeRoutedRule

* add DataSourceRoutedRule interface
上级 8d1561fb
......@@ -29,7 +29,7 @@ import org.apache.shardingsphere.encrypt.strategy.spi.Encryptor;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptor;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.type.TypedSPIRegistry;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import java.util.Collection;
import java.util.Collections;
......@@ -44,7 +44,7 @@ import java.util.stream.Collectors;
/**
* Encrypt rule.
*/
public final class EncryptRule implements BaseRule {
public final class EncryptRule implements ShardingSphereRule {
static {
ShardingSphereServiceLoader.register(Encryptor.class);
......@@ -273,9 +273,4 @@ public final class EncryptRule implements BaseRule {
public Collection<String> getEncryptTableNames() {
return tables.keySet();
}
@Override
public Map<String, Collection<String>> getDataSourceMapper() {
return Collections.emptyMap();
}
}
......@@ -53,8 +53,6 @@ import java.util.stream.Collectors;
*/
public final class ShardingMetaDataLoader implements RuleMetaDataLoader<ShardingRule> {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private static final int CPU_CORES = Runtime.getRuntime().availableProcessors();
private static final int FUTURE_GET_TIME_OUT_SECOND = 5;
......@@ -137,9 +135,9 @@ public final class ShardingMetaDataLoader implements RuleMetaDataLoader<Sharding
private void throwExceptionIfNecessary(final Collection<TableMetaDataViolation> violations, final String logicTableName) {
if (!violations.isEmpty()) {
StringBuilder errorMessage = new StringBuilder(
"Cannot get uniformed table structure for logic table `%s`, it has different meta data of actual tables are as follows:").append(LINE_SEPARATOR);
"Cannot get uniformed table structure for logic table `%s`, it has different meta data of actual tables are as follows:").append(System.lineSeparator());
for (TableMetaDataViolation each : violations) {
errorMessage.append("actual table: ").append(each.getActualTableName()).append(", meta data: ").append(each.getTableMetaData()).append(LINE_SEPARATOR);
errorMessage.append("actual table: ").append(each.getActualTableName()).append(", meta data: ").append(each.getTableMetaData()).append(System.lineSeparator());
}
throw new ShardingSphereException(errorMessage.toString(), logicTableName);
}
......
......@@ -23,7 +23,7 @@ import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfigura
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.masterslave.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.spi.type.TypedSPIRegistry;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.DataSourceRoutedRule;
import java.util.Collection;
import java.util.HashMap;
......@@ -37,7 +37,7 @@ import java.util.stream.Collectors;
* Databases and tables master-slave rule.
*/
@Getter
public final class MasterSlaveRule implements BaseRule {
public final class MasterSlaveRule implements DataSourceRoutedRule {
static {
ShardingSphereServiceLoader.register(MasterSlaveLoadBalanceAlgorithm.class);
......
......@@ -24,7 +24,7 @@ import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.underlying.common.config.RuleConfiguration;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import java.util.Collection;
import java.util.LinkedList;
......@@ -43,8 +43,8 @@ public final class RuleBuilder {
* @param shardingRuleConfig sharding rule configuration
* @return rules
*/
public static Collection<BaseRule> build(final Collection<String> dataSourceNames, final ShardingRuleConfiguration shardingRuleConfig) {
Collection<BaseRule> result = new LinkedList<>();
public static Collection<ShardingSphereRule> build(final Collection<String> dataSourceNames, final ShardingRuleConfiguration shardingRuleConfig) {
Collection<ShardingSphereRule> result = new LinkedList<>();
result.add(new ShardingRule(shardingRuleConfig, dataSourceNames));
result.addAll(shardingRuleConfig.getMasterSlaveRuleConfigs().stream().map(MasterSlaveRule::new).collect(Collectors.toList()));
if (null != shardingRuleConfig.getEncryptRuleConfig()) {
......@@ -60,8 +60,8 @@ public final class RuleBuilder {
* @param ruleConfigurations rule configurations
* @return rules
*/
public static Collection<BaseRule> build(final Collection<String> dataSourceNames, final Collection<RuleConfiguration> ruleConfigurations) {
Collection<BaseRule> result = new LinkedList<>();
public static Collection<ShardingSphereRule> build(final Collection<String> dataSourceNames, final Collection<RuleConfiguration> ruleConfigurations) {
Collection<ShardingSphereRule> result = new LinkedList<>();
for (RuleConfiguration each : ruleConfigurations) {
if (each instanceof ShardingRuleConfiguration) {
result.add(new ShardingRule((ShardingRuleConfiguration) each, dataSourceNames));
......
......@@ -19,17 +19,13 @@ package org.apache.shardingsphere.core.rule;
import lombok.Getter;
import org.apache.shardingsphere.api.config.shadow.ShadowRuleConfiguration;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
/**
* Databases shadow rule.
*/
@Getter
public final class ShadowRule implements BaseRule {
public final class ShadowRule implements ShardingSphereRule {
private ShadowRuleConfiguration ruleConfiguration;
......@@ -39,9 +35,4 @@ public final class ShadowRule implements BaseRule {
column = shadowRuleConfiguration.getColumn();
ruleConfiguration = shadowRuleConfiguration;
}
@Override
public Map<String, Collection<String>> getDataSourceMapper() {
return Collections.emptyMap();
}
}
......@@ -33,7 +33,7 @@ import org.apache.shardingsphere.spi.keygen.KeyGenerateAlgorithm;
import org.apache.shardingsphere.spi.type.TypedSPIRegistry;
import org.apache.shardingsphere.underlying.common.config.exception.ShardingSphereConfigurationException;
import org.apache.shardingsphere.underlying.common.rule.DataNode;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import java.util.Collection;
import java.util.HashMap;
......@@ -50,7 +50,7 @@ import java.util.stream.Collectors;
* Databases and tables sharding rule.
*/
@Getter
public final class ShardingRule implements TablesAggregationRule {
public final class ShardingRule implements DataNodeRoutedRule {
static {
ShardingSphereServiceLoader.register(KeyGenerateAlgorithm.class);
......
......@@ -32,7 +32,7 @@ import org.apache.shardingsphere.underlying.common.config.properties.Configurati
import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.underlying.common.metadata.datasource.DataSourceMetas;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaData;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.common.yaml.engine.YamlEngine;
import org.apache.shardingsphere.underlying.rewrite.SQLRewriteEntry;
import org.apache.shardingsphere.underlying.rewrite.engine.result.GenericSQLRewriteResult;
......@@ -76,7 +76,7 @@ public final class MixSQLRewriterParameterizedTest extends AbstractSQLRewriterPa
@Override
protected Collection<SQLRewriteUnit> createSQLRewriteUnits() throws IOException {
YamlRootShardingConfiguration ruleConfiguration = createRuleConfiguration();
Collection<BaseRule> rules = RuleBuilder.build(ruleConfiguration.getDataSources().keySet(), new ShardingRuleConfigurationYamlSwapper().swap(ruleConfiguration.getShardingRule()));
Collection<ShardingSphereRule> rules = RuleBuilder.build(ruleConfiguration.getDataSources().keySet(), new ShardingRuleConfigurationYamlSwapper().swap(ruleConfiguration.getShardingRule()));
SQLParserEngine sqlParserEngine = SQLParserEngineFactory.getSQLParserEngine(null == getTestParameters().getDatabaseType() ? "SQL92" : getTestParameters().getDatabaseType());
ShardingSphereMetaData metaData = createShardingSphereMetaData();
ConfigurationProperties properties = new ConfigurationProperties(ruleConfiguration.getProps());
......
......@@ -32,7 +32,7 @@ import org.apache.shardingsphere.underlying.common.config.properties.Configurati
import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.underlying.common.metadata.datasource.DataSourceMetas;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaData;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.common.yaml.engine.YamlEngine;
import org.apache.shardingsphere.underlying.rewrite.SQLRewriteEntry;
import org.apache.shardingsphere.underlying.rewrite.engine.result.GenericSQLRewriteResult;
......@@ -76,7 +76,7 @@ public final class ShardingSQLRewriterParameterizedTest extends AbstractSQLRewri
@Override
protected Collection<SQLRewriteUnit> createSQLRewriteUnits() throws IOException {
YamlRootShardingConfiguration ruleConfiguration = createRuleConfiguration();
Collection<BaseRule> rules = RuleBuilder.build(ruleConfiguration.getDataSources().keySet(), new ShardingRuleConfigurationYamlSwapper().swap(ruleConfiguration.getShardingRule()));
Collection<ShardingSphereRule> rules = RuleBuilder.build(ruleConfiguration.getDataSources().keySet(), new ShardingRuleConfigurationYamlSwapper().swap(ruleConfiguration.getShardingRule()));
SQLParserEngine sqlParserEngine = SQLParserEngineFactory.getSQLParserEngine(null == getTestParameters().getDatabaseType() ? "SQL92" : getTestParameters().getDatabaseType());
ShardingSphereMetaData metaData = createShardingSphereMetaData();
ConfigurationProperties properties = new ConfigurationProperties(ruleConfiguration.getProps());
......
......@@ -27,8 +27,8 @@ import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext
import org.apache.shardingsphere.underlying.common.metadata.refresh.MetaDataRefreshStrategy;
import org.apache.shardingsphere.underlying.common.metadata.refresh.MetaDataRefreshStrategyFactory;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaDataLoader;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import org.apache.shardingsphere.underlying.executor.kernel.InputGroup;
import org.apache.shardingsphere.underlying.executor.sql.ConnectionMode;
import org.apache.shardingsphere.underlying.executor.sql.QueryResult;
......@@ -94,7 +94,7 @@ public final class PreparedStatementExecutor {
}
private SQLExecutorCallback<QueryResult> getExecuteQueryExecutorCallback(final DefaultSQLExecutorCallback callback) {
Map<BaseRule, RuleExecuteQueryExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteQueryExecutorCallback.class);
Map<ShardingSphereRule, RuleExecuteQueryExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteQueryExecutorCallback.class);
return callbackMap.isEmpty() ? callback : callbackMap.values().iterator().next();
}
......@@ -123,17 +123,17 @@ public final class PreparedStatementExecutor {
});
List<Integer> results = sqlExecutor.execute(inputGroups, sqlExecutorCallback);
refreshTableMetaData(runtimeContext, sqlStatementContext);
return isNeedAccumulate(runtimeContext.getRules().stream().filter(rule -> rule instanceof TablesAggregationRule).collect(Collectors.toList()), sqlStatementContext)
return isNeedAccumulate(runtimeContext.getRules().stream().filter(rule -> rule instanceof DataNodeRoutedRule).collect(Collectors.toList()), sqlStatementContext)
? accumulate(results) : results.get(0);
}
private SQLExecutorCallback<Integer> getExecuteUpdateExecutorCallback(final DefaultSQLExecutorCallback callback) {
Map<BaseRule, RuleExecuteUpdateExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteUpdateExecutorCallback.class);
Map<ShardingSphereRule, RuleExecuteUpdateExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteUpdateExecutorCallback.class);
return callbackMap.isEmpty() ? callback : callbackMap.values().iterator().next();
}
private boolean isNeedAccumulate(final Collection<BaseRule> rules, final SQLStatementContext sqlStatementContext) {
return rules.stream().anyMatch(each -> ((TablesAggregationRule) each).isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames()));
private boolean isNeedAccumulate(final Collection<ShardingSphereRule> rules, final SQLStatementContext sqlStatementContext) {
return rules.stream().anyMatch(each -> ((DataNodeRoutedRule) each).isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames()));
}
private int accumulate(final List<Integer> results) {
......@@ -170,7 +170,7 @@ public final class PreparedStatementExecutor {
}
private SQLExecutorCallback<Boolean> getExecuteExecutorCallback(final DefaultSQLExecutorCallback callback) {
Map<BaseRule, RuleExecuteExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteExecutorCallback.class);
Map<ShardingSphereRule, RuleExecuteExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteExecutorCallback.class);
return callbackMap.isEmpty() ? callback : callbackMap.values().iterator().next();
}
......
......@@ -27,8 +27,8 @@ import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext
import org.apache.shardingsphere.underlying.common.metadata.refresh.MetaDataRefreshStrategy;
import org.apache.shardingsphere.underlying.common.metadata.refresh.MetaDataRefreshStrategyFactory;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaDataLoader;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import org.apache.shardingsphere.underlying.executor.kernel.InputGroup;
import org.apache.shardingsphere.underlying.executor.sql.ConnectionMode;
import org.apache.shardingsphere.underlying.executor.sql.QueryResult;
......@@ -94,7 +94,7 @@ public final class StatementExecutor {
}
private SQLExecutorCallback<QueryResult> getExecuteQueryExecutorCallback(final DefaultSQLExecutorCallback callback) {
Map<BaseRule, RuleExecuteQueryExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteQueryExecutorCallback.class);
Map<ShardingSphereRule, RuleExecuteQueryExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteQueryExecutorCallback.class);
return callbackMap.isEmpty() ? callback : callbackMap.values().iterator().next();
}
......@@ -166,19 +166,19 @@ public final class StatementExecutor {
});
List<Integer> results = sqlExecutor.execute(inputGroups, sqlExecutorCallback);
refreshTableMetaData(runtimeContext, sqlStatementContext);
if (isNeedAccumulate(runtimeContext.getRules().stream().filter(rule -> rule instanceof TablesAggregationRule).collect(Collectors.toList()), sqlStatementContext)) {
if (isNeedAccumulate(runtimeContext.getRules().stream().filter(rule -> rule instanceof DataNodeRoutedRule).collect(Collectors.toList()), sqlStatementContext)) {
return accumulate(results);
}
return null == results.get(0) ? 0 : results.get(0);
}
private SQLExecutorCallback<Integer> getExecuteUpdateExecutorCallback(final DefaultSQLExecutorCallback callback) {
Map<BaseRule, RuleExecuteUpdateExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteUpdateExecutorCallback.class);
Map<ShardingSphereRule, RuleExecuteUpdateExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteUpdateExecutorCallback.class);
return callbackMap.isEmpty() ? callback : callbackMap.values().iterator().next();
}
private boolean isNeedAccumulate(final Collection<BaseRule> rules, final SQLStatementContext sqlStatementContext) {
return rules.stream().anyMatch(each -> ((TablesAggregationRule) each).isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames()));
private boolean isNeedAccumulate(final Collection<ShardingSphereRule> rules, final SQLStatementContext sqlStatementContext) {
return rules.stream().anyMatch(each -> ((DataNodeRoutedRule) each).isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames()));
}
private int accumulate(final List<Integer> results) {
......@@ -259,7 +259,7 @@ public final class StatementExecutor {
}
private SQLExecutorCallback<Boolean> getExecuteExecutorCallback(final DefaultSQLExecutorCallback callback) {
Map<BaseRule, RuleExecuteExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteExecutorCallback.class);
Map<ShardingSphereRule, RuleExecuteExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteExecutorCallback.class);
return callbackMap.isEmpty() ? callback : callbackMap.values().iterator().next();
}
......
......@@ -24,8 +24,8 @@ import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.RuntimeContext;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.order.OrderedSPIRegistry;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import org.apache.shardingsphere.underlying.executor.kernel.InputGroup;
import org.apache.shardingsphere.underlying.executor.sql.ConnectionMode;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionUnit;
......@@ -140,17 +140,17 @@ public final class BatchPreparedStatementExecutor {
}
});
List<int[]> results = sqlExecutor.execute(inputGroups, callback);
return isNeedAccumulate(runtimeContext.getRules().stream().filter(rule -> rule instanceof TablesAggregationRule).collect(Collectors.toList()), sqlStatementContext)
return isNeedAccumulate(runtimeContext.getRules().stream().filter(rule -> rule instanceof DataNodeRoutedRule).collect(Collectors.toList()), sqlStatementContext)
? accumulate(results) : results.get(0);
}
private SQLExecutorCallback<int[]> getExecuteBatchExecutorCallback(final DefaultSQLExecutorCallback callback) {
Map<BaseRule, RuleExecuteBatchExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteBatchExecutorCallback.class);
Map<ShardingSphereRule, RuleExecuteBatchExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(runtimeContext.getRules(), RuleExecuteBatchExecutorCallback.class);
return callbackMap.isEmpty() ? callback : callbackMap.values().iterator().next();
}
private boolean isNeedAccumulate(final Collection<BaseRule> rules, final SQLStatementContext sqlStatementContext) {
return rules.stream().anyMatch(each -> ((TablesAggregationRule) each).isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames()));
private boolean isNeedAccumulate(final Collection<ShardingSphereRule> rules, final SQLStatementContext sqlStatementContext) {
return rules.stream().anyMatch(each -> ((DataNodeRoutedRule) each).isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames()));
}
private int[] accumulate(final List<int[]> results) {
......
......@@ -18,11 +18,11 @@
package org.apache.shardingsphere.shardingjdbc.executor.callback;
import org.apache.shardingsphere.spi.order.OrderedSPI;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.executor.SQLExecutorCallback;
/**
* Rule based SQL executor callback for execute batch.
*/
public interface RuleExecuteBatchExecutorCallback extends SQLExecutorCallback<int[]>, OrderedSPI<BaseRule> {
public interface RuleExecuteBatchExecutorCallback extends SQLExecutorCallback<int[]>, OrderedSPI<ShardingSphereRule> {
}
......@@ -18,11 +18,11 @@
package org.apache.shardingsphere.shardingjdbc.executor.callback;
import org.apache.shardingsphere.spi.order.OrderedSPI;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.executor.SQLExecutorCallback;
/**
* Rule based SQL executor callback for execute.
*/
public interface RuleExecuteExecutorCallback extends SQLExecutorCallback<Boolean>, OrderedSPI<BaseRule> {
public interface RuleExecuteExecutorCallback extends SQLExecutorCallback<Boolean>, OrderedSPI<ShardingSphereRule> {
}
......@@ -18,12 +18,12 @@
package org.apache.shardingsphere.shardingjdbc.executor.callback;
import org.apache.shardingsphere.spi.order.OrderedSPI;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.QueryResult;
import org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.executor.SQLExecutorCallback;
/**
* Rule based SQL executor callback for execute query.
*/
public interface RuleExecuteQueryExecutorCallback extends SQLExecutorCallback<QueryResult>, OrderedSPI<BaseRule> {
public interface RuleExecuteQueryExecutorCallback extends SQLExecutorCallback<QueryResult>, OrderedSPI<ShardingSphereRule> {
}
......@@ -18,11 +18,11 @@
package org.apache.shardingsphere.shardingjdbc.executor.callback;
import org.apache.shardingsphere.spi.order.OrderedSPI;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.executor.SQLExecutorCallback;
/**
* Rule based SQL executor callback for execute update.
*/
public interface RuleExecuteUpdateExecutorCallback extends SQLExecutorCallback<Integer>, OrderedSPI<BaseRule> {
public interface RuleExecuteUpdateExecutorCallback extends SQLExecutorCallback<Integer>, OrderedSPI<ShardingSphereRule> {
}
......@@ -24,7 +24,7 @@ import org.apache.shardingsphere.underlying.common.database.type.DatabaseTypes;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.RuntimeContext;
import org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationDataSource;
import org.apache.shardingsphere.underlying.common.database.type.DatabaseType;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import javax.sql.DataSource;
import java.io.PrintWriter;
......@@ -52,13 +52,13 @@ public abstract class AbstractDataSourceAdapter extends AbstractUnsupportedOpera
@Setter
private PrintWriter logWriter = new PrintWriter(System.out);
public AbstractDataSourceAdapter(final Map<String, DataSource> dataSourceMap, final Collection<BaseRule> rules, final Properties props) throws SQLException {
public AbstractDataSourceAdapter(final Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> rules, final Properties props) throws SQLException {
this.dataSourceMap = dataSourceMap;
databaseType = createDatabaseType();
runtimeContext = new RuntimeContext(dataSourceMap, databaseType, rules, props);
}
public AbstractDataSourceAdapter(final DataSource dataSource, final Collection<BaseRule> rules, final Properties props) throws SQLException {
public AbstractDataSourceAdapter(final DataSource dataSource, final Collection<ShardingSphereRule> rules, final Properties props) throws SQLException {
dataSourceMap = new HashMap<>(1, 1);
dataSourceMap.put("unique", dataSource);
databaseType = createDatabaseType();
......
......@@ -25,7 +25,7 @@ import org.apache.shardingsphere.shardingjdbc.jdbc.core.resultset.ShardingSphere
import org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingStatement;
import org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationResultSet;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
import java.sql.ResultSet;
......@@ -66,7 +66,7 @@ public abstract class AbstractResultSetAdapter extends AbstractUnsupportedOperat
return new ShardingSphereResultSetMetaData(resultSets.get(0).getMetaData(), getRules(), executionContext.getSqlStatementContext());
}
private Collection<BaseRule> getRules() {
private Collection<ShardingSphereRule> getRules() {
ShardingConnection connection = statement instanceof ShardingPreparedStatement ? ((ShardingPreparedStatement) statement).getConnection() : ((ShardingStatement) statement).getConnection();
return connection.getRuntimeContext().getRules();
}
......
......@@ -35,7 +35,7 @@ import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaDa
import org.apache.shardingsphere.underlying.common.metadata.datasource.DataSourceMetas;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaData;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaDataLoader;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.kernel.ExecutorKernel;
import javax.sql.DataSource;
......@@ -59,7 +59,7 @@ public final class RuntimeContext implements AutoCloseable {
private final DatabaseType databaseType;
private final Collection<BaseRule> rules;
private final Collection<ShardingSphereRule> rules;
private final ConfigurationProperties properties;
......@@ -74,7 +74,7 @@ public final class RuntimeContext implements AutoCloseable {
@Setter
private ShardingSphereMetaData metaData;
public RuntimeContext(final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType, final Collection<BaseRule> rules, final Properties props) throws SQLException {
public RuntimeContext(final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType, final Collection<ShardingSphereRule> rules, final Properties props) throws SQLException {
this.dataSourceMap = dataSourceMap;
this.databaseType = databaseType;
this.rules = rules;
......@@ -90,7 +90,7 @@ public final class RuntimeContext implements AutoCloseable {
ConfigurationLogger.log(props);
}
public RuntimeContext(final DataSource dataSource, final DatabaseType databaseType, final Collection<BaseRule> rules, final Properties props) throws SQLException {
public RuntimeContext(final DataSource dataSource, final DatabaseType databaseType, final Collection<ShardingSphereRule> rules, final Properties props) throws SQLException {
this(ImmutableMap.of("ds", dataSource), databaseType, rules, props);
}
......
......@@ -21,7 +21,7 @@ import com.google.common.base.Preconditions;
import org.apache.shardingsphere.shardingjdbc.jdbc.adapter.AbstractDataSourceAdapter;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.ShardingConnection;
import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import javax.sql.DataSource;
import java.sql.SQLException;
......@@ -34,7 +34,7 @@ import java.util.Properties;
*/
public class ShardingDataSource extends AbstractDataSourceAdapter {
public ShardingDataSource(final Map<String, DataSource> dataSourceMap, final Collection<BaseRule> rules, final Properties props) throws SQLException {
public ShardingDataSource(final Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> rules, final Properties props) throws SQLException {
super(dataSourceMap, rules, props);
checkDataSource(dataSourceMap);
}
......
......@@ -22,8 +22,8 @@ import org.apache.shardingsphere.shardingjdbc.jdbc.adapter.AbstractConnectionAda
import org.apache.shardingsphere.shardingjdbc.jdbc.core.resultset.DatabaseMetaDataResultSet;
import org.apache.shardingsphere.underlying.common.database.DefaultSchema;
import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
......@@ -42,7 +42,7 @@ public final class ShardingSphereDatabaseMetaData extends AdaptedDatabaseMetaDat
private final AbstractConnectionAdapter connection;
private final Collection<BaseRule> rules;
private final Collection<ShardingSphereRule> rules;
private final Collection<String> datasourceNames;
......@@ -204,9 +204,9 @@ public final class ShardingSphereDatabaseMetaData extends AdaptedDatabaseMetaDat
if (null == tableNamePattern) {
return null;
}
Optional<TablesAggregationRule> tablesAggregationRule = findTablesAggregationRule();
if (tablesAggregationRule.isPresent()) {
return tablesAggregationRule.get().findFirstActualTable(tableNamePattern).isPresent() ? "%" + tableNamePattern + "%" : tableNamePattern;
Optional<DataNodeRoutedRule> dataNodeRoutedRule = findDataNodeRoutedRule();
if (dataNodeRoutedRule.isPresent()) {
return dataNodeRoutedRule.get().findFirstActualTable(tableNamePattern).isPresent() ? "%" + tableNamePattern + "%" : tableNamePattern;
}
return tableNamePattern;
}
......@@ -215,12 +215,12 @@ public final class ShardingSphereDatabaseMetaData extends AdaptedDatabaseMetaDat
if (null == table) {
return null;
}
Optional<TablesAggregationRule> tablesAggregationRule = findTablesAggregationRule();
return tablesAggregationRule.isPresent() ? tablesAggregationRule.get().findFirstActualTable(table).orElse(table) : table;
Optional<DataNodeRoutedRule> dataNodeRoutedRule = findDataNodeRoutedRule();
return dataNodeRoutedRule.isPresent() ? dataNodeRoutedRule.get().findFirstActualTable(table).orElse(table) : table;
}
private Optional<TablesAggregationRule> findTablesAggregationRule() {
return rules.stream().filter(each -> each instanceof TablesAggregationRule).findFirst().map(rule -> (TablesAggregationRule) rule);
private Optional<DataNodeRoutedRule> findDataNodeRoutedRule() {
return rules.stream().filter(each -> each instanceof DataNodeRoutedRule).findFirst().map(rule -> (DataNodeRoutedRule) rule);
}
private ResultSet createDatabaseMetaDataResultSet(final ResultSet resultSet) throws SQLException {
......
......@@ -19,8 +19,8 @@ package org.apache.shardingsphere.shardingjdbc.jdbc.core.resultset;
import lombok.EqualsAndHashCode;
import org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedDatabaseMetaDataResultSet;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import java.sql.Date;
import java.sql.ResultSet;
......@@ -51,7 +51,7 @@ public final class DatabaseMetaDataResultSet extends AbstractUnsupportedDatabase
private final int concurrency;
private final Collection<BaseRule> rules;
private final Collection<ShardingSphereRule> rules;
private final ResultSetMetaData resultSetMetaData;
......@@ -63,7 +63,7 @@ public final class DatabaseMetaDataResultSet extends AbstractUnsupportedDatabase
private DatabaseMetaDataObject currentDatabaseMetaDataObject;
public DatabaseMetaDataResultSet(final ResultSet resultSet, final Collection<BaseRule> rules) throws SQLException {
public DatabaseMetaDataResultSet(final ResultSet resultSet, final Collection<ShardingSphereRule> rules) throws SQLException {
this.type = resultSet.getType();
this.concurrency = resultSet.getConcurrency();
this.rules = rules;
......@@ -97,11 +97,11 @@ public final class DatabaseMetaDataResultSet extends AbstractUnsupportedDatabase
private DatabaseMetaDataObject generateDatabaseMetaDataObject(final int tableNameColumnIndex, final int indexNameColumnIndex, final ResultSet resultSet) throws SQLException {
DatabaseMetaDataObject result = new DatabaseMetaDataObject(resultSetMetaData.getColumnCount());
Optional<BaseRule> tablesAggregationRule = findTablesAggregationRule();
Optional<DataNodeRoutedRule> dataNodeRoutedRule = findDataNodeRoutedRule();
for (int i = 1; i <= columnLabelIndexMap.size(); i++) {
if (tableNameColumnIndex == i) {
String tableName = resultSet.getString(i);
Optional<String> logicTableName = tablesAggregationRule.isPresent() ? ((TablesAggregationRule) tablesAggregationRule.get()).findLogicTableByActualTable(tableName) : Optional.empty();
Optional<String> logicTableName = dataNodeRoutedRule.isPresent() ? dataNodeRoutedRule.get().findLogicTableByActualTable(tableName) : Optional.empty();
result.addObject(logicTableName.orElse(tableName));
} else if (indexNameColumnIndex == i) {
String tableName = resultSet.getString(tableNameColumnIndex);
......@@ -114,8 +114,8 @@ public final class DatabaseMetaDataResultSet extends AbstractUnsupportedDatabase
return result;
}
private Optional<BaseRule> findTablesAggregationRule() {
return rules.stream().filter(each -> each instanceof TablesAggregationRule).findFirst();
private Optional<DataNodeRoutedRule> findDataNodeRoutedRule() {
return rules.stream().filter(each -> each instanceof DataNodeRoutedRule).findFirst().map(rule -> (DataNodeRoutedRule) rule);
}
@Override
......
......@@ -25,8 +25,8 @@ import org.apache.shardingsphere.sql.parser.binder.segment.select.projection.imp
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.underlying.common.database.DefaultSchema;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
......@@ -42,7 +42,7 @@ public final class ShardingSphereResultSetMetaData extends WrapperAdapter implem
private final ResultSetMetaData resultSetMetaData;
private final Collection<BaseRule> rules;
private final Collection<ShardingSphereRule> rules;
private final SQLStatementContext sqlStatementContext;
......@@ -124,8 +124,8 @@ public final class ShardingSphereResultSetMetaData extends WrapperAdapter implem
@Override
public String getTableName(final int column) throws SQLException {
String actualTableName = resultSetMetaData.getTableName(column);
Optional<BaseRule> rule = rules.stream().filter(each -> each instanceof TablesAggregationRule).findFirst();
return rule.isPresent() ? ((TablesAggregationRule) rule.get()).findLogicTableByActualTable(actualTableName).orElse(actualTableName) : actualTableName;
Optional<ShardingSphereRule> rule = rules.stream().filter(each -> each instanceof DataNodeRoutedRule).findFirst();
return rule.isPresent() ? ((DataNodeRoutedRule) rule.get()).findLogicTableByActualTable(actualTableName).orElse(actualTableName) : actualTableName;
}
@Override
......
......@@ -30,7 +30,7 @@ import org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.metadata.Shard
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContextBuilder;
import org.apache.shardingsphere.underlying.executor.sql.context.SQLUnit;
......@@ -173,7 +173,7 @@ public final class EncryptPreparedStatement extends AbstractShardingPreparedStat
@SuppressWarnings("unchecked")
private SQLUnit getSQLUnit(final String sql) {
Collection<BaseRule> rules = runtimeContext.getRules();
Collection<ShardingSphereRule> rules = runtimeContext.getRules();
RouteContext routeContext = new DataNodeRouter(runtimeContext.getMetaData(), runtimeContext.getProperties(), rules).route(sqlStatement, sql, getParameters());
sqlStatementContext = routeContext.getSqlStatementContext();
SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(
......
......@@ -27,7 +27,7 @@ import org.apache.shardingsphere.shardingjdbc.jdbc.core.resultset.EncryptResultS
import org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationStatement;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContextBuilder;
import org.apache.shardingsphere.underlying.executor.sql.log.SQLLogger;
......@@ -93,7 +93,7 @@ public final class EncryptStatement extends AbstractUnsupportedOperationStatemen
}
private String getRewriteSQL(final String sql) {
Collection<BaseRule> rules = runtimeContext.getRules();
Collection<ShardingSphereRule> rules = runtimeContext.getRules();
RouteContext routeContext = new DataNodeRouter(runtimeContext.getMetaData(), runtimeContext.getProperties(),
rules).route(runtimeContext.getSqlParserEngine().parse(sql, false), sql, Collections.emptyList());
sqlStatementContext = routeContext.getSqlStatementContext();
......
......@@ -27,7 +27,7 @@ import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.RuntimeContext;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.metadata.ShardingSphereParameterMetaData;
import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContextBuilder;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionUnit;
......@@ -77,7 +77,7 @@ public final class MasterSlavePreparedStatement extends AbstractMasterSlavePrepa
sqlStatement = connection.getRuntimeContext().getSqlParserEngine().parse(sql, true);
parameterMetaData = new ShardingSphereParameterMetaData(sqlStatement);
RuntimeContext runtimeContext = connection.getRuntimeContext();
Collection<BaseRule> rules = runtimeContext.getRules();
Collection<ShardingSphereRule> rules = runtimeContext.getRules();
RouteContext routeContext = new DataNodeRouter(runtimeContext.getMetaData(), runtimeContext.getProperties(), rules).route(sqlStatement, sql, Collections.emptyList());
SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(
runtimeContext.getMetaData().getSchema().getConfiguredSchemaMetaData(), runtimeContext.getProperties(), rules).rewrite(sql, Collections.emptyList(), routeContext);
......@@ -100,7 +100,7 @@ public final class MasterSlavePreparedStatement extends AbstractMasterSlavePrepa
sqlStatement = connection.getRuntimeContext().getSqlParserEngine().parse(sql, true);
parameterMetaData = new ShardingSphereParameterMetaData(sqlStatement);
RuntimeContext runtimeContext = connection.getRuntimeContext();
Collection<BaseRule> rules = runtimeContext.getRules();
Collection<ShardingSphereRule> rules = runtimeContext.getRules();
RouteContext routeContext = new DataNodeRouter(runtimeContext.getMetaData(), runtimeContext.getProperties(), rules).route(sqlStatement, sql, Collections.emptyList());
SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(
runtimeContext.getMetaData().getSchema().getConfiguredSchemaMetaData(), runtimeContext.getProperties(), rules).rewrite(sql, Collections.emptyList(), routeContext);
......@@ -122,7 +122,7 @@ public final class MasterSlavePreparedStatement extends AbstractMasterSlavePrepa
sqlStatement = connection.getRuntimeContext().getSqlParserEngine().parse(sql, true);
parameterMetaData = new ShardingSphereParameterMetaData(sqlStatement);
RuntimeContext runtimeContext = connection.getRuntimeContext();
Collection<BaseRule> rules = runtimeContext.getRules();
Collection<ShardingSphereRule> rules = runtimeContext.getRules();
RouteContext routeContext = new DataNodeRouter(runtimeContext.getMetaData(), runtimeContext.getProperties(), rules).route(sqlStatement, sql, Collections.emptyList());
SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(
runtimeContext.getMetaData().getSchema().getConfiguredSchemaMetaData(), runtimeContext.getProperties(), rules).rewrite(sql, Collections.emptyList(), routeContext);
......@@ -144,7 +144,7 @@ public final class MasterSlavePreparedStatement extends AbstractMasterSlavePrepa
sqlStatement = connection.getRuntimeContext().getSqlParserEngine().parse(sql, true);
parameterMetaData = new ShardingSphereParameterMetaData(sqlStatement);
RuntimeContext runtimeContext = connection.getRuntimeContext();
Collection<BaseRule> rules = runtimeContext.getRules();
Collection<ShardingSphereRule> rules = runtimeContext.getRules();
RouteContext routeContext = new DataNodeRouter(runtimeContext.getMetaData(), runtimeContext.getProperties(), rules).route(sqlStatement, sql, Collections.emptyList());
SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(
runtimeContext.getMetaData().getSchema().getConfiguredSchemaMetaData(), runtimeContext.getProperties(), rules).rewrite(sql, Collections.emptyList(), routeContext);
......
......@@ -28,7 +28,7 @@ import org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.MasterSlaveCo
import org.apache.shardingsphere.shardingjdbc.jdbc.core.constant.SQLExceptionConstant;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.RuntimeContext;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContextBuilder;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionUnit;
......@@ -89,7 +89,7 @@ public final class MasterSlaveStatement extends AbstractStatementAdapter {
}
clearPrevious();
RuntimeContext runtimeContext = connection.getRuntimeContext();
Collection<BaseRule> rules = runtimeContext.getRules();
Collection<ShardingSphereRule> rules = runtimeContext.getRules();
RouteContext routeContext = new DataNodeRouter(runtimeContext.getMetaData(), runtimeContext.getProperties(),
rules).route(runtimeContext.getSqlParserEngine().parse(sql, false), sql, Collections.emptyList());
SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(
......
......@@ -36,7 +36,7 @@ import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.DALStatement;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.underlying.common.exception.ShardingSphereException;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import org.apache.shardingsphere.underlying.executor.kernel.InputGroup;
import org.apache.shardingsphere.underlying.executor.sql.QueryResult;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
......@@ -357,7 +357,7 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta
@Override
public boolean isAccumulate() {
return connection.getRuntimeContext().getRules().stream().anyMatch(
each -> ((TablesAggregationRule) each).isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames()));
each -> ((DataNodeRoutedRule) each).isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames()));
}
@Override
......
......@@ -34,7 +34,7 @@ import org.apache.shardingsphere.sql.parser.sql.statement.dal.DALStatement;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.underlying.common.exception.ShardingSphereException;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import org.apache.shardingsphere.underlying.executor.kernel.InputGroup;
import org.apache.shardingsphere.underlying.executor.sql.QueryResult;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
......@@ -338,7 +338,7 @@ public final class ShardingStatement extends AbstractStatementAdapter {
@Override
public boolean isAccumulate() {
return connection.getRuntimeContext().getRules().stream().anyMatch(
each -> ((TablesAggregationRule) each).isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames()));
each -> ((DataNodeRoutedRule) each).isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames()));
}
@Override
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.shardingjdbc.fixture;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import org.apache.shardingsphere.shardingjdbc.jdbc.adapter.AbstractDataSourceAdapter;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.mockito.ArgumentMatchers;
import javax.sql.DataSource;
......@@ -44,7 +44,7 @@ public final class TestDataSource extends AbstractDataSourceAdapter {
private boolean throwExceptionWhenClosing;
public TestDataSource(final String name) throws SQLException {
super(Collections.singletonMap("test", getDataSource()), Collections.singletonList(mock(BaseRule.class)), new Properties());
super(Collections.singletonMap("test", getDataSource()), Collections.singletonList(mock(ShardingSphereRule.class)), new Properties());
this.name = name;
}
......
......@@ -40,7 +40,7 @@ import org.apache.shardingsphere.underlying.common.config.DataSourceConfiguratio
import org.apache.shardingsphere.underlying.common.config.RuleConfiguration;
import org.apache.shardingsphere.underlying.common.database.DefaultSchema;
import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import java.sql.SQLException;
import java.util.Collections;
......@@ -144,7 +144,7 @@ public class OrchestrationShardingDataSource extends AbstractOrchestrationDataSo
public synchronized void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
OrchestrationShardingSchema shardingSchema = disabledStateChangedEvent.getShardingSchema();
if (DefaultSchema.LOGIC_NAME.equals(shardingSchema.getSchemaName())) {
for (BaseRule each : dataSource.getRuntimeContext().getRules()) {
for (ShardingSphereRule each : dataSource.getRuntimeContext().getRules()) {
if (each instanceof MasterSlaveRule) {
((MasterSlaveRule) each).updateDisabledDataSourceNames(shardingSchema.getDataSourceName(), disabledStateChangedEvent.isDisabled());
}
......
......@@ -39,7 +39,7 @@ import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DDLStatement;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import org.apache.shardingsphere.underlying.executor.sql.QueryResult;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.underlying.executor.sql.log.SQLLogger;
......@@ -127,9 +127,8 @@ public final class JDBCDatabaseCommunicationEngine implements DatabaseCommunicat
}
private boolean isNeedAccumulate(final SQLStatementContext sqlStatementContext) {
Optional<TablesAggregationRule> tablesAggregationRule = logicSchema.getRules().stream().filter(
each -> each instanceof TablesAggregationRule).findFirst().map(rule -> (TablesAggregationRule) rule);
return tablesAggregationRule.isPresent() && tablesAggregationRule.get().isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames());
Optional<DataNodeRoutedRule> dataNodeRoutedRule = logicSchema.getRules().stream().filter(each -> each instanceof DataNodeRoutedRule).findFirst().map(rule -> (DataNodeRoutedRule) rule);
return dataNodeRoutedRule.isPresent() && dataNodeRoutedRule.get().isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames());
}
private MergedResult mergeQuery(final SQLStatementContext sqlStatementContext, final List<QueryResult> queryResults) throws SQLException {
......
......@@ -35,7 +35,7 @@ import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext
import org.apache.shardingsphere.sql.parser.sql.statement.dml.DeleteStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dml.UpdateStatement;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.kernel.InputGroup;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.StatementExecuteUnit;
......@@ -103,7 +103,7 @@ public final class JDBCExecuteEngine implements SQLExecuteEngine {
}
private SQLExecutorCallback<ExecuteResponse> getSQLExecutorCallback(final ProxySQLExecutorCallback callback) {
Map<BaseRule, RuleProxySQLExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(backendConnection.getLogicSchema().getRules(), RuleProxySQLExecutorCallback.class);
Map<ShardingSphereRule, RuleProxySQLExecutorCallback> callbackMap = OrderedSPIRegistry.getRegisteredServices(backendConnection.getLogicSchema().getRules(), RuleProxySQLExecutorCallback.class);
return callbackMap.isEmpty() ? callback : callbackMap.values().iterator().next();
}
......
......@@ -19,11 +19,11 @@ package org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.execu
import org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.execute.response.ExecuteResponse;
import org.apache.shardingsphere.spi.order.OrderedSPI;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.executor.SQLExecutorCallback;
/**
* Rule based SQL executor callback for Proxy.
*/
public interface RuleProxySQLExecutorCallback extends SQLExecutorCallback<ExecuteResponse>, OrderedSPI<BaseRule> {
public interface RuleProxySQLExecutorCallback extends SQLExecutorCallback<ExecuteResponse>, OrderedSPI<ShardingSphereRule> {
}
......@@ -34,7 +34,7 @@ import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext
import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dml.DMLStatement;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContextBuilder;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionUnit;
......@@ -87,7 +87,7 @@ public final class PreparedStatementExecutorWrapper implements JDBCExecutorWrapp
}
private ExecutionContext doShardingRoute(final String sql) {
Collection<BaseRule> rules = logicSchema.getRules();
Collection<ShardingSphereRule> rules = logicSchema.getRules();
SQLStatement sqlStatement = logicSchema.getSqlParserEngine().parse(sql, true);
RouteContext routeContext = new DataNodeRouter(logicSchema.getMetaData(), SHARDING_PROXY_CONTEXT.getProperties(), rules).route(sqlStatement, sql, parameters);
SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(logicSchema.getMetaData().getSchema().getConfiguredSchemaMetaData(),
......
......@@ -34,7 +34,7 @@ import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dml.DMLStatement;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaData;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionContextBuilder;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionUnit;
......@@ -84,7 +84,7 @@ public final class StatementExecutorWrapper implements JDBCExecutorWrapper {
}
private ExecutionContext doShardingRoute(final String sql) {
Collection<BaseRule> rules = logicSchema.getRules();
Collection<ShardingSphereRule> rules = logicSchema.getRules();
SQLStatement sqlStatement = logicSchema.getSqlParserEngine().parse(sql, false);
RouteContext routeContext = new DataNodeRouter(logicSchema.getMetaData(), SHARDING_PROXY_CONTEXT.getProperties(), rules).route(sqlStatement, sql, Collections.emptyList());
SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(logicSchema.getMetaData().getSchema().getConfiguredSchemaMetaData(),
......
......@@ -24,7 +24,7 @@ import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
import org.apache.shardingsphere.sql.parser.binder.segment.select.projection.Projection;
import org.apache.shardingsphere.sql.parser.binder.segment.select.projection.ProjectionsContext;
import org.apache.shardingsphere.sql.parser.binder.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
......@@ -78,10 +78,9 @@ public final class QueryHeader {
notNull = resultSetMetaData.isNullable(columnIndex) == ResultSetMetaData.columnNoNulls;
autoIncrement = resultSetMetaData.isAutoIncrement(columnIndex);
String actualTableName = resultSetMetaData.getTableName(columnIndex);
Optional<TablesAggregationRule> tablesAggregationRule = logicSchema.getRules().stream().filter(
each -> each instanceof TablesAggregationRule).findFirst().map(rule -> (TablesAggregationRule) rule);
if (null != actualTableName && tablesAggregationRule.isPresent()) {
table = tablesAggregationRule.get().findLogicTableByActualTable(actualTableName).orElse("");
Optional<DataNodeRoutedRule> dataNodeRoutedRule = logicSchema.getRules().stream().filter(each -> each instanceof DataNodeRoutedRule).findFirst().map(rule -> (DataNodeRoutedRule) rule);
if (null != actualTableName && dataNodeRoutedRule.isPresent()) {
table = dataNodeRoutedRule.get().findLogicTableByActualTable(actualTableName).orElse("");
TableMetaData tableMetaData = logicSchema.getMetaData().getSchema().getConfiguredSchemaMetaData().get(table);
primaryKey = null != tableMetaData && tableMetaData.getColumns().get(resultSetMetaData.getColumnName(columnIndex).toLowerCase()).isPrimaryKey();
} else {
......
......@@ -38,7 +38,7 @@ import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaDa
import org.apache.shardingsphere.underlying.common.metadata.datasource.DataSourceMetas;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaData;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaDataLoader;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import java.sql.SQLException;
import java.util.Collection;
......@@ -57,13 +57,13 @@ public abstract class LogicSchema {
private final SQLParserEngine sqlParserEngine;
@Setter
private Collection<BaseRule> rules;
private Collection<ShardingSphereRule> rules;
private JDBCBackendDataSource backendDataSource;
private ShardingSphereMetaData metaData;
public LogicSchema(final String name, final Map<String, YamlDataSourceParameter> dataSources, final Collection<BaseRule> rules) throws SQLException {
public LogicSchema(final String name, final Map<String, YamlDataSourceParameter> dataSources, final Collection<ShardingSphereRule> rules) throws SQLException {
this.name = name;
this.rules = rules;
sqlParserEngine = SQLParserEngineFactory.getSQLParserEngine(DatabaseTypes.getTrunkDatabaseTypeName(LogicSchemas.getInstance().getDatabaseType()));
......@@ -72,7 +72,7 @@ public abstract class LogicSchema {
ShardingOrchestrationEventBus.getInstance().register(this);
}
private ShardingSphereMetaData loadOrCreateMetaData(final String name, final Collection<BaseRule> rules) throws SQLException {
private ShardingSphereMetaData loadOrCreateMetaData(final String name, final Collection<ShardingSphereRule> rules) throws SQLException {
boolean isOverwrite = null != ShardingOrchestrationFacade.getInstance() && ShardingOrchestrationFacade.getInstance().isOverwrite();
DatabaseType databaseType = LogicSchemas.getInstance().getDatabaseType();
DataSourceMetas dataSourceMetas = new DataSourceMetas(databaseType, getDatabaseAccessConfigurationMap());
......@@ -89,7 +89,7 @@ public abstract class LogicSchema {
return new ShardingSphereMetaData(dataSourceMetas, ruleSchemaMetaData);
}
private RuleSchemaMetaData loadRuleSchemaMetaData(final DatabaseType databaseType, final Collection<BaseRule> rules) throws SQLException {
private RuleSchemaMetaData loadRuleSchemaMetaData(final DatabaseType databaseType, final Collection<ShardingSphereRule> rules) throws SQLException {
return new RuleSchemaMetaDataLoader(rules).load(databaseType, getBackendDataSource().getDataSources(), ShardingProxyContext.getInstance().getProperties());
}
......
......@@ -35,7 +35,7 @@ import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext
import org.apache.shardingsphere.underlying.common.metadata.refresh.MetaDataRefreshStrategy;
import org.apache.shardingsphere.underlying.common.metadata.refresh.MetaDataRefreshStrategyFactory;
import org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaDataLoader;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import java.sql.SQLException;
import java.util.Map;
......@@ -72,7 +72,7 @@ public final class ShardingSchema extends LogicSchema {
public synchronized void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
OrchestrationShardingSchema shardingSchema = disabledStateChangedEvent.getShardingSchema();
if (getName().equals(shardingSchema.getSchemaName())) {
for (BaseRule each : getRules()) {
for (ShardingSphereRule each : getRules()) {
if (each instanceof MasterSlaveRule) {
((MasterSlaveRule) each).updateDisabledDataSourceNames(shardingSchema.getDataSourceName(), disabledStateChangedEvent.isDisabled());
}
......
......@@ -33,8 +33,6 @@ import java.util.Collections;
@RequiredArgsConstructor
public final class SQLCaseAssertContext {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private static final SQLCasesLoader SQL_CASES_LOADER = SQLCasesRegistry.getInstance().getSqlCasesLoader();
private static final SQLParserTestCasesRegistry SQL_PARSER_TEST_CASES_REGISTRY = SQLParserTestCasesRegistryFactory.getInstance().getRegistry();
......@@ -51,7 +49,7 @@ public final class SQLCaseAssertContext {
* @return message text
*/
public String getText(final String failureMessage) {
StringBuilder result = new StringBuilder(LINE_SEPARATOR);
StringBuilder result = new StringBuilder(System.lineSeparator());
appendSQLCaseId(result);
appendSQL(result);
appendFailureMessage(failureMessage, result);
......@@ -61,25 +59,25 @@ public final class SQLCaseAssertContext {
private void appendSQLCaseId(final StringBuilder builder) {
builder.append("SQL Case ID : ");
builder.append(sqlCaseId);
builder.append(LINE_SEPARATOR);
builder.append(System.lineSeparator());
}
private void appendSQL(final StringBuilder builder) {
builder.append("SQL : ");
if (SQLCaseType.Placeholder == sqlCaseType) {
builder.append(SQL_CASES_LOADER.getSQL(sqlCaseId, sqlCaseType, Collections.emptyList()));
builder.append(LINE_SEPARATOR);
builder.append(System.lineSeparator());
builder.append("SQL Params : ");
builder.append(SQL_PARSER_TEST_CASES_REGISTRY.get(sqlCaseId).getParameters());
builder.append(LINE_SEPARATOR);
builder.append(System.lineSeparator());
} else {
builder.append(SQL_CASES_LOADER.getSQL(sqlCaseId, sqlCaseType, SQL_PARSER_TEST_CASES_REGISTRY.get(sqlCaseId).getParameters()));
}
}
private void appendFailureMessage(final String failureMessage, final StringBuilder builder) {
builder.append(LINE_SEPARATOR);
builder.append(System.lineSeparator());
builder.append(failureMessage);
builder.append(LINE_SEPARATOR);
builder.append(System.lineSeparator());
}
}
......@@ -28,9 +28,9 @@ import org.apache.shardingsphere.underlying.common.config.properties.Configurati
import org.apache.shardingsphere.underlying.common.database.type.DatabaseType;
import org.apache.shardingsphere.underlying.common.metadata.schema.spi.RuleMetaDataDecorator;
import org.apache.shardingsphere.underlying.common.metadata.schema.spi.RuleMetaDataLoader;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodes;
import org.apache.shardingsphere.underlying.common.rule.TablesAggregationRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodeRoutedRule;
import javax.sql.DataSource;
import java.sql.SQLException;
......@@ -52,7 +52,7 @@ public final class RuleSchemaMetaDataLoader {
ShardingSphereServiceLoader.register(RuleMetaDataDecorator.class);
}
private final Collection<BaseRule> rules;
private final Collection<ShardingSphereRule> rules;
/**
* Load rule schema meta data.
......@@ -67,11 +67,11 @@ public final class RuleSchemaMetaDataLoader {
public RuleSchemaMetaData load(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final ConfigurationProperties properties) throws SQLException {
Collection<String> excludedTableNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
SchemaMetaData configuredSchemaMetaData = new SchemaMetaData(new HashMap<>());
for (Entry<BaseRule, RuleMetaDataLoader> entry : OrderedSPIRegistry.getRegisteredServices(rules, RuleMetaDataLoader.class).entrySet()) {
for (Entry<ShardingSphereRule, RuleMetaDataLoader> entry : OrderedSPIRegistry.getRegisteredServices(rules, RuleMetaDataLoader.class).entrySet()) {
SchemaMetaData schemaMetaData = entry.getValue().load(databaseType, dataSourceMap, new DataNodes(rules), entry.getKey(), properties, excludedTableNames);
excludedTableNames.addAll(schemaMetaData.getAllTableNames());
if (entry.getKey() instanceof TablesAggregationRule) {
excludedTableNames.addAll(((TablesAggregationRule) entry.getKey()).getAllActualTables());
if (entry.getKey() instanceof DataNodeRoutedRule) {
excludedTableNames.addAll(((DataNodeRoutedRule) entry.getKey()).getAllActualTables());
}
configuredSchemaMetaData.merge(schemaMetaData);
}
......@@ -116,7 +116,7 @@ public final class RuleSchemaMetaDataLoader {
@SuppressWarnings("unchecked")
public Optional<TableMetaData> load(final DatabaseType databaseType,
final Map<String, DataSource> dataSourceMap, final String tableName, final ConfigurationProperties properties) throws SQLException {
for (Entry<BaseRule, RuleMetaDataLoader> entry : OrderedSPIRegistry.getRegisteredServices(rules, RuleMetaDataLoader.class).entrySet()) {
for (Entry<ShardingSphereRule, RuleMetaDataLoader> entry : OrderedSPIRegistry.getRegisteredServices(rules, RuleMetaDataLoader.class).entrySet()) {
Optional<TableMetaData> result = entry.getValue().load(databaseType, dataSourceMap, new DataNodes(rules), tableName, entry.getKey(), properties);
if (result.isPresent()) {
return Optional.of(decorate(tableName, result.get()));
......@@ -145,9 +145,9 @@ public final class RuleSchemaMetaDataLoader {
@SuppressWarnings("unchecked")
private SchemaMetaData decorate(final SchemaMetaData schemaMetaData) {
Map<String, TableMetaData> result = new HashMap<>(schemaMetaData.getAllTableNames().size(), 1);
Map<BaseRule, RuleMetaDataDecorator> decorators = OrderedSPIRegistry.getRegisteredServices(rules, RuleMetaDataDecorator.class);
Map<ShardingSphereRule, RuleMetaDataDecorator> decorators = OrderedSPIRegistry.getRegisteredServices(rules, RuleMetaDataDecorator.class);
for (String each : schemaMetaData.getAllTableNames()) {
for (Entry<BaseRule, RuleMetaDataDecorator> entry : decorators.entrySet()) {
for (Entry<ShardingSphereRule, RuleMetaDataDecorator> entry : decorators.entrySet()) {
result.put(each, entry.getValue().decorate(each, result.getOrDefault(each, schemaMetaData.get(each)), entry.getKey()));
}
}
......@@ -157,7 +157,7 @@ public final class RuleSchemaMetaDataLoader {
@SuppressWarnings("unchecked")
private TableMetaData decorate(final String tableName, final TableMetaData tableMetaData) {
TableMetaData result = tableMetaData;
for (Entry<BaseRule, RuleMetaDataDecorator> entry : OrderedSPIRegistry.getRegisteredServices(rules, RuleMetaDataDecorator.class).entrySet()) {
for (Entry<ShardingSphereRule, RuleMetaDataDecorator> entry : OrderedSPIRegistry.getRegisteredServices(rules, RuleMetaDataDecorator.class).entrySet()) {
result = entry.getValue().decorate(tableName, tableMetaData, entry.getKey());
}
return result;
......
......@@ -19,12 +19,12 @@ package org.apache.shardingsphere.underlying.common.metadata.schema.spi;
import org.apache.shardingsphere.spi.order.OrderedSPI;
import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
/**
* Rule meta data decorator.
*/
public interface RuleMetaDataDecorator<T extends BaseRule> extends OrderedSPI<T> {
public interface RuleMetaDataDecorator<T extends ShardingSphereRule> extends OrderedSPI<T> {
/**
* Decorate table meta data.
......
......@@ -22,7 +22,7 @@ import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaDat
import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.underlying.common.database.type.DatabaseType;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.common.rule.DataNodes;
import javax.sql.DataSource;
......@@ -36,7 +36,7 @@ import java.util.Optional;
*
* @param <T> type of base rule
*/
public interface RuleMetaDataLoader<T extends BaseRule> extends OrderedSPI<T> {
public interface RuleMetaDataLoader<T extends ShardingSphereRule> extends OrderedSPI<T> {
/**
* Load schema meta data.
......
......@@ -32,8 +32,6 @@ import java.util.Properties;
*/
public abstract class TypedProperties<E extends Enum & TypedPropertyKey> {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
@Getter
private final Properties props;
......@@ -58,7 +56,7 @@ public abstract class TypedProperties<E extends Enum & TypedPropertyKey> {
result.put(each, value);
}
if (!errorMessages.isEmpty()) {
throw new ShardingSphereConfigurationException(Joiner.on(LINE_SEPARATOR).join(errorMessages));
throw new ShardingSphereConfigurationException(Joiner.on(System.lineSeparator()).join(errorMessages));
}
return result;
}
......
......@@ -22,9 +22,9 @@ import java.util.Map;
import java.util.Optional;
/**
* Tables aggregation rule.
* Data node routed rule.
*/
public interface TablesAggregationRule extends BaseRule {
public interface DataNodeRoutedRule extends ShardingSphereRule {
/**
* Get all data nodes.
......
......@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public final class DataNodes {
private final Collection<BaseRule> rules;
private final Collection<ShardingSphereRule> rules;
/**
* Get data nodes.
......@@ -44,19 +44,18 @@ public final class DataNodes {
* @return data nodes
*/
public Collection<DataNode> getDataNodes(final String tableName) {
Optional<TablesAggregationRule> tablesAggregationRule = rules.stream().filter(each -> each instanceof TablesAggregationRule).findFirst().map(rule -> (TablesAggregationRule) rule);
if (!tablesAggregationRule.isPresent()) {
Optional<DataNodeRoutedRule> dataNodeRoutedRule = rules.stream().filter(each -> each instanceof DataNodeRoutedRule).findFirst().map(rule -> (DataNodeRoutedRule) rule);
if (!dataNodeRoutedRule.isPresent()) {
return Collections.emptyList();
}
Collection<DataNode> result = new LinkedList<>(tablesAggregationRule.get().getAllDataNodes().get(tableName));
for (BaseRule each : rules) {
if (each instanceof TablesAggregationRule) {
continue;
}
for (Entry<String, Collection<String>> entry : each.getDataSourceMapper().entrySet()) {
Collection<DataNode> dataNodes = find(result, entry.getKey());
result.removeAll(dataNodes);
result.addAll(regenerate(dataNodes, entry.getValue()));
Collection<DataNode> result = new LinkedList<>(dataNodeRoutedRule.get().getAllDataNodes().get(tableName));
for (ShardingSphereRule each : rules) {
if (each instanceof DataSourceRoutedRule) {
for (Entry<String, Collection<String>> entry : ((DataSourceRoutedRule) each).getDataSourceMapper().entrySet()) {
Collection<DataNode> dataNodes = find(result, entry.getKey());
result.removeAll(dataNodes);
result.addAll(regenerate(dataNodes, entry.getValue()));
}
}
}
return result;
......
/*
* 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.underlying.common.rule;
import java.util.Collection;
import java.util.Map;
/**
* Data source routed rule.
*/
public interface DataSourceRoutedRule extends ShardingSphereRule {
/**
* Get data source mapper.
*
* @return data source mapper
*/
Map<String, Collection<String>> getDataSourceMapper();
}
......@@ -19,20 +19,10 @@ package org.apache.shardingsphere.underlying.common.rule;
import org.apache.shardingsphere.underlying.common.config.RuleConfiguration;
import java.util.Collection;
import java.util.Map;
/**
* Base rule.
* ShardingSphere rule.
*/
public interface BaseRule {
/**
* Get data source mapper.
*
* @return data source mapper
*/
Map<String, Collection<String>> getDataSourceMapper();
public interface ShardingSphereRule {
/**
* Get rule configuration.
......
......@@ -17,7 +17,7 @@
package org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.group;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.ConnectionMode;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionUnit;
import org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.StatementExecuteUnit;
......@@ -35,7 +35,7 @@ import java.util.List;
*/
public final class PreparedStatementExecuteGroupEngine extends ExecuteGroupEngine<StatementExecuteUnit, JDBCExecutionConnection, Connection, StatementOption> {
public PreparedStatementExecuteGroupEngine(final int maxConnectionsSizePerQuery, final Collection<BaseRule> rules) {
public PreparedStatementExecuteGroupEngine(final int maxConnectionsSizePerQuery, final Collection<ShardingSphereRule> rules) {
super(maxConnectionsSizePerQuery, rules);
}
......
......@@ -17,7 +17,7 @@
package org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.group;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.ConnectionMode;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionUnit;
import org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.StatementExecuteUnit;
......@@ -34,7 +34,7 @@ import java.util.Collection;
*/
public final class StatementExecuteGroupEngine extends ExecuteGroupEngine<StatementExecuteUnit, JDBCExecutionConnection, Connection, StatementOption> {
public StatementExecuteGroupEngine(final int maxConnectionsSizePerQuery, final Collection<BaseRule> rules) {
public StatementExecuteGroupEngine(final int maxConnectionsSizePerQuery, final Collection<ShardingSphereRule> rules) {
super(maxConnectionsSizePerQuery, rules);
}
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.underlying.executor.sql.group;
import com.google.common.collect.Lists;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.order.OrderedSPIRegistry;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.kernel.InputGroup;
import org.apache.shardingsphere.underlying.executor.sql.ConnectionMode;
import org.apache.shardingsphere.underlying.executor.sql.ExecutionConnection;
......@@ -53,9 +53,9 @@ public abstract class ExecuteGroupEngine<U extends StorageResourceExecuteUnit, E
private final int maxConnectionsSizePerQuery;
private final Map<BaseRule, ExecuteGroupDecorator> decorators;
private final Map<ShardingSphereRule, ExecuteGroupDecorator> decorators;
public ExecuteGroupEngine(final int maxConnectionsSizePerQuery, final Collection<BaseRule> rules) {
public ExecuteGroupEngine(final int maxConnectionsSizePerQuery, final Collection<ShardingSphereRule> rules) {
this.maxConnectionsSizePerQuery = maxConnectionsSizePerQuery;
decorators = OrderedSPIRegistry.getRegisteredServices(rules, ExecuteGroupDecorator.class);
}
......@@ -80,7 +80,7 @@ public abstract class ExecuteGroupEngine<U extends StorageResourceExecuteUnit, E
@SuppressWarnings("unchecked")
private Collection<InputGroup<U>> decorate(final Collection<InputGroup<U>> inputGroups) {
Collection<InputGroup<U>> result = inputGroups;
for (Entry<BaseRule, ExecuteGroupDecorator> each : decorators.entrySet()) {
for (Entry<ShardingSphereRule, ExecuteGroupDecorator> each : decorators.entrySet()) {
result = each.getValue().decorate(result);
}
return result;
......
......@@ -17,7 +17,7 @@
package org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.group;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.kernel.InputGroup;
import org.apache.shardingsphere.underlying.executor.sql.ConnectionMode;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionUnit;
......@@ -49,7 +49,7 @@ public final class PreparedStatementExecuteGroupEngineTest {
@Test
public void assertGetExecuteUnitGroupForOneShardMemoryStrictly() throws SQLException {
preparedStatementExecuteGroupEngine = new PreparedStatementExecuteGroupEngine(2, Collections.singletonList(mock(BaseRule.class)));
preparedStatementExecuteGroupEngine = new PreparedStatementExecuteGroupEngine(2, Collections.singletonList(mock(ShardingSphereRule.class)));
Collection<InputGroup<StatementExecuteUnit>> actual = preparedStatementExecuteGroupEngine.generate(
mockShardRouteUnit(1, 1), mockExecutionConnection(1, ConnectionMode.MEMORY_STRICTLY), new StatementOption(true));
assertThat(actual.size(), is(1));
......@@ -60,7 +60,7 @@ public final class PreparedStatementExecuteGroupEngineTest {
@Test
public void assertGetExecuteUnitGroupForMultiShardConnectionStrictly() throws SQLException {
preparedStatementExecuteGroupEngine = new PreparedStatementExecuteGroupEngine(1, Collections.singletonList(mock(BaseRule.class)));
preparedStatementExecuteGroupEngine = new PreparedStatementExecuteGroupEngine(1, Collections.singletonList(mock(ShardingSphereRule.class)));
Collection<InputGroup<StatementExecuteUnit>> actual = preparedStatementExecuteGroupEngine.generate(
mockShardRouteUnit(10, 2), mockExecutionConnection(1, ConnectionMode.CONNECTION_STRICTLY), new StatementOption(true));
assertThat(actual.size(), is(10));
......
......@@ -17,7 +17,7 @@
package org.apache.shardingsphere.underlying.executor.sql.execute.jdbc.group;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.kernel.InputGroup;
import org.apache.shardingsphere.underlying.executor.sql.ConnectionMode;
import org.apache.shardingsphere.underlying.executor.sql.context.ExecutionUnit;
......@@ -49,7 +49,7 @@ public final class StatementExecuteGroupEngineTest {
@Test
public void assertGetExecuteUnitGroupForOneShardMemoryStrictly() throws SQLException {
executeGroupEngine = new StatementExecuteGroupEngine(2, Collections.singletonList(mock(BaseRule.class)));
executeGroupEngine = new StatementExecuteGroupEngine(2, Collections.singletonList(mock(ShardingSphereRule.class)));
Collection<InputGroup<StatementExecuteUnit>> actual = executeGroupEngine.generate(
mockShardRouteUnit(1, 1), mockExecutionConnection(1, ConnectionMode.MEMORY_STRICTLY), new StatementOption(true));
assertThat(actual.size(), is(1));
......@@ -60,7 +60,7 @@ public final class StatementExecuteGroupEngineTest {
@Test
public void assertGetExecuteUnitGroupForMultiShardConnectionStrictly() throws SQLException {
executeGroupEngine = new StatementExecuteGroupEngine(1, Collections.singletonList(mock(BaseRule.class)));
executeGroupEngine = new StatementExecuteGroupEngine(1, Collections.singletonList(mock(ShardingSphereRule.class)));
Collection<InputGroup<StatementExecuteUnit>> actual = executeGroupEngine.generate(
mockShardRouteUnit(10, 2), mockExecutionConnection(1, ConnectionMode.CONNECTION_STRICTLY), new StatementOption(true));
assertThat(actual.size(), is(10));
......
......@@ -23,7 +23,7 @@ import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaDat
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.underlying.common.database.type.DatabaseType;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.QueryResult;
import org.apache.shardingsphere.underlying.merge.engine.ResultProcessEngine;
import org.apache.shardingsphere.underlying.merge.engine.decorator.ResultDecorator;
......@@ -55,9 +55,9 @@ public final class MergeEngine {
private final ConfigurationProperties properties;
private final Map<BaseRule, ResultProcessEngine> engines;
private final Map<ShardingSphereRule, ResultProcessEngine> engines;
public MergeEngine(final DatabaseType databaseType, final SchemaMetaData schemaMetaData, final ConfigurationProperties properties, final Collection<BaseRule> rules) {
public MergeEngine(final DatabaseType databaseType, final SchemaMetaData schemaMetaData, final ConfigurationProperties properties, final Collection<ShardingSphereRule> rules) {
this.databaseType = databaseType;
this.schemaMetaData = schemaMetaData;
this.properties = properties;
......@@ -80,7 +80,7 @@ public final class MergeEngine {
@SuppressWarnings("unchecked")
private Optional<MergedResult> executeMerge(final List<QueryResult> queryResults, final SQLStatementContext sqlStatementContext) throws SQLException {
for (Entry<BaseRule, ResultProcessEngine> entry : engines.entrySet()) {
for (Entry<ShardingSphereRule, ResultProcessEngine> entry : engines.entrySet()) {
if (entry.getValue() instanceof ResultMergerEngine) {
ResultMerger resultMerger = ((ResultMergerEngine) entry.getValue()).newInstance(databaseType, entry.getKey(), properties, sqlStatementContext);
return Optional.of(resultMerger.merge(queryResults, sqlStatementContext, schemaMetaData));
......@@ -92,7 +92,7 @@ public final class MergeEngine {
@SuppressWarnings("unchecked")
private MergedResult decorate(final MergedResult mergedResult, final SQLStatementContext sqlStatementContext) throws SQLException {
MergedResult result = null;
for (Entry<BaseRule, ResultProcessEngine> entry : engines.entrySet()) {
for (Entry<ShardingSphereRule, ResultProcessEngine> entry : engines.entrySet()) {
if (entry.getValue() instanceof ResultDecoratorEngine) {
ResultDecorator resultDecorator = ((ResultDecoratorEngine) entry.getValue()).newInstance(databaseType, schemaMetaData, entry.getKey(), properties, sqlStatementContext);
result = null == result ? resultDecorator.decorate(mergedResult, sqlStatementContext, schemaMetaData) : resultDecorator.decorate(result, sqlStatementContext, schemaMetaData);
......@@ -104,7 +104,7 @@ public final class MergeEngine {
@SuppressWarnings("unchecked")
private Optional<MergedResult> decorate(final QueryResult queryResult, final SQLStatementContext sqlStatementContext) throws SQLException {
MergedResult result = null;
for (Entry<BaseRule, ResultProcessEngine> entry : engines.entrySet()) {
for (Entry<ShardingSphereRule, ResultProcessEngine> entry : engines.entrySet()) {
if (entry.getValue() instanceof ResultDecoratorEngine) {
ResultDecorator resultDecorator = ((ResultDecoratorEngine) entry.getValue()).newInstance(databaseType, schemaMetaData, entry.getKey(), properties, sqlStatementContext);
result = null == result ? resultDecorator.decorate(queryResult, sqlStatementContext, schemaMetaData) : resultDecorator.decorate(result, sqlStatementContext, schemaMetaData);
......
......@@ -18,12 +18,12 @@
package org.apache.shardingsphere.underlying.merge.engine;
import org.apache.shardingsphere.spi.order.OrderedSPI;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
/**
* Result process engine.
*
* @param <T> type of rule
*/
public interface ResultProcessEngine<T extends BaseRule> extends OrderedSPI<T> {
public interface ResultProcessEngine<T extends ShardingSphereRule> extends OrderedSPI<T> {
}
......@@ -21,7 +21,7 @@ import org.apache.shardingsphere.underlying.common.database.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.merge.engine.ResultProcessEngine;
/**
......@@ -29,7 +29,7 @@ import org.apache.shardingsphere.underlying.merge.engine.ResultProcessEngine;
*
* @param <T> type of rule
*/
public interface ResultDecoratorEngine<T extends BaseRule> extends ResultProcessEngine<T> {
public interface ResultDecoratorEngine<T extends ShardingSphereRule> extends ResultProcessEngine<T> {
/**
* Create new instance of result decorator.
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.underlying.merge.engine.merger;
import org.apache.shardingsphere.underlying.common.database.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.merge.engine.ResultProcessEngine;
/**
......@@ -28,7 +28,7 @@ import org.apache.shardingsphere.underlying.merge.engine.ResultProcessEngine;
*
* @param <T> type of rule
*/
public interface ResultMergerEngine<T extends BaseRule> extends ResultProcessEngine<T> {
public interface ResultMergerEngine<T extends ShardingSphereRule> extends ResultProcessEngine<T> {
/**
* Create new instance of result merger engine.
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.underlying.merge.result.impl.memory;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.executor.sql.QueryResult;
import org.apache.shardingsphere.underlying.merge.result.MergedResult;
......@@ -41,7 +41,7 @@ import java.util.List;
* @param <T> type of rule
*/
@RequiredArgsConstructor
public abstract class MemoryMergedResult<T extends BaseRule> implements MergedResult {
public abstract class MemoryMergedResult<T extends ShardingSphereRule> implements MergedResult {
private final Iterator<MemoryQueryResultRow> memoryResultSetRows;
......
......@@ -18,21 +18,12 @@
package org.apache.shardingsphere.underlying.merge.result.impl.fixture;
import org.apache.shardingsphere.underlying.common.config.RuleConfiguration;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
/**
* Rule for test.
*/
public final class TestRule implements BaseRule {
@Override
public Map<String, Collection<String>> getDataSourceMapper() {
return Collections.emptyMap();
}
public final class TestRule implements ShardingSphereRule {
@Override
public RuleConfiguration getRuleConfiguration() {
......
......@@ -22,7 +22,7 @@ import org.apache.shardingsphere.spi.order.OrderedSPIRegistry;
import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContext;
import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContextDecorator;
import org.apache.shardingsphere.underlying.rewrite.engine.GenericSQLRewriteEngine;
......@@ -47,9 +47,9 @@ public final class SQLRewriteEntry {
private final ConfigurationProperties properties;
private final Map<BaseRule, SQLRewriteContextDecorator> decorators;
private final Map<ShardingSphereRule, SQLRewriteContextDecorator> decorators;
public SQLRewriteEntry(final SchemaMetaData schemaMetaData, final ConfigurationProperties properties, final Collection<BaseRule> rules) {
public SQLRewriteEntry(final SchemaMetaData schemaMetaData, final ConfigurationProperties properties, final Collection<ShardingSphereRule> rules) {
this.schemaMetaData = schemaMetaData;
this.properties = properties;
decorators = OrderedSPIRegistry.getRegisteredServices(rules, SQLRewriteContextDecorator.class);
......@@ -77,7 +77,7 @@ public final class SQLRewriteEntry {
}
@SuppressWarnings("unchecked")
private void decorate(final Map<BaseRule, SQLRewriteContextDecorator> decorators, final SQLRewriteContext sqlRewriteContext, final RouteContext routeContext) {
private void decorate(final Map<ShardingSphereRule, SQLRewriteContextDecorator> decorators, final SQLRewriteContext sqlRewriteContext, final RouteContext routeContext) {
decorators.forEach((key, value) -> value.decorate(key, properties, sqlRewriteContext, routeContext));
}
}
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.underlying.rewrite.context;
import org.apache.shardingsphere.spi.order.OrderedSPI;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.route.context.RouteContext;
/**
......@@ -27,7 +27,7 @@ import org.apache.shardingsphere.underlying.route.context.RouteContext;
*
* @param <T> type of rule
*/
public interface SQLRewriteContextDecorator<T extends BaseRule> extends OrderedSPI<T> {
public interface SQLRewriteContextDecorator<T extends ShardingSphereRule> extends OrderedSPI<T> {
/**
* Decorate SQL rewrite context.
......
......@@ -25,7 +25,7 @@ import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext
import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.route.context.RouteContext;
import org.apache.shardingsphere.underlying.route.context.RouteResult;
import org.apache.shardingsphere.underlying.route.decorator.RouteDecorator;
......@@ -49,11 +49,11 @@ public final class DataNodeRouter {
private final ConfigurationProperties properties;
private final Map<BaseRule, RouteDecorator> decorators;
private final Map<ShardingSphereRule, RouteDecorator> decorators;
private SPIRoutingHook routingHook;
public DataNodeRouter(final ShardingSphereMetaData metaData, final ConfigurationProperties properties, final Collection<BaseRule> rules) {
public DataNodeRouter(final ShardingSphereMetaData metaData, final ConfigurationProperties properties, final Collection<ShardingSphereRule> rules) {
this.metaData = metaData;
this.properties = properties;
decorators = OrderedSPIRegistry.getRegisteredServices(rules, RouteDecorator.class);
......@@ -85,7 +85,7 @@ public final class DataNodeRouter {
@SuppressWarnings("unchecked")
private RouteContext executeRoute(final SQLStatement sqlStatement, final String sql, final List<Object> parameters) {
RouteContext result = createRouteContext(sqlStatement, sql, parameters);
for (Entry<BaseRule, RouteDecorator> entry : decorators.entrySet()) {
for (Entry<ShardingSphereRule, RouteDecorator> entry : decorators.entrySet()) {
result = entry.getValue().decorate(result, metaData, entry.getKey(), properties);
}
return result;
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.underlying.route.decorator;
import org.apache.shardingsphere.spi.order.OrderedSPI;
import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.underlying.common.rule.BaseRule;
import org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule;
import org.apache.shardingsphere.underlying.route.context.RouteContext;
/**
......@@ -28,7 +28,7 @@ import org.apache.shardingsphere.underlying.route.context.RouteContext;
*
* @param <T> type of rule
*/
public interface RouteDecorator<T extends BaseRule> extends OrderedSPI<T> {
public interface RouteDecorator<T extends ShardingSphereRule> extends OrderedSPI<T> {
/**
* Decorate route context.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册