This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 5b36922 Remove SchemaRulesBuilderMaterials (#15221)
5b36922 is described below
commit 5b36922208c63b7a56fdfcd8f202a18eed951e2d
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 31 06:19:56 2022 +0800
Remove SchemaRulesBuilderMaterials (#15221)
* Simplify SchemaRulesBuilderMaterials
* Simplify SchemaRulesBuilderMaterials
* Remove SchemaRulesBuilderMaterials
* Remove SchemaRulesBuilderMaterials
---
...orithmProvidedDatabaseDiscoveryRuleBuilder.java | 10 +++--
.../rule/builder/DatabaseDiscoveryRuleBuilder.java | 9 +++--
...hmProvidedDatabaseDiscoveryRuleBuilderTest.java | 19 ++++------
.../builder/DatabaseDiscoveryRuleBuilderTest.java | 14 ++-----
.../AlgorithmProvidedEncryptRuleBuilder.java | 9 +++--
.../encrypt/rule/builder/EncryptRuleBuilder.java | 9 +++--
.../AlgorithmProvidedEncryptRuleBuilderTest.java | 7 +---
.../rule/builder/EncryptRuleBuilderTest.java | 4 +-
...rithmProvidedReadwriteSplittingRuleBuilder.java | 8 ++--
.../builder/ReadwriteSplittingRuleBuilder.java | 7 +++-
...mProvidedReadwriteSplittingRuleBuilderTest.java | 25 ++++++-------
.../builder/ReadwriteSplittingRuleBuilderTest.java | 22 +++++------
.../AlgorithmProvidedShadowRuleBuilder.java | 7 +++-
.../shadow/rule/builder/ShadowRuleBuilder.java | 7 +++-
.../shadow/rule/builder/ShadowRuleBuilderTest.java | 7 +---
.../AlgorithmProvidedShardingRuleBuilder.java | 10 ++---
.../sharding/rule/builder/ShardingRuleBuilder.java | 10 ++---
.../AlgorithmProvidedShardingRuleBuilderTest.java | 18 +++------
.../rule/builder/ShardingRuleBuilderTest.java | 34 +++++++++--------
.../rule/builder/schema/SchemaRuleBuilder.java | 9 ++++-
.../rule/builder/schema/SchemaRulesBuilder.java | 18 +++++----
.../schema/SchemaRulesBuilderMaterials.java | 43 ----------------------
.../fixture/TestShardingSphereRuleBuilder.java | 7 +++-
.../builder/schema/SchemaRulesBuilderTest.java | 5 ++-
.../rule/builder/SingleTableRuleBuilder.java | 9 +++--
.../rule/builder/SingleTableRuleBuilderTest.java | 24 +++++-------
.../mode/metadata/MetaDataContextsBuilder.java | 12 ++----
.../mode/metadata/fixture/FixtureRuleBuilder.java | 7 +++-
.../AbstractSQLRewriterParameterizedTest.java | 9 +++--
29 files changed, 169 insertions(+), 210 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 25c1aac..98243b5 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
@@ -20,11 +20,13 @@ package org.apache.shardingsphere.dbdiscovery.rule.builder;
import
org.apache.shardingsphere.dbdiscovery.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.constant.DatabaseDiscoveryOrder;
import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
+import javax.sql.DataSource;
import java.util.Collection;
+import java.util.Map;
/**
* Algorithm provided database discovery rule builder.
@@ -32,9 +34,9 @@ import java.util.Collection;
public final class AlgorithmProvidedDatabaseDiscoveryRuleBuilder implements
SchemaRuleBuilder<AlgorithmProvidedDatabaseDiscoveryRuleConfiguration> {
@Override
- public DatabaseDiscoveryRule build(final SchemaRulesBuilderMaterials
materials, final AlgorithmProvidedDatabaseDiscoveryRuleConfiguration config,
- final Collection<ShardingSphereRule>
builtRules) {
- return new DatabaseDiscoveryRule(materials.getSchemaName(),
materials.getDataSourceMap(), config);
+ public DatabaseDiscoveryRule build(final
AlgorithmProvidedDatabaseDiscoveryRuleConfiguration config, final String
schemaName,
+ final Map<String, DataSource>
dataSources, final Collection<ShardingSphereRule> builtRules, final
ConfigurationProperties props) {
+ return new DatabaseDiscoveryRule(schemaName, dataSources, config);
}
@Override
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 82580ee..305b846 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
@@ -21,8 +21,8 @@ import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleCon
import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.constant.DatabaseDiscoveryOrder;
import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
import javax.sql.DataSource;
@@ -36,14 +36,15 @@ import java.util.Map;
public final class DatabaseDiscoveryRuleBuilder implements
SchemaRuleBuilder<DatabaseDiscoveryRuleConfiguration> {
@Override
- public DatabaseDiscoveryRule build(final SchemaRulesBuilderMaterials
materials, final DatabaseDiscoveryRuleConfiguration config, final
Collection<ShardingSphereRule> builtRules) {
+ public DatabaseDiscoveryRule build(final
DatabaseDiscoveryRuleConfiguration config, final String schemaName,
+ final Map<String, DataSource>
dataSources, final Collection<ShardingSphereRule> builtRules, final
ConfigurationProperties props) {
Map<String, DataSource> realDataSourceMap = new HashMap<>();
for (DatabaseDiscoveryDataSourceRuleConfiguration each :
config.getDataSources()) {
for (String datasourceName : each.getDataSourceNames()) {
- realDataSourceMap.put(datasourceName,
materials.getDataSourceMap().get(datasourceName));
+ realDataSourceMap.put(datasourceName,
dataSources.get(datasourceName));
}
}
- return new DatabaseDiscoveryRule(materials.getSchemaName(),
realDataSourceMap, config);
+ return new DatabaseDiscoveryRule(schemaName, realDataSourceMap,
config);
}
@Override
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 af98556..8d5cb1a 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
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.dbdiscovery.fixture.TestDatabaseDiscoveryType;
import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
import org.junit.Test;
@@ -36,7 +35,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public final class AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
@@ -47,15 +45,12 @@ public final class
AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
- AlgorithmProvidedDatabaseDiscoveryRuleConfiguration
algorithmProvidedRuleConfig =
mock(AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.class);
- DatabaseDiscoveryDataSourceRuleConfiguration ruleConfig = new
DatabaseDiscoveryDataSourceRuleConfiguration("name",
Collections.singletonList("name"), "", "discoveryTypeName");
-
when(algorithmProvidedRuleConfig.getDataSources()).thenReturn(Collections.singletonList(ruleConfig));
-
when(algorithmProvidedRuleConfig.getDiscoveryHeartbeats()).thenReturn(Collections.singletonMap("ha_heartbeat",
new DatabaseDiscoveryHeartBeatConfiguration(new Properties())));
-
when(algorithmProvidedRuleConfig.getDiscoveryTypes()).thenReturn(Collections.singletonMap("discoveryTypeName",
new TestDatabaseDiscoveryType()));
- SchemaRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(
- SchemaRuleBuilder.class,
Collections.singletonList(algorithmProvidedRuleConfig)).get(algorithmProvidedRuleConfig);
- assertThat(builder.build(new SchemaRulesBuilderMaterials("",
Collections.emptyList(),
- Collections.singletonMap("name", mock(DataSource.class)), new
ConfigurationProperties(new Properties())),
- algorithmProvidedRuleConfig, Collections.emptyList()),
instanceOf(DatabaseDiscoveryRule.class));
+ AlgorithmProvidedDatabaseDiscoveryRuleConfiguration
algorithmProvidedRuleConfig = new
AlgorithmProvidedDatabaseDiscoveryRuleConfiguration(
+ Collections.singletonList(new
DatabaseDiscoveryDataSourceRuleConfiguration("name",
Collections.singletonList("name"), "", "discoveryTypeName")),
+ Collections.singletonMap("ha_heartbeat",
+ new DatabaseDiscoveryHeartBeatConfiguration(new
Properties())), Collections.singletonMap("discoveryTypeName", new
TestDatabaseDiscoveryType()));
+ SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(algorithmProvidedRuleConfig)).get(algorithmProvidedRuleConfig);
+ assertThat(builder.build(algorithmProvidedRuleConfig, "",
Collections.singletonMap("name", mock(DataSource.class)),
Collections.emptyList(), new ConfigurationProperties(new Properties())),
+ 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 e3773cf..a163658 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
@@ -24,15 +24,12 @@ import
org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
import org.junit.Test;
import javax.sql.DataSource;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -48,15 +45,12 @@ public final class DatabaseDiscoveryRuleBuilderTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceConfig =
- new DatabaseDiscoveryDataSourceRuleConfiguration("name",
Collections.singletonList("name"), "", "TEST");
DatabaseDiscoveryRuleConfiguration config = new
DatabaseDiscoveryRuleConfiguration(
- Collections.singleton(dataSourceConfig),
Collections.singletonMap("ha_heartbeat", new
DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
+ Collections.singleton(new
DatabaseDiscoveryDataSourceRuleConfiguration("name",
Collections.singletonList("name"), "", "TEST")),
+ Collections.singletonMap("ha_heartbeat", new
DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
Collections.singletonMap("TEST", new
ShardingSphereAlgorithmConfiguration("TEST", new Properties())));
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(config)).get(config);
- Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
- dataSourceMap.put("name", mock(DataSource.class));
- assertThat(builder.build(new
SchemaRulesBuilderMaterials("test_schema", Collections.emptyList(),
- dataSourceMap, new ConfigurationProperties(new Properties())),
config, Collections.emptyList()), instanceOf(DatabaseDiscoveryRule.class));
+ assertThat(builder.build(config, "test_schema",
Collections.singletonMap("name", mock(DataSource.class)),
Collections.emptyList(), new ConfigurationProperties(new Properties())),
+ 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 0e8e530..b2e879e 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
@@ -20,11 +20,13 @@ package org.apache.shardingsphere.encrypt.rule.builder;
import
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
+import javax.sql.DataSource;
import java.util.Collection;
+import java.util.Map;
/**
* Algorithm provided encrypt rule builder.
@@ -32,8 +34,9 @@ import java.util.Collection;
public final class AlgorithmProvidedEncryptRuleBuilder implements
SchemaRuleBuilder<AlgorithmProvidedEncryptRuleConfiguration> {
@Override
- public EncryptRule build(final SchemaRulesBuilderMaterials materials,
final AlgorithmProvidedEncryptRuleConfiguration config, final
Collection<ShardingSphereRule> builtRules) {
- return new EncryptRule(config, materials.getDataSourceMap());
+ public EncryptRule build(final AlgorithmProvidedEncryptRuleConfiguration
config, final String schemaName,
+ final Map<String, DataSource> dataSources, final
Collection<ShardingSphereRule> builtRules, final ConfigurationProperties props)
{
+ return new EncryptRule(config, dataSources);
}
@Override
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 2dbe672..097b875 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
@@ -20,11 +20,13 @@ package org.apache.shardingsphere.encrypt.rule.builder;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
+import javax.sql.DataSource;
import java.util.Collection;
+import java.util.Map;
/**
* Encrypt rule builder.
@@ -32,8 +34,9 @@ import java.util.Collection;
public final class EncryptRuleBuilder implements
SchemaRuleBuilder<EncryptRuleConfiguration> {
@Override
- public EncryptRule build(final SchemaRulesBuilderMaterials materials,
final EncryptRuleConfiguration config, final Collection<ShardingSphereRule>
builtRules) {
- return new EncryptRule(config, materials.getDataSourceMap());
+ public EncryptRule build(final EncryptRuleConfiguration config, final
String schemaName,
+ final Map<String, DataSource> dataSources, final
Collection<ShardingSphereRule> builtRules, final ConfigurationProperties props)
{
+ return new EncryptRule(config, dataSources);
}
@Override
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 66bc0da..dd2414c 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
@@ -21,7 +21,6 @@ import
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncry
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
import org.junit.Test;
@@ -31,7 +30,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
public final class AlgorithmProvidedEncryptRuleBuilderTest {
@@ -42,9 +40,8 @@ public final class AlgorithmProvidedEncryptRuleBuilderTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
- AlgorithmProvidedEncryptRuleConfiguration ruleConfig =
mock(AlgorithmProvidedEncryptRuleConfiguration.class);
+ AlgorithmProvidedEncryptRuleConfiguration ruleConfig = new
AlgorithmProvidedEncryptRuleConfiguration();
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
- assertThat(builder.build(new SchemaRulesBuilderMaterials("",
Collections.emptyList(),
- Collections.emptyMap(), new ConfigurationProperties(new
Properties())), ruleConfig, Collections.emptyList()),
instanceOf(EncryptRule.class));
+ assertThat(builder.build(ruleConfig, "", Collections.emptyMap(),
Collections.emptyList(), new ConfigurationProperties(new Properties())),
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 54b7915..2330c64 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
@@ -21,7 +21,6 @@ import
org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
import org.junit.Test;
@@ -44,7 +43,6 @@ public final class EncryptRuleBuilderTest {
public void assertBuild() {
EncryptRuleConfiguration ruleConfig =
mock(EncryptRuleConfiguration.class);
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
- assertThat(builder.build(new SchemaRulesBuilderMaterials("",
Collections.emptyList(),
- Collections.emptyMap(), new ConfigurationProperties(new
Properties())), ruleConfig, Collections.emptyList()),
instanceOf(EncryptRule.class));
+ assertThat(builder.build(ruleConfig, "", Collections.emptyMap(),
Collections.emptyList(), new ConfigurationProperties(new Properties())),
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 fe0376b..8d6b1ee 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
@@ -17,14 +17,16 @@
package org.apache.shardingsphere.readwritesplitting.rule.builder;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
import
org.apache.shardingsphere.readwritesplitting.algorithm.config.AlgorithmProvidedReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingOrder;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
+import javax.sql.DataSource;
import java.util.Collection;
+import java.util.Map;
/**
* Algorithm provided readwrite-splitting rule builder.
@@ -32,8 +34,8 @@ import java.util.Collection;
public final class AlgorithmProvidedReadwriteSplittingRuleBuilder implements
SchemaRuleBuilder<AlgorithmProvidedReadwriteSplittingRuleConfiguration> {
@Override
- public ReadwriteSplittingRule build(final SchemaRulesBuilderMaterials
materials, final AlgorithmProvidedReadwriteSplittingRuleConfiguration config,
- final Collection<ShardingSphereRule>
builtRules) {
+ public ReadwriteSplittingRule build(final
AlgorithmProvidedReadwriteSplittingRuleConfiguration config, final String
schemaName,
+ final Map<String, DataSource>
dataSources, final Collection<ShardingSphereRule> builtRules, final
ConfigurationProperties props) {
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 7746219..b976cd0 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
@@ -17,14 +17,16 @@
package org.apache.shardingsphere.readwritesplitting.rule.builder;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingOrder;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
+import javax.sql.DataSource;
import java.util.Collection;
+import java.util.Map;
/**
* Readwrite-splitting rule builder.
@@ -32,7 +34,8 @@ import java.util.Collection;
public final class ReadwriteSplittingRuleBuilder implements
SchemaRuleBuilder<ReadwriteSplittingRuleConfiguration> {
@Override
- public ReadwriteSplittingRule build(final SchemaRulesBuilderMaterials
materials, final ReadwriteSplittingRuleConfiguration config, final
Collection<ShardingSphereRule> builtRules) {
+ public ReadwriteSplittingRule build(final
ReadwriteSplittingRuleConfiguration config, final String schemaName,
+ final Map<String, DataSource>
dataSources, final Collection<ShardingSphereRule> builtRules, final
ConfigurationProperties props) {
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 b48e438..e593960 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
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.readwritesplitting.rule.builder;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import
org.apache.shardingsphere.readwritesplitting.algorithm.config.AlgorithmProvidedReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
@@ -32,8 +31,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public final class AlgorithmProvidedReadwriteSplittingRuleBuilderTest {
@@ -44,16 +41,16 @@ public final class
AlgorithmProvidedReadwriteSplittingRuleBuilderTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
- AlgorithmProvidedReadwriteSplittingRuleConfiguration
algorithmProvidedRuleConfig =
mock(AlgorithmProvidedReadwriteSplittingRuleConfiguration.class);
- Properties props = new Properties();
- props.setProperty("write-data-source-name", "writeDataSourceName");
- props.setProperty("read-data-source-names", "readDataSourceName");
- ReadwriteSplittingDataSourceRuleConfiguration ruleConfig = new
ReadwriteSplittingDataSourceRuleConfiguration(
- "name", "Static", props, "loadBalancerName");
-
when(algorithmProvidedRuleConfig.getDataSources()).thenReturn(Collections.singletonList(ruleConfig));
- SchemaRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(
- SchemaRuleBuilder.class,
Collections.singletonList(algorithmProvidedRuleConfig)).get(algorithmProvidedRuleConfig);
- assertThat(builder.build(new SchemaRulesBuilderMaterials("",
Collections.emptyList(),
- Collections.emptyMap(), new ConfigurationProperties(new
Properties())), algorithmProvidedRuleConfig, Collections.emptyList()),
instanceOf(ReadwriteSplittingRule.class));
+ AlgorithmProvidedReadwriteSplittingRuleConfiguration ruleConfig = new
AlgorithmProvidedReadwriteSplittingRuleConfiguration(
+ Collections.singletonList(new
ReadwriteSplittingDataSourceRuleConfiguration("name", "Static",
createProperties(), "loadBalancerName")), Collections.emptyMap());
+ SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
+ assertThat(builder.build(ruleConfig, "", Collections.emptyMap(),
Collections.emptyList(), new ConfigurationProperties(new Properties())),
instanceOf(ReadwriteSplittingRule.class));
+ }
+
+ private Properties createProperties() {
+ Properties result = new Properties();
+ result.setProperty("write-data-source-name", "writeDataSourceName");
+ result.setProperty("read-data-source-names", "readDataSourceName");
+ return result;
}
}
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 426b394..e57f8a0 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
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.readwritesplitting.rule.builder;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
@@ -32,8 +31,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public final class ReadwriteSplittingRuleBuilderTest {
@@ -44,15 +41,16 @@ public final class ReadwriteSplittingRuleBuilderTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
- ReadwriteSplittingRuleConfiguration ruleConfig =
mock(ReadwriteSplittingRuleConfiguration.class);
- Properties props = new Properties();
- props.setProperty("write-data-source-name", "writeDataSourceName");
- props.setProperty("read-data-source-names", "readDataSourceName");
- ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig =
new ReadwriteSplittingDataSourceRuleConfiguration(
- "name", "Static", props, "loadBalancerName");
-
when(ruleConfig.getDataSources()).thenReturn(Collections.singletonList(dataSourceRuleConfig));
+ ReadwriteSplittingRuleConfiguration ruleConfig = new
ReadwriteSplittingRuleConfiguration(
+ Collections.singletonList(new
ReadwriteSplittingDataSourceRuleConfiguration("name", "Static",
createProperties(), "loadBalancerName")), Collections.emptyMap());
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
- assertThat(builder.build(new SchemaRulesBuilderMaterials("",
Collections.emptyList(),
- Collections.emptyMap(), new ConfigurationProperties(new
Properties())), ruleConfig, Collections.emptyList()),
instanceOf(ReadwriteSplittingRule.class));
+ assertThat(builder.build(ruleConfig, "", Collections.emptyMap(),
Collections.emptyList(), new ConfigurationProperties(new Properties())),
instanceOf(ReadwriteSplittingRule.class));
+ }
+
+ private Properties createProperties() {
+ Properties result = new Properties();
+ result.setProperty("write-data-source-name", "writeDataSourceName");
+ result.setProperty("read-data-source-names", "readDataSourceName");
+ return result;
}
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/builder/AlgorithmProvidedShadowRuleBuilder.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/builder/AlgorithmProvidedShadowRuleBuilder.java
index 3e0e624..7297315 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/builder/AlgorithmProvidedShadowRuleBuilder.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/builder/AlgorithmProvidedShadowRuleBuilder.java
@@ -17,14 +17,16 @@
package org.apache.shardingsphere.shadow.rule.builder;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
import
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
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;
/**
* Algorithm provided shadow rule builder.
@@ -32,7 +34,8 @@ import java.util.Collection;
public final class AlgorithmProvidedShadowRuleBuilder implements
SchemaRuleBuilder<AlgorithmProvidedShadowRuleConfiguration> {
@Override
- public ShadowRule build(final SchemaRulesBuilderMaterials materials, final
AlgorithmProvidedShadowRuleConfiguration config, final
Collection<ShardingSphereRule> builtRules) {
+ public ShadowRule build(final AlgorithmProvidedShadowRuleConfiguration
config, final String schemaName,
+ final Map<String, DataSource> dataSources, final
Collection<ShardingSphereRule> builtRules, final ConfigurationProperties props)
{
return new ShadowRule(config);
}
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 a54f667..8845e5e 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
@@ -17,14 +17,16 @@
package org.apache.shardingsphere.shadow.rule.builder;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
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;
/**
* Shadow rule builder.
@@ -32,7 +34,8 @@ import java.util.Collection;
public final class ShadowRuleBuilder implements
SchemaRuleBuilder<ShadowRuleConfiguration> {
@Override
- public ShadowRule build(final SchemaRulesBuilderMaterials materials, final
ShadowRuleConfiguration config, final Collection<ShardingSphereRule>
builtRules) {
+ public ShadowRule build(final ShadowRuleConfiguration config, final String
schemaName,
+ final Map<String, DataSource> dataSources, final
Collection<ShardingSphereRule> builtRules, final ConfigurationProperties props)
{
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 26494d0..969cf16 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
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.shadow.rule.builder;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
@@ -31,7 +30,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
public final class ShadowRuleBuilderTest {
@@ -42,9 +40,8 @@ public final class ShadowRuleBuilderTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
- ShadowRuleConfiguration ruleConfig =
mock(ShadowRuleConfiguration.class);
+ ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration();
SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
- assertThat(builder.build(new SchemaRulesBuilderMaterials("",
Collections.emptyList(),
- Collections.emptyMap(), new ConfigurationProperties(new
Properties())), ruleConfig, Collections.emptyList()),
instanceOf(ShadowRule.class));
+ assertThat(builder.build(ruleConfig, "", Collections.emptyMap(),
Collections.emptyList(), new ConfigurationProperties(new Properties())),
instanceOf(ShadowRule.class));
}
}
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 a8d1a6d..46c68dc 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
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.sharding.rule.builder;
import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
import
org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.constant.ShardingOrder;
@@ -35,10 +35,10 @@ import java.util.Map;
public final class AlgorithmProvidedShardingRuleBuilder implements
SchemaRuleBuilder<AlgorithmProvidedShardingRuleConfiguration> {
@Override
- public ShardingRule build(final SchemaRulesBuilderMaterials materials,
final AlgorithmProvidedShardingRuleConfiguration config, final
Collection<ShardingSphereRule> builtRules) {
- Map<String, DataSource> dataSourceMap = materials.getDataSourceMap();
- Preconditions.checkArgument(null != dataSourceMap &&
!dataSourceMap.isEmpty(), "Data sources cannot be empty.");
- return new ShardingRule(config, dataSourceMap.keySet());
+ public ShardingRule build(final AlgorithmProvidedShardingRuleConfiguration
config, final String schemaName,
+ final Map<String, DataSource> dataSources, final
Collection<ShardingSphereRule> builtRules, final ConfigurationProperties props)
{
+ Preconditions.checkArgument(null != dataSources &&
!dataSources.isEmpty(), "Data sources cannot be empty.");
+ return new ShardingRule(config, dataSources.keySet());
}
@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 2947cbf..244f0b7 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
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.sharding.rule.builder;
import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.constant.ShardingOrder;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -35,10 +35,10 @@ import java.util.Map;
public final class ShardingRuleBuilder implements
SchemaRuleBuilder<ShardingRuleConfiguration> {
@Override
- public ShardingRule build(final SchemaRulesBuilderMaterials materials,
final ShardingRuleConfiguration config, final Collection<ShardingSphereRule>
builtRules) {
- Map<String, DataSource> dataSourceMap = materials.getDataSourceMap();
- Preconditions.checkArgument(null != dataSourceMap &&
!dataSourceMap.isEmpty(), "Data source names cannot be empty.");
- return new ShardingRule(config, dataSourceMap.keySet());
+ public ShardingRule build(final ShardingRuleConfiguration config, final
String schemaName,
+ final Map<String, DataSource> dataSources, final
Collection<ShardingSphereRule> builtRules, final ConfigurationProperties props)
{
+ Preconditions.checkArgument(null != dataSources &&
!dataSources.isEmpty(), "Data source names cannot be empty.");
+ return new ShardingRule(config, dataSources.keySet());
}
@Override
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 1e2af9e..ea88046 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
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.rule.builder;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import
org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
@@ -29,7 +28,6 @@ import org.junit.Test;
import javax.sql.DataSource;
import java.util.Collections;
-import java.util.Map;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -50,32 +48,26 @@ public final class AlgorithmProvidedShardingRuleBuilderTest
{
@Before
public void setUp() {
- ruleConfig = mock(AlgorithmProvidedShardingRuleConfiguration.class);
+ ruleConfig = new AlgorithmProvidedShardingRuleConfiguration();
builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
}
@SuppressWarnings("unchecked")
@Test
public void assertBuild() {
- SchemaRulesBuilderMaterials materials =
createSchemaRulesBuilderMaterials(Collections.singletonMap("name",
mock(DataSource.class, RETURNS_DEEP_STUBS)));
- assertThat(builder.build(materials, ruleConfig,
Collections.emptyList()), instanceOf(ShardingRule.class));
+ assertThat(builder.build(ruleConfig, "test_schema",
+ Collections.singletonMap("name", mock(DataSource.class,
RETURNS_DEEP_STUBS)), Collections.emptyList(), new ConfigurationProperties(new
Properties())), instanceOf(ShardingRule.class));
}
@SuppressWarnings("unchecked")
@Test(expected = IllegalArgumentException.class)
public void assertBuildWithNullDataSourceMap() {
- SchemaRulesBuilderMaterials materials =
createSchemaRulesBuilderMaterials(null);
- assertThat(builder.build(materials, ruleConfig,
Collections.emptyList()), instanceOf(ShardingRule.class));
+ assertThat(builder.build(ruleConfig, "test_schema", null,
Collections.emptyList(), new ConfigurationProperties(new Properties())),
instanceOf(ShardingRule.class));
}
@SuppressWarnings("unchecked")
@Test(expected = IllegalArgumentException.class)
public void assertBuildWithEmptyDataSourceMap() {
- SchemaRulesBuilderMaterials materials =
createSchemaRulesBuilderMaterials(Collections.emptyMap());
- assertThat(builder.build(materials, ruleConfig,
Collections.emptyList()), instanceOf(ShardingRule.class));
- }
-
- private SchemaRulesBuilderMaterials
createSchemaRulesBuilderMaterials(final Map<String, DataSource> dataSourceMap) {
- return new SchemaRulesBuilderMaterials("test_schema",
Collections.emptyList(), dataSourceMap, new ConfigurationProperties(new
Properties()));
+ assertThat(builder.build(ruleConfig, "test_schema",
Collections.emptyMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties())), 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 3baee36..7b81125 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
@@ -19,11 +19,11 @@ package org.apache.shardingsphere.sharding.rule.builder;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
+import org.junit.Before;
import org.junit.Test;
import javax.sql.DataSource;
@@ -41,29 +41,33 @@ public final class ShardingRuleBuilderTest {
ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
}
- @SuppressWarnings({"rawtypes", "unchecked"})
+ private ShardingRuleConfiguration ruleConfig;
+
+ @SuppressWarnings("rawtypes")
+ private SchemaRuleBuilder builder;
+
+ @Before
+ public void setUp() {
+ ruleConfig = new ShardingRuleConfiguration();
+ builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
+ }
+
+ @SuppressWarnings("unchecked")
@Test
public void assertBuild() {
- ShardingRuleConfiguration ruleConfig =
mock(ShardingRuleConfiguration.class);
- SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
- assertThat(builder.build(new
SchemaRulesBuilderMaterials("test_schema", Collections.emptyList(),
Collections.singletonMap("name", mock(DataSource.class, RETURNS_DEEP_STUBS)),
- new ConfigurationProperties(new Properties())), ruleConfig,
Collections.emptyList()), instanceOf(ShardingRule.class));
+ assertThat(builder.build(ruleConfig, "test_schema",
+ Collections.singletonMap("name", mock(DataSource.class,
RETURNS_DEEP_STUBS)), Collections.emptyList(), new ConfigurationProperties(new
Properties())), instanceOf(ShardingRule.class));
}
- @SuppressWarnings({"rawtypes", "unchecked"})
+ @SuppressWarnings("unchecked")
@Test(expected = IllegalArgumentException.class)
public void assertBuildWithNullDataSourceMap() {
- ShardingRuleConfiguration ruleConfig =
mock(ShardingRuleConfiguration.class);
- SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
- builder.build(new SchemaRulesBuilderMaterials("test_schema",
Collections.emptyList(), null, new ConfigurationProperties(new Properties())),
ruleConfig, Collections.emptyList());
+ assertThat(builder.build(ruleConfig, "test_schema", null,
Collections.emptyList(), new ConfigurationProperties(new Properties())),
instanceOf(ShardingRule.class));
}
- @SuppressWarnings({"rawtypes", "unchecked"})
+ @SuppressWarnings("unchecked")
@Test(expected = IllegalArgumentException.class)
public void assertBuildWithEmptyDataSourceMap() {
- ShardingRuleConfiguration ruleConfig =
mock(ShardingRuleConfiguration.class);
- SchemaRuleBuilder builder =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class,
Collections.singletonList(ruleConfig)).get(ruleConfig);
- builder.build(new SchemaRulesBuilderMaterials("test_schema",
Collections.emptyList(),
- Collections.emptyMap(), new ConfigurationProperties(new
Properties())), ruleConfig, Collections.emptyList());
+ assertThat(builder.build(ruleConfig, "test_schema",
Collections.emptyMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties())), instanceOf(ShardingRule.class));
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilder.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilder.java
index 5add30c..f405221 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilder.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilder.java
@@ -18,11 +18,14 @@
package org.apache.shardingsphere.infra.rule.builder.schema;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.RuleBuilder;
import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule;
+import javax.sql.DataSource;
import java.util.Collection;
+import java.util.Map;
/**
* Schema rule builder.
@@ -34,10 +37,12 @@ public interface SchemaRuleBuilder<T extends
RuleConfiguration> extends RuleBuil
/**
* Build schema rule.
*
- * @param materials rules builder materials
* @param config rule configuration
+ * @param schemaName schema name
+ * @param dataSources data sources
* @param builtRules built rules
+ * @param props configuration properties
* @return built schema rule
*/
- SchemaRule build(SchemaRulesBuilderMaterials materials, T config,
Collection<ShardingSphereRule> builtRules);
+ SchemaRule build(T config, String schemaName, Map<String, DataSource>
dataSources, Collection<ShardingSphereRule> builtRules, ConfigurationProperties
props);
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java
index 48e25be..4ee99cb 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java
@@ -22,6 +22,8 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.function.DistributedRuleConfiguration;
import
org.apache.shardingsphere.infra.config.function.EnhancedRuleConfiguration;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.config.schema.SchemaConfiguration;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
@@ -49,23 +51,25 @@ public final class SchemaRulesBuilder {
/**
* Build rules.
*
- * @param materials rules builder materials
+ * @param schemaName schema name
+ * @param schemaConfig schema configuration
+ * @param props configuration properties
* @return built rules
*/
@SuppressWarnings({"unchecked", "rawtypes"})
- public static Collection<ShardingSphereRule> buildRules(final
SchemaRulesBuilderMaterials materials) {
+ public static Collection<ShardingSphereRule> buildRules(final String
schemaName, final SchemaConfiguration schemaConfig, final
ConfigurationProperties props) {
Collection<ShardingSphereRule> result = new LinkedList<>();
- for (Entry<RuleConfiguration, SchemaRuleBuilder> entry :
getRuleBuilderMap(materials).entrySet()) {
- result.add(entry.getValue().build(materials, entry.getKey(),
result));
+ for (Entry<RuleConfiguration, SchemaRuleBuilder> entry :
getRuleBuilderMap(schemaConfig).entrySet()) {
+ result.add(entry.getValue().build(entry.getKey(), schemaName,
schemaConfig.getDataSources(), result, props));
}
return result;
}
@SuppressWarnings("rawtypes")
- private static Map<RuleConfiguration, SchemaRuleBuilder>
getRuleBuilderMap(final SchemaRulesBuilderMaterials materials) {
+ private static Map<RuleConfiguration, SchemaRuleBuilder>
getRuleBuilderMap(final SchemaConfiguration schemaConfig) {
Map<RuleConfiguration, SchemaRuleBuilder> result = new
LinkedHashMap<>();
-
result.putAll(getDistributedRuleBuilderMap(materials.getSchemaRuleConfigs()));
-
result.putAll(getEnhancedRuleBuilderMap(materials.getSchemaRuleConfigs()));
+
result.putAll(getDistributedRuleBuilderMap(schemaConfig.getRuleConfigurations()));
+
result.putAll(getEnhancedRuleBuilderMap(schemaConfig.getRuleConfigurations()));
result.putAll(getMissedDefaultRuleBuilderMap(result.values()));
return result;
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderMaterials.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderMaterials.java
deleted file mode 100644
index d7f4c57..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderMaterials.java
+++ /dev/null
@@ -1,43 +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.builder.schema;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Schema rules builder materials.
- */
-@RequiredArgsConstructor
-@Getter
-public final class SchemaRulesBuilderMaterials {
-
- private final String schemaName;
-
- private final Collection<RuleConfiguration> schemaRuleConfigs;
-
- private final Map<String, DataSource> dataSourceMap;
-
- private final ConfigurationProperties props;
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestShardingSphereRuleBuilder.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestShardingSphereRuleBuilder.java
index 66439e9..6dcb499 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestShardingSphereRuleBuilder.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestShardingSphereRuleBuilder.java
@@ -18,12 +18,14 @@
package org.apache.shardingsphere.infra.fixture;
import lombok.Getter;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule;
+import javax.sql.DataSource;
import java.util.Collection;
+import java.util.Map;
public final class TestShardingSphereRuleBuilder implements
SchemaRuleBuilder<TestRuleConfiguration> {
@@ -31,7 +33,8 @@ public final class TestShardingSphereRuleBuilder implements
SchemaRuleBuilder<Te
private static final SchemaRule RULE = new TestShardingSphereRule();
@Override
- public SchemaRule build(final SchemaRulesBuilderMaterials materials, final
TestRuleConfiguration config, final Collection<ShardingSphereRule> builtRules) {
+ public SchemaRule build(final TestRuleConfiguration config, final String
schemaName,
+ final Map<String, DataSource> dataSources, final
Collection<ShardingSphereRule> builtRules, final ConfigurationProperties props)
{
return RULE;
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java
index 5ff0584..e6c49ad 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.rule.builder.schema;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.config.schema.impl.DataSourceProvidedSchemaConfiguration;
import org.apache.shardingsphere.infra.fixture.TestRuleConfiguration;
import org.apache.shardingsphere.infra.fixture.TestShardingSphereRule;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -35,8 +36,8 @@ public final class SchemaRulesBuilderTest {
@Test
public void assertBuild() {
- Collection<ShardingSphereRule> actual =
SchemaRulesBuilder.buildRules(new SchemaRulesBuilderMaterials(
- "schema_name", Collections.singleton(new
TestRuleConfiguration()), Collections.emptyMap(), new
ConfigurationProperties(new Properties())));
+ Collection<ShardingSphereRule> actual = SchemaRulesBuilder.buildRules(
+ "schema_name", new
DataSourceProvidedSchemaConfiguration(Collections.emptyMap(),
Collections.singleton(new TestRuleConfiguration())), new
ConfigurationProperties(new Properties()));
assertThat(actual.size(), is(1));
assertThat(actual.iterator().next(),
instanceOf(TestShardingSphereRule.class));
}
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilder.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilder.java
index 4115567..113a0fb 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilder.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilder.java
@@ -17,15 +17,17 @@
package org.apache.shardingsphere.singletable.rule.builder;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRecognizer;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import
org.apache.shardingsphere.singletable.config.SingleTableRuleConfiguration;
import org.apache.shardingsphere.singletable.constant.SingleTableOrder;
import org.apache.shardingsphere.singletable.rule.SingleTableRule;
+import javax.sql.DataSource;
import java.util.Collection;
+import java.util.Map;
/**
* Single table rule builder.
@@ -33,8 +35,9 @@ import java.util.Collection;
public final class SingleTableRuleBuilder implements
SchemaRuleBuilder<SingleTableRuleConfiguration> {
@Override
- public SingleTableRule build(final SchemaRulesBuilderMaterials materials,
final SingleTableRuleConfiguration config, final Collection<ShardingSphereRule>
builtRules) {
- return new SingleTableRule(config,
DatabaseTypeRecognizer.getDatabaseType(materials.getDataSourceMap().values()),
materials.getDataSourceMap(), builtRules, materials.getProps());
+ public SingleTableRule build(final SingleTableRuleConfiguration config,
final String schemaName,
+ final Map<String, DataSource> dataSources,
final Collection<ShardingSphereRule> builtRules, final ConfigurationProperties
props) {
+ return new SingleTableRule(config,
DatabaseTypeRecognizer.getDatabaseType(dataSources.values()), dataSources,
builtRules, props);
}
@Override
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilderTest.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilderTest.java
index 3e8b963..17a0b22 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilderTest.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilderTest.java
@@ -21,7 +21,6 @@ import
org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule;
import
org.apache.shardingsphere.singletable.config.SingleTableRuleConfiguration;
import org.apache.shardingsphere.singletable.rule.SingleTableRule;
@@ -39,7 +38,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public final class SingleTableRuleBuilderTest {
@@ -51,29 +49,25 @@ public final class SingleTableRuleBuilderTest {
public void assertBuild() {
Collection<SchemaRuleBuilder> builders =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class);
SchemaRuleBuilder builder = builders.iterator().next();
- SchemaRulesBuilderMaterials materials =
mock(SchemaRulesBuilderMaterials.class);
- Properties properties = new Properties();
-
properties.setProperty(ConfigurationPropertyKey.CHECK_DUPLICATE_TABLE_ENABLED.getKey(),
Boolean.FALSE.toString());
- when(materials.getProps()).thenReturn(new
ConfigurationProperties(properties));
- SingleTableRuleConfiguration configuration =
mock(SingleTableRuleConfiguration.class);
+ Properties props = new Properties();
+
props.setProperty(ConfigurationPropertyKey.CHECK_DUPLICATE_TABLE_ENABLED.getKey(),
Boolean.FALSE.toString());
+ SingleTableRuleConfiguration config =
mock(SingleTableRuleConfiguration.class);
ShardingSphereRule shardingSphereRule = mock(ShardingSphereRule.class);
- SchemaRule schemaRule = builder.build(materials, configuration,
Collections.singletonList(shardingSphereRule));
+ SchemaRule schemaRule = builder.build(config, "",
Collections.emptyMap(), Collections.singletonList(shardingSphereRule), new
ConfigurationProperties(props));
assertThat(schemaRule, instanceOf(SingleTableRule.class));
assertFalse(((SingleTableRule)
schemaRule).getDefaultDataSource().isPresent());
}
@Test
public void assertBuildWithDefaultDataSource() {
- Properties properties = new Properties();
-
properties.setProperty(ConfigurationPropertyKey.CHECK_DUPLICATE_TABLE_ENABLED.getKey(),
Boolean.FALSE.toString());
- SchemaRulesBuilderMaterials materials =
mock(SchemaRulesBuilderMaterials.class);
- when(materials.getProps()).thenReturn(new
ConfigurationProperties(properties));
+ Properties props = new Properties();
+
props.setProperty(ConfigurationPropertyKey.CHECK_DUPLICATE_TABLE_ENABLED.getKey(),
Boolean.FALSE.toString());
ShardingSphereRule shardingSphereRule = mock(ShardingSphereRule.class);
Collection<SchemaRuleBuilder> builders =
OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class);
SchemaRuleBuilder builder = builders.iterator().next();
- SingleTableRuleConfiguration configuration = new
SingleTableRuleConfiguration();
- configuration.setDefaultDataSource("ds_0");
- SchemaRule schemaRule = builder.build(materials, configuration,
Collections.singletonList(shardingSphereRule));
+ SingleTableRuleConfiguration config = new
SingleTableRuleConfiguration();
+ config.setDefaultDataSource("ds_0");
+ SchemaRule schemaRule = builder.build(config, "",
Collections.emptyMap(), Collections.singletonList(shardingSphereRule), new
ConfigurationProperties(props));
assertThat(schemaRule, instanceOf(SingleTableRule.class));
assertTrue(((SingleTableRule)
schemaRule).getDefaultDataSource().isPresent());
assertThat(((SingleTableRule)
schemaRule).getDefaultDataSource().get(), is("ds_0"));
diff --git
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilder.java
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilder.java
index dd1e2ed..c133d10 100644
---
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilder.java
@@ -31,10 +31,8 @@ import
org.apache.shardingsphere.infra.metadata.schema.loader.SchemaLoader;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
-import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
@@ -76,17 +74,15 @@ public final class MetaDataContextsBuilder {
* @throws SQLException SQL exception
*/
public void addSchema(final String schemaName, final SchemaConfiguration
schemaConfig, final Properties props) throws SQLException {
- Map<String, DataSource> dataSourceMap = schemaConfig.getDataSources();
- Collection<ShardingSphereRule> schemaRules =
getSchemaRules(schemaName, schemaConfig.getRuleConfigurations(), dataSourceMap,
props);
- ShardingSphereSchema schema = SchemaLoader.load(dataSourceMap,
schemaRules, props);
+ Collection<ShardingSphereRule> schemaRules =
getSchemaRules(schemaName, schemaConfig, props);
+ ShardingSphereSchema schema =
SchemaLoader.load(schemaConfig.getDataSources(), schemaRules, props);
schemaConfigMap.put(schemaName, schemaConfig);
schemaRulesMap.put(schemaName, schemaRules);
schemaMap.put(schemaName, schema);
}
- private Collection<ShardingSphereRule> getSchemaRules(final String
schemaName,
- final
Collection<RuleConfiguration> schemaRuleConfigs, final Map<String, DataSource>
dataSourceMap, final Properties props) {
- return SchemaRulesBuilder.buildRules(new
SchemaRulesBuilderMaterials(schemaName, schemaRuleConfigs, dataSourceMap, new
ConfigurationProperties(props)));
+ private Collection<ShardingSphereRule> getSchemaRules(final String
schemaName, final SchemaConfiguration schemaConfig, final Properties props) {
+ return SchemaRulesBuilder.buildRules(schemaName, schemaConfig, new
ConfigurationProperties(props));
}
/**
diff --git
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/fixture/FixtureRuleBuilder.java
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/fixture/FixtureRuleBuilder.java
index 189e507..245a486 100644
---
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/fixture/FixtureRuleBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/fixture/FixtureRuleBuilder.java
@@ -17,16 +17,19 @@
package org.apache.shardingsphere.mode.metadata.fixture;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.rule.builder.schema.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 SchemaRulesBuilderMaterials materials,
final FixtureRuleConfiguration config, final Collection<ShardingSphereRule>
builtRules) {
+ public FixtureRule build(final FixtureRuleConfiguration config, final
String schemaName,
+ final Map<String, DataSource> dataSources, final
Collection<ShardingSphereRule> builtRules, final ConfigurationProperties props)
{
return new FixtureRule();
}
diff --git
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/engine/AbstractSQLRewriterParameterizedTest.java
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/engine/AbstractSQLRewriterParameterizedTest.java
index 6867d9c..ad06f81 100644
---
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/engine/AbstractSQLRewriterParameterizedTest.java
+++
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/engine/AbstractSQLRewriterParameterizedTest.java
@@ -23,6 +23,8 @@ import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.config.schema.SchemaConfiguration;
+import
org.apache.shardingsphere.infra.config.schema.impl.DataSourceProvidedSchemaConfiguration;
import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
@@ -38,7 +40,6 @@ 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.schema.SchemaRulesBuilder;
-import
org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilderMaterials;
import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.swapper.YamlDataSourceConfigurationSwapper;
import
org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapperEngine;
@@ -87,9 +88,9 @@ public abstract class AbstractSQLRewriterParameterizedTest {
private Collection<SQLRewriteUnit> createSQLRewriteUnits() throws
IOException {
YamlRootConfiguration rootConfig = createRootConfiguration();
String databaseType = getTestParameters().getDatabaseType();
- Collection<ShardingSphereRule> rules =
SchemaRulesBuilder.buildRules(new SchemaRulesBuilderMaterials("schema_name",
- new
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(rootConfig.getRules()),
- new
YamlDataSourceConfigurationSwapper().swapToDataSources(rootConfig.getDataSources()),
new ConfigurationProperties(new Properties())));
+ SchemaConfiguration schemaConfig = new
DataSourceProvidedSchemaConfiguration(
+ new
YamlDataSourceConfigurationSwapper().swapToDataSources(rootConfig.getDataSources()),
new
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(rootConfig.getRules()));
+ Collection<ShardingSphereRule> rules =
SchemaRulesBuilder.buildRules("schema_name", schemaConfig, new
ConfigurationProperties(new Properties()));
mockRules(rules);
rules.add(sqlParserRule);
ConfigurationProperties props = new
ConfigurationProperties(rootConfig.getProps());