This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 1ea833b remove create table and drop table event (#11423)
1ea833b is described below
commit 1ea833bd9d9b26f80f34e8442b726ca9a2752a6f
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Wed Jul 21 18:15:49 2021 +0800
remove create table and drop table event (#11423)
* remove create table and drop table event
* fix encrypt test case
* optimize single table route logic
* update param name
---
...orithmProvidedDatabaseDiscoveryRuleBuilder.java | 5 +--
.../rule/builder/DatabaseDiscoveryRuleBuilder.java | 4 ++-
...hmProvidedDatabaseDiscoveryRuleBuilderTest.java | 3 +-
.../builder/DatabaseDiscoveryRuleBuilderTest.java | 3 +-
.../AlgorithmProvidedEncryptRuleBuilder.java | 4 ++-
.../encrypt/rule/builder/EncryptRuleBuilder.java | 4 ++-
.../AlgorithmProvidedEncryptRuleBuilderTest.java | 3 +-
.../rule/builder/EncryptRuleBuilderTest.java | 3 +-
...rithmProvidedReadwriteSplittingRuleBuilder.java | 5 +--
.../builder/ReadwriteSplittingRuleBuilder.java | 4 ++-
...mProvidedReadwriteSplittingRuleBuilderTest.java | 2 +-
.../builder/ReadwriteSplittingRuleBuilderTest.java | 3 +-
.../shadow/rule/builder/ShadowRuleBuilder.java | 4 ++-
.../shadow/rule/builder/ShadowRuleBuilderTest.java | 3 +-
.../shardingsphere/sharding/rule/ShardingRule.java | 6 ++--
.../AlgorithmProvidedShardingRuleBuilder.java | 6 ++--
.../sharding/rule/builder/ShardingRuleBuilder.java | 6 ++--
.../dal/show/ShowCreateTableMergedResultTest.java | 3 +-
.../merge/dal/show/ShowTablesMergedResultTest.java | 3 +-
.../engine/fixture/AbstractRoutingEngineTest.java | 29 +++++++--------
...ShardingDatabaseBroadcastRoutingEngineTest.java | 3 +-
.../ShardingTableBroadcastRoutingEngineTest.java | 2 +-
.../engine/type/standard/AbstractSQLRouteTest.java | 7 ++--
.../unicast/ShardingUnicastRoutingEngineTest.java | 3 +-
.../sharding/rule/ShardingRuleTest.java | 23 ++++++------
.../AlgorithmProvidedShardingRuleBuilderTest.java | 4 ++-
.../rule/builder/ShardingRuleBuilderTest.java | 4 ++-
.../schema/refresher/event/CreateTableEvent.java | 36 -------------------
.../schema/refresher/event/DropTableEvent.java | 31 ----------------
.../type/AlterTableStatementSchemaRefresher.java | 21 +++++++----
.../type/CreateTableStatementSchemaRefresher.java | 13 +++++--
.../type/CreateViewStatementSchemaRefresher.java | 13 +++++--
.../type/DropTableStatementSchemaRefresher.java | 7 ++--
.../type/DropViewStatementSchemaRefresher.java | 7 ++--
.../infra/rule/aware/PreviousRulesAware.java | 35 ------------------
.../rule/builder/ShardingSphereRulesBuilder.java | 17 ++-------
.../rule/builder/scope/SchemaRuleBuilder.java | 4 ++-
.../builder/single/SingleTableRuleBuilder.java | 16 +++------
.../infra/rule/single/SingleTableRule.java | 41 +++++++---------------
.../fixture/TestShardingSphereRuleBuilder.java | 4 ++-
.../infra/context/fixture/FixtureRuleBuilder.java | 4 ++-
.../infra/route/SingleTableSQLRouter.java | 14 ++++----
.../engine/single/SingleTableRouteEngine.java | 34 ++++++++++++------
.../ShardingSphereDatabaseMetaDataTest.java | 3 +-
.../scaling/core/util/JobConfigurationUtil.java | 2 +-
.../EncryptSQLRewriterParameterizedTest.java | 13 ++++++-
.../ShardingSQLRewriterParameterizedTest.java | 17 +++++----
47 files changed, 218 insertions(+), 263 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
index 6cfa605..a5e6c7d 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.infra.rule.builder.level.FeatureRuleBuilder;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
/**
@@ -33,8 +34,8 @@ import java.util.Map;
public final class AlgorithmProvidedDatabaseDiscoveryRuleBuilder implements
FeatureRuleBuilder,
SchemaRuleBuilder<AlgorithmProvidedDatabaseDiscoveryRuleConfiguration> {
@Override
- public DatabaseDiscoveryRule build(final String schemaName, final
Map<String, DataSource> dataSourceMap, final DatabaseType databaseType,
- final
AlgorithmProvidedDatabaseDiscoveryRuleConfiguration ruleConfig) {
+ public DatabaseDiscoveryRule build(final String schemaName, final
Map<String, DataSource> dataSourceMap, final DatabaseType databaseType,
+ final
AlgorithmProvidedDatabaseDiscoveryRuleConfiguration ruleConfig, final
Collection<String> occupiedTables) {
return new DatabaseDiscoveryRule(ruleConfig, databaseType,
dataSourceMap, schemaName);
}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
index 8b2ee90..f376548 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
@@ -26,6 +26,7 @@ import
org.apache.shardingsphere.infra.rule.builder.level.FeatureRuleBuilder;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -35,7 +36,8 @@ import java.util.Map;
public final class DatabaseDiscoveryRuleBuilder implements FeatureRuleBuilder,
SchemaRuleBuilder<DatabaseDiscoveryRuleConfiguration> {
@Override
- public DatabaseDiscoveryRule build(final String schemaName, final
Map<String, DataSource> dataSourceMap, final DatabaseType databaseType, final
DatabaseDiscoveryRuleConfiguration ruleConfig) {
+ public DatabaseDiscoveryRule build(final String schemaName, final
Map<String, DataSource> dataSourceMap, final DatabaseType databaseType,
+ final
DatabaseDiscoveryRuleConfiguration ruleConfig, final Collection<String>
occupiedTables) {
Map<String, DataSource> realDataSourceMap = new HashMap<>();
for (DatabaseDiscoveryDataSourceRuleConfiguration each :
ruleConfig.getDataSources()) {
for (String datasourceName : each.getDataSourceNames()) {
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
index 6e6e343..b6dc2ed 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.dbdiscovery.rule.builder;
+import com.google.common.collect.Sets;
import
org.apache.shardingsphere.dbdiscovery.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
@@ -46,6 +47,6 @@ public final class
AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
DatabaseDiscoveryDataSourceRuleConfiguration ruleConfig = new
DatabaseDiscoveryDataSourceRuleConfiguration("name",
Collections.singletonList("name"), "discoveryTypeName");
when(algorithmProvidedRuleConfig.getDataSources()).thenReturn(Collections.singletonList(ruleConfig));
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(algorithmProvidedRuleConfig),
SchemaRuleBuilder.class).get(algorithmProvidedRuleConfig);
- assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), algorithmProvidedRuleConfig),
instanceOf(DatabaseDiscoveryRule.class));
+ assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), algorithmProvidedRuleConfig, Sets.newHashSet()),
instanceOf(DatabaseDiscoveryRule.class));
}
}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
index 35c6ec0..f023b39 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.dbdiscovery.rule.builder;
+import com.google.common.collect.Sets;
import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
@@ -51,6 +52,6 @@ public final class DatabaseDiscoveryRuleBuilderTest {
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig),
SchemaRuleBuilder.class).get(ruleConfig);
Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
dataSourceMap.put("primaryDataSourceName", mock(DataSource.class));
- assertThat(builder.build("test_schema", dataSourceMap,
mock(DatabaseType.class), ruleConfig), instanceOf(DatabaseDiscoveryRule.class));
+ assertThat(builder.build("test_schema", dataSourceMap,
mock(DatabaseType.class), ruleConfig, Sets.newHashSet()),
instanceOf(DatabaseDiscoveryRule.class));
}
}
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/AlgorithmProvidedEncryptRuleBuilder.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/AlgorithmProvidedEncryptRuleBuilder.java
index f96aaa0..df0e83d 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/AlgorithmProvidedEncryptRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/AlgorithmProvidedEncryptRuleBuilder.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.infra.rule.builder.level.FeatureRuleBuilder;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
/**
@@ -33,7 +34,8 @@ import java.util.Map;
public final class AlgorithmProvidedEncryptRuleBuilder implements
FeatureRuleBuilder,
SchemaRuleBuilder<AlgorithmProvidedEncryptRuleConfiguration> {
@Override
- public EncryptRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType, final
AlgorithmProvidedEncryptRuleConfiguration config) {
+ public EncryptRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType,
+ final AlgorithmProvidedEncryptRuleConfiguration
config, final Collection<String> occupiedTables) {
return new EncryptRule(config);
}
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java
index ff45f9a..fc96ee7 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.infra.rule.builder.level.FeatureRuleBuilder;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
/**
@@ -33,7 +34,8 @@ import java.util.Map;
public final class EncryptRuleBuilder implements FeatureRuleBuilder,
SchemaRuleBuilder<EncryptRuleConfiguration> {
@Override
- public EncryptRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType, final
EncryptRuleConfiguration config) {
+ public EncryptRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType,
+ final EncryptRuleConfiguration config, final
Collection<String> occupiedTables) {
return new EncryptRule(config);
}
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/AlgorithmProvidedEncryptRuleBuilderTest.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/AlgorithmProvidedEncryptRuleBuilderTest.java
index 441a426..1f83f5c 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/AlgorithmProvidedEncryptRuleBuilderTest.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/AlgorithmProvidedEncryptRuleBuilderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.encrypt.rule.builder;
+import com.google.common.collect.Sets;
import
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
@@ -42,6 +43,6 @@ public final class AlgorithmProvidedEncryptRuleBuilderTest {
public void assertBuild() {
AlgorithmProvidedEncryptRuleConfiguration ruleConfig =
mock(AlgorithmProvidedEncryptRuleConfiguration.class);
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig),
SchemaRuleBuilder.class).get(ruleConfig);
- assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), ruleConfig), instanceOf(EncryptRule.class));
+ assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), ruleConfig, Sets.newHashSet()),
instanceOf(EncryptRule.class));
}
}
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
index eff43e6..6268452 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.encrypt.rule.builder;
+import com.google.common.collect.Sets;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
@@ -42,6 +43,6 @@ public final class EncryptRuleBuilderTest {
public void assertBuild() {
EncryptRuleConfiguration ruleConfig =
mock(EncryptRuleConfiguration.class);
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig),
SchemaRuleBuilder.class).get(ruleConfig);
- assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), ruleConfig), instanceOf(EncryptRule.class));
+ assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), ruleConfig, Sets.newHashSet()),
instanceOf(EncryptRule.class));
}
}
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/builder/AlgorithmProvidedReadwriteSplittingRuleBuilder.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/builder/AlgorithmProvidedReadwriteSplittingRuleBuilder.java
index 4189c63..bfa648e 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/builder/AlgorithmProvidedReadwriteSplittingRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/builder/AlgorithmProvidedReadwriteSplittingRuleBuilder.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingO
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
/**
@@ -33,8 +34,8 @@ import java.util.Map;
public final class AlgorithmProvidedReadwriteSplittingRuleBuilder implements
FeatureRuleBuilder,
SchemaRuleBuilder<AlgorithmProvidedReadwriteSplittingRuleConfiguration> {
@Override
- public ReadwriteSplittingRule build(final String schemaName,
- final Map<String, DataSource>
dataSourceMap, final DatabaseType databaseType, final
AlgorithmProvidedReadwriteSplittingRuleConfiguration config) {
+ public ReadwriteSplittingRule build(final String schemaName, final
Map<String, DataSource> dataSourceMap, final DatabaseType databaseType,
+ final
AlgorithmProvidedReadwriteSplittingRuleConfiguration config, final
Collection<String> occupiedTables) {
return new ReadwriteSplittingRule(config);
}
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilder.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilder.java
index ae73ff5..5f6a5ef 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilder.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingO
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
/**
@@ -33,7 +34,8 @@ import java.util.Map;
public final class ReadwriteSplittingRuleBuilder implements
FeatureRuleBuilder, SchemaRuleBuilder<ReadwriteSplittingRuleConfiguration> {
@Override
- public ReadwriteSplittingRule build(final String schemaName, final
Map<String, DataSource> dataSourceMap, final DatabaseType databaseType, final
ReadwriteSplittingRuleConfiguration config) {
+ public ReadwriteSplittingRule build(final String schemaName, final
Map<String, DataSource> dataSourceMap, final DatabaseType databaseType,
+ final
ReadwriteSplittingRuleConfiguration config, final Collection<String>
occupiedTables) {
return new ReadwriteSplittingRule(config);
}
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/AlgorithmProvidedReadwriteSplittingRuleBuilderTest.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/AlgorithmProvidedReadwriteSplittingRuleBuilderTest.java
index 455cc33a..ac9121c 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/AlgorithmProvidedReadwriteSplittingRuleBuilderTest.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/AlgorithmProvidedReadwriteSplittingRuleBuilderTest.java
@@ -47,6 +47,6 @@ public final class
AlgorithmProvidedReadwriteSplittingRuleBuilderTest {
"name", "pr_ds", "writeDataSourceName",
Collections.singletonList("name"), "loadBalancerName");
when(algorithmProvidedRuleConfig.getDataSources()).thenReturn(Collections.singletonList(ruleConfig));
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(algorithmProvidedRuleConfig),
SchemaRuleBuilder.class).get(algorithmProvidedRuleConfig);
- assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), algorithmProvidedRuleConfig),
instanceOf(ReadwriteSplittingRule.class));
+ assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), algorithmProvidedRuleConfig,
Collections.emptyList()), instanceOf(ReadwriteSplittingRule.class));
}
}
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
index 2b8f85a..0e41cbf 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.readwritesplitting.rule.builder;
+import com.google.common.collect.Sets;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -47,6 +48,6 @@ public final class ReadwriteSplittingRuleBuilderTest {
"name", "pr_ds", "writeDataSourceName",
Collections.singletonList("name"), "loadBalancerName");
when(ruleConfig.getDataSources()).thenReturn(Collections.singletonList(dataSourceRuleConfig));
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig),
SchemaRuleBuilder.class).get(ruleConfig);
- assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), ruleConfig),
instanceOf(ReadwriteSplittingRule.class));
+ assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), ruleConfig, Sets.newHashSet()),
instanceOf(ReadwriteSplittingRule.class));
}
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilder.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilder.java
index 1101fac..7e31d27 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilder.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.shadow.constant.ShadowOrder;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
/**
@@ -33,7 +34,8 @@ import java.util.Map;
public final class ShadowRuleBuilder implements FeatureRuleBuilder,
SchemaRuleBuilder<ShadowRuleConfiguration> {
@Override
- public ShadowRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType, final
ShadowRuleConfiguration config) {
+ public ShadowRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType,
+ final ShadowRuleConfiguration config, final
Collection<String> occupiedTables) {
return new ShadowRule(config);
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java
index 05dd692..e4172e6 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.shadow.rule.builder;
+import com.google.common.collect.Sets;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -42,6 +43,6 @@ public final class ShadowRuleBuilderTest {
public void assertBuild() {
ShadowRuleConfiguration ruleConfig =
mock(ShadowRuleConfiguration.class);
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig),
SchemaRuleBuilder.class).get(ruleConfig);
- assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), ruleConfig), instanceOf(ShadowRule.class));
+ assertThat(builder.build("", Collections.emptyMap(),
mock(DatabaseType.class), ruleConfig, Sets.newHashSet()),
instanceOf(ShadowRule.class));
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index f95c778..4548e53 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -89,7 +89,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
private final KeyGenerateAlgorithm defaultKeyGenerateAlgorithm;
- public ShardingRule(final ShardingRuleConfiguration config, final
Map<String, DataSource> dataSourceMap) {
+ public ShardingRule(final ShardingRuleConfiguration config, final
Map<String, DataSource> dataSourceMap, final Collection<String> occupiedTables)
{
Preconditions.checkArgument(null != dataSourceMap &&
!dataSourceMap.isEmpty(), "Data sources cannot be empty.");
dataSourceNames = getDataSourceNames(config.getTables(),
config.getAutoTables(), dataSourceMap.keySet());
config.getShardingAlgorithms().forEach((key, value) ->
shardingAlgorithms.put(key,
ShardingSphereAlgorithmFactory.createAlgorithm(value,
ShardingAlgorithm.class)));
@@ -102,9 +102,10 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
defaultTableShardingStrategyConfig = null ==
config.getDefaultTableShardingStrategy() ? new
NoneShardingStrategyConfiguration() : config.getDefaultTableShardingStrategy();
defaultKeyGenerateAlgorithm = null ==
config.getDefaultKeyGenerateStrategy()
?
TypedSPIRegistry.getRegisteredService(KeyGenerateAlgorithm.class) :
keyGenerators.get(config.getDefaultKeyGenerateStrategy().getKeyGeneratorName());
+ occupiedTables.addAll(getAllTables());
}
- public ShardingRule(final AlgorithmProvidedShardingRuleConfiguration
config, final Map<String, DataSource> dataSourceMap) {
+ public ShardingRule(final AlgorithmProvidedShardingRuleConfiguration
config, final Map<String, DataSource> dataSourceMap, final Collection<String>
occupiedTables) {
Preconditions.checkArgument(null != dataSourceMap &&
!dataSourceMap.isEmpty(), "Data sources cannot be empty.");
dataSourceNames = getDataSourceNames(config.getTables(),
config.getAutoTables(), dataSourceMap.keySet());
shardingAlgorithms.putAll(config.getShardingAlgorithms());
@@ -117,6 +118,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
defaultTableShardingStrategyConfig = null ==
config.getDefaultTableShardingStrategy() ? new
NoneShardingStrategyConfiguration() : config.getDefaultTableShardingStrategy();
defaultKeyGenerateAlgorithm = null ==
config.getDefaultKeyGenerateStrategy()
?
TypedSPIRegistry.getRegisteredService(KeyGenerateAlgorithm.class) :
keyGenerators.get(config.getDefaultKeyGenerateStrategy().getKeyGeneratorName());
+ occupiedTables.addAll(getAllTables());
}
private Collection<String> getDataSourceNames(final
Collection<ShardingTableRuleConfiguration> tableRuleConfigs,
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/AlgorithmProvidedShardingRuleBuilder.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/AlgorithmProvidedShardingRuleBuilder.java
index 0491d4c..7e83dbe 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/AlgorithmProvidedShardingRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/AlgorithmProvidedShardingRuleBuilder.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.sharding.constant.ShardingOrder;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
/**
@@ -33,8 +34,9 @@ import java.util.Map;
public final class AlgorithmProvidedShardingRuleBuilder implements
FeatureRuleBuilder,
SchemaRuleBuilder<AlgorithmProvidedShardingRuleConfiguration> {
@Override
- public ShardingRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType, final
AlgorithmProvidedShardingRuleConfiguration config) {
- return new ShardingRule(config, dataSourceMap);
+ public ShardingRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType,
+ final AlgorithmProvidedShardingRuleConfiguration
config, final Collection<String> occupiedTables) {
+ return new ShardingRule(config, dataSourceMap, occupiedTables);
}
@Override
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
index 42d6b61..964b272 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.sharding.constant.ShardingOrder;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
/**
@@ -33,8 +34,9 @@ import java.util.Map;
public final class ShardingRuleBuilder implements FeatureRuleBuilder,
SchemaRuleBuilder<ShardingRuleConfiguration> {
@Override
- public ShardingRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType, final
ShardingRuleConfiguration config) {
- return new ShardingRule(config, dataSourceMap);
+ public ShardingRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType,
+ final ShardingRuleConfiguration config, final
Collection<String> occupiedTables) {
+ return new ShardingRule(config, dataSourceMap, occupiedTables);
}
@Override
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
index c428255..ae01434 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.merge.dal.show;
+import com.google.common.collect.Sets;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
@@ -55,7 +56,7 @@ public final class ShowCreateTableMergedResultTest {
ShardingTableRuleConfiguration tableRuleConfig = new
ShardingTableRuleConfiguration("table", "ds.table_${0..2}");
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(tableRuleConfig);
- return new ShardingRule(shardingRuleConfig,
Collections.singletonMap("ds", mock(DataSource.class, RETURNS_DEEP_STUBS)));
+ return new ShardingRule(shardingRuleConfig,
Collections.singletonMap("ds", mock(DataSource.class, RETURNS_DEEP_STUBS)),
Sets.newHashSet());
}
private ShardingSphereSchema buildSchema() {
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
index 937a43f..6873153 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.merge.dal.show;
+import com.google.common.collect.Sets;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
@@ -55,7 +56,7 @@ public final class ShowTablesMergedResultTest {
ShardingTableRuleConfiguration tableRuleConfig = new
ShardingTableRuleConfiguration("table", "ds.table_${0..2}");
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(tableRuleConfig);
- return new ShardingRule(shardingRuleConfig,
Collections.singletonMap("ds", mock(DataSource.class, RETURNS_DEEP_STUBS)));
+ return new ShardingRule(shardingRuleConfig,
Collections.singletonMap("ds", mock(DataSource.class, RETURNS_DEEP_STUBS)),
Sets.newHashSet());
}
private ShardingSphereSchema buildSchema() {
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
index 4b872ec..d56d55a 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
@@ -17,12 +17,9 @@
package org.apache.shardingsphere.sharding.route.engine.fixture;
+import com.google.common.collect.Sets;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.CreateTableEvent;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -58,7 +55,7 @@ public abstract class AbstractRoutingEngineTest {
Properties props1 = new Properties();
props1.setProperty("algorithm-expression", "t_order_${order_id % 2}");
shardingRuleConfig.getShardingAlgorithms().put("t_order_inline", new
ShardingSphereAlgorithmConfiguration("INLINE", props1));
- return new ShardingRule(shardingRuleConfig, createDataSourceMap());
+ return new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet());
}
protected final ShardingRule createErrorShardingRule() {
@@ -70,7 +67,7 @@ public abstract class AbstractRoutingEngineTest {
Properties props1 = new Properties();
props1.setProperty("algorithm-expression", "t_order_${order_id % 3}");
shardingRuleConfig.getShardingAlgorithms().put("t_order_inline", new
ShardingSphereAlgorithmConfiguration("INLINE", props1));
- return new ShardingRule(shardingRuleConfig, createDataSourceMap());
+ return new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet());
}
protected final ShardingRule createBindingShardingRule() {
@@ -87,7 +84,7 @@ public abstract class AbstractRoutingEngineTest {
Properties props2 = new Properties();
props2.setProperty("algorithm-expression", "t_order_item_${order_id %
2}");
shardingRuleConfig.getShardingAlgorithms().put("t_order_item_inline",
new ShardingSphereAlgorithmConfiguration("INLINE", props2));
- return new ShardingRule(shardingRuleConfig, createDataSourceMap());
+ return new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet());
}
protected final ShardingRule createBroadcastShardingRule() {
@@ -104,14 +101,14 @@ public abstract class AbstractRoutingEngineTest {
Properties props2 = new Properties();
props2.setProperty("algorithm-expression", "t_order_item_${order_id %
2}");
shardingRuleConfig.getShardingAlgorithms().put("t_order_item_inline",
new ShardingSphereAlgorithmConfiguration("INLINE", props2));
- return new ShardingRule(shardingRuleConfig, createDataSourceMap());
+ return new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet());
}
protected final ShardingRule createHintShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleWithHintConfig());
shardingRuleConfig.getShardingAlgorithms().put("hint_test", new
ShardingSphereAlgorithmConfiguration("HINT_TEST", new Properties()));
- return new ShardingRule(shardingRuleConfig, createDataSourceMap());
+ return new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet());
}
protected final ShardingRule createMixedShardingRule() {
@@ -127,10 +124,10 @@ public abstract class AbstractRoutingEngineTest {
Properties props1 = new Properties();
props1.setProperty("algorithm-expression", "t_hint_ds_test_${order_id
% 2}");
shardingRuleConfig.getShardingAlgorithms().put("t_hint_ds_test_inline", new
ShardingSphereAlgorithmConfiguration("INLINE", props1));
- return new ShardingRule(shardingRuleConfig, createDataSourceMap());
+ return new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet());
}
- protected final ShardingRule createAllShardingRule() {
+ protected final ShardingRule createAllShardingRule(final
Collection<String> occupiedTables) {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getBroadcastTables().add("t_product");
Properties props0 = new Properties();
@@ -152,7 +149,7 @@ public abstract class AbstractRoutingEngineTest {
props3.setProperty("algorithm-expression", "t_user_${user_id % 2}");
shardingRuleConfig.getShardingAlgorithms().put("t_user_inline", new
ShardingSphereAlgorithmConfiguration("INLINE", props3));
shardingRuleConfig.getShardingAlgorithms().put("hint_test", new
ShardingSphereAlgorithmConfiguration("HINT_TEST", new Properties()));
- return new ShardingRule(shardingRuleConfig,
createDataSourceMapWithMain());
+ return new ShardingRule(shardingRuleConfig,
createDataSourceMapWithMain(), occupiedTables);
}
protected final ShardingRule createIntervalTableShardingRule() {
@@ -167,7 +164,7 @@ public abstract class AbstractRoutingEngineTest {
props0.setProperty("datetime-interval-amount", "1");
props0.setProperty("datetime-interval-unit", "MONTHS");
shardingRuleConfig.getShardingAlgorithms().put("interval_test", new
ShardingSphereAlgorithmConfiguration("INTERVAL", props0));
- return new ShardingRule(shardingRuleConfig, createDataSourceMap());
+ return new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet());
}
private ShardingTableRuleConfiguration createInlineTableRuleConfig(final
String tableName, final String actualDataNodes, final String
algorithmExpression, final String dsAlgorithmExpression) {
@@ -243,10 +240,10 @@ public abstract class AbstractRoutingEngineTest {
return result;
}
- protected SingleTableRule createAllSingleTableRule(final
Collection<ShardingSphereRule> rules) {
+ protected SingleTableRule createAllSingleTableRule(final
Collection<String> occupiedTables) {
Map<String, DataSource> dataSourceMap = createDataSourceMapWithMain();
- SingleTableRule singleTableRule = new
SingleTableRule(mock(DatabaseType.class), dataSourceMap, rules);
- ShardingSphereEventBus.getInstance().post(new
CreateTableEvent(dataSourceMap.keySet().iterator().next(), "t_category",
mock(TableMetaData.class)));
+ SingleTableRule singleTableRule = new
SingleTableRule(mock(DatabaseType.class), dataSourceMap, occupiedTables);
+ singleTableRule.addSingleTableDataNode("t_category",
dataSourceMap.keySet().iterator().next());
return singleTableRule;
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDatabaseBroadcastRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDatabaseBroadcastRoutingEngineTest.java
index 5350cbf..2e221bf 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDatabaseBroadcastRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDatabaseBroadcastRoutingEngineTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.route.engine.type.broadcast;
+import com.google.common.collect.Sets;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -44,7 +45,7 @@ public final class ShardingDatabaseBroadcastRoutingEngineTest
{
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(new
ShardingTableRuleConfiguration("t_order", "ds_${0..1}.t_order_${0..2}"));
RouteContext routeContext = new RouteContext();
- shardingDatabaseBroadcastRoutingEngine.route(routeContext, new
ShardingRule(shardingRuleConfig, createDataSourceMap()));
+ shardingDatabaseBroadcastRoutingEngine.route(routeContext, new
ShardingRule(shardingRuleConfig, createDataSourceMap(), Sets.newHashSet()));
List<RouteUnit> routeUnits = new
ArrayList<>(routeContext.getRouteUnits());
assertThat(routeContext.getRouteUnits().size(), is(2));
assertThat(routeUnits.get(0).getDataSourceMapper().getActualName(),
is("ds_0"));
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java
index cb0c605..f3f57fa 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java
@@ -155,7 +155,7 @@ public final class ShardingTableBroadcastRoutingEngineTest
extends AbstractRouti
dataSourceMap.put("ds0", mock(DataSource.class, RETURNS_DEEP_STUBS));
dataSourceMap.put("ds1", mock(DataSource.class, RETURNS_DEEP_STUBS));
- return new ShardingRule(shardingRuleConfiguration, dataSourceMap);
+ return new ShardingRule(shardingRuleConfiguration, dataSourceMap,
Sets.newHashSet());
}
private SQLStatementContext<?> createSQLStatementContext(final
List<String> tableNames) {
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
index cfafd91..6aa67cf 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
@@ -38,8 +38,10 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
import java.sql.Types;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -56,8 +58,9 @@ public abstract class AbstractSQLRouteTest extends
AbstractRoutingEngineTest {
}
protected final RouteContext assertRoute(final String sql, final
List<Object> parameters, final int routeUnitSize) {
- ShardingRule shardingRule = createAllShardingRule();
- SingleTableRule singleTableRule =
createAllSingleTableRule(Collections.singletonList(shardingRule));
+ Collection<String> occupiedTables = new HashSet<>();
+ ShardingRule shardingRule = createAllShardingRule(occupiedTables);
+ SingleTableRule singleTableRule =
createAllSingleTableRule(occupiedTables);
ShardingSphereSchema schema = buildSchema();
ConfigurationProperties props = new ConfigurationProperties(new
Properties());
SQLStatementParserEngine sqlStatementParserEngine = new
SQLStatementParserEngine("MySQL");
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
index bb996c2..d384b3a 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.route.engine.type.unicast;
+import com.google.common.collect.Sets;
import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -47,7 +48,7 @@ public final class ShardingUnicastRoutingEngineTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(new
ShardingTableRuleConfiguration("t_order", "ds_${0..1}.t_order_${0..2}"));
shardingRuleConfig.getBroadcastTables().add("t_config");
- shardingRule = new ShardingRule(shardingRuleConfig,
createDataSourceMap());
+ shardingRule = new ShardingRule(shardingRuleConfig,
createDataSourceMap(), Sets.newHashSet());
}
@Test
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index 75ef282..93bb095 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.rule;
+import com.google.common.collect.Sets;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -51,7 +52,7 @@ public final class ShardingRuleTest {
@Test(expected = IllegalArgumentException.class)
public void assertNewShardingRuleWithEmptyDataSourceNames() {
- new ShardingRule(new ShardingRuleConfiguration(),
Collections.emptyMap());
+ new ShardingRule(new ShardingRuleConfiguration(),
Collections.emptyMap(), Sets.newHashSet());
}
@Test
@@ -202,7 +203,7 @@ public final class ShardingRuleTest {
shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies());
shardingRuleConfig.setDefaultDatabaseShardingStrategy(new
StandardShardingStrategyConfiguration("column", "STANDARD_TEST"));
shardingRuleConfig.getShardingAlgorithms().put("standard", new
ShardingSphereAlgorithmConfiguration("STANDARD_TEST", new Properties()));
- assertTrue(new ShardingRule(shardingRuleConfig,
createDataSourceMap()).isShardingColumn("column", "LOGIC_TABLE"));
+ assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet()).isShardingColumn("column", "LOGIC_TABLE"));
}
@Test
@@ -211,7 +212,7 @@ public final class ShardingRuleTest {
shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies());
shardingRuleConfig.setDefaultTableShardingStrategy(new
StandardShardingStrategyConfiguration("column", "STANDARD_TEST"));
shardingRuleConfig.getShardingAlgorithms().put("standard", new
ShardingSphereAlgorithmConfiguration("STANDARD_TEST", new Properties()));
- assertTrue(new ShardingRule(shardingRuleConfig,
createDataSourceMap()).isShardingColumn("column", "LOGIC_TABLE"));
+ assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet()).isShardingColumn("column", "LOGIC_TABLE"));
}
@Test
@@ -219,7 +220,7 @@ public final class ShardingRuleTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies());
shardingRuleConfig.getShardingAlgorithms().put("standard", new
ShardingSphereAlgorithmConfiguration("STANDARD_TEST", new Properties()));
- assertTrue(new ShardingRule(shardingRuleConfig,
createDataSourceMap()).isShardingColumn("column", "logic_Table"));
+ assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet()).isShardingColumn("column", "logic_Table"));
}
@Test
@@ -227,14 +228,14 @@ public final class ShardingRuleTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleConfigWithTableStrategies());
shardingRuleConfig.getShardingAlgorithms().put("standard", new
ShardingSphereAlgorithmConfiguration("STANDARD_TEST", new Properties()));
- assertTrue(new ShardingRule(shardingRuleConfig,
createDataSourceMap()).isShardingColumn("column", "logic_Table"));
+ assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet()).isShardingColumn("column", "logic_Table"));
}
@Test
public void assertIsNotShardingColumn() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies());
- assertFalse(new ShardingRule(shardingRuleConfig,
createDataSourceMap()).isShardingColumn("column", "other_Table"));
+ assertFalse(new ShardingRule(shardingRuleConfig,
createDataSourceMap(), Sets.newHashSet()).isShardingColumn("column",
"other_Table"));
}
@Test
@@ -278,7 +279,7 @@ public final class ShardingRuleTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfig =
createTableRuleConfiguration("LOGIC_TABLE", "pr_ds_${0..1}.table_${0..2}");
shardingRuleConfig.getTables().add(shardingTableRuleConfig);
- new ShardingRule(shardingRuleConfig, Collections.emptyMap());
+ new ShardingRule(shardingRuleConfig, Collections.emptyMap(),
Sets.newHashSet());
}
@Test
@@ -312,7 +313,7 @@ public final class ShardingRuleTest {
Properties props = new Properties();
props.put("sharding-count", 4);
shardingRuleConfig.getShardingAlgorithms().put("hash_mod", new
ShardingSphereAlgorithmConfiguration("hash_mod", props));
- ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSourceMap());
+ ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSourceMap(), Sets.newHashSet());
assertThat(shardingRule.getDataSourceNames(), is(new
LinkedHashSet<>(Arrays.asList("ds_0", "ds_1", "resource0", "resource1"))));
}
@@ -321,7 +322,7 @@ public final class ShardingRuleTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfig = new
ShardingTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
shardingRuleConfig.getTables().add(shardingTableRuleConfig);
- ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSourceMap());
+ ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSourceMap(), Sets.newHashSet());
assertThat(shardingRule.getDataSourceNames(), is(new
LinkedHashSet<>(Arrays.asList("ds_0", "ds_1"))));
}
@@ -348,14 +349,14 @@ public final class ShardingRuleTest {
shardingRuleConfig.getShardingAlgorithms().put("standard", new
ShardingSphereAlgorithmConfiguration("STANDARD_TEST", new Properties()));
shardingRuleConfig.getKeyGenerators().put("increment", new
ShardingSphereAlgorithmConfiguration("INCREMENT", new Properties()));
shardingRuleConfig.getKeyGenerators().put("default", new
ShardingSphereAlgorithmConfiguration("INCREMENT", new Properties()));
- return new ShardingRule(shardingRuleConfig, createDataSourceMap());
+ return new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet());
}
private ShardingRule createMinimumShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfig =
createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
shardingRuleConfig.getTables().add(shardingTableRuleConfig);
- return new ShardingRule(shardingRuleConfig, createDataSourceMap());
+ return new ShardingRule(shardingRuleConfig, createDataSourceMap(),
Sets.newHashSet());
}
private ShardingTableRuleConfiguration createTableRuleConfiguration(final
String logicTableName, final String actualDataNodes) {
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/AlgorithmProvidedShardingRuleBuilderTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/AlgorithmProvidedShardingRuleBuilderTest.java
index 6cc1334..7d6c687 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/AlgorithmProvidedShardingRuleBuilderTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/AlgorithmProvidedShardingRuleBuilderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.rule.builder;
+import com.google.common.collect.Sets;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -44,6 +45,7 @@ public final class AlgorithmProvidedShardingRuleBuilderTest {
public void assertBuild() {
AlgorithmProvidedShardingRuleConfiguration ruleConfig =
mock(AlgorithmProvidedShardingRuleConfiguration.class);
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig),
SchemaRuleBuilder.class).get(ruleConfig);
- assertThat(builder.build("test_schema",
Collections.singletonMap("name", mock(DataSource.class, RETURNS_DEEP_STUBS)),
mock(DatabaseType.class), ruleConfig), instanceOf(ShardingRule.class));
+ assertThat(builder.build("test_schema",
Collections.singletonMap("name", mock(DataSource.class, RETURNS_DEEP_STUBS)),
+ mock(DatabaseType.class), ruleConfig, Sets.newHashSet()),
instanceOf(ShardingRule.class));
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java
index 735126d..59a1d6d 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.rule.builder;
+import com.google.common.collect.Sets;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -44,6 +45,7 @@ public final class ShardingRuleBuilderTest {
public void assertBuild() {
ShardingRuleConfiguration ruleConfig =
mock(ShardingRuleConfiguration.class);
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig),
SchemaRuleBuilder.class).get(ruleConfig);
- assertThat(builder.build("test_schema",
Collections.singletonMap("name", mock(DataSource.class, RETURNS_DEEP_STUBS)),
mock(DatabaseType.class), ruleConfig), instanceOf(ShardingRule.class));
+ assertThat(builder.build("test_schema",
Collections.singletonMap("name", mock(DataSource.class, RETURNS_DEEP_STUBS)),
+ mock(DatabaseType.class), ruleConfig, Sets.newHashSet()),
instanceOf(ShardingRule.class));
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/event/CreateTableEvent.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/event/CreateTableEvent.java
deleted file mode 100644
index 46d06f5..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/event/CreateTableEvent.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.event;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-
-/**
- * Create table event.
- */
-@RequiredArgsConstructor
-@Getter
-public final class CreateTableEvent {
-
- private final String dataSourceName;
-
- private final String tableName;
-
- private final TableMetaData tableMetaData;
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/event/DropTableEvent.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/event/DropTableEvent.java
deleted file mode 100644
index b10eb80..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/event/DropTableEvent.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.event;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * Drop table event.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DropTableEvent {
-
- private final String tableName;
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresher.java
index 98b6140..0aa54c5 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresher.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresher.java
@@ -17,16 +17,15 @@
package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
import
org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder;
import
org.apache.shardingsphere.infra.metadata.schema.builder.loader.TableMetaDataLoader;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.CreateTableEvent;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.DropTableEvent;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
+import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
import org.apache.shardingsphere.infra.rule.type.TableContainedRule;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
@@ -47,15 +46,16 @@ public final class AlterTableStatementSchemaRefresher
implements SchemaRefresher
String tableName =
sqlStatement.getTable().getTableName().getIdentifier().getValue();
if (sqlStatement.getRenameTable().isPresent()) {
putTableMetaData(schema, routeDataSourceNames, materials,
sqlStatement.getRenameTable().get().getTableName().getIdentifier().getValue());
- removeTableMetaData(schema, tableName);
+ removeTableMetaData(schema, materials, tableName);
} else {
putTableMetaData(schema, routeDataSourceNames, materials,
tableName);
}
}
- private void removeTableMetaData(final ShardingSphereSchema schema, final
String tableName) {
+ private void removeTableMetaData(final ShardingSphereSchema schema, final
SchemaBuilderMaterials materials, final String tableName) {
schema.remove(tableName);
- ShardingSphereEventBus.getInstance().post(new
DropTableEvent(tableName));
+ materials.getRules().stream().filter(each -> each instanceof
SingleTableRule).map(each
+ -> (SingleTableRule) each).findFirst().ifPresent(rule ->
rule.dropSingleTableDataNode(tableName));
}
private void putTableMetaData(final ShardingSphereSchema schema, final
Collection<String> routeDataSourceNames,
@@ -67,7 +67,14 @@ public final class AlterTableStatementSchemaRefresher
implements SchemaRefresher
tableMetaData = TableMetaDataBuilder.build(tableName,
materials).orElse(new TableMetaData());
}
schema.put(tableName, tableMetaData);
- ShardingSphereEventBus.getInstance().post(new
CreateTableEvent(routeDataSourceNames.iterator().next(), tableName,
tableMetaData));
+ if (isSingleTable(tableName, materials)) {
+ materials.getRules().stream().filter(each -> each instanceof
SingleTableRule).map(each
+ -> (SingleTableRule) each).findFirst().ifPresent(rule ->
rule.addSingleTableDataNode(tableName,
routeDataSourceNames.iterator().next()));
+ }
+ }
+
+ private boolean isSingleTable(final String tableName, final
SchemaBuilderMaterials materials) {
+ return materials.getRules().stream().noneMatch(each -> each instanceof
DataNodeContainedRule && ((DataNodeContainedRule)
each).getAllTables().contains(tableName));
}
private boolean containsInTableContainedRule(final String tableName, final
SchemaBuilderMaterials materials) {
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresher.java
index 4e71b19..e26d45e 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresher.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresher.java
@@ -17,15 +17,15 @@
package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
import
org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder;
import
org.apache.shardingsphere.infra.metadata.schema.builder.loader.TableMetaDataLoader;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.CreateTableEvent;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
+import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
import org.apache.shardingsphere.infra.rule.type.TableContainedRule;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
@@ -51,7 +51,14 @@ public final class CreateTableStatementSchemaRefresher
implements SchemaRefreshe
tableMetaData = loadTableMetaData(tableName, routeDataSourceNames,
materials);
}
schema.put(tableName, tableMetaData);
- ShardingSphereEventBus.getInstance().post(new
CreateTableEvent(routeDataSourceNames.iterator().next(), tableName,
tableMetaData));
+ if (isSingleTable(tableName, materials)) {
+ materials.getRules().stream().filter(each -> each instanceof
SingleTableRule).map(each
+ -> (SingleTableRule) each).findFirst().ifPresent(rule ->
rule.addSingleTableDataNode(tableName, routeDataSourceNames.iterator().next()));
+ }
+ }
+
+ private boolean isSingleTable(final String tableName, final
SchemaBuilderMaterials materials) {
+ return materials.getRules().stream().noneMatch(each -> each instanceof
DataNodeContainedRule && ((DataNodeContainedRule)
each).getAllTables().contains(tableName));
}
private boolean containsInTableContainedRule(final String tableName, final
SchemaBuilderMaterials materials) {
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresher.java
index 1d268b6..e719241 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresher.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresher.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.CreateTableEvent;
+import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
+import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewStatement;
import java.util.Collection;
@@ -37,6 +37,13 @@ public final class CreateViewStatementSchemaRefresher
implements SchemaRefresher
String viewName =
sqlStatement.getView().getTableName().getIdentifier().getValue();
TableMetaData tableMetaData = new TableMetaData();
schema.put(viewName, tableMetaData);
- ShardingSphereEventBus.getInstance().post(new
CreateTableEvent(routeDataSourceNames.iterator().next(), viewName,
tableMetaData));
+ if (isSingleTable(viewName, materials)) {
+ materials.getRules().stream().filter(each -> each instanceof
SingleTableRule).map(each
+ -> (SingleTableRule) each).findFirst().ifPresent(rule ->
rule.addSingleTableDataNode(viewName, routeDataSourceNames.iterator().next()));
+ }
+ }
+
+ private boolean isSingleTable(final String tableName, final
SchemaBuilderMaterials materials) {
+ return materials.getRules().stream().noneMatch(each -> each instanceof
DataNodeContainedRule && ((DataNodeContainedRule)
each).getAllTables().contains(tableName));
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresher.java
index b2a1128..26ca096 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresher.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresher.java
@@ -17,15 +17,15 @@
package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.DropTableEvent;
+import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
import java.util.Collection;
+import java.util.Optional;
/**
* ShardingSphere schema refresher for drop table statement.
@@ -35,8 +35,9 @@ public final class DropTableStatementSchemaRefresher
implements SchemaRefresher<
@Override
public void refresh(final ShardingSphereSchema schema, final
Collection<String> routeDataSourceNames, final DropTableStatement sqlStatement,
final SchemaBuilderMaterials materials) {
sqlStatement.getTables().forEach(each ->
schema.remove(each.getTableName().getIdentifier().getValue()));
+ Optional<SingleTableRule> singleTableRule =
materials.getRules().stream().filter(each -> each instanceof
SingleTableRule).map(each -> (SingleTableRule) each).findFirst();
for (SimpleTableSegment each : sqlStatement.getTables()) {
- ShardingSphereEventBus.getInstance().post(new
DropTableEvent(each.getTableName().getIdentifier().getValue()));
+ singleTableRule.ifPresent(rule ->
rule.dropSingleTableDataNode(each.getTableName().getIdentifier().getValue()));
}
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresher.java
index 1a37e76..939919c 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresher.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresher.java
@@ -17,15 +17,15 @@
package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.DropTableEvent;
+import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
import java.util.Collection;
+import java.util.Optional;
/**
* ShardingSphere schema refresher for drop view statement.
@@ -35,8 +35,9 @@ public final class DropViewStatementSchemaRefresher
implements SchemaRefresher<D
@Override
public void refresh(final ShardingSphereSchema schema, final
Collection<String> routeDataSourceNames, final DropViewStatement sqlStatement,
final SchemaBuilderMaterials materials) {
sqlStatement.getViews().forEach(each ->
schema.remove(each.getTableName().getIdentifier().getValue()));
+ Optional<SingleTableRule> singleTableRule =
materials.getRules().stream().filter(each -> each instanceof
SingleTableRule).map(each -> (SingleTableRule) each).findFirst();
for (SimpleTableSegment each : sqlStatement.getViews()) {
- ShardingSphereEventBus.getInstance().post(new
DropTableEvent(each.getTableName().getIdentifier().getValue()));
+ singleTableRule.ifPresent(rule ->
rule.dropSingleTableDataNode(each.getTableName().getIdentifier().getValue()));
}
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/aware/PreviousRulesAware.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/aware/PreviousRulesAware.java
deleted file mode 100644
index 6572940..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/aware/PreviousRulesAware.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.aware;
-
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-
-import java.util.Collection;
-
-/**
- * Previous rules aware.
- */
-public interface PreviousRulesAware {
-
- /**
- * Set previous rules.
- *
- * @param previousRules previous rules
- */
- void setPreviousRules(Collection<ShardingSphereRule> previousRules);
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/ShardingSphereRulesBuilder.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/ShardingSphereRulesBuilder.java
index b0174c1..fffc81a 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/ShardingSphereRulesBuilder.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/ShardingSphereRulesBuilder.java
@@ -25,7 +25,6 @@ import
org.apache.shardingsphere.infra.config.single.SingleTableRuleConfiguratio
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.aware.PreviousRulesAware;
import
org.apache.shardingsphere.infra.rule.builder.level.DefaultKernelRuleConfigurationBuilder;
import org.apache.shardingsphere.infra.rule.builder.level.KernelRuleBuilder;
import org.apache.shardingsphere.infra.rule.builder.scope.GlobalRuleBuilder;
@@ -36,6 +35,7 @@ import
org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
import javax.sql.DataSource;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
@@ -67,19 +67,8 @@ public final class ShardingSphereRulesBuilder {
final
DatabaseType databaseType, final Map<String, DataSource> dataSourceMap) {
Map<RuleConfiguration, SchemaRuleBuilder> builders =
OrderedSPIRegistry.getRegisteredServices(getAllSchemaRuleConfigurations(schemaRuleConfigurations),
SchemaRuleBuilder.class);
appendDefaultKernelSchemaRuleConfigurationBuilder(builders);
- Collection<ShardingSphereRule> result = new LinkedList<>();
- for (Map.Entry<RuleConfiguration, SchemaRuleBuilder> entry :
builders.entrySet()) {
- setUpSchemaRuleBuilder(entry.getValue(), result);
- result.add(entry.getValue().build(schemaName, dataSourceMap,
databaseType, entry.getKey()));
- }
- return result;
- }
-
- @SuppressWarnings("rawtypes")
- private static void setUpSchemaRuleBuilder(final SchemaRuleBuilder
builder, final Collection<ShardingSphereRule> rules) {
- if (builder instanceof PreviousRulesAware) {
- ((PreviousRulesAware) builder).setPreviousRules(rules);
- }
+ Collection<String> occupiedTables = new HashSet<>();
+ return builders.entrySet().stream().map(entry ->
entry.getValue().build(schemaName, dataSourceMap, databaseType, entry.getKey(),
occupiedTables)).collect(Collectors.toList());
}
private static Collection<RuleConfiguration>
getAllSchemaRuleConfigurations(final Collection<RuleConfiguration>
schemaRuleConfigurations) {
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/scope/SchemaRuleBuilder.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/scope/SchemaRuleBuilder.java
index 4c93c55..8d37c84 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/scope/SchemaRuleBuilder.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/scope/SchemaRuleBuilder.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.scope.SchemaRule;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
/**
@@ -38,7 +39,8 @@ public interface SchemaRuleBuilder<T extends
RuleConfiguration> extends RuleBuil
* @param dataSourceMap dataSource map
* @param databaseType database type
* @param config rule configuration
+ * @param occupiedTables occupied tables
* @return built schema rule
*/
- SchemaRule build(String schemaName, Map<String, DataSource> dataSourceMap,
DatabaseType databaseType, T config);
+ SchemaRule build(String schemaName, Map<String, DataSource> dataSourceMap,
DatabaseType databaseType, T config, Collection<String> occupiedTables);
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/SingleTableRuleBuilder.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/SingleTableRuleBuilder.java
index f4fa2ba..2f0ec7a 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/SingleTableRuleBuilder.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/SingleTableRuleBuilder.java
@@ -20,8 +20,6 @@ package org.apache.shardingsphere.infra.rule.builder.single;
import
org.apache.shardingsphere.infra.config.single.SingleTableRuleConfiguration;
import org.apache.shardingsphere.infra.constant.SingleTableOrder;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.aware.PreviousRulesAware;
import org.apache.shardingsphere.infra.rule.builder.level.FeatureRuleBuilder;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
@@ -33,13 +31,12 @@ import java.util.Map;
/**
* Single table rule builder.
*/
-public final class SingleTableRuleBuilder implements FeatureRuleBuilder,
SchemaRuleBuilder<SingleTableRuleConfiguration>, PreviousRulesAware {
-
- private Collection<ShardingSphereRule> previousRules;
+public final class SingleTableRuleBuilder implements FeatureRuleBuilder,
SchemaRuleBuilder<SingleTableRuleConfiguration> {
@Override
- public SingleTableRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType, final
SingleTableRuleConfiguration config) {
- return new SingleTableRule(databaseType, dataSourceMap, previousRules);
+ public SingleTableRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType,
+ final SingleTableRuleConfiguration config,
final Collection<String> occupiedTables) {
+ return new SingleTableRule(databaseType, dataSourceMap,
occupiedTables);
}
@Override
@@ -51,9 +48,4 @@ public final class SingleTableRuleBuilder implements
FeatureRuleBuilder, SchemaR
public Class<SingleTableRuleConfiguration> getTypeClass() {
return SingleTableRuleConfiguration.class;
}
-
- @Override
- public void setPreviousRules(final Collection<ShardingSphereRule>
previousRules) {
- this.previousRules = previousRules;
- }
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/single/SingleTableRule.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/single/SingleTableRule.java
index 0ef8a49..867546b 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/single/SingleTableRule.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/single/SingleTableRule.java
@@ -18,16 +18,10 @@
package org.apache.shardingsphere.infra.rule.single;
import com.google.common.collect.Sets;
-import com.google.common.eventbus.Subscribe;
import lombok.Getter;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.CreateTableEvent;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.DropTableEvent;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.level.FeatureRule;
import org.apache.shardingsphere.infra.rule.scope.SchemaRule;
-import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
import javax.sql.DataSource;
import java.util.Collection;
@@ -45,13 +39,9 @@ public final class SingleTableRule implements FeatureRule,
SchemaRule {
private final Map<String, SingleTableDataNode> singleTableDataNodes;
- private final Collection<String> excludedTables;
-
- public SingleTableRule(final DatabaseType databaseType, final Map<String,
DataSource> dataSourceMap, final Collection<ShardingSphereRule> rules) {
+ public SingleTableRule(final DatabaseType databaseType, final Map<String,
DataSource> dataSourceMap, final Collection<String> occupiedTables) {
dataSourceNames = dataSourceMap.keySet();
- excludedTables = getExcludedTables(rules);
- singleTableDataNodes = SingleTableDataNodeLoader.load(databaseType,
dataSourceMap, excludedTables);
- ShardingSphereEventBus.getInstance().register(this);
+ singleTableDataNodes = SingleTableDataNodeLoader.load(databaseType,
dataSourceMap, occupiedTables);
}
/**
@@ -73,32 +63,27 @@ public final class SingleTableRule implements FeatureRule,
SchemaRule {
* @return sharding logic table names
*/
public Collection<String> getSingleTableNames(final Collection<String>
logicTableNames) {
- return logicTableNames.stream().filter(each ->
!excludedTables.contains(each)).collect(Collectors.toCollection(LinkedList::new));
+ return
logicTableNames.stream().filter(singleTableDataNodes::containsKey).collect(Collectors.toCollection(LinkedList::new));
}
/**
- * Add single table.
+ * Add single table data node.
*
- * @param event create table event
+ * @param tableName table name
+ * @param dataSourceName data source name
*/
- @Subscribe
- public void createSingleTable(final CreateTableEvent event) {
- if (dataSourceNames.contains(event.getDataSourceName()) &&
!excludedTables.contains(event.getTableName())) {
- singleTableDataNodes.put(event.getTableName(), new
SingleTableDataNode(event.getTableName(), event.getDataSourceName()));
+ public void addSingleTableDataNode(final String tableName, final String
dataSourceName) {
+ if (dataSourceNames.contains(dataSourceName) &&
!singleTableDataNodes.containsKey(tableName)) {
+ singleTableDataNodes.put(tableName, new
SingleTableDataNode(tableName, dataSourceName));
}
}
/**
- * Drop single table.
+ * Drop single table data node.
*
- * @param event drop table event
+ * @param tableName table name
*/
- @Subscribe
- public void dropSingleTable(final DropTableEvent event) {
- singleTableDataNodes.remove(event.getTableName());
- }
-
- private Collection<String> getExcludedTables(final
Collection<ShardingSphereRule> rules) {
- return rules.stream().filter(each -> each instanceof
DataNodeContainedRule).flatMap(each -> ((DataNodeContainedRule)
each).getAllTables().stream()).collect(Collectors.toList());
+ public void dropSingleTableDataNode(final String tableName) {
+ singleTableDataNodes.remove(tableName);
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestShardingSphereRuleBuilder.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestShardingSphereRuleBuilder.java
index cdb3bb1..6651127 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestShardingSphereRuleBuilder.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestShardingSphereRuleBuilder.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import org.apache.shardingsphere.infra.rule.scope.SchemaRule;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
public final class TestShardingSphereRuleBuilder implements
SchemaRuleBuilder<TestRuleConfiguration> {
@@ -31,7 +32,8 @@ public final class TestShardingSphereRuleBuilder implements
SchemaRuleBuilder<Te
private static final SchemaRule RULE = new TestShardingSphereRule();
@Override
- public SchemaRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType, final
TestRuleConfiguration config) {
+ public SchemaRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType,
+ final TestRuleConfiguration config, final
Collection<String> occupiedTables) {
return RULE;
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/fixture/FixtureRuleBuilder.java
b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/fixture/FixtureRuleBuilder.java
index a1b2a67..2e35230 100644
---
a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/fixture/FixtureRuleBuilder.java
+++
b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/fixture/FixtureRuleBuilder.java
@@ -21,12 +21,14 @@ import
org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import javax.sql.DataSource;
+import java.util.Collection;
import java.util.Map;
public final class FixtureRuleBuilder implements
SchemaRuleBuilder<FixtureRuleConfiguration> {
@Override
- public FixtureRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType, final
FixtureRuleConfiguration config) {
+ public FixtureRule build(final String schemaName, final Map<String,
DataSource> dataSourceMap, final DatabaseType databaseType,
+ final FixtureRuleConfiguration config, final
Collection<String> occupiedTables) {
return new FixtureRule();
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/SingleTableSQLRouter.java
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/SingleTableSQLRouter.java
index bcebe63..6f16514 100644
---
a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/SingleTableSQLRouter.java
+++
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/SingleTableSQLRouter.java
@@ -28,6 +28,7 @@ import
org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import
org.apache.shardingsphere.infra.route.engine.single.SingleTableRouteEngine;
import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
import java.util.Collection;
import java.util.stream.Collectors;
@@ -46,19 +47,18 @@ public final class SingleTableSQLRouter implements
SQLRouter<SingleTableRule> {
private void route(final LogicSQL logicSQL, final SingleTableRule rule,
final RouteContext result) {
SQLStatementContext<?> sqlStatementContext =
logicSQL.getSqlStatementContext();
- Collection<String> singleTableNames =
getSingleTableNames(sqlStatementContext, rule);
- if (singleTableNames.isEmpty()) {
- return;
+ Collection<String> singleTableNames =
getSingleTableNames(sqlStatementContext, rule, result);
+ if (!singleTableNames.isEmpty()) {
+ validateSameDataSource(rule, sqlStatementContext,
singleTableNames);
+ new SingleTableRouteEngine(singleTableNames,
sqlStatementContext.getSqlStatement()).route(result, rule);
}
- validateSameDataSource(rule, sqlStatementContext, singleTableNames);
- new SingleTableRouteEngine(singleTableNames,
sqlStatementContext.getSqlStatement()).route(result, rule);
}
- private Collection<String> getSingleTableNames(final
SQLStatementContext<?> sqlStatementContext, final SingleTableRule rule) {
+ private Collection<String> getSingleTableNames(final
SQLStatementContext<?> sqlStatementContext, final SingleTableRule rule, final
RouteContext result) {
Collection<String> tableNames = sqlStatementContext instanceof
TableAvailable
? ((TableAvailable)
sqlStatementContext).getAllTables().stream().map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList())
: sqlStatementContext.getTablesContext().getTableNames();
- return rule.getSingleTableNames(tableNames);
+ return result.getRouteUnits().isEmpty() &&
sqlStatementContext.getSqlStatement() instanceof CreateTableStatement ?
tableNames : rule.getSingleTableNames(tableNames);
}
private void validateSameDataSource(final SingleTableRule rule, final
SQLStatementContext<?> sqlStatementContext, final Collection<String>
singleTableNames) {
diff --git
a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/single/SingleTableRouteEngine.java
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/single/SingleTableRouteEngine.java
index fcffcfd..3992bb0 100644
---
a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/single/SingleTableRouteEngine.java
+++
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/single/SingleTableRouteEngine.java
@@ -24,6 +24,7 @@ import
org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.apache.shardingsphere.infra.rule.single.SingleTableDataNode;
import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
@@ -53,14 +54,14 @@ public final class SingleTableRouteEngine {
* Route for single table.
*
* @param routeContext route context
- * @param singleTableRule single table rule
+ * @param rule single table rule
*/
- public void route(final RouteContext routeContext, final SingleTableRule
singleTableRule) {
+ public void route(final RouteContext routeContext, final SingleTableRule
rule) {
if (routeContext.getRouteUnits().isEmpty() || sqlStatement instanceof
SelectStatement) {
- route0(routeContext, singleTableRule);
+ route0(routeContext, rule);
} else {
RouteContext newRouteContext = new RouteContext();
- route0(newRouteContext, singleTableRule);
+ route0(newRouteContext, rule);
combineRouteContext(routeContext, newRouteContext);
}
}
@@ -77,16 +78,16 @@ public final class SingleTableRouteEngine {
return
newRouteContext.getRouteUnits().stream().collect(Collectors.toMap(each ->
each.getDataSourceMapper().getLogicName(), Function.identity(), (oldValue,
currentValue) -> oldValue));
}
- private void route0(final RouteContext routeContext, final SingleTableRule
singleTableRule) {
- if (isDDLTableStatement() ||
singleTableRule.isSingleTableInSameDataSource(singleTableNames)) {
- Set<String> existSingleTables =
Sets.intersection(singleTableRule.getSingleTableDataNodes().keySet(),
Sets.newHashSet(singleTableNames));
+ private void route0(final RouteContext routeContext, final SingleTableRule
rule) {
+ if (isDDLTableStatement() || isAllTablesInSameDataSource(routeContext,
rule)) {
+ Set<String> existSingleTables =
Sets.intersection(rule.getSingleTableDataNodes().keySet(),
Sets.newHashSet(singleTableNames));
if (!existSingleTables.isEmpty()) {
- fillRouteContext(singleTableRule, routeContext,
existSingleTables);
+ fillRouteContext(rule, routeContext, existSingleTables);
} else {
-
routeContext.getRouteUnits().add(getRandomRouteUnit(singleTableRule));
+ routeContext.getRouteUnits().add(getRandomRouteUnit(rule));
}
} else {
- fillRouteContext(singleTableRule, routeContext, singleTableNames);
+ fillRouteContext(rule, routeContext, singleTableNames);
if (1 < routeContext.getRouteUnits().size()) {
routeContext.setFederated(true);
}
@@ -97,6 +98,19 @@ public final class SingleTableRouteEngine {
return sqlStatement instanceof CreateTableStatement || sqlStatement
instanceof AlterTableStatement || sqlStatement instanceof DropTableStatement;
}
+ private boolean isAllTablesInSameDataSource(final RouteContext
routeContext, final SingleTableRule rule) {
+ if (!rule.isSingleTableInSameDataSource(singleTableNames)) {
+ return false;
+ }
+ SingleTableDataNode dataNode =
rule.getSingleTableDataNodes().get(singleTableNames.iterator().next());
+ for (RouteUnit each : routeContext.getRouteUnits()) {
+ if
(!each.getDataSourceMapper().getLogicName().equals(dataNode.getDataSourceName()))
{
+ return false;
+ }
+ }
+ return true;
+ }
+
private RouteUnit getRandomRouteUnit(final SingleTableRule
singleTableRule) {
Collection<String> dataSourceNames =
singleTableRule.getDataSourceNames();
String dataSource =
Lists.newArrayList(dataSourceNames).get(ThreadLocalRandom.current().nextInt(dataSourceNames.size()));
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
index 1287c45..775cef4 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.driver.jdbc.core.datasource.metadata;
import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Sets;
import
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import
org.apache.shardingsphere.driver.jdbc.core.resultset.DatabaseMetaDataResultSet;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
@@ -104,7 +105,7 @@ public final class ShardingSphereDatabaseMetaDataTest {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfig = new
ShardingTableRuleConfiguration(TABLE_NAME, DATA_SOURCE_NAME + "." + TABLE_NAME);
ruleConfig.setTables(Collections.singletonList(shardingTableRuleConfig));
- return new ShardingRule(ruleConfig,
Collections.singletonMap(DATA_SOURCE_NAME, mock(DataSource.class,
RETURNS_DEEP_STUBS)));
+ return new ShardingRule(ruleConfig,
Collections.singletonMap(DATA_SOURCE_NAME, mock(DataSource.class,
RETURNS_DEEP_STUBS)), Sets.newHashSet());
}
@Test
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
index 2d121d9..51fe419 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
@@ -224,7 +224,7 @@ public final class JobConfigurationUtil {
ShardingRuleConfiguration sourceRuleConfig =
ShardingRuleConfigurationSwapper.findAndConvertShardingRuleConfiguration(sourceConfig.getRootRuleConfigs().getRules());
Map<String, DataSourceConfiguration> sourceDataSource =
getDataSourceConfigurations(sourceConfig.getRootRuleConfigs().getDataSources());
Map<String, DataSource> dataSourceMap =
sourceDataSource.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
entry -> entry.getValue().createDataSource()));
- Map<String, Map<String, String>> dataSourceTableNameMap =
toDataSourceTableNameMap(new ShardingRule(sourceRuleConfig, dataSourceMap));
+ Map<String, Map<String, String>> dataSourceTableNameMap =
toDataSourceTableNameMap(new ShardingRule(sourceRuleConfig, dataSourceMap,
Sets.newHashSet()));
Optional<ShardingRuleConfiguration> targetRuleConfig =
getTargetRuleConfiguration(jobConfig);
filterByShardingDataSourceTables(dataSourceTableNameMap,
jobConfig.getHandleConfig());
Map<String, Set<String>> shardingColumnsMap =
getShardingColumnsMap(targetRuleConfig.orElse(sourceRuleConfig));
diff --git
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/EncryptSQLRewriterParameterizedTest.java
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/EncryptSQLRewriterParameterizedTest.java
index 97e4d02..09cd962 100644
---
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/EncryptSQLRewriterParameterizedTest.java
+++
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/EncryptSQLRewriterParameterizedTest.java
@@ -38,10 +38,11 @@ import
org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.engine.SQLRouteEngine;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.ShardingSphereRulesBuilder;
+import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
import
org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootRuleConfigurations;
-import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import
org.apache.shardingsphere.infra.yaml.config.swapper.YamlDataSourceConfigurationSwapper;
import
org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapperEngine;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import
org.apache.shardingsphere.sharding.rewrite.parameterized.engine.AbstractSQLRewriterParameterizedTest;
import
org.apache.shardingsphere.sharding.rewrite.parameterized.engine.parameter.SQLRewriteEngineTestParameters;
import
org.apache.shardingsphere.sharding.rewrite.parameterized.engine.parameter.SQLRewriteEngineTestParametersBuilder;
@@ -55,6 +56,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -79,6 +81,7 @@ public final class EncryptSQLRewriterParameterizedTest
extends AbstractSQLRewrit
Collection<ShardingSphereRule> rules =
ShardingSphereRulesBuilder.buildSchemaRules("schema_name", new
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(
ruleConfigurations.getRules()),
DatabaseTypeRegistry.getTrunkDatabaseType(databaseType),
new
YamlDataSourceConfigurationSwapper().swapToDataSources(ruleConfigurations.getDataSources()));
+ mockEncryptRuleSingleTable(rules);
SQLStatementParserEngine sqlStatementParserEngine = new
SQLStatementParserEngine(databaseType);
ShardingSphereSchema schema = mockSchema();
ConfigurationProperties props = new
ConfigurationProperties(ruleConfigurations.getProps());
@@ -95,6 +98,14 @@ public final class EncryptSQLRewriterParameterizedTest
extends AbstractSQLRewrit
? Collections.singletonList(((GenericSQLRewriteResult)
sqlRewriteResult).getSqlRewriteUnit()) : (((RouteSQLRewriteResult)
sqlRewriteResult).getSqlRewriteUnits()).values();
}
+ private void mockEncryptRuleSingleTable(final
Collection<ShardingSphereRule> rules) {
+ Optional<SingleTableRule> singleTableRule = rules.stream().filter(each
-> each instanceof SingleTableRule).map(each -> (SingleTableRule)
each).findFirst();
+ if (singleTableRule.isPresent()) {
+ singleTableRule.get().addSingleTableDataNode("t_account",
"encrypt_ds");
+ singleTableRule.get().addSingleTableDataNode("t_account_bak",
"encrypt_ds");
+ }
+ }
+
private YamlRootRuleConfigurations createRuleConfigurations() throws
IOException {
URL url =
EncryptSQLRewriterParameterizedTest.class.getClassLoader().getResource(getTestParameters().getRuleFile());
Preconditions.checkNotNull(url, "Cannot found rewrite rule yaml
configuration.");
diff --git
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
index 7052533..b3ceb90 100644
---
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
+++
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
@@ -32,7 +31,6 @@ import
org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.CreateTableEvent;
import org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngine;
import org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry;
import
org.apache.shardingsphere.infra.rewrite.engine.result.GenericSQLRewriteResult;
@@ -43,10 +41,11 @@ import
org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.engine.SQLRouteEngine;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.ShardingSphereRulesBuilder;
+import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
import
org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootRuleConfigurations;
-import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import
org.apache.shardingsphere.infra.yaml.config.swapper.YamlDataSourceConfigurationSwapper;
import
org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapperEngine;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import
org.apache.shardingsphere.sharding.rewrite.parameterized.engine.AbstractSQLRewriterParameterizedTest;
import
org.apache.shardingsphere.sharding.rewrite.parameterized.engine.parameter.SQLRewriteEngineTestParameters;
import
org.apache.shardingsphere.sharding.rewrite.parameterized.engine.parameter.SQLRewriteEngineTestParametersBuilder;
@@ -62,6 +61,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Optional;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -95,7 +95,7 @@ public final class ShardingSQLRewriterParameterizedTest
extends AbstractSQLRewri
SQLStatementContext<?> sqlStatementContext =
SQLStatementContextFactory.newInstance(metaDataMap,
getTestParameters().getInputParameters(),
sqlStatementParserEngine.parse(getTestParameters().getInputSQL(), false),
DefaultSchema.LOGIC_NAME);
LogicSQL logicSQL = new LogicSQL(sqlStatementContext,
getTestParameters().getInputSQL(), getTestParameters().getInputParameters());
- mockShardingSphereRuleSingleTable();
+ mockShardingSphereRuleSingleTable(rules);
ConfigurationProperties props = new
ConfigurationProperties(yamlRootRuleConfigs.getProps());
RouteContext routeContext = new SQLRouteEngine(rules,
props).route(logicSQL, metaData);
SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(
@@ -104,9 +104,12 @@ public final class ShardingSQLRewriterParameterizedTest
extends AbstractSQLRewri
? Collections.singletonList(((GenericSQLRewriteResult)
sqlRewriteResult).getSqlRewriteUnit()) : (((RouteSQLRewriteResult)
sqlRewriteResult).getSqlRewriteUnits()).values();
}
- private void mockShardingSphereRuleSingleTable() {
- ShardingSphereEventBus.getInstance().post(new CreateTableEvent("db",
"t_single", mock(TableMetaData.class)));
- ShardingSphereEventBus.getInstance().post(new CreateTableEvent("db",
"t_single_extend", mock(TableMetaData.class)));
+ private void mockShardingSphereRuleSingleTable(final
Collection<ShardingSphereRule> rules) {
+ Optional<SingleTableRule> singleTableRule = rules.stream().filter(each
-> each instanceof SingleTableRule).map(each -> (SingleTableRule)
each).findFirst();
+ if (singleTableRule.isPresent()) {
+ singleTableRule.get().addSingleTableDataNode("t_single", "db");
+ singleTableRule.get().addSingleTableDataNode("t_single_extend",
"db");
+ }
}
private YamlRootRuleConfigurations createYamlRootRuleConfigurations()
throws IOException {