You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/02/02 17:12:57 UTC
[shardingsphere] branch master updated: Remove ShardingSphereAlgorithmFactory (#23947)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 820de2fd171 Remove ShardingSphereAlgorithmFactory (#23947)
820de2fd171 is described below
commit 820de2fd1717a1486b2b042a09401b264c241c8a
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Feb 3 01:12:39 2023 +0800
Remove ShardingSphereAlgorithmFactory (#23947)
* Remove useless toString for JobRateLimitAlgorithm impls
* Remove ShardingSphereAlgorithmFactory
---
.../distsql/hint/impl/AddShardingExecutor.java | 2 +-
.../hint/impl/SetReadwriteSplittingExecutor.java | 2 +-
.../distsql/hint/impl/SetShardingExecutor.java | 2 +-
.../dbdiscovery/rule/DatabaseDiscoveryRule.java | 4 +-
.../MGRDatabaseDiscoveryProviderAlgorithmTest.java | 10 ++---
.../shardingsphere/encrypt/rule/EncryptRule.java | 12 +++---
.../algorithm/encrypt/AESEncryptAlgorithmTest.java | 10 ++---
.../algorithm/encrypt/MD5EncryptAlgorithmTest.java | 9 ++---
.../algorithm/encrypt/RC4EncryptAlgorithmTest.java | 7 ++--
.../like/CharDigestLikeEncryptAlgorithmTest.java | 14 +++----
.../merge/dql/EncryptAlgorithmMetaDataTest.java | 6 +--
.../sm/algorithm/SM3EncryptAlgorithmTest.java | 6 +--
.../sm/algorithm/SM4EncryptAlgorithmTest.java | 24 +++++++-----
.../apache/shardingsphere/mask/rule/MaskRule.java | 4 +-
.../mask/merge/dql/MaskAlgorithmMetaDataTest.java | 6 +--
...ReadwriteSplittingRuleConfigurationChecker.java | 4 +-
.../rule/ReadwriteSplittingRule.java | 12 ++++--
...icaWeightReadQueryLoadBalanceAlgorithmTest.java | 19 +++++-----
...ionWeightReadQueryLoadBalanceAlgorithmTest.java | 11 +++---
.../WeightReadQueryLoadBalanceAlgorithmTest.java | 22 +++++------
.../shardingsphere/shadow/rule/ShadowRule.java | 4 +-
.../ColumnRegexMatchShadowAlgorithmTest.java | 13 +++----
.../ColumnValueMatchShadowAlgorithmTest.java | 13 +++----
.../shadow/hint/SQLHintShadowAlgorithmTest.java | 6 +--
.../ColumnShadowAlgorithmDeterminerTest.java | 7 ++--
.../HintShadowAlgorithmDeterminerTest.java | 5 +--
.../shardingsphere/sharding/rule/ShardingRule.java | 7 ++--
...ardingConditionsShardingAuditAlgorithmTest.java | 6 +--
.../keygen/SnowflakeKeyGenerateAlgorithmTest.java | 33 +++++++----------
.../ClassBasedShardingAlgorithmTest.java | 37 ++++++++-----------
.../ComplexInlineShardingAlgorithmTest.java | 9 ++---
.../AutoIntervalShardingAlgorithmTest.java | 17 +++------
.../datetime/IntervalShardingAlgorithmTest.java | 22 +++++------
.../hint/HintInlineShardingAlgorithmTest.java | 7 ++--
.../inline/InlineShardingAlgorithmTest.java | 18 ++++-----
.../sharding/mod/HashModShardingAlgorithmTest.java | 6 +--
.../sharding/mod/ModShardingAlgorithmTest.java | 23 +++++-------
.../BoundaryBasedRangeShardingAlgorithmTest.java | 7 ++--
.../VolumeBasedRangeShardingAlgorithmTest.java | 5 +--
.../dml/ShardingInsertStatementValidatorTest.java | 7 ++--
.../dml/ShardingUpdateStatementValidatorTest.java | 6 +--
.../sharding/rule/TableRuleTest.java | 9 ++---
.../checker/ShardingTableRuleStatementChecker.java | 13 ++-----
.../keygen/CosIdKeyGenerateAlgorithmTest.java | 12 +++---
.../CosIdSnowflakeKeyGenerateAlgorithmTest.java | 15 ++++----
...osIdSnowflakeIntervalShardingAlgorithmTest.java | 11 +++---
.../IntervalShardingAlgorithmDataFixture.java | 5 +--
.../mod/CosIdModShardingAlgorithmTest.java | 6 +--
.../keygen/NanoIdKeyGenerateAlgorithmTest.java | 8 +---
.../algorithm/ShardingSphereAlgorithmFactory.java | 43 ----------------------
.../ShardingSphereAlgorithmFactoryTest.java | 39 --------------------
.../fixture/ShardingSphereAlgorithmFixture.java | 42 ---------------------
.../authority/rule/AuthorityRule.java | 4 +-
...sePermittedPrivilegesProviderAlgorithmTest.java | 6 +--
.../AbstractInventoryIncrementalJobAPIImpl.java | 4 +-
.../DataConsistencyCalculateAlgorithmChooser.java | 5 +--
...AbstractInventoryIncrementalProcessContext.java | 8 ++--
.../shardingsphere/traffic/rule/TrafficRule.java | 9 +++--
.../segment/SQLMatchTrafficAlgorithmTest.java | 7 ++--
.../segment/SQLRegexTrafficAlgorithmTest.java | 7 ++--
60 files changed, 245 insertions(+), 452 deletions(-)
diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/AddShardingExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/AddShardingExecutor.java
index afb3fd5ef71..03cea485d09 100644
--- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/AddShardingExecutor.java
+++ b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/AddShardingExecutor.java
@@ -49,7 +49,7 @@ public final class AddShardingExecutor extends AbstractHintExecutor {
private void executeShow() throws SQLException {
log.info("show ...");
ResultSet resultSet = statement.executeQuery(SHOW_STATUS);
- log.info(new Gson().toJson(getResultData(resultSet)));;
+ log.info(new Gson().toJson(getResultData(resultSet)));
}
private void executeAdd() throws SQLException {
diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/SetReadwriteSplittingExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/SetReadwriteSplittingExecutor.java
index c997c458cdd..269c9306ca1 100644
--- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/SetReadwriteSplittingExecutor.java
+++ b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/SetReadwriteSplittingExecutor.java
@@ -47,7 +47,7 @@ public final class SetReadwriteSplittingExecutor extends AbstractHintExecutor {
private void executeShow() throws SQLException {
log.info("show ...");
ResultSet resultSet = statement.executeQuery(SHOW_STATUS);
- log.info(new Gson().toJson(getResultData(resultSet)));;
+ log.info(new Gson().toJson(getResultData(resultSet)));
}
private void executeSet() throws SQLException {
diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/SetShardingExecutor.java b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/SetShardingExecutor.java
index 5ead30cf1c4..eddf92bb18e 100644
--- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/SetShardingExecutor.java
+++ b/examples/shardingsphere-proxy-example/shardingsphere-proxy-distsql-example/src/main/java/org/apache/shardingsphere/example/proxy/distsql/hint/impl/SetShardingExecutor.java
@@ -52,6 +52,6 @@ public final class SetShardingExecutor extends AbstractHintExecutor {
private void executeShow() throws SQLException {
log.info("show ...");
ResultSet resultSet = statement.executeQuery(SHOW_STATUS);
- log.info(new Gson().toJson(getResultData(resultSet)));;
+ log.info(new Gson().toJson(getResultData(resultSet)));
}
}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index 4a6749c8c67..d0c8836cdcd 100644
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -27,7 +27,6 @@ import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHe
import org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryDataSourceRuleNotFoundException;
import org.apache.shardingsphere.dbdiscovery.heartbeat.HeartbeatJob;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
@@ -42,6 +41,7 @@ import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.
import org.apache.shardingsphere.infra.schedule.CronJob;
import org.apache.shardingsphere.infra.schedule.ScheduleContext;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mode.metadata.storage.event.PrimaryDataSourceChangedEvent;
import org.apache.shardingsphere.mode.metadata.storage.event.StorageNodeDataSourceChangedEvent;
import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
@@ -92,7 +92,7 @@ public final class DatabaseDiscoveryRule implements DatabaseRule, DataSourceCont
private static Map<String, DatabaseDiscoveryProviderAlgorithm> getDiscoveryProviderAlgorithms(final Map<String, AlgorithmConfiguration> discoveryTypesConfig) {
Map<String, DatabaseDiscoveryProviderAlgorithm> result = new LinkedHashMap<>(discoveryTypesConfig.size(), 1);
for (Entry<String, AlgorithmConfiguration> entry : discoveryTypesConfig.entrySet()) {
- result.put(entry.getKey(), ShardingSphereAlgorithmFactory.createAlgorithm(entry.getValue(), DatabaseDiscoveryProviderAlgorithm.class));
+ result.put(entry.getKey(), TypedSPILoader.getService(DatabaseDiscoveryProviderAlgorithm.class, entry.getValue().getType(), entry.getValue().getProps()));
}
return result;
}
diff --git a/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryProviderAlgorithmTest.java b/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryProviderAlgorithmTest.java
index e9b165fa201..612f0e094f2 100644
--- a/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryProviderAlgorithmTest.java
+++ b/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryProviderAlgorithmTest.java
@@ -19,8 +19,7 @@ package org.apache.shardingsphere.dbdiscovery.mysql.type;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
@@ -29,7 +28,6 @@ import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -44,8 +42,7 @@ public final class MGRDatabaseDiscoveryProviderAlgorithmTest {
@Test
public void assertCheckEnvironment() throws SQLException {
- DatabaseDiscoveryProviderAlgorithm actual = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("MySQL.MGR", PropertiesBuilder.build(new Property("group-name", "foo_group"))), DatabaseDiscoveryProviderAlgorithm.class);
+ DatabaseDiscoveryProviderAlgorithm actual = TypedSPILoader.getService(DatabaseDiscoveryProviderAlgorithm.class, "MySQL.MGR", PropertiesBuilder.build(new Property("group-name", "foo_group")));
actual.checkEnvironment("foo_db", Collections.singletonList(mockEnvironmentAvailableDataSource()));
}
@@ -64,8 +61,7 @@ public final class MGRDatabaseDiscoveryProviderAlgorithmTest {
@Test
public void assertIsPrimaryInstance() throws SQLException {
- DatabaseDiscoveryProviderAlgorithm actual = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("MySQL.MGR", new Properties()), DatabaseDiscoveryProviderAlgorithm.class);
+ DatabaseDiscoveryProviderAlgorithm actual = TypedSPILoader.getService(DatabaseDiscoveryProviderAlgorithm.class, "MySQL.MGR");
assertTrue(actual.isPrimaryInstance(mockPrimaryDataSource()));
}
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
index deb8ba4876f..6c693a83595 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
@@ -27,13 +27,13 @@ import org.apache.shardingsphere.encrypt.exception.metadata.EncryptEncryptorNotF
import org.apache.shardingsphere.encrypt.exception.metadata.EncryptLikeQueryEncryptorNotFoundException;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.rewrite.sql.token.generator.aware.SchemaMetaDataAware;
import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
import org.apache.shardingsphere.infra.rule.identifier.type.TableContainedRule;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import java.util.Collection;
import java.util.Collections;
@@ -63,16 +63,16 @@ public final class EncryptRule implements DatabaseRule, TableContainedRule {
public EncryptRule(final EncryptRuleConfiguration ruleConfig) {
configuration = ruleConfig;
- ruleConfig.getEncryptors().forEach((key, value) -> putAllEncryptors(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, EncryptAlgorithm.class)));
+ ruleConfig.getEncryptors().forEach((key, value) -> putAllEncryptors(key, TypedSPILoader.getService(EncryptAlgorithm.class, value.getType(), value.getProps())));
ruleConfig.getTables().forEach(each -> tables.put(each.getName().toLowerCase(), new EncryptTable(each)));
queryWithCipherColumn = ruleConfig.isQueryWithCipherColumn();
}
- private void putAllEncryptors(final String encryptorName, final EncryptAlgorithm encryptAlgorithm) {
- if (encryptAlgorithm instanceof StandardEncryptAlgorithm) {
- standardEncryptors.put(encryptorName, (StandardEncryptAlgorithm) encryptAlgorithm);
+ private void putAllEncryptors(final String encryptorName, final EncryptAlgorithm algorithm) {
+ if (algorithm instanceof StandardEncryptAlgorithm) {
+ standardEncryptors.put(encryptorName, (StandardEncryptAlgorithm) algorithm);
} else {
- likeEncryptors.put(encryptorName, (LikeEncryptAlgorithm) encryptAlgorithm);
+ likeEncryptors.put(encryptorName, (LikeEncryptAlgorithm) algorithm);
}
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithmTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithmTest.java
index ceb50b28f4f..5afa9243fc3 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithmTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithmTest.java
@@ -21,15 +21,12 @@ import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlg
import org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
@@ -39,14 +36,15 @@ public final class AESEncryptAlgorithmTest {
private StandardEncryptAlgorithm<Object, String> encryptAlgorithm;
+ @SuppressWarnings("unchecked")
@Before
public void setUp() {
- encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("AES", PropertiesBuilder.build(new Property("aes-key-value", "test"))), EncryptAlgorithm.class);
+ encryptAlgorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "AES", PropertiesBuilder.build(new Property("aes-key-value", "test")));
}
@Test(expected = EncryptAlgorithmInitializationException.class)
public void assertCreateNewInstanceWithoutAESKey() {
- ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("AES", new Properties()), EncryptAlgorithm.class);
+ TypedSPILoader.getService(EncryptAlgorithm.class, "AES");
}
@Test
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/MD5EncryptAlgorithmTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/MD5EncryptAlgorithmTest.java
index db01507703b..6ec9cce9617 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/MD5EncryptAlgorithmTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/MD5EncryptAlgorithmTest.java
@@ -20,15 +20,12 @@ package org.apache.shardingsphere.encrypt.algorithm.encrypt;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
@@ -38,10 +35,10 @@ public final class MD5EncryptAlgorithmTest {
private StandardEncryptAlgorithm<Object, String> encryptAlgorithm;
+ @SuppressWarnings("unchecked")
@Before
public void setUp() {
-
- encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MD5", new Properties()), EncryptAlgorithm.class);
+ encryptAlgorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "MD5");
}
@Test
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithmTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithmTest.java
index ed1f08aa361..fbbfb645d00 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithmTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithmTest.java
@@ -21,8 +21,7 @@ import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlg
import org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
@@ -40,10 +39,10 @@ public final class RC4EncryptAlgorithmTest {
private StandardEncryptAlgorithm<Object, String> encryptAlgorithm;
+ @SuppressWarnings("unchecked")
@Before
public void setUp() {
- encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("RC4", PropertiesBuilder.build(new Property("rc4-key-value", "test-sharding"))), EncryptAlgorithm.class);
+ encryptAlgorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "RC4", PropertiesBuilder.build(new Property("rc4-key-value", "test-sharding")));
}
@Test
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithmTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithmTest.java
index 4b0358a3137..93f6c9ebfb3 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithmTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithmTest.java
@@ -20,15 +20,12 @@ package org.apache.shardingsphere.encrypt.algorithm.like;
import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
@@ -42,12 +39,13 @@ public final class CharDigestLikeEncryptAlgorithmTest {
private LikeEncryptAlgorithm<Object, String> koreanLikeEncryptAlgorithm;
+ @SuppressWarnings("unchecked")
@Before
public void setUp() {
- englishLikeEncryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CHAR_DIGEST_LIKE", new Properties()), EncryptAlgorithm.class);
- chineseLikeEncryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CHAR_DIGEST_LIKE", new Properties()), EncryptAlgorithm.class);
- koreanLikeEncryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("CHAR_DIGEST_LIKE", PropertiesBuilder.build(new Property("dict", "한국어시험"), new Property("start", "44032"))), EncryptAlgorithm.class);
+ englishLikeEncryptAlgorithm = (LikeEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "CHAR_DIGEST_LIKE");
+ chineseLikeEncryptAlgorithm = (LikeEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "CHAR_DIGEST_LIKE");
+ koreanLikeEncryptAlgorithm = (LikeEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class,
+ "CHAR_DIGEST_LIKE", PropertiesBuilder.build(new Property("dict", "한국어시험"), new Property("start", "44032")));
}
@Test
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
index 299cc4b53c5..ca798765fcf 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
@@ -21,17 +21,16 @@ import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlg
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.binder.segment.select.projection.ProjectionsContext;
import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.DerivedProjection;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,7 +43,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -89,7 +87,7 @@ public final class EncryptAlgorithmMetaDataTest {
when(selectStatementContext.getDatabaseType()).thenReturn(new MySQLDatabaseType());
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
- encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MD5", new Properties()), EncryptAlgorithm.class);
+ encryptAlgorithm = (StandardEncryptAlgorithm<?, ?>) TypedSPILoader.getService(EncryptAlgorithm.class, "MD5");
}
@Test
diff --git a/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM3EncryptAlgorithmTest.java b/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM3EncryptAlgorithmTest.java
index 00910900876..5b6758f2817 100644
--- a/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM3EncryptAlgorithmTest.java
+++ b/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM3EncryptAlgorithmTest.java
@@ -20,8 +20,7 @@ package org.apache.shardingsphere.encrypt.sm.algorithm;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
@@ -38,9 +37,10 @@ public final class SM3EncryptAlgorithmTest {
private StandardEncryptAlgorithm<Object, String> encryptAlgorithm;
+ @SuppressWarnings("unchecked")
@Before
public void setUp() {
- encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM3", PropertiesBuilder.build(new Property("sm3-salt", "test1234"))), EncryptAlgorithm.class);
+ encryptAlgorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "SM3", PropertiesBuilder.build(new Property("sm3-salt", "test1234")));
}
@Test
diff --git a/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM4EncryptAlgorithmTest.java b/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM4EncryptAlgorithmTest.java
index 75687dd6572..ea9334929de 100644
--- a/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM4EncryptAlgorithmTest.java
+++ b/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM4EncryptAlgorithmTest.java
@@ -21,8 +21,7 @@ import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlg
import org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
@@ -38,31 +37,34 @@ public final class SM4EncryptAlgorithmTest {
@Test(expected = EncryptAlgorithmInitializationException.class)
public void assertInitWithoutKey() {
- StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
- algorithm.init(PropertiesBuilder.build(new Property("sm4-mode", "ECB"), new Property("sm4-padding", "PKCS5Padding")));
+ TypedSPILoader.getService(EncryptAlgorithm.class, "SM4", PropertiesBuilder.build(new Property("sm4-mode", "ECB"), new Property("sm4-padding", "PKCS5Padding")));
}
+ @SuppressWarnings("unchecked")
@Test
public void assertEncryptNullValue() {
- StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
+ StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "SM4", createECBProperties());
assertNull(algorithm.encrypt(null, mock(EncryptContext.class)));
}
+ @SuppressWarnings("unchecked")
@Test
public void assertEncryptWithECBMode() {
- StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
+ StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "SM4", createECBProperties());
assertThat(algorithm.encrypt("test", mock(EncryptContext.class)), is("028654f2ca4f575dee9e1faae85dadde"));
}
+ @SuppressWarnings("unchecked")
@Test
public void assertDecryptNullValue() {
- StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
+ StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "SM4", createECBProperties());
assertNull(algorithm.decrypt(null, mock(EncryptContext.class)));
}
+ @SuppressWarnings("unchecked")
@Test
public void assertDecryptWithECBMode() {
- StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
+ StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "SM4", createECBProperties());
assertThat(algorithm.decrypt("028654f2ca4f575dee9e1faae85dadde", mock(EncryptContext.class)).toString(), is("test"));
}
@@ -70,15 +72,17 @@ public final class SM4EncryptAlgorithmTest {
return PropertiesBuilder.build(new Property("sm4-key", "4D744E003D713D054E7E407C350E447E"), new Property("sm4-mode", "ECB"), new Property("sm4-padding", "PKCS5Padding"));
}
+ @SuppressWarnings("unchecked")
@Test
public void assertEncryptWithCBCMode() {
- StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createCBCProperties()), EncryptAlgorithm.class);
+ StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "SM4", createCBCProperties());
assertThat(algorithm.encrypt("test", mock(EncryptContext.class)), is("dca2127b57ba8cac36a0914e0208dc11"));
}
+ @SuppressWarnings("unchecked")
@Test
public void assertDecrypt() {
- StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createCBCProperties()), EncryptAlgorithm.class);
+ StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) TypedSPILoader.getService(EncryptAlgorithm.class, "SM4", createCBCProperties());
assertThat(algorithm.decrypt("dca2127b57ba8cac36a0914e0208dc11", mock(EncryptContext.class)).toString(), is("test"));
}
diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java
index ebaeacd6d85..139b2489a8f 100644
--- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java
+++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java
@@ -18,10 +18,10 @@
package org.apache.shardingsphere.mask.rule;
import lombok.Getter;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
import org.apache.shardingsphere.infra.rule.identifier.type.TableContainedRule;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
@@ -45,7 +45,7 @@ public final class MaskRule implements DatabaseRule, TableContainedRule {
public MaskRule(final MaskRuleConfiguration ruleConfig) {
configuration = ruleConfig;
- ruleConfig.getMaskAlgorithms().forEach((key, value) -> maskAlgorithms.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, MaskAlgorithm.class)));
+ ruleConfig.getMaskAlgorithms().forEach((key, value) -> maskAlgorithms.put(key, TypedSPILoader.getService(MaskAlgorithm.class, value.getType(), value.getProps())));
ruleConfig.getTables().forEach(each -> tables.put(each.getName().toLowerCase(), new MaskTable(each)));
}
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaDataTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaDataTest.java
index 11a2267fc79..c7ca045390a 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaDataTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaDataTest.java
@@ -17,13 +17,12 @@
package org.apache.shardingsphere.mask.merge.dql;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mask.rule.MaskRule;
import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.junit.Before;
@@ -35,7 +34,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import java.util.Optional;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -62,7 +60,7 @@ public final class MaskAlgorithmMetaDataTest {
@Before
public void setUp() {
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
- maskAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MD5", new Properties()), MaskAlgorithm.class);
+ maskAlgorithm = TypedSPILoader.getService(MaskAlgorithm.class, "MD5");
}
@SuppressWarnings("rawtypes")
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
index 05dea72b19b..611bf4333c3 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
@@ -19,13 +19,13 @@ package org.apache.shardingsphere.readwritesplitting.checker;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.expr.InlineExpressionParser;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.WeightAware;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -157,7 +157,7 @@ public final class ReadwriteSplittingRuleConfigurationChecker implements RuleCon
private Map<String, ReadQueryLoadBalanceAlgorithm> getLoadBalancer(final ReadwriteSplittingRuleConfiguration config) {
Map<String, ReadQueryLoadBalanceAlgorithm> result = new LinkedHashMap<>(config.getLoadBalancers().size(), 1);
- config.getLoadBalancers().forEach((key, value) -> result.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, ReadQueryLoadBalanceAlgorithm.class)));
+ config.getLoadBalancers().forEach((key, value) -> result.put(key, TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, value.getType(), value.getProps())));
return result;
}
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
index b0747acfc86..101682eb36b 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.readwritesplitting.rule;
import com.google.common.base.Preconditions;
import lombok.Getter;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
@@ -68,9 +68,13 @@ public final class ReadwriteSplittingRule implements DatabaseRule, DataSourceCon
public ReadwriteSplittingRule(final ReadwriteSplittingRuleConfiguration ruleConfig, final Collection<ShardingSphereRule> builtRules) {
configuration = ruleConfig;
- ruleConfig.getDataSources().stream().filter(each -> null != ruleConfig.getLoadBalancers().get(each.getLoadBalancerName()))
- .forEach(each -> loadBalancers.put(each.getName() + "." + each.getLoadBalancerName(),
- ShardingSphereAlgorithmFactory.createAlgorithm(ruleConfig.getLoadBalancers().get(each.getLoadBalancerName()), ReadQueryLoadBalanceAlgorithm.class)));
+ for (ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfiguration : ruleConfig.getDataSources()) {
+ if (ruleConfig.getLoadBalancers().containsKey(dataSourceRuleConfiguration.getLoadBalancerName())) {
+ AlgorithmConfiguration algorithmConfig = ruleConfig.getLoadBalancers().get(dataSourceRuleConfiguration.getLoadBalancerName());
+ loadBalancers.put(dataSourceRuleConfiguration.getName() + "." + dataSourceRuleConfiguration.getLoadBalancerName(),
+ TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, algorithmConfig.getType(), algorithmConfig.getProps()));
+ }
+ }
dataSourceRules = new HashMap<>(ruleConfig.getDataSources().size(), 1);
for (ReadwriteSplittingDataSourceRuleConfiguration each : ruleConfig.getDataSources()) {
dataSourceRules.putAll(createReadwriteSplittingDataSourceRules(each, builtRules));
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest.java
index d82040f0616..055eb06cd81 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.context.transaction.TransactionConnectionContext;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
@@ -49,8 +48,8 @@ public final class FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetSingleReadDataSourceInTransaction() {
- ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("FIXED_REPLICA_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"))), ReadQueryLoadBalanceAlgorithm.class);
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(
+ ReadQueryLoadBalanceAlgorithm.class, "FIXED_REPLICA_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5")));
TransactionConnectionContext context = new TransactionConnectionContext();
context.setInTransaction(true);
String routeDataSource = loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", Collections.singletonList("test_read_ds_1"), context);
@@ -60,8 +59,8 @@ public final class FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetMultipleReadDataSourcesWithoutTransaction() {
- ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration(
- "FIXED_REPLICA_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5"))), ReadQueryLoadBalanceAlgorithm.class);
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class,
+ "FIXED_REPLICA_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5")));
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
@@ -76,8 +75,8 @@ public final class FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetMultipleReadDataSourcesInTransaction() {
- ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration(
- "FIXED_REPLICA_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5"))), ReadQueryLoadBalanceAlgorithm.class);
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class,
+ "FIXED_REPLICA_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5")));
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
@@ -92,8 +91,8 @@ public final class FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetDataSourceWhenReadDataSourceChanged() {
- ReadQueryLoadBalanceAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration(
- "FIXED_REPLICA_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "1"), new Property("test_read_ds_2", "2"))), ReadQueryLoadBalanceAlgorithm.class);
+ ReadQueryLoadBalanceAlgorithm algorithm = TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class,
+ "FIXED_REPLICA_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "1"), new Property("test_read_ds_2", "2")));
algorithm.getDataSource("ds", "test_write_ds", Arrays.asList("test_read_ds_1", "test_read_ds_1"), new TransactionConnectionContext());
assertThat(algorithm.getDataSource("ds", "test_write_ds", Collections.singletonList("test_read_ds_1"), new TransactionConnectionContext()), is("test_read_ds_1"));
}
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/TransactionWeightReadQueryLoadBalanceAlgorithmTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/TransactionWeightReadQueryLoadBalanceAlgorithmTest.java
index 3e4b4328bdf..3fac838c1ed 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/TransactionWeightReadQueryLoadBalanceAlgorithmTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/TransactionWeightReadQueryLoadBalanceAlgorithmTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.context.transaction.TransactionConnectionContext;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
@@ -38,8 +37,8 @@ public final class TransactionWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetSingleReadDataSource() {
- TransactionWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("TRANSACTION_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"))), ReadQueryLoadBalanceAlgorithm.class);
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(
+ ReadQueryLoadBalanceAlgorithm.class, "TRANSACTION_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5")));
TransactionConnectionContext context = new TransactionConnectionContext();
context.setInTransaction(true);
assertThat(loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", Collections.singletonList("test_read_ds_1"), context), is("test_read_ds_1"));
@@ -47,8 +46,8 @@ public final class TransactionWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetMultipleReadDataSources() {
- TransactionWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration(
- "TRANSACTION_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5"))), ReadQueryLoadBalanceAlgorithm.class);
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(
+ ReadQueryLoadBalanceAlgorithm.class, "TRANSACTION_WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5")));
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithmTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithmTest.java
index 3babf6b9912..1216f3c3d87 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithmTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithmTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.context.transaction.TransactionConnectionContext;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
@@ -37,15 +36,14 @@ public final class WeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetSingleReadDataSource() {
- WeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"))), ReadQueryLoadBalanceAlgorithm.class);
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, "WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5")));
assertThat(loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", Collections.singletonList("test_read_ds_1"), new TransactionConnectionContext()), is("test_read_ds_1"));
}
@Test
public void assertGetMultipleReadDataSources() {
- WeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5"))), ReadQueryLoadBalanceAlgorithm.class);
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class,
+ "WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5")));
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
@@ -57,8 +55,8 @@ public final class WeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetReadDataSourceInTransaction() {
- WeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5"))), ReadQueryLoadBalanceAlgorithm.class);
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class,
+ "WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5")));
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
@@ -70,9 +68,9 @@ public final class WeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetDataSourceWhenReadDataSourceChanged() {
- WeightReadQueryLoadBalanceAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "1"), new Property("test_read_ds_2", "2"))), ReadQueryLoadBalanceAlgorithm.class);
- algorithm.getDataSource("ds", "test_write_ds", Arrays.asList("test_read_ds_1", "test_read_ds_1"), new TransactionConnectionContext());
- assertThat(algorithm.getDataSource("ds", "test_write_ds", Collections.singletonList("test_read_ds_1"), new TransactionConnectionContext()), is("test_read_ds_1"));
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class,
+ "WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5")));
+ loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", Arrays.asList("test_read_ds_1", "test_read_ds_1"), new TransactionConnectionContext());
+ assertThat(loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", Collections.singletonList("test_read_ds_1"), new TransactionConnectionContext()), is("test_read_ds_1"));
}
}
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
index e371db88069..3717a86e333 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.shadow.rule;
import lombok.Getter;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
@@ -74,7 +74,7 @@ public final class ShadowRule implements DatabaseRule, DataSourceContainedRule {
private void initShadowAlgorithmConfigurations(final Map<String, AlgorithmConfiguration> shadowAlgorithmConfigs) {
shadowAlgorithmConfigs.forEach((key, value) -> {
- ShadowAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(value, ShadowAlgorithm.class);
+ ShadowAlgorithm algorithm = TypedSPILoader.getService(ShadowAlgorithm.class, value.getType(), value.getProps());
if (algorithm instanceof HintShadowAlgorithm<?>) {
hintShadowAlgorithmNames.add(key);
}
diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
index 38532684ce3..607034a99d0 100644
--- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
+++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
@@ -17,16 +17,13 @@
package org.apache.shardingsphere.shadow.algorithm.shadow.column;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.exception.data.UnsupportedShadowColumnTypeException;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
-import java.util.Properties;
-
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -34,16 +31,16 @@ public final class ColumnRegexMatchShadowAlgorithmTest extends AbstractColumnSha
@Test
public void assertIsShadow() {
- Properties props = PropertiesBuilder.build(new Property("column", SHADOW_COLUMN), new Property("operation", "insert"), new Property("regex", "[1]"));
- ColumnRegexMatchedShadowAlgorithm shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("REGEX_MATCH", props), ShadowAlgorithm.class);
+ ColumnRegexMatchedShadowAlgorithm shadowAlgorithm = (ColumnRegexMatchedShadowAlgorithm) TypedSPILoader.getService(ShadowAlgorithm.class,
+ "REGEX_MATCH", PropertiesBuilder.build(new Property("column", SHADOW_COLUMN), new Property("operation", "insert"), new Property("regex", "[1]")));
createPreciseColumnShadowValuesFalseCase().forEach(each -> assertFalse(shadowAlgorithm.isShadow(each)));
createPreciseColumnShadowValuesTrueCase().forEach(each -> assertTrue(shadowAlgorithm.isShadow(each)));
}
@Test(expected = UnsupportedShadowColumnTypeException.class)
public void assertExceptionCase() {
- Properties props = PropertiesBuilder.build(new Property("column", SHADOW_COLUMN), new Property("operation", "insert"), new Property("regex", "[1]"));
- ColumnRegexMatchedShadowAlgorithm shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("REGEX_MATCH", props), ShadowAlgorithm.class);
+ ColumnRegexMatchedShadowAlgorithm shadowAlgorithm = (ColumnRegexMatchedShadowAlgorithm) TypedSPILoader.getService(ShadowAlgorithm.class,
+ "REGEX_MATCH", PropertiesBuilder.build(new Property("column", SHADOW_COLUMN), new Property("operation", "insert"), new Property("regex", "[1]")));
createPreciseColumnShadowValuesExceptionCase().forEach(each -> assertFalse(shadowAlgorithm.isShadow(each)));
}
}
diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
index 9f86009200e..b62db17807e 100644
--- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
+++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
@@ -17,16 +17,13 @@
package org.apache.shardingsphere.shadow.algorithm.shadow.column;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.exception.data.UnsupportedShadowColumnTypeException;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
-import java.util.Properties;
-
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -34,16 +31,16 @@ public final class ColumnValueMatchShadowAlgorithmTest extends AbstractColumnSha
@Test
public void assertIsShadow() {
- Properties props = PropertiesBuilder.build(new Property("column", SHADOW_COLUMN), new Property("operation", "insert"), new Property("value", "1"));
- ColumnValueMatchedShadowAlgorithm shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("VALUE_MATCH", props), ShadowAlgorithm.class);
+ ColumnValueMatchedShadowAlgorithm shadowAlgorithm = (ColumnValueMatchedShadowAlgorithm) TypedSPILoader.getService(ShadowAlgorithm.class,
+ "VALUE_MATCH", PropertiesBuilder.build(new Property("column", SHADOW_COLUMN), new Property("operation", "insert"), new Property("value", "1")));
createPreciseColumnShadowValuesTrueCase().forEach(each -> assertTrue(shadowAlgorithm.isShadow(each)));
createPreciseColumnShadowValuesFalseCase().forEach(each -> assertFalse(shadowAlgorithm.isShadow(each)));
}
@Test(expected = UnsupportedShadowColumnTypeException.class)
public void assertExceptionCase() {
- Properties props = PropertiesBuilder.build(new Property("column", SHADOW_COLUMN), new Property("operation", "insert"), new Property("value", "1"));
- ColumnValueMatchedShadowAlgorithm shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("VALUE_MATCH", props), ShadowAlgorithm.class);
+ ColumnValueMatchedShadowAlgorithm shadowAlgorithm = (ColumnValueMatchedShadowAlgorithm) TypedSPILoader.getService(ShadowAlgorithm.class,
+ "VALUE_MATCH", PropertiesBuilder.build(new Property("column", SHADOW_COLUMN), new Property("operation", "insert"), new Property("value", "1")));
createPreciseColumnShadowValuesExceptionCase().forEach(each -> assertFalse(shadowAlgorithm.isShadow(each)));
}
}
diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SQLHintShadowAlgorithmTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SQLHintShadowAlgorithmTest.java
index 0767c692cf5..1c6376cb3d9 100644
--- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SQLHintShadowAlgorithmTest.java
+++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SQLHintShadowAlgorithmTest.java
@@ -17,8 +17,7 @@
package org.apache.shardingsphere.shadow.algorithm.shadow.hint;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.hint.PreciseHintShadowValue;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
@@ -38,8 +37,7 @@ public final class SQLHintShadowAlgorithmTest {
@Before
public void init() {
- shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("SIMPLE_HINT", PropertiesBuilder.build(new Property("shadow", Boolean.TRUE.toString()))), ShadowAlgorithm.class);
+ shadowAlgorithm = (SQLHintShadowAlgorithm) TypedSPILoader.getService(ShadowAlgorithm.class, "SIMPLE_HINT", PropertiesBuilder.build(new Property("shadow", Boolean.TRUE.toString())));
}
@Test
diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java
index 826d149b67c..7c82a339d05 100644
--- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java
+++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.shadow.route.engine.determiner;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
+import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
@@ -34,11 +34,12 @@ import static org.junit.Assert.assertTrue;
public final class ColumnShadowAlgorithmDeterminerTest {
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void assertIsShadow() {
Properties props = PropertiesBuilder.build(new Property("column", "user_id"), new Property("operation", "insert"), new Property("regex", "[1]"));
assertTrue(ColumnShadowAlgorithmDeterminer.isShadow(
- ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("REGEX_MATCH", props), ShadowAlgorithm.class), createShadowDetermineCondition()));
+ (ColumnShadowAlgorithm) TypedSPILoader.getService(ShadowAlgorithm.class, "REGEX_MATCH", props), createShadowDetermineCondition()));
}
private ShadowDetermineCondition createShadowDetermineCondition() {
diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java
index 9ff09ad8b7c..013b2c728cd 100644
--- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java
+++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.shadow.route.engine.determiner;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
@@ -42,8 +42,7 @@ public final class HintShadowAlgorithmDeterminerTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertIsShadow() {
- HintShadowAlgorithm hintShadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("SIMPLE_HINT", PropertiesBuilder.build(new Property("foo", "foo_value"))), ShadowAlgorithm.class);
+ HintShadowAlgorithm hintShadowAlgorithm = (HintShadowAlgorithm) TypedSPILoader.getService(ShadowAlgorithm.class, "SIMPLE_HINT", PropertiesBuilder.build(new Property("foo", "foo_value")));
assertTrue(HintShadowAlgorithmDeterminer.isShadow(hintShadowAlgorithm, createShadowDetermineCondition(), new ShadowRule(createShadowRuleConfiguration())));
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index d8f982f5e41..9b8c88f2052 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.sharding.rule;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import lombok.Getter;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
@@ -118,9 +117,9 @@ public final class ShardingRule implements DatabaseRule, DataNodeContainedRule,
public ShardingRule(final ShardingRuleConfiguration ruleConfig, final Collection<String> dataSourceNames, final InstanceContext instanceContext) {
configuration = ruleConfig;
this.dataSourceNames = getDataSourceNames(ruleConfig.getTables(), ruleConfig.getAutoTables(), dataSourceNames);
- ruleConfig.getShardingAlgorithms().forEach((key, value) -> shardingAlgorithms.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, ShardingAlgorithm.class)));
- ruleConfig.getKeyGenerators().forEach((key, value) -> keyGenerators.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, KeyGenerateAlgorithm.class)));
- ruleConfig.getAuditors().forEach((key, value) -> auditors.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, ShardingAuditAlgorithm.class)));
+ ruleConfig.getShardingAlgorithms().forEach((key, value) -> shardingAlgorithms.put(key, TypedSPILoader.getService(ShardingAlgorithm.class, value.getType(), value.getProps())));
+ ruleConfig.getKeyGenerators().forEach((key, value) -> keyGenerators.put(key, TypedSPILoader.getService(KeyGenerateAlgorithm.class, value.getType(), value.getProps())));
+ ruleConfig.getAuditors().forEach((key, value) -> auditors.put(key, TypedSPILoader.getService(ShardingAuditAlgorithm.class, value.getType(), value.getProps())));
tableRules.putAll(createTableRules(ruleConfig.getTables(), ruleConfig.getDefaultKeyGenerateStrategy()));
tableRules.putAll(createAutoTableRules(ruleConfig.getAutoTables(), ruleConfig.getDefaultKeyGenerateStrategy()));
broadcastTables = createBroadcastTables(ruleConfig.getBroadcastTables());
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithmTest.java
index 528b3c41374..55d6e7d9cb6 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithmTest.java
@@ -17,13 +17,12 @@
package org.apache.shardingsphere.sharding.algorithm.audit;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.executor.audit.exception.SQLAuditException;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.spi.ShardingAuditAlgorithm;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatement;
@@ -32,7 +31,6 @@ import org.junit.Before;
import org.junit.Test;
import java.util.Collections;
-import java.util.Properties;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -53,7 +51,7 @@ public final class DMLShardingConditionsShardingAuditAlgorithmTest {
@Before
public void setUp() {
- shardingAuditAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()), ShardingAuditAlgorithm.class);
+ shardingAuditAlgorithm = TypedSPILoader.getService(ShardingAuditAlgorithm.class, "DML_SHARDING_CONDITIONS");
sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
rule = mock(ShardingRule.class);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
index f373da62162..7dcabf7160f 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.sharding.algorithm.keygen;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -28,6 +26,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.algorithm.keygen.fixture.FixedTimeService;
import org.apache.shardingsphere.sharding.algorithm.keygen.fixture.WorkerIdGeneratorFixture;
import org.apache.shardingsphere.sharding.exception.algorithm.keygen.KeyGenerateAlgorithmInitializationException;
@@ -74,7 +73,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
int threadNumber = Runtime.getRuntime().availableProcessors() * 2;
ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
int taskNumber = threadNumber * 4;
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE");
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -88,7 +87,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKeyWithSingleThread() {
SnowflakeKeyGenerateAlgorithm.setTimeService(new FixedTimeService(1));
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE");
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -103,8 +102,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertLastDigitalOfGenerateKeySameMillisecond() {
SnowflakeKeyGenerateAlgorithm.setTimeService(new FixedTimeService(5));
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "3"))), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "3")));
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -118,8 +116,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertLastDigitalOfGenerateKeyDifferentMillisecond() throws InterruptedException {
SnowflakeKeyGenerateAlgorithm.setTimeService(new TimeService());
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "3"))), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "3")));
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -143,7 +140,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
public void assertGenerateKeyWithClockCallBack() {
TimeService timeService = new FixedTimeService(1);
SnowflakeKeyGenerateAlgorithm.setTimeService(timeService);
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE");
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -160,8 +157,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
public void assertGenerateKeyWithClockCallBackBeyondTolerateTime() {
TimeService timeService = new FixedTimeService(1);
SnowflakeKeyGenerateAlgorithm.setTimeService(timeService);
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-tolerate-time-difference-milliseconds", "0"))), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE", PropertiesBuilder.build(new Property("max-tolerate-time-difference-milliseconds", "0")));
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -177,7 +173,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
public void assertGenerateKeyBeyondMaxSequencePerMilliSecond() {
TimeService timeService = new FixedTimeService(2);
SnowflakeKeyGenerateAlgorithm.setTimeService(timeService);
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE");
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -203,7 +199,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test(expected = IllegalArgumentException.class)
public void assertSetWorkerIdFailureWhenNegative() {
- SnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ SnowflakeKeyGenerateAlgorithm algorithm = (SnowflakeKeyGenerateAlgorithm) TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE");
InstanceContext instanceContext = new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), new WorkerIdGeneratorFixture(-1),
new ModeConfiguration("Standalone", null), mock(ModeContextManager.class), mock(LockContext.class), new EventBusContext());
algorithm.setInstanceContext(instanceContext);
@@ -212,13 +208,12 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test(expected = KeyGenerateAlgorithmInitializationException.class)
public void assertSetMaxVibrationOffsetFailureWhenNegative() {
- ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "-1"))), KeyGenerateAlgorithm.class)).generateKey();
+ TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "-1"))).generateKey();
}
@Test(expected = IllegalArgumentException.class)
public void assertSetWorkerIdFailureWhenOutOfRange() {
- SnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ SnowflakeKeyGenerateAlgorithm algorithm = (SnowflakeKeyGenerateAlgorithm) TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE");
InstanceContext instanceContext = new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), new WorkerIdGeneratorFixture(Integer.MIN_VALUE),
new ModeConfiguration("Standalone", null), mock(ModeContextManager.class), mock(LockContext.class), new EventBusContext());
algorithm.setInstanceContext(instanceContext);
@@ -227,14 +222,12 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test(expected = KeyGenerateAlgorithmInitializationException.class)
public void assertSetMaxVibrationOffsetFailureWhenOutOfRange() {
- ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "4096"))), KeyGenerateAlgorithm.class)).generateKey();
+ TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "4096"))).generateKey();
}
@Test
public void assertSetMaxTolerateTimeDifferenceMilliseconds() throws ReflectiveOperationException {
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-tolerate-time-difference-milliseconds", "1"))), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "SNOWFLAKE", PropertiesBuilder.build(new Property("max-tolerate-time-difference-milliseconds", "1")));
assertThat(((Properties) Plugins.getMemberAccessor().get(algorithm.getClass().getDeclaredField("props"), algorithm)).getProperty("max-tolerate-time-difference-milliseconds"), is("1"));
}
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmTest.java
index 90f599920c1..03c2eec6175 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmTest.java
@@ -18,9 +18,8 @@
package org.apache.shardingsphere.sharding.algorithm.sharding.classbased;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.complex.ComplexKeysShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.hint.HintShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
@@ -37,7 +36,6 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -46,46 +44,43 @@ public final class ClassBasedShardingAlgorithmTest {
@Test(expected = ShardingAlgorithmInitializationException.class)
public void assertInitWithNullStrategy() {
- Properties props = PropertiesBuilder.build();
- ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
+ TypedSPILoader.getService(ShardingAlgorithm.class, "CLASS_BASED");
}
@Test(expected = IllegalArgumentException.class)
public void assertInitWithWrongStrategy() {
- Properties props = PropertiesBuilder.build(new Property("strategy", "wrong"));
- ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
+ TypedSPILoader.getService(ShardingAlgorithm.class, "CLASS_BASED", PropertiesBuilder.build(new Property("strategy", "wrong")));
}
@Test(expected = ShardingAlgorithmInitializationException.class)
public void assertInitWithNullClass() {
- Properties props = PropertiesBuilder.build(new Property("strategy", "standard"));
- ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
+ TypedSPILoader.getService(ShardingAlgorithm.class, "CLASS_BASED", PropertiesBuilder.build(new Property("strategy", "standard")));
}
@Test(expected = ClassNotFoundException.class)
public void assertInitWithUndefinedClass() {
- Properties props = PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", "org.apache.shardingsphere.sharding.UndefinedClass"));
- ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
+ TypedSPILoader.getService(ShardingAlgorithm.class,
+ "CLASS_BASED", PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", "org.apache.shardingsphere.sharding.UndefinedClass")));
}
@Test(expected = ShardingAlgorithmClassImplementationException.class)
public void assertInitWithMismatchStrategy() {
- Properties props = PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", ClassBasedComplexKeysShardingAlgorithmFixture.class.getName()));
- ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
+ TypedSPILoader.getService(ShardingAlgorithm.class,
+ "CLASS_BASED", PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", ClassBasedComplexKeysShardingAlgorithmFixture.class.getName())));
}
@Test
public void assertPreciseDoSharding() {
- Properties props = PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", ClassBasedStandardShardingAlgorithmFixture.class.getName()));
- ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
+ ClassBasedShardingAlgorithm algorithm = (ClassBasedShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class,
+ "CLASS_BASED", PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", ClassBasedStandardShardingAlgorithmFixture.class.getName())));
Collection<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
assertThat(algorithm.doSharding(availableTargetNames, new PreciseShardingValue<>("t_order", "order_id", new DataNodeInfo("t_order_", 1, '0'), 0)), is("t_order_0"));
}
@Test
public void assertRangeDoSharding() {
- Properties props = PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", ClassBasedStandardShardingAlgorithmFixture.class.getName()));
- ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
+ ClassBasedShardingAlgorithm algorithm = (ClassBasedShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class,
+ "CLASS_BASED", PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", ClassBasedStandardShardingAlgorithmFixture.class.getName())));
Collection<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
Collection<String> actual = algorithm.doSharding(availableTargetNames, new RangeShardingValue<>("t_order", "order_id", new DataNodeInfo("t_order_", 1, '0'), Range.closed(2, 15)));
assertThat(actual.size(), is(4));
@@ -93,8 +88,8 @@ public final class ClassBasedShardingAlgorithmTest {
@Test
public void assertComplexKeysDoSharding() {
- Properties props = PropertiesBuilder.build(new Property("strategy", "complex"), new Property("algorithmClassName", ClassBasedComplexKeysShardingAlgorithmFixture.class.getName()));
- ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
+ ClassBasedShardingAlgorithm algorithm = (ClassBasedShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class,
+ "CLASS_BASED", PropertiesBuilder.build(new Property("strategy", "complex"), new Property("algorithmClassName", ClassBasedComplexKeysShardingAlgorithmFixture.class.getName())));
Collection<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
Collection<String> actual = algorithm.doSharding(availableTargetNames, new ComplexKeysShardingValue<>("t_order", null, null));
assertThat(actual.size(), is(4));
@@ -102,8 +97,8 @@ public final class ClassBasedShardingAlgorithmTest {
@Test
public void assertHintDoSharding() {
- Properties props = PropertiesBuilder.build(new Property("strategy", "hint"), new Property("algorithmClassName", ClassBasedHintShardingAlgorithmFixture.class.getName()));
- ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
+ ClassBasedShardingAlgorithm algorithm = (ClassBasedShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class,
+ "CLASS_BASED", PropertiesBuilder.build(new Property("strategy", "hint"), new Property("algorithmClassName", ClassBasedHintShardingAlgorithmFixture.class.getName())));
Collection<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
Collection<String> actual = algorithm.doSharding(availableTargetNames, new HintShardingValue<>("t_order", "order_id", null));
assertThat(actual.size(), is(4));
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithmTest.java
index 6a8e3417205..508e611841b 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithmTest.java
@@ -18,8 +18,7 @@
package org.apache.shardingsphere.sharding.algorithm.sharding.complex;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.complex.ComplexKeysShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -41,7 +40,7 @@ public final class ComplexInlineShardingAlgorithmTest {
@Test
public void assertDoSharding() {
Properties props = PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${type % 2}_${order_id % 2}"), new Property("sharding-columns", "type,order_id"));
- ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COMPLEX_INLINE", props), ShardingAlgorithm.class);
+ ComplexInlineShardingAlgorithm algorithm = (ComplexInlineShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "COMPLEX_INLINE", props);
List<String> availableTargetNames = Arrays.asList("t_order_0_0", "t_order_0_1", "t_order_1_0", "t_order_1_1");
Collection<String> actual = algorithm.doSharding(availableTargetNames, createComplexKeysShardingValue(Collections.singletonList(2)));
assertTrue(1 == actual.size() && actual.contains("t_order_0_0"));
@@ -50,7 +49,7 @@ public final class ComplexInlineShardingAlgorithmTest {
@Test
public void assertDoShardingWithMultiValue() {
Properties props = PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${type % 2}_${order_id % 2}"), new Property("sharding-columns", "type,order_id"));
- ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COMPLEX_INLINE", props), ShardingAlgorithm.class);
+ ComplexInlineShardingAlgorithm algorithm = (ComplexInlineShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "COMPLEX_INLINE", props);
List<String> availableTargetNames = Arrays.asList("t_order_0_0", "t_order_0_1", "t_order_1_0", "t_order_1_1");
Collection<String> actual = algorithm.doSharding(availableTargetNames, createComplexKeysShardingValue(Arrays.asList(1, 2)));
assertTrue(actual.containsAll(availableTargetNames));
@@ -67,7 +66,7 @@ public final class ComplexInlineShardingAlgorithmTest {
public void assertDoShardingWithRangeValue() {
Properties props = PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${type % 2}_${order_id % 2}"),
new Property("sharding-columns", "type,order_id"), new Property("allow-range-query-with-inline-sharding", Boolean.TRUE.toString()));
- ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COMPLEX_INLINE", props), ShardingAlgorithm.class);
+ ComplexInlineShardingAlgorithm algorithm = (ComplexInlineShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "COMPLEX_INLINE", props);
List<String> availableTargetNames = Arrays.asList("t_order_0_0", "t_order_0_1", "t_order_1_0", "t_order_1_1");
Collection<String> actual = algorithm.doSharding(availableTargetNames, new ComplexKeysShardingValue<>("t_order", Collections.emptyMap(), Collections.singletonMap("type", Range.all())));
assertTrue(actual.containsAll(availableTargetNames));
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithmTest.java
index e5f2f3a1ed4..c4fc9960dcc 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithmTest.java
@@ -18,9 +18,8 @@
package org.apache.shardingsphere.sharding.algorithm.sharding.datetime;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
@@ -47,8 +46,8 @@ public final class AutoIntervalShardingAlgorithmTest {
@Before
public void setup() {
- shardingAlgorithm = createAutoIntervalShardingAlgorithm(PropertiesBuilder.build(
- new Property("datetime-lower", "2020-01-01 00:00:00"), new Property("datetime-upper", "2020-01-01 00:00:16"), new Property("sharding-seconds", "4")));
+ shardingAlgorithm = (AutoIntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "AUTO_INTERVAL",
+ PropertiesBuilder.build(new Property("datetime-lower", "2020-01-01 00:00:00"), new Property("datetime-upper", "2020-01-01 00:00:16"), new Property("sharding-seconds", "4")));
}
@Test
@@ -111,14 +110,14 @@ public final class AutoIntervalShardingAlgorithmTest {
public void assertGetAutoTablesAmount() {
Properties props = PropertiesBuilder.build(
new Property("datetime-lower", "2020-01-01 00:00:00"), new Property("datetime-upper", "2021-01-01 00:00:00"), new Property("sharding-seconds", "86400"));
- assertThat(createAutoIntervalShardingAlgorithm(props).getAutoTablesAmount(), is(368));
+ assertThat(((AutoIntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "AUTO_INTERVAL", props)).getAutoTablesAmount(), is(368));
}
@Test
public void assertRangeDoShardingWithGreaterTenTables() {
Properties props = PropertiesBuilder.build(
new Property("datetime-lower", "2020-01-01 00:00:00"), new Property("datetime-upper", "2020-01-01 00:00:30"), new Property("sharding-seconds", "1"));
- AutoIntervalShardingAlgorithm shardingAlgorithm = createAutoIntervalShardingAlgorithm(props);
+ AutoIntervalShardingAlgorithm shardingAlgorithm = (AutoIntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "AUTO_INTERVAL", props);
List<String> availableTargetNames = new LinkedList<>();
for (int i = 0; i < 32; i++) {
availableTargetNames.add("t_order_" + i);
@@ -132,7 +131,7 @@ public final class AutoIntervalShardingAlgorithmTest {
public void assertRangeDoShardingInValueWithMilliseconds() {
Properties props = PropertiesBuilder.build(
new Property("datetime-lower", "2020-01-01 00:00:00"), new Property("datetime-upper", "2020-01-01 00:00:30"), new Property("sharding-seconds", "1"));
- AutoIntervalShardingAlgorithm shardingAlgorithm = createAutoIntervalShardingAlgorithm(props);
+ AutoIntervalShardingAlgorithm shardingAlgorithm = (AutoIntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "AUTO_INTERVAL", props);
List<String> availableTargetNames = new LinkedList<>();
for (int i = 0; i < 32; i++) {
availableTargetNames.add("t_order_" + i);
@@ -150,8 +149,4 @@ public final class AutoIntervalShardingAlgorithmTest {
new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed("2020-01-01 00:00:11.123", "2020-01-01 00:00:21.123")));
assertThat(actualWithThreeMilliseconds.size(), is(11));
}
-
- private AutoIntervalShardingAlgorithm createAutoIntervalShardingAlgorithm(final Properties props) {
- return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("AUTO_INTERVAL", props), ShardingAlgorithm.class);
- }
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
index 59f58458bf8..d79257557ff 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
@@ -19,9 +19,8 @@ package org.apache.shardingsphere.sharding.algorithm.sharding.datetime;
import com.google.common.collect.Range;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
@@ -114,7 +113,7 @@ public final class IntervalShardingAlgorithmTest {
new Property("sharding-suffix-pattern", "yyyyQQ"),
new Property("datetime-interval-amount", "3"),
new Property("datetime-interval-unit", "Months"));
- shardingAlgorithmByQuarter = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
+ shardingAlgorithmByQuarter = (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
for (int i = 2016; i <= 2020; i++) {
for (int j = 1; j <= 4; j++) {
availableTablesForQuarterDataSources.add(String.format("t_order_%04d%02d", i, j));
@@ -130,7 +129,7 @@ public final class IntervalShardingAlgorithmTest {
new Property("sharding-suffix-pattern", "yyyyMM"),
new Property("datetime-interval-amount", "1"),
new Property("datetime-interval-unit", "Months"));
- shardingAlgorithmByMonth = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
+ shardingAlgorithmByMonth = (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
for (int i = 2016; i <= 2020; i++) {
for (int j = 1; j <= 12; j++) {
availableTablesForMonthDataSources.add(String.format("t_order_%04d%02d", i, j));
@@ -146,7 +145,7 @@ public final class IntervalShardingAlgorithmTest {
new Property("datetime-upper", "2021-07-31 00:00:00"),
new Property("sharding-suffix-pattern", "yyyyMMdd"),
new Property("datetime-interval-amount", Integer.toString(stepAmount)));
- shardingAlgorithmByDay = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
+ shardingAlgorithmByDay = (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
for (int j = 6; j <= 7; j++) {
for (int i = 1; j == 6 ? i <= 30 : i <= 31; i = i + stepAmount) {
availableTablesForDayDataSources.add(String.format("t_order_%04d%02d%02d", 2021, j, i));
@@ -163,8 +162,7 @@ public final class IntervalShardingAlgorithmTest {
new Property("sharding-suffix-pattern", "yyyyMMdd"),
new Property("datetime-interval-amount", Integer.toString(stepAmount)),
new Property("datetime-interval-unit", "DAYS"));
- shardingAlgorithmByDayWithMillisecond = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
+ shardingAlgorithmByDayWithMillisecond = (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
for (int j = 6; j <= 7; j++) {
for (int i = 1; j == 6 ? i <= 30 : i <= 31; i = i + stepAmount) {
availableTablesForDayWithMillisecondDataSources.add(String.format("t_order_%04d%02d%02d", 2021, j, i));
@@ -180,7 +178,7 @@ public final class IntervalShardingAlgorithmTest {
new Property("datetime-upper", "2021-07-31"),
new Property("sharding-suffix-pattern", "yyyyMMdd"),
new Property("datetime-interval-amount", Integer.toString(stepAmount)));
- shardingAlgorithmByJDBCDate = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
+ shardingAlgorithmByJDBCDate = (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
for (int j = 6; j <= 7; j++) {
for (int i = 1; j == 6 ? i <= 30 : i <= 31; i = i + stepAmount) {
availableTablesForJDBCDateDataSources.add(String.format("t_order_%04d%02d%02d", 2021, j, i));
@@ -197,7 +195,7 @@ public final class IntervalShardingAlgorithmTest {
new Property("sharding-suffix-pattern", "HHmm"),
new Property("datetime-interval-amount", Integer.toString(stepAmount)),
new Property("datetime-interval-unit", "Hours"));
- shardingAlgorithmByJDBCTime = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
+ shardingAlgorithmByJDBCTime = (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
for (int i = 2; i < 13; i++) {
availableTablesForJDBCTimeDataSources.add(String.format("t_order_%02d%02d", i, 0));
}
@@ -212,7 +210,7 @@ public final class IntervalShardingAlgorithmTest {
new Property("sharding-suffix-pattern", "yyyy"),
new Property("datetime-interval-amount", Integer.toString(stepAmount)),
new Property("datetime-interval-unit", "Years"));
- shardingAlgorithmByYear = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
+ shardingAlgorithmByYear = (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
for (int i = 2000; i < 2023; i++) {
availableTablesForYearDataSources.add(String.format("t_order_%04d", i));
}
@@ -227,7 +225,7 @@ public final class IntervalShardingAlgorithmTest {
new Property("sharding-suffix-pattern", "yyyyMM"),
new Property("datetime-interval-amount", Integer.toString(stepAmount)),
new Property("datetime-interval-unit", "Years"));
- shardingAlgorithmByYearMonth = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
+ shardingAlgorithmByYearMonth = (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
for (int i = 2016; i <= 2021; i++) {
for (int j = 1; j <= 12; j++) {
availableTablesForYearMonthDataSources.add(String.format("t_order_%04d%02d", i, j));
@@ -244,7 +242,7 @@ public final class IntervalShardingAlgorithmTest {
new Property("sharding-suffix-pattern", "MM"),
new Property("datetime-interval-amount", Integer.toString(stepAmount)),
new Property("datetime-interval-unit", "Months"));
- shardingAlgorithmByMonthInJSR310 = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
+ shardingAlgorithmByMonthInJSR310 = (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
for (int i = 2; i < 13; i++) {
availableTablesForMonthInJSR310DataSources.add(String.format("t_order_%02d", i));
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/hint/HintInlineShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/hint/HintInlineShardingAlgorithmTest.java
index 41926732856..2be8a0418ab 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/hint/HintInlineShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/hint/HintInlineShardingAlgorithmTest.java
@@ -17,8 +17,7 @@
package org.apache.shardingsphere.sharding.algorithm.sharding.hint;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.hint.HintShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -42,8 +41,8 @@ public final class HintInlineShardingAlgorithmTest {
@Before
public void setUp() {
- hintInlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("HINT_INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_$->{value % 4}"))), ShardingAlgorithm.class);
+ hintInlineShardingAlgorithm = (HintInlineShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class,
+ "HINT_INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_$->{value % 4}")));
hintInlineShardingAlgorithmDefault = new HintInlineShardingAlgorithm();
hintInlineShardingAlgorithmDefault.init(new Properties());
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
index 535a63ab7e3..4fd2223acd7 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
@@ -19,9 +19,8 @@ package org.apache.shardingsphere.sharding.algorithm.sharding.inline;
import com.google.common.collect.Lists;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.exception.algorithm.sharding.MismatchedInlineShardingAlgorithmExpressionAndColumnException;
@@ -35,7 +34,6 @@ import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -54,14 +52,12 @@ public final class InlineShardingAlgorithmTest {
@Before
public void setUp() {
- Properties allowRangeQueryProps = PropertiesBuilder.build(
- new Property("algorithm-expression", "t_order_$->{order_id % 4}"), new Property("allow-range-query-with-inline-sharding", Boolean.TRUE.toString()));
- inlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", allowRangeQueryProps), ShardingAlgorithm.class);
- Properties disallowRangeQueryProps = PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${order_id % 4}"));
- inlineShardingAlgorithmWithSimplified = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", disallowRangeQueryProps), ShardingAlgorithm.class);
- Properties negativeAllowRangeQuery = PropertiesBuilder.build(
- new Property("algorithm-expression", "t_order_$->{(order_id % 4).abs()}"), new Property("allow-range-query-with-inline-sharding", Boolean.TRUE.toString()));
- negativeNumberInlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", negativeAllowRangeQuery), ShardingAlgorithm.class);
+ inlineShardingAlgorithm = (InlineShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INLINE",
+ PropertiesBuilder.build(new Property("algorithm-expression", "t_order_$->{order_id % 4}"), new Property("allow-range-query-with-inline-sharding", Boolean.TRUE.toString())));
+ inlineShardingAlgorithmWithSimplified = (InlineShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INLINE",
+ PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${order_id % 4}")));
+ negativeNumberInlineShardingAlgorithm = (InlineShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INLINE",
+ PropertiesBuilder.build(new Property("algorithm-expression", "t_order_$->{(order_id % 4).abs()}"), new Property("allow-range-query-with-inline-sharding", Boolean.TRUE.toString())));
}
@Test(expected = MismatchedInlineShardingAlgorithmExpressionAndColumnException.class)
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithmTest.java
index da25c5913cf..c182624d0d6 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithmTest.java
@@ -18,9 +18,8 @@
package org.apache.shardingsphere.sharding.algorithm.sharding.mod;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
@@ -44,8 +43,7 @@ public final class HashModShardingAlgorithmTest {
@Before
public void setup() {
- shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("HASH_MOD", PropertiesBuilder.build(new Property("sharding-count", "4"))), ShardingAlgorithm.class);
+ shardingAlgorithm = (HashModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "HASH_MOD", PropertiesBuilder.build(new Property("sharding-count", "4")));
}
@Test
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java
index 85b08344e95..471b646e4e6 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java
@@ -18,9 +18,8 @@
package org.apache.shardingsphere.sharding.algorithm.sharding.mod;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.exception.algorithm.sharding.ShardingAlgorithmInitializationException;
@@ -43,30 +42,26 @@ public final class ModShardingAlgorithmTest {
@Test
public void assertPreciseDoShardingWithIntShardingValue() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "16"))), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", PropertiesBuilder.build(new Property("sharding-count", "16")));
assertThat(algorithm.doSharding(createAvailableTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, 17)), is("t_order_1"));
}
@Test
public void assertPreciseDoShardingWithBigIntegerShardingValue() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "16"))), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", PropertiesBuilder.build(new Property("sharding-count", "16")));
assertThat(algorithm.doSharding(createAvailableTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_12"));
}
@Test
public void assertRangeDoShardingWithAllTargets() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "16"))), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", PropertiesBuilder.build(new Property("sharding-count", "16")));
Collection<String> actual = algorithm.doSharding(createAvailableTargetNames(), new RangeShardingValue<>("t_order", "order_id", DATA_NODE_INFO, Range.closed(1L, 16L)));
assertThat(actual.size(), is(16));
}
@Test
public void assertRangeDoShardingWithPartTargets() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "16"))), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", PropertiesBuilder.build(new Property("sharding-count", "16")));
Collection<String> actual = algorithm.doSharding(createAvailableTargetNames(),
new RangeShardingValue<>("t_order", "order_id", DATA_NODE_INFO, Range.closed(1L, 2L)));
assertThat(actual.size(), is(2));
@@ -81,13 +76,13 @@ public final class ModShardingAlgorithmTest {
@Test
public void assertPreciseDoShardingWithValueIsBigIntegerAndZeroPadding() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createZeroPaddingProperties()), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", createZeroPaddingProperties());
assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07"));
}
@Test
public void assertRangeDoShardingWithAllTargetsZeroPadding() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createZeroPaddingProperties()), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", createZeroPaddingProperties());
Collection<String> actual = algorithm.doSharding(createAvailableIncludeZeroTargetNames(),
new RangeShardingValue<>("t_order", "order_id", DATA_NODE_INFO, Range.closed(1L, 16L)));
assertThat(actual.size(), is(16));
@@ -97,7 +92,7 @@ public final class ModShardingAlgorithmTest {
public void assertRangeDoShardingWithWrongArgumentForStartOffset() {
Properties props = createZeroPaddingProperties();
props.setProperty("start-offset", "-1");
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", props), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", props);
assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07"));
}
@@ -105,7 +100,7 @@ public final class ModShardingAlgorithmTest {
public void assertRangeDoShardingWithWrongArgumentForStopOffset() {
Properties props = createZeroPaddingProperties();
props.setProperty("stop-offset", "-1");
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", props), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", props);
assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07"));
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithmTest.java
index 2a5fa210f51..6a3f5f5070e 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithmTest.java
@@ -18,9 +18,8 @@
package org.apache.shardingsphere.sharding.algorithm.sharding.range;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
@@ -45,8 +44,8 @@ public final class BoundaryBasedRangeShardingAlgorithmTest {
@Before
public void setUp() {
- shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("BOUNDARY_RANGE", PropertiesBuilder.build(new Property("sharding-ranges", "1,5,10"))), ShardingAlgorithm.class);
+ shardingAlgorithm = (BoundaryBasedRangeShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class,
+ "BOUNDARY_RANGE", PropertiesBuilder.build(new Property("sharding-ranges", "1,5,10")));
}
@Test
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithmTest.java
index 8051d240a7b..735830e1538 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithmTest.java
@@ -18,9 +18,8 @@
package org.apache.shardingsphere.sharding.algorithm.sharding.range;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
@@ -46,7 +45,7 @@ public final class VolumeBasedRangeShardingAlgorithmTest {
@Before
public void setUp() {
- shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("VOLUME_RANGE", createProperties()), ShardingAlgorithm.class);
+ shardingAlgorithm = (VolumeBasedRangeShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "VOLUME_RANGE", createProperties());
}
private Properties createProperties() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
index b407e24f3dd..04b48328c6f 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
@@ -17,11 +17,9 @@
package org.apache.shardingsphere.sharding.route.engine.validator.dml;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
@@ -34,6 +32,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.exception.algorithm.sharding.DuplicateInsertDataRecordException;
import org.apache.shardingsphere.sharding.exception.syntax.DMLWithMultipleShardingTablesException;
@@ -227,8 +226,8 @@ public final class ShardingInsertStatementValidatorTest {
when(databaseStrategyConfig.getShardingColumn()).thenReturn("id");
when(databaseStrategyConfig.getShardingAlgorithmName()).thenReturn("database_inline");
when(shardingRule.getDatabaseShardingStrategyConfiguration(tableRule)).thenReturn(databaseStrategyConfig);
- when(shardingRule.getShardingAlgorithms()).thenReturn(Collections.singletonMap("database_inline", ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${id % 2}"))), ShardingAlgorithm.class)));
+ when(shardingRule.getShardingAlgorithms()).thenReturn(Collections.singletonMap("database_inline",
+ TypedSPILoader.getService(ShardingAlgorithm.class, "INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${id % 2}")))));
}
private RouteContext createSingleRouteContext() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
index 07371b2951f..596f5f8ec2f 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
@@ -17,16 +17,15 @@
package org.apache.shardingsphere.sharding.route.engine.validator.dml;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.exception.syntax.DMLWithMultipleShardingTablesException;
import org.apache.shardingsphere.sharding.exception.syntax.UnsupportedUpdatingShardingValueException;
@@ -137,8 +136,7 @@ public final class ShardingUpdateStatementValidatorTest {
}
private Map<String, ShardingAlgorithm> createShardingAlgorithmMap() {
- return Collections.singletonMap("database_inline", ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${id % 2}"))), ShardingAlgorithm.class));
+ return Collections.singletonMap("database_inline", TypedSPILoader.getService(ShardingAlgorithm.class, "INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${id % 2}"))));
}
private RouteContext createSingleRouteContext() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
index 17e8c4e454f..640f99266de 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
@@ -17,10 +17,9 @@
package org.apache.shardingsphere.sharding.rule;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.algorithm.sharding.mod.ModShardingAlgorithm;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -82,8 +81,7 @@ public final class TableRuleTest {
public void assertCreateAutoTableRuleWithModAlgorithm() {
ShardingAutoTableRuleConfiguration tableRuleConfig = new ShardingAutoTableRuleConfiguration("LOGIC_TABLE", "ds0,ds1");
tableRuleConfig.setShardingStrategy(new StandardShardingStrategyConfiguration("col_1", "MOD"));
- ModShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "4"))), ShardingAlgorithm.class);
+ ModShardingAlgorithm shardingAlgorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", PropertiesBuilder.build(new Property("sharding-count", "4")));
TableRule actual = new TableRule(tableRuleConfig, Arrays.asList("ds0", "ds1", "ds2"), shardingAlgorithm, null);
assertThat(actual.getLogicTable(), is("LOGIC_TABLE"));
assertThat(actual.getActualDataNodes().size(), is(4));
@@ -97,8 +95,7 @@ public final class TableRuleTest {
public void assertCreateAutoTableRuleWithModAlgorithmWithoutActualDataSources() {
ShardingAutoTableRuleConfiguration tableRuleConfig = new ShardingAutoTableRuleConfiguration("LOGIC_TABLE", null);
tableRuleConfig.setShardingStrategy(new StandardShardingStrategyConfiguration("col_1", "MOD"));
- ModShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "4"))), ShardingAlgorithm.class);
+ ModShardingAlgorithm shardingAlgorithm = (ModShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "MOD", PropertiesBuilder.build(new Property("sharding-count", "4")));
TableRule actual = new TableRule(tableRuleConfig, Arrays.asList("ds0", "ds1", "ds2"), shardingAlgorithm, null);
assertThat(actual.getLogicTable(), is("LOGIC_TABLE"));
assertThat(actual.getActualDataNodes().size(), is(4));
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
index d03caf0211a..36b346dc80b 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
@@ -25,8 +25,6 @@ import org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfi
import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
@@ -143,7 +141,7 @@ public final class ShardingTableRuleStatementChecker {
Collection<String> allDataSourceNames = getDataSourceNames(checkedConfig.getTables(), checkedConfig.getAutoTables(), dataSourceNames);
Map<String, ShardingAlgorithm> shardingAlgorithms = new HashMap<>(checkedConfig.getShardingAlgorithms().size(), 1);
Map<String, TableRule> tableRules = new HashMap<>();
- checkedConfig.getShardingAlgorithms().forEach((key, value) -> shardingAlgorithms.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, ShardingAlgorithm.class)));
+ checkedConfig.getShardingAlgorithms().forEach((key, value) -> shardingAlgorithms.put(key, TypedSPILoader.getService(ShardingAlgorithm.class, value.getType(), value.getProps())));
tableRules.putAll(createTableRules(checkedConfig.getTables(), checkedConfig.getDefaultKeyGenerateStrategy(), allDataSourceNames));
tableRules.putAll(createAutoTableRules(checkedConfig.getAutoTables(), shardingAlgorithms, checkedConfig.getDefaultKeyGenerateStrategy(), allDataSourceNames));
Collection<String> broadcastTables = createBroadcastTables(checkedConfig.getBroadcastTables());
@@ -289,8 +287,7 @@ public final class ShardingTableRuleStatementChecker {
ShardingSpherePreconditions.checkState(TypedSPILoader.findService(
ShardingAlgorithm.class, each.getShardingAlgorithmSegment().getName(), each.getShardingAlgorithmSegment().getProps()).isPresent(),
() -> new InvalidAlgorithmConfigurationException("sharding", each.getShardingAlgorithmSegment().getName()));
- ShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration(each.getShardingAlgorithmSegment().getName(), each.getShardingAlgorithmSegment().getProps()), ShardingAlgorithm.class);
+ ShardingAlgorithm shardingAlgorithm = TypedSPILoader.getService(ShardingAlgorithm.class, each.getShardingAlgorithmSegment().getName(), each.getShardingAlgorithmSegment().getProps());
ShardingSpherePreconditions.checkState(shardingAlgorithm instanceof ShardingAutoTableAlgorithm, () -> new InvalidAlgorithmConfigurationException("sharding", shardingAlgorithm.getType(),
String.format("auto sharding algorithm is required for rule `%s`", each.getLogicTable())));
});
@@ -311,8 +308,7 @@ public final class ShardingTableRuleStatementChecker {
if (databaseStrategySegment.isPresent()) {
AlgorithmSegment databaseShardingAlgorithm = databaseStrategySegment.get().getShardingAlgorithm();
if (null != databaseShardingAlgorithm) {
- ShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration(databaseShardingAlgorithm.getName(), databaseShardingAlgorithm.getProps()), ShardingAlgorithm.class);
+ ShardingAlgorithm shardingAlgorithm = TypedSPILoader.getService(ShardingAlgorithm.class, databaseShardingAlgorithm.getName(), databaseShardingAlgorithm.getProps());
ShardingSpherePreconditions.checkState(!(shardingAlgorithm instanceof ShardingAutoTableAlgorithm),
() -> new InvalidAlgorithmConfigurationException("sharding", shardingAlgorithm.getType(),
String.format("auto sharding algorithm cannot be used to create a table in Table mode `%s`", each.getLogicTable())));
@@ -325,8 +321,7 @@ public final class ShardingTableRuleStatementChecker {
if (tableStrategySegment.isPresent()) {
AlgorithmSegment tableShardingAlgorithm = tableStrategySegment.get().getShardingAlgorithm();
if (null != tableShardingAlgorithm) {
- ShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration(tableShardingAlgorithm.getName(), tableShardingAlgorithm.getProps()), ShardingAlgorithm.class);
+ ShardingAlgorithm shardingAlgorithm = TypedSPILoader.getService(ShardingAlgorithm.class, tableShardingAlgorithm.getName(), tableShardingAlgorithm.getProps());
ShardingSpherePreconditions.checkState(!(shardingAlgorithm instanceof ShardingAutoTableAlgorithm),
() -> new InvalidAlgorithmConfigurationException("sharding", shardingAlgorithm.getType(),
String.format("auto sharding algorithm cannot be used to create a table in Table mode `%s`", each.getLogicTable())));
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdKeyGenerateAlgorithmTest.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdKeyGenerateAlgorithmTest.java
index 49b3d485da5..8f5f5ab70c2 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdKeyGenerateAlgorithmTest.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdKeyGenerateAlgorithmTest.java
@@ -26,8 +26,7 @@ import me.ahoo.cosid.provider.NotFoundIdGeneratorException;
import me.ahoo.cosid.segment.DefaultSegmentId;
import me.ahoo.cosid.segment.IdSegmentDistributor;
import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -49,8 +48,7 @@ public final class CosIdKeyGenerateAlgorithmTest {
String idName = "test-cosid";
DefaultSegmentId defaultSegmentId = new DefaultSegmentId(new IdSegmentDistributor.Mock());
DefaultIdGeneratorProvider.INSTANCE.set(idName, defaultSegmentId);
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("COSID", PropertiesBuilder.build(new Property(CosIdAlgorithmConstants.ID_NAME_KEY, idName))), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID", PropertiesBuilder.build(new Property(CosIdAlgorithmConstants.ID_NAME_KEY, idName)));
assertThat(algorithm.generateKey(), is(1L));
assertThat(algorithm.generateKey(), is(2L));
}
@@ -59,7 +57,7 @@ public final class CosIdKeyGenerateAlgorithmTest {
public void assertGenerateKeyWhenNotSetIdName() {
DefaultSegmentId defaultSegmentId = new DefaultSegmentId(new IdSegmentDistributor.Mock());
DefaultIdGeneratorProvider.INSTANCE.setShare(defaultSegmentId);
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", new Properties()), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID");
assertThat(algorithm.generateKey(), is(1L));
assertThat(algorithm.generateKey(), is(2L));
}
@@ -67,7 +65,7 @@ public final class CosIdKeyGenerateAlgorithmTest {
@Test(expected = NotFoundIdGeneratorException.class)
public void assertGenerateKeyWhenIdProviderIsEmpty() {
DefaultIdGeneratorProvider.INSTANCE.clear();
- ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", new Properties()), KeyGenerateAlgorithm.class)).generateKey();
+ TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID").generateKey();
}
@Test
@@ -77,7 +75,7 @@ public final class CosIdKeyGenerateAlgorithmTest {
IdGenerator idGeneratorDecorator = new StringIdGeneratorDecorator(new MillisecondSnowflakeId(1, 0), new PrefixIdConverter(prefix, Radix62IdConverter.INSTANCE));
DefaultIdGeneratorProvider.INSTANCE.set(idName, idGeneratorDecorator);
Properties props = PropertiesBuilder.build(new Property(CosIdAlgorithmConstants.ID_NAME_KEY, idName), new Property("as-string", Boolean.TRUE.toString()));
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", props), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID", props);
Comparable<?> actual = algorithm.generateKey();
assertThat(actual, instanceOf(String.class));
assertThat(actual.toString(), startsWith(prefix));
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
index e5cf1d15cae..73e764fc076 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
@@ -22,8 +22,6 @@ import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
import me.ahoo.cosid.snowflake.MillisecondSnowflakeIdStateParser;
import me.ahoo.cosid.snowflake.SnowflakeIdState;
import me.ahoo.cosid.snowflake.SnowflakeIdStateParser;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -31,6 +29,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.cosid.algorithm.keygen.fixture.WorkerIdGeneratorFixture;
import org.apache.shardingsphere.sharding.exception.ShardingPluginException;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
@@ -62,7 +61,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKey() {
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID_SNOWFLAKE");
algorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID),
new ModeConfiguration("Standalone", null), mock(ModeContextManager.class), mock(LockContext.class), eventBusContext));
long firstActualKey = (Long) algorithm.generateKey();
@@ -78,7 +77,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKeyModUniformity() {
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID_SNOWFLAKE");
algorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID),
new ModeConfiguration("Standalone", null), mock(ModeContextManager.class), mock(LockContext.class), eventBusContext));
int divisor = 4;
@@ -120,7 +119,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKeyAsString() {
Properties props = PropertiesBuilder.build(new Property(CosIdSnowflakeKeyGenerateAlgorithm.AS_STRING_KEY, Boolean.TRUE.toString()));
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", props), KeyGenerateAlgorithm.class);
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID_SNOWFLAKE", props);
algorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)),
new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), new ModeConfiguration("Standalone", null),
mock(ModeContextManager.class), mock(LockContext.class), eventBusContext));
@@ -136,12 +135,12 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test(expected = ShardingPluginException.class)
public void assertGenerateKeyWhenNoneInstanceContext() {
- ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class)).generateKey();
+ TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID_SNOWFLAKE").generateKey();
}
@Test(expected = IllegalArgumentException.class)
public void assertGenerateKeyWhenNegative() {
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID_SNOWFLAKE");
algorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), new WorkerIdGeneratorFixture(-1),
new ModeConfiguration("Standalone", null), mock(ModeContextManager.class), mock(LockContext.class), eventBusContext));
algorithm.generateKey();
@@ -149,7 +148,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test(expected = IllegalArgumentException.class)
public void assertGenerateKeyWhenGreaterThen1023() {
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) TypedSPILoader.getService(KeyGenerateAlgorithm.class, "COSID_SNOWFLAKE");
algorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), new WorkerIdGeneratorFixture(1024),
new ModeConfiguration("Standalone", null), mock(ModeContextManager.class), mock(LockContext.class), eventBusContext));
algorithm.generateKey();
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithmTest.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithmTest.java
index f930399d72b..9beb248cfa8 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithmTest.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithmTest.java
@@ -20,9 +20,8 @@ package org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval;
import com.google.common.collect.Range;
import lombok.RequiredArgsConstructor;
import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
@@ -79,8 +78,8 @@ public final class CosIdSnowflakeIntervalShardingAlgorithmTest {
@Test
public void assertDoSharding() {
- CosIdSnowflakeIntervalShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("COSID_INTERVAL_SNOWFLAKE", createProperties()), ShardingAlgorithm.class);
+ CosIdSnowflakeIntervalShardingAlgorithm algorithm = (CosIdSnowflakeIntervalShardingAlgorithm) TypedSPILoader.getService(
+ ShardingAlgorithm.class, "COSID_INTERVAL_SNOWFLAKE", createProperties());
PreciseShardingValue shardingValue = new PreciseShardingValue<>(IntervalShardingAlgorithmDataFixture.LOGIC_NAME,
IntervalShardingAlgorithmDataFixture.COLUMN_NAME, new DataNodeInfo(IntervalShardingAlgorithmDataFixture.LOGIC_NAME_PREFIX, 6, '0'), snowflakeId);
String actual = algorithm.doSharding(IntervalShardingAlgorithmDataFixture.ALL_NODES, shardingValue);
@@ -103,8 +102,8 @@ public final class CosIdSnowflakeIntervalShardingAlgorithmTest {
@Test
public void assertDoSharding() {
- CosIdSnowflakeIntervalShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("COSID_INTERVAL_SNOWFLAKE", createProperties()), ShardingAlgorithm.class);
+ CosIdSnowflakeIntervalShardingAlgorithm algorithm = (CosIdSnowflakeIntervalShardingAlgorithm) TypedSPILoader.getService(
+ ShardingAlgorithm.class, "COSID_INTERVAL_SNOWFLAKE", createProperties());
RangeShardingValue shardingValue = new RangeShardingValue<>(IntervalShardingAlgorithmDataFixture.LOGIC_NAME,
IntervalShardingAlgorithmDataFixture.COLUMN_NAME, new DataNodeInfo(IntervalShardingAlgorithmDataFixture.LOGIC_NAME_PREFIX, 6, '0'), rangeValue);
assertThat(algorithm.doSharding(IntervalShardingAlgorithmDataFixture.ALL_NODES, shardingValue), is(expected));
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/fixture/IntervalShardingAlgorithmDataFixture.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/fixture/IntervalShardingAlgorithmDataFixture.java
index 84bd4e098ad..ffc3162195b 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/fixture/IntervalShardingAlgorithmDataFixture.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/fixture/IntervalShardingAlgorithmDataFixture.java
@@ -21,8 +21,7 @@ import com.google.common.collect.Range;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import me.ahoo.cosid.sharding.ExactCollection;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.cosid.algorithm.Arguments;
import org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
import org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.CosIdIntervalShardingAlgorithm;
@@ -136,6 +135,6 @@ public final class IntervalShardingAlgorithmDataFixture {
new Property(CosIdIntervalShardingAlgorithm.SHARDING_SUFFIX_FORMAT_KEY, SUFFIX_FORMATTER_STRING),
new Property(CosIdIntervalShardingAlgorithm.INTERVAL_UNIT_KEY, "MONTHS"),
new Property(CosIdIntervalShardingAlgorithm.INTERVAL_AMOUNT_KEY, "1"));
- return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_INTERVAL", props), ShardingAlgorithm.class);
+ return (CosIdIntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "COSID_INTERVAL", props);
}
}
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/mod/CosIdModShardingAlgorithmTest.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/mod/CosIdModShardingAlgorithmTest.java
index 53a706a65f6..27f66f6f34a 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/mod/CosIdModShardingAlgorithmTest.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/mod/CosIdModShardingAlgorithmTest.java
@@ -20,9 +20,8 @@ package org.apache.shardingsphere.sharding.cosid.algorithm.sharding.mod;
import com.google.common.collect.Range;
import lombok.RequiredArgsConstructor;
import me.ahoo.cosid.sharding.ExactCollection;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.cosid.algorithm.Arguments;
@@ -54,9 +53,10 @@ public final class CosIdModShardingAlgorithmTest {
static final ExactCollection<String> ALL_NODES = new ExactCollection<>("t_mod_0", "t_mod_1", "t_mod_2", "t_mod_3");
+ @SuppressWarnings("unchecked")
static CosIdModShardingAlgorithm<Long> createShardingAlgorithm() {
Properties props = PropertiesBuilder.build(new Property(CosIdAlgorithmConstants.LOGIC_NAME_PREFIX_KEY, LOGIC_NAME_PREFIX), new Property("mod", Integer.toString(DIVISOR)));
- return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_MOD", props), ShardingAlgorithm.class);
+ return (CosIdModShardingAlgorithm<Long>) TypedSPILoader.getService(ShardingAlgorithm.class, "COSID_MOD", props);
}
@RunWith(Parameterized.class)
diff --git a/features/sharding/plugin/nanoid/src/test/java/org/apache/shardingsphere/sharding/nanoid/algorithm/keygen/NanoIdKeyGenerateAlgorithmTest.java b/features/sharding/plugin/nanoid/src/test/java/org/apache/shardingsphere/sharding/nanoid/algorithm/keygen/NanoIdKeyGenerateAlgorithmTest.java
index 0522a0f4c3a..61bf0cf52c6 100644
--- a/features/sharding/plugin/nanoid/src/test/java/org/apache/shardingsphere/sharding/nanoid/algorithm/keygen/NanoIdKeyGenerateAlgorithmTest.java
+++ b/features/sharding/plugin/nanoid/src/test/java/org/apache/shardingsphere/sharding/nanoid/algorithm/keygen/NanoIdKeyGenerateAlgorithmTest.java
@@ -17,13 +17,10 @@
package org.apache.shardingsphere.sharding.nanoid.algorithm.keygen;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -31,7 +28,6 @@ public final class NanoIdKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKey() {
- KeyGenerateAlgorithm generateAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("NANOID", new Properties()), KeyGenerateAlgorithm.class);
- assertThat(generateAlgorithm.generateKey().toString().length(), is(21));
+ assertThat(TypedSPILoader.getService(KeyGenerateAlgorithm.class, "NANOID").generateKey().toString().length(), is(21));
}
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactory.java
deleted file mode 100644
index 01cb2438aec..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactory.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.algorithm;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-
-/**
- * ShardingSphere algorithm factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShardingSphereAlgorithmFactory {
-
- /**
- * Create algorithm.
- *
- * @param algorithmConfig algorithm configuration
- * @param algorithmClass algorithm class
- * @param <T> type of algorithm
- * @return algorithm
- */
- @SuppressWarnings("unchecked")
- public static <T extends ShardingSphereAlgorithm> T createAlgorithm(final AlgorithmConfiguration algorithmConfig, final Class<? extends ShardingSphereAlgorithm> algorithmClass) {
- return (T) TypedSPILoader.getService(algorithmClass, algorithmConfig.getType(), algorithmConfig.getProps());
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactoryTest.java
deleted file mode 100644
index 56f565eedcc..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactoryTest.java
+++ /dev/null
@@ -1,39 +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.algorithm;
-
-import org.apache.shardingsphere.infra.algorithm.fixture.ShardingSphereAlgorithmFixture;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class ShardingSphereAlgorithmFactoryTest {
-
- @Test
- public void assertCreateAlgorithm() {
- ShardingSphereAlgorithm actual = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("FIXTURE", PropertiesBuilder.build(new Property("key", "value"))), ShardingSphereAlgorithm.class);
- assertThat(actual, instanceOf(ShardingSphereAlgorithmFixture.class));
- assertThat(((ShardingSphereAlgorithmFixture) actual).getTestValue(), is("value"));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/fixture/ShardingSphereAlgorithmFixture.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/fixture/ShardingSphereAlgorithmFixture.java
deleted file mode 100644
index 04a65dfe016..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/fixture/ShardingSphereAlgorithmFixture.java
+++ /dev/null
@@ -1,42 +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.algorithm.fixture;
-
-import lombok.Getter;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithm;
-
-import java.util.Properties;
-
-@Getter
-public final class ShardingSphereAlgorithmFixture implements ShardingSphereAlgorithm {
-
- private Properties props;
-
- private String testValue;
-
- @Override
- public void init(final Properties props) {
- this.props = props;
- testValue = props.getProperty("key");
- }
-
- @Override
- public String getType() {
- return "FIXTURE";
- }
-}
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
index 0936253260f..3886c42adcd 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
+++ b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
@@ -22,11 +22,11 @@ import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
import org.apache.shardingsphere.authority.model.AuthorityRegistry;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import java.util.Collection;
import java.util.Map;
@@ -49,7 +49,7 @@ public final class AuthorityRule implements GlobalRule {
public AuthorityRule(final AuthorityRuleConfiguration ruleConfig, final Map<String, ShardingSphereDatabase> databases) {
configuration = ruleConfig;
users = ruleConfig.getUsers();
- provider = ShardingSphereAlgorithmFactory.createAlgorithm(ruleConfig.getProvider(), AuthorityProviderAlgorithm.class);
+ provider = TypedSPILoader.getService(AuthorityProviderAlgorithm.class, ruleConfig.getProvider().getType(), ruleConfig.getProvider().getProps());
authorityRegistry = provider.buildAuthorityRegistry(databases, ruleConfig.getUsers());
}
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/schema/DatabasePermittedPrivilegesProviderAlgorithmTest.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/schema/DatabasePermittedPrivilegesProviderAlgorithmTest.java
index 2e8a3694d9a..81f9ab346e2 100644
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/schema/DatabasePermittedPrivilegesProviderAlgorithmTest.java
+++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/schema/DatabasePermittedPrivilegesProviderAlgorithmTest.java
@@ -21,10 +21,9 @@ import org.apache.shardingsphere.authority.model.AuthorityRegistry;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.provider.database.DatabasePermittedPrivilegesProviderAlgorithm;
import org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
@@ -41,8 +40,7 @@ public final class DatabasePermittedPrivilegesProviderAlgorithmTest {
public void assertBuildAuthorityRegistry() {
Properties props = PropertiesBuilder.build(
new Property(DatabasePermittedPrivilegesProviderAlgorithm.PROP_USER_DATABASE_MAPPINGS, "root@localhost=test, user1@127.0.0.1=db_dal_admin, user1@=test, user1@=test1, user1@=*"));
- DatabasePermittedPrivilegesProviderAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("DATABASE_PERMITTED", props), AuthorityProviderAlgorithm.class);
+ AuthorityProviderAlgorithm algorithm = TypedSPILoader.getService(AuthorityProviderAlgorithm.class, "DATABASE_PERMITTED", props);
AuthorityRegistry actual = algorithm.buildAuthorityRegistry(Collections.emptyMap(), Collections.singletonList(new ShardingSphereUser("user1", "", "127.0.0.2")));
Optional<ShardingSpherePrivileges> privileges = actual.findPrivileges(new Grantee("user1", "127.0.0.2"));
assertTrue(privileges.isPresent());
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractInventoryIncrementalJobAPIImpl.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractInventoryIncrementalJobAPIImpl.java
index 5af8d9f2843..98d26fe701b 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractInventoryIncrementalJobAPIImpl.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractInventoryIncrementalJobAPIImpl.java
@@ -44,8 +44,6 @@ import org.apache.shardingsphere.data.pipeline.core.task.InventoryTask;
import org.apache.shardingsphere.data.pipeline.spi.check.consistency.DataConsistencyCalculateAlgorithm;
import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
import org.apache.shardingsphere.infra.algorithm.AlgorithmDescription;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
@@ -195,7 +193,7 @@ public abstract class AbstractInventoryIncrementalJobAPIImpl extends AbstractPip
? DataConsistencyCalculateAlgorithmChooser.choose(
TypedSPILoader.getService(DatabaseType.class, jobConfig.getSourceDatabaseType()),
TypedSPILoader.getService(DatabaseType.class, getTargetDatabaseType(jobConfig)))
- : ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration(algorithmType, algorithmProps), DataConsistencyCalculateAlgorithm.class);
+ : TypedSPILoader.getService(DataConsistencyCalculateAlgorithm.class, algorithmType, algorithmProps);
}
@Override
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/DataConsistencyCalculateAlgorithmChooser.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/DataConsistencyCalculateAlgorithmChooser.java
index 5350d89ba48..8a7a404ca6d 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/DataConsistencyCalculateAlgorithmChooser.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/DataConsistencyCalculateAlgorithmChooser.java
@@ -20,10 +20,9 @@ package org.apache.shardingsphere.data.pipeline.core.check.consistency;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.data.pipeline.spi.check.consistency.DataConsistencyCalculateAlgorithm;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
/**
* Data consistency calculate algorithm chooser.
@@ -47,6 +46,6 @@ public final class DataConsistencyCalculateAlgorithmChooser {
} else {
algorithmType = "DATA_MATCH";
}
- return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration(algorithmType, null), DataConsistencyCalculateAlgorithm.class);
+ return TypedSPILoader.getService(DataConsistencyCalculateAlgorithm.class, algorithmType);
}
}
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/context/AbstractInventoryIncrementalProcessContext.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/context/AbstractInventoryIncrementalProcessContext.java
index f13e9602b50..d015b12738d 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/context/AbstractInventoryIncrementalProcessContext.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/context/AbstractInventoryIncrementalProcessContext.java
@@ -28,8 +28,8 @@ import org.apache.shardingsphere.data.pipeline.core.config.process.PipelineProce
import org.apache.shardingsphere.data.pipeline.core.execute.ExecuteEngine;
import org.apache.shardingsphere.data.pipeline.spi.ingest.channel.PipelineChannelCreator;
import org.apache.shardingsphere.data.pipeline.spi.ratelimit.JobRateLimitAlgorithm;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
/**
* Abstract inventory incremental process context.
@@ -56,12 +56,12 @@ public abstract class AbstractInventoryIncrementalProcessContext implements Inve
this.pipelineProcessConfig = processConfig;
PipelineReadConfiguration readConfig = processConfig.getRead();
AlgorithmConfiguration readRateLimiter = readConfig.getRateLimiter();
- readRateLimitAlgorithm = null == readRateLimiter ? null : ShardingSphereAlgorithmFactory.createAlgorithm(readRateLimiter, JobRateLimitAlgorithm.class);
+ readRateLimitAlgorithm = null == readRateLimiter ? null : TypedSPILoader.getService(JobRateLimitAlgorithm.class, readRateLimiter.getType(), readRateLimiter.getProps());
PipelineWriteConfiguration writeConfig = processConfig.getWrite();
AlgorithmConfiguration writeRateLimiter = writeConfig.getRateLimiter();
- writeRateLimitAlgorithm = null == writeRateLimiter ? null : ShardingSphereAlgorithmFactory.createAlgorithm(writeRateLimiter, JobRateLimitAlgorithm.class);
+ writeRateLimitAlgorithm = null == writeRateLimiter ? null : TypedSPILoader.getService(JobRateLimitAlgorithm.class, writeRateLimiter.getType(), writeRateLimiter.getProps());
AlgorithmConfiguration streamChannel = processConfig.getStreamChannel();
- pipelineChannelCreator = ShardingSphereAlgorithmFactory.createAlgorithm(streamChannel, PipelineChannelCreator.class);
+ pipelineChannelCreator = TypedSPILoader.getService(PipelineChannelCreator.class, streamChannel.getType(), streamChannel.getProps());
inventoryDumperExecuteEngineLazyInitializer = new LazyInitializer<ExecuteEngine>() {
@Override
diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/TrafficRule.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/TrafficRule.java
index 3c5305abe0e..dfa71426712 100644
--- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/TrafficRule.java
+++ b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/TrafficRule.java
@@ -19,12 +19,12 @@ package org.apache.shardingsphere.traffic.rule;
import com.google.common.base.Preconditions;
import lombok.Getter;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
import org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration;
@@ -70,7 +70,8 @@ public final class TrafficRule implements GlobalRule {
if (null == trafficAlgorithms.get(each.getAlgorithmName())) {
break;
}
- result.put(each.getName() + "." + each.getAlgorithmName(), ShardingSphereAlgorithmFactory.createAlgorithm(trafficAlgorithms.get(each.getAlgorithmName()), TrafficAlgorithm.class));
+ AlgorithmConfiguration algorithmConfig = trafficAlgorithms.get(each.getAlgorithmName());
+ result.put(each.getName() + "." + each.getAlgorithmName(), TypedSPILoader.getService(TrafficAlgorithm.class, algorithmConfig.getType(), algorithmConfig.getProps()));
}
return result;
}
@@ -81,8 +82,8 @@ public final class TrafficRule implements GlobalRule {
if (null == loadBalancers.get(each.getLoadBalancerName())) {
break;
}
- result.put(each.getName() + "." + each.getLoadBalancerName(),
- ShardingSphereAlgorithmFactory.createAlgorithm(loadBalancers.get(each.getLoadBalancerName()), TrafficLoadBalanceAlgorithm.class));
+ AlgorithmConfiguration algorithmConfig = loadBalancers.get(each.getLoadBalancerName());
+ result.put(each.getName() + "." + each.getLoadBalancerName(), TypedSPILoader.getService(TrafficLoadBalanceAlgorithm.class, algorithmConfig.getType(), algorithmConfig.getProps()));
}
return result;
}
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithmTest.java b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithmTest.java
index 1169424ccff..88159281247 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithmTest.java
+++ b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithmTest.java
@@ -17,8 +17,7 @@
package org.apache.shardingsphere.traffic.algorithm.traffic.segment;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -38,8 +37,8 @@ public final class SQLMatchTrafficAlgorithmTest {
@Before
public void setUp() {
- sqlMatchAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SQL_MATCH",
- PropertiesBuilder.build(new Property("sql", "SELECT * FROM t_order; UPDATE t_order SET order_id = ? WHERE user_id = ?;"))), TrafficAlgorithm.class);
+ sqlMatchAlgorithm = (SQLMatchTrafficAlgorithm) TypedSPILoader.getService(TrafficAlgorithm.class, "SQL_MATCH",
+ PropertiesBuilder.build(new Property("sql", "SELECT * FROM t_order; UPDATE t_order SET order_id = ? WHERE user_id = ?;")));
}
@Test
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithmTest.java b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithmTest.java
index eac643d58a8..b7889973f21 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithmTest.java
+++ b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithmTest.java
@@ -17,8 +17,7 @@
package org.apache.shardingsphere.traffic.algorithm.traffic.segment;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -38,8 +37,8 @@ public final class SQLRegexTrafficAlgorithmTest {
@Before
public void setUp() {
- sqlRegexAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("SQL_REGEX", PropertiesBuilder.build(new Property("regex", "(?i)^(UPDATE|SELECT).*WHERE user_id.*"))), TrafficAlgorithm.class);
+ sqlRegexAlgorithm = (SQLRegexTrafficAlgorithm) TypedSPILoader.getService(
+ TrafficAlgorithm.class, "SQL_REGEX", PropertiesBuilder.build(new Property("regex", "(?i)^(UPDATE|SELECT).*WHERE user_id.*")));
}
@Test