You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/04/27 05:37:48 UTC
[shardingsphere] branch master updated: Add SchemaRuleBuilderFactory (#17136)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 965fd141ad2 Add SchemaRuleBuilderFactory (#17136)
965fd141ad2 is described below
commit 965fd141ad235e9fcbf3c639aaa5581ece4f4700
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Apr 27 13:37:30 2022 +0800
Add SchemaRuleBuilderFactory (#17136)
---
...hmProvidedDatabaseDiscoveryRuleBuilderTest.java | 9 +--
.../builder/DatabaseDiscoveryRuleBuilderTest.java | 9 +--
.../AlgorithmProvidedEncryptRuleBuilderTest.java | 9 +--
.../rule/builder/EncryptRuleBuilderTest.java | 9 +--
...mProvidedReadwriteSplittingRuleBuilderTest.java | 9 +--
.../builder/ReadwriteSplittingRuleBuilderTest.java | 9 +--
.../shadow/rule/builder/ShadowRuleBuilderTest.java | 9 +--
.../AlgorithmProvidedShardingRuleBuilderTest.java | 9 +--
.../rule/builder/ShardingRuleBuilderTest.java | 9 +--
.../builder/schema/SchemaRuleBuilderFactory.java | 70 ++++++++++++++++++++++
.../rule/builder/schema/SchemaRulesBuilder.java | 7 +--
.../rule/builder/SingleTableRuleBuilderTest.java | 13 ++--
.../spi/type/ordered/OrderedSPIRegistry.java | 6 +-
13 files changed, 99 insertions(+), 78 deletions(-)
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 4dd7ab4c9e9..a1758090663 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,8 +24,7 @@ import org.apache.shardingsphere.dbdiscovery.fixture.CoreFixtureDatabaseDiscover
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.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
+import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilderFactory;
import org.junit.Test;
import javax.sql.DataSource;
@@ -38,10 +37,6 @@ import static org.mockito.Mockito.mock;
public final class AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
@@ -50,7 +45,7 @@ public final class AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
Collections.singletonMap("ha_heartbeat",
new DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
Collections.singletonMap("discoveryTypeName", new CoreFixtureDatabaseDiscoveryProviderAlgorithm()));
- SchemaRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, Collections.singletonList(algorithmProvidedRuleConfig)).get(algorithmProvidedRuleConfig);
+ SchemaRuleBuilder builder = SchemaRuleBuilderFactory.newInstance(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 a53953fae1e..2e4fb9aad54 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,8 +24,7 @@ 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.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
+import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilderFactory;
import org.junit.Test;
import javax.sql.DataSource;
@@ -38,10 +37,6 @@ import static org.mockito.Mockito.mock;
public final class DatabaseDiscoveryRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
@@ -49,7 +44,7 @@ public final class DatabaseDiscoveryRuleBuilderTest {
Collections.singleton(new DatabaseDiscoveryDataSourceRuleConfiguration("name", Collections.singletonList("name"), "", "CORE.FIXTURE")),
Collections.singletonMap("ha_heartbeat", new DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
Collections.singletonMap("CORE.FIXTURE", new ShardingSphereAlgorithmConfiguration("CORE.FIXTURE", new Properties())));
- SchemaRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, Collections.singletonList(config)).get(config);
+ SchemaRuleBuilder builder = SchemaRuleBuilderFactory.newInstance(Collections.singletonList(config)).get(config);
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/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 5f521b13558..ea3607a27d7 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,8 +21,7 @@ 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.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
+import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilderFactory;
import org.junit.Test;
import java.util.Collections;
@@ -33,15 +32,11 @@ import static org.junit.Assert.assertThat;
public final class AlgorithmProvidedEncryptRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
AlgorithmProvidedEncryptRuleConfiguration ruleConfig = new AlgorithmProvidedEncryptRuleConfiguration();
- SchemaRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, Collections.singletonList(ruleConfig)).get(ruleConfig);
+ SchemaRuleBuilder builder = SchemaRuleBuilderFactory.newInstance(Collections.singletonList(ruleConfig)).get(ruleConfig);
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 0b4a751e8e3..5c480666901 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,8 +21,7 @@ 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.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
+import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilderFactory;
import org.junit.Test;
import java.util.Collections;
@@ -34,15 +33,11 @@ import static org.mockito.Mockito.mock;
public final class EncryptRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
EncryptRuleConfiguration ruleConfig = mock(EncryptRuleConfiguration.class);
- SchemaRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, Collections.singletonList(ruleConfig)).get(ruleConfig);
+ SchemaRuleBuilder builder = SchemaRuleBuilderFactory.newInstance(Collections.singletonList(ruleConfig)).get(ruleConfig);
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/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 714162ca496..e31ecf599b6 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,11 +19,10 @@ 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.SchemaRuleBuilderFactory;
import org.apache.shardingsphere.readwritesplitting.algorithm.config.AlgorithmProvidedReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
import org.junit.Test;
import java.util.Collections;
@@ -34,16 +33,12 @@ import static org.junit.Assert.assertThat;
public final class AlgorithmProvidedReadwriteSplittingRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
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);
+ SchemaRuleBuilder builder = SchemaRuleBuilderFactory.newInstance(Collections.singletonList(ruleConfig)).get(ruleConfig);
assertThat(builder.build(ruleConfig, "", Collections.emptyMap(), Collections.emptyList(), new ConfigurationProperties(new Properties())), 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 3a8ecb3fd54..a25414d2ccf 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,11 +19,10 @@ 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.SchemaRuleBuilderFactory;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
import org.junit.Test;
import java.util.Collections;
@@ -34,16 +33,12 @@ import static org.junit.Assert.assertThat;
public final class ReadwriteSplittingRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
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);
+ SchemaRuleBuilder builder = SchemaRuleBuilderFactory.newInstance(Collections.singletonList(ruleConfig)).get(ruleConfig);
assertThat(builder.build(ruleConfig, "", Collections.emptyMap(), Collections.emptyList(), new ConfigurationProperties(new Properties())), instanceOf(ReadwriteSplittingRule.class));
}
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 fa42f052b66..3a67db23b94 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,10 +19,9 @@ 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.SchemaRuleBuilderFactory;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
import org.junit.Test;
import java.util.Collections;
@@ -33,15 +32,11 @@ import static org.junit.Assert.assertThat;
public final class ShadowRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration();
- SchemaRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, Collections.singletonList(ruleConfig)).get(ruleConfig);
+ SchemaRuleBuilder builder = SchemaRuleBuilderFactory.newInstance(Collections.singletonList(ruleConfig)).get(ruleConfig);
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/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 9018cdceac5..237d16a5eba 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,10 +19,9 @@ 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.SchemaRuleBuilderFactory;
import org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
import org.junit.Before;
import org.junit.Test;
@@ -37,10 +36,6 @@ import static org.mockito.Mockito.mock;
public final class AlgorithmProvidedShardingRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
private AlgorithmProvidedShardingRuleConfiguration ruleConfig;
@SuppressWarnings("rawtypes")
@@ -49,7 +44,7 @@ public final class AlgorithmProvidedShardingRuleBuilderTest {
@Before
public void setUp() {
ruleConfig = new AlgorithmProvidedShardingRuleConfiguration();
- builder = OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, Collections.singletonList(ruleConfig)).get(ruleConfig);
+ builder = SchemaRuleBuilderFactory.newInstance(Collections.singletonList(ruleConfig)).get(ruleConfig);
}
@SuppressWarnings("unchecked")
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 31b474b3440..125cdeca0bb 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,10 +19,9 @@ 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.SchemaRuleBuilderFactory;
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.type.ordered.OrderedSPIRegistry;
import org.junit.Before;
import org.junit.Test;
@@ -37,10 +36,6 @@ import static org.mockito.Mockito.mock;
public final class ShardingRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
private ShardingRuleConfiguration ruleConfig;
@SuppressWarnings("rawtypes")
@@ -49,7 +44,7 @@ public final class ShardingRuleBuilderTest {
@Before
public void setUp() {
ruleConfig = new ShardingRuleConfiguration();
- builder = OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, Collections.singletonList(ruleConfig)).get(ruleConfig);
+ builder = SchemaRuleBuilderFactory.newInstance(Collections.singletonList(ruleConfig)).get(ruleConfig);
}
@SuppressWarnings("unchecked")
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilderFactory.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilderFactory.java
new file mode 100644
index 00000000000..eaf5674e74c
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilderFactory.java
@@ -0,0 +1,70 @@
+/*
+ * 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.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Map;
+
+/**
+ * Schema rule builder factory.
+ */
+@SuppressWarnings("rawtypes")
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SchemaRuleBuilderFactory {
+
+ static {
+ ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
+ }
+
+ /**
+ * Create new instance of schema rule builder.
+ *
+ * @return new instance of schema rule builder
+ */
+ public static Collection<SchemaRuleBuilder> newInstance() {
+ return OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class);
+ }
+
+ /**
+ * Create new instance of schema rule builder.
+ *
+ * @param ruleConfigs rule configurations
+ * @return new instance of schema rule builder
+ */
+ public static Map<RuleConfiguration, SchemaRuleBuilder> newInstance(final Collection<RuleConfiguration> ruleConfigs) {
+ return OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, ruleConfigs);
+ }
+
+ /**
+ * Create new instance of schema rule builder.
+ *
+ * @param ruleConfigs rule configurations
+ * @param orderComparator order comparator
+ * @return new instance of schema rule builder
+ */
+ public static Map<RuleConfiguration, SchemaRuleBuilder> newInstance(final Collection<RuleConfiguration> ruleConfigs, final Comparator<Integer> orderComparator) {
+ return OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, ruleConfigs, orderComparator);
+ }
+}
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 e28fa805aad..a031167f6d1 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
@@ -44,7 +44,6 @@ import java.util.stream.Collectors;
public final class SchemaRulesBuilder {
static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
ShardingSphereServiceLoader.register(DefaultSchemaRuleConfigurationBuilder.class);
}
@@ -77,13 +76,13 @@ public final class SchemaRulesBuilder {
@SuppressWarnings("rawtypes")
private static Map<RuleConfiguration, SchemaRuleBuilder> getDistributedRuleBuilderMap(final Collection<RuleConfiguration> ruleConfigs) {
Collection<RuleConfiguration> distributedRuleConfigs = ruleConfigs.stream().filter(each -> isAssignableFrom(each, DistributedRuleConfiguration.class)).collect(Collectors.toList());
- return OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, distributedRuleConfigs, Comparator.reverseOrder());
+ return SchemaRuleBuilderFactory.newInstance(distributedRuleConfigs, Comparator.reverseOrder());
}
@SuppressWarnings("rawtypes")
private static Map<RuleConfiguration, SchemaRuleBuilder> getEnhancedRuleBuilderMap(final Collection<RuleConfiguration> ruleConfigs) {
Collection<RuleConfiguration> enhancedRuleConfigs = ruleConfigs.stream().filter(each -> isAssignableFrom(each, EnhancedRuleConfiguration.class)).collect(Collectors.toList());
- return OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class, enhancedRuleConfigs);
+ return SchemaRuleBuilderFactory.newInstance(enhancedRuleConfigs);
}
private static boolean isAssignableFrom(final RuleConfiguration ruleConfig, final Class<? extends RuleConfiguration> ruleConfigClass) {
@@ -105,6 +104,6 @@ public final class SchemaRulesBuilder {
@SuppressWarnings({"unchecked", "rawtypes"})
private static Collection<SchemaRuleBuilder> getMissedDefaultRuleBuilders(final Collection<SchemaRuleBuilder> configuredBuilders) {
Collection<Class<SchemaRuleBuilder>> configuredBuilderClasses = configuredBuilders.stream().map(each -> (Class<SchemaRuleBuilder>) each.getClass()).collect(Collectors.toSet());
- return OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class).stream().filter(each -> !configuredBuilderClasses.contains(each.getClass())).collect(Collectors.toList());
+ return SchemaRuleBuilderFactory.newInstance().stream().filter(each -> !configuredBuilderClasses.contains(each.getClass())).collect(Collectors.toList());
}
}
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 0087778f5db..ac5dabc9dfd 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,11 +21,10 @@ 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.SchemaRuleBuilderFactory;
import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule;
import org.apache.shardingsphere.singletable.config.SingleTableRuleConfiguration;
import org.apache.shardingsphere.singletable.rule.SingleTableRule;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
import org.junit.Test;
import java.util.Collection;
@@ -41,13 +40,10 @@ import static org.mockito.Mockito.mock;
public final class SingleTableRuleBuilderTest {
- static {
- ShardingSphereServiceLoader.register(SchemaRuleBuilder.class);
- }
-
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuild() {
- Collection<SchemaRuleBuilder> builders = OrderedSPIRegistry.getRegisteredServices(SchemaRuleBuilder.class);
+ Collection<SchemaRuleBuilder> builders = SchemaRuleBuilderFactory.newInstance();
SchemaRuleBuilder builder = builders.iterator().next();
Properties props = new Properties();
props.setProperty(ConfigurationPropertyKey.CHECK_DUPLICATE_TABLE_ENABLED.getKey(), Boolean.FALSE.toString());
@@ -58,12 +54,13 @@ public final class SingleTableRuleBuilderTest {
assertFalse(((SingleTableRule) schemaRule).getDefaultDataSource().isPresent());
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertBuildWithDefaultDataSource() {
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);
+ Collection<SchemaRuleBuilder> builders = SchemaRuleBuilderFactory.newInstance();
SchemaRuleBuilder builder = builders.iterator().next();
SingleTableRuleConfiguration config = new SingleTableRuleConfiguration();
config.setDefaultDataSource("ds_0");
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistry.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistry.java
index dfd8af00862..c78393c2e6c 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistry.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/ordered/OrderedSPIRegistry.java
@@ -73,16 +73,16 @@ public final class OrderedSPIRegistry {
* @param types types
* @param <K> type of key
* @param <V> type of ordered SPI class
- * @param comparator comparator
+ * @param orderComparator order comparator
* @return registered services
*/
@SuppressWarnings("unchecked")
- public static <K, V extends OrderedSPI<?>> Map<K, V> getRegisteredServices(final Class<V> spiClass, final Collection<K> types, final Comparator<Integer> comparator) {
+ public static <K, V extends OrderedSPI<?>> Map<K, V> getRegisteredServices(final Class<V> spiClass, final Collection<K> types, final Comparator<Integer> orderComparator) {
Optional<Map<K, V>> cachedServices = OrderedServicesCache.findCachedServices(spiClass, types).map(optional -> (Map<K, V>) optional);
if (cachedServices.isPresent()) {
return cachedServices.get();
}
- Collection<V> registeredServices = getRegisteredServices(spiClass, comparator);
+ Collection<V> registeredServices = getRegisteredServices(spiClass, orderComparator);
Map<K, V> result = new LinkedHashMap<>(registeredServices.size(), 1);
for (V each : registeredServices) {
types.stream().filter(type -> each.getTypeClass() == type.getClass()).forEach(type -> result.put(type, each));