You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/12/29 15:01:39 UTC
[shardingsphere] branch master updated: Use way of AgentServiceLoader to simplify ShardingSphereServiceLoader (#23170)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 cd9bbd1b79f Use way of AgentServiceLoader to simplify ShardingSphereServiceLoader (#23170)
cd9bbd1b79f is described below
commit cd9bbd1b79fe05b2a0c68627781817eda4edd854
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Dec 29 23:01:32 2022 +0800
Use way of AgentServiceLoader to simplify ShardingSphereServiceLoader (#23170)
* Refactor ShardingSphereServiceLoader
* Remove AuthorityProviderAlgorithmFactory
* Remove ClusterPersistRepositoryFactory
* Remove DistributedLockCreatorFactory
* Remove PipelineDistributedBarrierFactory
* Remove DataConsistencyCalculateAlgorithmFactory
* Remove JdbcQueryPropertiesExtensionFactory
* Remove CreateTableSQLGeneratorFactory
* Remove ImporterCreatorFactory
* Remove IncrementalDumperCreatorFactory
* Remove CreateTableSQLGeneratorFactory
* Remove PipelineChannelCreatorFactory
* Remove PositionInitializerFactory
* Remove JobRateLimitAlgorithmFactory
* Remove ShardingColumnsExtractorFactory
* Remove CDCJobAPIFactory
* Remove DataSourceCheckerFactory
* Remove PipelineDataSourceCreatorFactory
* Remove ColumnValueReaderFactory
* Remove PipelineJobAPIFactory
* Remove PipelineJobAPIFactory
* Remove PipelineChangedJobConfigurationProcessorFactory
* Remove PipelineChangedJobConfigurationProcessorFactory
* Remove PipelineMetaDataChangedEventHandlerFactory
* Remove DataSourcePreparerFactory
* Remove PipelineSQLBuilderFactory
* Remove MySQLDataTypeHandlerFactory
* Remove DatetimeLoadingSQLProviderFactory
* Remove DatabaseDiscoveryProviderAlgorithmFactory
* Remove SQLDialectExceptionMapperFactory
* Remove RuleDefinitionUpdaterFactory
* Remove RALUpdaterFactory
* Remove RuleDefinitionUpdaterFactory
* Remove FeaturedDistSQLStatementParserFacadeFactory
* Remove EncryptAlgorithmFactory
* Remove SQLFederationDeciderFactory
* Remove RuleConfigurationCheckerFactory
* Remove DatabaseTypeFactory
* Remove DataNodeBuilderFactory
* Remove DataSourcePoolActiveDetectorFactory
* Remove DataSourcePoolMetaDataFactory
* Refactor InstanceMetaDataFactory
* Remove ShardingSphereDataBuilderFactory
* Remove ShardingSphereDataCollectorFactory
* Remove RuleBasedSchemaMetaDataDecoratorFactory
* Remove DataTypeLoaderFactory
* Remove DialectSchemaMetaDataLoaderFactory
* Remove DefaultDatabaseRuleConfigurationBuilderFactory
* Remove GlobalRuleBuilderFactory
* Remove DefaultGlobalRuleConfigurationBuilderFactory
* Remove MetaDataRefresherFactory
* Remove ExecuteProcessReporterFactory
* Remove ResultProcessEngineFactory
* Refactor RequiredSPIRegistryTest
* Refactor TypedSPIRegistryTest
* Refactor OrderedServicesCacheTest
* Refactor OrderedSPIRegistryTest
* Refactor OptionalSPIRegistryTest
* Refactor ShardingSphereAlgorithmFactoryTest
* Remove DefaultGlobalRuleConfigurationBuilderFactory
* Remove YamlPersistRepositoryConfigurationSwapperFactory
* Remove DatetimeServiceFactory
* Remove ExecutionPrepareDecoratorFactory
* Remove SaneQueryResultEngineFactory
* Remove SQLCheckerFactory
* Remove RawExecutorCallbackFactory
* Remove DriverStateFactory
* Remove DialectQueryResultDataRowLoaderFactory
* Remove DatabaseProtocolFrontendEngineFactory
* Remove ShardingSphereYamlTupleProcessorFactory
* Remove QueryableScalingRALBackendHandlerFactory
* Remove UpdatableGlobalRuleRALBackendHandlerFactory
* Remove QueryableGlobalRuleRALBackendHandlerFactory
* Remove SQLExecutionUnitBuilderFactory
* Remove DatabaseTypedSQLParserFacadeFactory
* Remove SQLExecutionHookFactory
* Remove SQLRouterFactory
* Remove SQLRewriteContextDecoratorFactory
* Remove YamlRuleConfigurationSwapperFactory
* Remove PostgreSQLSessionVariableHandlerFactory
* Remove MaskAlgorithmFactory
* Remove XAConnectionWrapperFactory
* Remove ShadowAlgorithmFactory
* Remove DataSourcePropertyProviderFactory
* Remove MaskAlgorithmFactory
* Remove SQLFederationExecutorFactory
* Remove ShardingSphereTransactionManagerFactory
* Remove ContextManagerBuilderFactory
* Remove ContextManagerBuilderFactory
* Remove ShardingSphereYamlConstructFactory
* Remove JDBCRepositoryProviderFactory
* Remove XADataSourceDefinitionFactory
* Remove XADataSourceFactory
* Remove TrafficLoadBalanceAlgorithmFactory
* Remove TrafficAlgorithmFactory
* Remove DatabaseRuleBuilderFactory
* Remove SQLParseResultReporterCreatorFactory
* Remove ShardingSphereYamlShortcutsFactory
* Remove ContextManagerLifecycleListenerFactory
* Refactor ExampleScenarioFactory
* Remove StatementMemoryStrictlyFetchSizeSetterFactory
* Remove ReadQueryLoadBalanceAlgorithmFactory
* Remove MySQLSessionVariableHandlerFactory
* Remove ReplayRequiredSessionVariablesLoader
* Fix checkstyle
* Remove KeyGenerateAlgorithmFactory
* Remove ShardingAlgorithmFactory
* Remove ShardingAuditAlgorithmFactory
* Refactor CreateReadwriteSplittingRuleStatementUpdaterTest
* Remove OptimizerSQLDialectBuilderFactory
* Refactor ProxyBackendHandlerFactory
* Remove DatabaseAdminExecutorCreatorFactory
* Remove SQLVisitorFacadeFactory
* Refactor RQLBackendHandlerFactory
* Remove QueryHeaderBuilderFactory
* Remove SQLTranslatorFactory
* Remove StandalonePersistRepositoryFactory
* Remove XATransactionManagerProviderFactory
* Refactor JobTypeFactory
* Refactor PipelineAPIFactory
* Remove ShardingSphereServiceLoader.register
* Remove empty module
* Resolve conflicts
* Resolve conflicts
* Resolve conflicts
---
.../agent/bootstrap/spi/AgentServiceLoader.java | 4 +-
.../transformer/AgentTransformerTest.java | 2 +-
.../dialect/SQLExceptionTransformEngine.java | 4 +-
.../mapper/SQLDialectExceptionMapperFactory.java | 46 -----------
.../SQLDialectExceptionMapperFactoryTest.java | 34 ---------
.../fixture/FixtureSQLDialectExceptionMapper.java | 36 ---------
...sphere.dialect.mapper.SQLDialectExceptionMapper | 18 -----
.../distsql/handler/update/RALUpdaterFactory.java | 45 -----------
.../update/RuleDefinitionUpdaterFactory.java | 46 -----------
.../fixture/config/FixtureRuleConfiguration.java | 29 -------
.../fixture/statement/FixtureRALStatement.java | 23 ------
.../fixture/statement/FixtureRuleStatement.java | 28 -------
.../handler/fixture/updater/FixtureRALUpdater.java | 33 --------
.../updater/FixtureRuleDefinitionUpdater.java | 40 ----------
.../handler/update/RALUpdaterFactoryTest.java | 33 --------
.../update/RuleDefinitionUpdaterFactoryTest.java | 34 ---------
...hardingsphere.distsql.handler.update.RALUpdater | 18 -----
...re.distsql.handler.update.RuleDefinitionUpdater | 18 -----
.../FeaturedDistSQLStatementParserEngine.java | 6 +-
...eaturedDistSQLStatementParserFacadeFactory.java | 56 --------------
.../generator/core/ExampleGeneratorFactory.java | 5 --
.../generator/scenario/ExampleScenarioFactory.java | 7 --
.../DatabaseDiscoveryProviderAlgorithmFactory.java | 57 --------------
.../dbdiscovery/rule/DatabaseDiscoveryRule.java | 6 +-
...abaseDiscoveryRuleConfigurationCheckerTest.java | 18 ++---
.../route/DatabaseDiscoverySQLRouterTest.java | 5 +-
.../builder/DatabaseDiscoveryRuleBuilderTest.java | 8 +-
...abaseDiscoveryRuleConfigurationSwapperTest.java | 5 +-
...AlterDatabaseDiscoveryRuleStatementUpdater.java | 9 ++-
...AlterDatabaseDiscoveryTypeStatementUpdater.java | 9 ++-
...reateDatabaseDiscoveryRuleStatementUpdater.java | 9 ++-
...reateDatabaseDiscoveryTypeStatementUpdater.java | 9 ++-
.../MGRDatabaseDiscoveryProviderAlgorithmTest.java | 9 ++-
.../encrypt/factory/EncryptAlgorithmFactory.java | 57 --------------
.../shardingsphere/encrypt/rule/EncryptRule.java | 4 +-
.../algorithm/encrypt/AESEncryptAlgorithmTest.java | 8 +-
.../algorithm/encrypt/MD5EncryptAlgorithmTest.java | 7 +-
.../algorithm/encrypt/RC4EncryptAlgorithmTest.java | 6 +-
.../like/CharDigestLikeEncryptAlgorithmTest.java | 13 ++--
.../EncryptRuleConfigurationCheckerTest.java | 30 +++-----
.../merge/EncryptResultDecoratorEngineTest.java | 9 ++-
.../merge/dql/EncryptAlgorithmMetaDataTest.java | 5 +-
.../EncryptSchemaMetaDataDecoratorTest.java | 5 +-
.../rule/builder/EncryptRuleBuilderTest.java | 4 +-
.../YamlEncryptRuleConfigurationSwapperTest.java | 5 +-
.../update/AlterEncryptRuleStatementUpdater.java | 5 +-
.../update/CreateEncryptRuleStatementUpdater.java | 5 +-
.../sm/algorithm/SM3EncryptAlgorithmTest.java | 6 +-
.../sm/algorithm/SM4EncryptAlgorithmTest.java | 18 ++---
.../mask/factory/MaskAlgorithmFactory.java | 59 --------------
.../apache/shardingsphere/mask/rule/MaskRule.java | 4 +-
.../mask/merge/MaskResultDecoratorEngineTest.java | 7 +-
.../mask/merge/dql/MaskAlgorithmMetaDataTest.java | 4 +-
.../mask/rule/builder/MaskRuleBuilderTest.java | 4 +-
.../YamlMaskRuleConfigurationSwapperTest.java | 5 +-
.../update/CreateMaskRuleStatementUpdater.java | 5 +-
.../ReadQueryLoadBalanceAlgorithmFactory.java | 67 ----------------
.../ReplicaLoadBalanceAlgorithmFactoryTest.java | 46 -----------
.../ReadQueryLoadBalanceAlgorithmFixture.java | 46 -----------
...ritesplitting.spi.ReadQueryLoadBalanceAlgorithm | 18 -----
...ReadwriteSplittingRuleConfigurationChecker.java | 4 +-
.../rule/ReadwriteSplittingRule.java | 12 +--
...icaWeightReadQueryLoadBalanceAlgorithmTest.java | 19 ++---
...ionWeightReadQueryLoadBalanceAlgorithmTest.java | 13 ++--
.../WeightReadQueryLoadBalanceAlgorithmTest.java | 39 +++++-----
...writeSplittingRuleConfigurationCheckerTest.java | 42 ++++------
.../route/ReadwriteSplittingSQLRouterTest.java | 49 ++++++------
.../builder/ReadwriteSplittingRuleBuilderTest.java | 4 +-
...writeSplittingRuleConfigurationSwapperTest.java | 7 +-
.../ReadwriteSplittingRuleStatementChecker.java | 5 +-
...ReadwriteSplittingRuleStatementUpdaterTest.java | 9 +--
.../shadow/factory/ShadowAlgorithmFactory.java | 57 --------------
.../shardingsphere/shadow/rule/ShadowRule.java | 4 +-
.../ColumnRegexMatchShadowAlgorithmTest.java | 11 +--
.../ColumnValueMatchShadowAlgorithmTest.java | 11 +--
.../shadow/hint/SimpleHintShadowAlgorithmTest.java | 5 +-
.../ColumnShadowAlgorithmDeterminerTest.java | 12 +--
.../HintShadowAlgorithmDeterminerTest.java | 12 +--
.../shadow/rule/builder/ShadowRuleBuilderTest.java | 4 +-
...lterDefaultShadowAlgorithmStatementUpdater.java | 20 ++---
.../update/AlterShadowRuleStatementUpdater.java | 6 +-
...eateDefaultShadowAlgorithmStatementUpdater.java | 9 ++-
.../update/CreateShadowRuleStatementUpdater.java | 6 +-
.../factory/KeyGenerateAlgorithmFactory.java | 67 ----------------
.../sharding/factory/ShardingAlgorithmFactory.java | 57 --------------
.../factory/ShardingAuditAlgorithmFactory.java | 57 --------------
.../factory/KeyGenerateAlgorithmFactoryTest.java | 46 -----------
.../factory/ShardingAlgorithmFactoryTest.java | 41 ----------
.../factory/ShardingAuditAlgorithmFactoryTest.java | 41 ----------
.../fixture/KeyGenerateAlgorithmFixture.java | 44 -----------
.../sharding/fixture/ShardingAlgorithmFixture.java | 39 ----------
.../fixture/ShardingAuditAlgorithmFixture.java | 47 ------------
...hardingsphere.sharding.spi.KeyGenerateAlgorithm | 18 -----
...e.shardingsphere.sharding.spi.ShardingAlgorithm | 18 -----
...rdingsphere.sharding.spi.ShardingAuditAlgorithm | 18 -----
.../impl/InsertClauseShardingConditionEngine.java | 4 +-
.../ConditionValueBetweenOperatorGenerator.java | 5 +-
.../ConditionValueCompareOperatorGenerator.java | 5 +-
.../impl/ConditionValueInOperatorGenerator.java | 4 +-
.../shardingsphere/sharding/rule/ShardingRule.java | 13 ++--
...ardingConditionsShardingAuditAlgorithmTest.java | 4 +-
.../keygen/SnowflakeKeyGenerateAlgorithmTest.java | 26 +++----
.../ClassBasedShardingAlgorithmTest.java | 23 +++---
.../ComplexInlineShardingAlgorithmTest.java | 15 ++--
.../AutoIntervalShardingAlgorithmTest.java | 5 +-
.../datetime/IntervalShardingAlgorithmTest.java | 31 ++++----
.../hint/HintInlineShardingAlgorithmTest.java | 5 +-
.../inline/InlineShardingAlgorithmTest.java | 11 +--
.../sharding/mod/HashModShardingAlgorithmTest.java | 5 +-
.../sharding/mod/ModShardingAlgorithmTest.java | 19 ++---
.../BoundaryBasedRangeShardingAlgorithmTest.java | 5 +-
.../VolumeBasedRangeShardingAlgorithmTest.java | 5 +-
.../ShardingRuleConfigurationCheckerTest.java | 21 +++--
.../merge/ShardingResultMergerEngineTest.java | 11 +--
.../common/IteratorStreamMergedResultTest.java | 15 ++--
.../merge/dql/ShardingDQLResultMergerTest.java | 46 +++++------
.../dql/groupby/GroupByMemoryMergedResultTest.java | 11 +--
.../dql/groupby/GroupByStreamMergedResultTest.java | 13 ++--
.../dql/orderby/OrderByStreamMergedResultTest.java | 15 ++--
.../pagination/LimitDecoratorMergedResultTest.java | 9 ++-
.../RowNumberDecoratorMergedResultTest.java | 11 +--
.../TopAndRowNumberDecoratorMergedResultTest.java | 13 ++--
.../ShardingSchemaMetaDataDecoratorTest.java | 5 +-
.../engine/type/standard/AbstractSQLRouteTest.java | 6 +-
.../dml/ShardingInsertStatementValidatorTest.java | 5 +-
.../dml/ShardingUpdateStatementValidatorTest.java | 4 +-
.../sharding/rule/TableRuleTest.java | 9 ++-
.../rule/builder/ShardingRuleBuilderTest.java | 4 +-
.../checker/ShardingTableRuleStatementChecker.java | 27 ++++---
.../handler/query/ShardingTableNodesResultSet.java | 9 ++-
...reateShardingTableRuleStatementUpdaterTest.java | 7 +-
.../CacheableShardingAlgorithmChecker.java | 1 -
.../checker/ShardingRouteCacheableCheckerTest.java | 8 +-
.../keygen/CosIdKeyGenerateAlgorithmTest.java | 12 +--
.../CosIdSnowflakeKeyGenerateAlgorithmTest.java | 21 +++--
...osIdSnowflakeIntervalShardingAlgorithmTest.java | 15 ++--
.../IntervalShardingAlgorithmDataFixture.java | 14 ++--
.../mod/CosIdModShardingAlgorithmTest.java | 6 +-
.../keygen/NanoIdKeyGenerateAlgorithmTest.java | 6 +-
.../decider/SQLFederationDeciderFactory.java | 49 ------------
.../decider/engine/SQLFederationDeciderEngine.java | 4 +-
.../statement/CommonSQLStatementContext.java | 18 ++---
.../projection/engine/ProjectionEngineTest.java | 31 ++++----
.../checker/RuleConfigurationCheckerFactory.java | 51 -------------
.../infra/database/type/DatabaseTypeEngine.java | 9 ++-
.../infra/database/type/DatabaseTypeFactory.java | 55 -------------
.../database/type/dialect/H2DatabaseType.java | 4 +-
.../database/type/dialect/MariaDBDatabaseType.java | 4 +-
.../infra/datanode/DataNodeBuilderFactory.java | 49 ------------
.../shardingsphere/infra/datanode/DataNodes.java | 3 +-
.../pool/creator/DataSourcePoolCreator.java | 4 +-
.../pool/creator/DataSourceReflection.java | 5 +-
.../pool/destroyer/DataSourcePoolDestroyer.java | 6 +-
.../DataSourcePoolActiveDetectorFactory.java | 43 -----------
.../metadata/DataSourcePoolMetaDataFactory.java | 46 -----------
.../datasource/props/DataSourceProperties.java | 4 +-
.../props/DataSourcePropertiesCreator.java | 4 +-
.../props/DataSourcePropertiesValidator.java | 4 +-
...erFactory.java => InstanceMetaDataFactory.java} | 21 +----
.../builder/ShardingSphereDataBuilderFactory.java | 49 ------------
.../ShardingSphereDataCollectorFactory.java | 46 -----------
.../schema/builder/GenericSchemaBuilder.java | 4 +-
.../RuleBasedSchemaMetaDataDecoratorFactory.java | 46 -----------
.../schema/loader/SchemaMetaDataLoaderEngine.java | 4 +-
.../loader/dialect/H2SchemaMetaDataLoader.java | 6 +-
.../loader/dialect/MySQLSchemaMetaDataLoader.java | 11 ++-
.../dialect/OpenGaussSchemaMetaDataLoader.java | 10 ++-
.../loader/dialect/OracleSchemaMetaDataLoader.java | 13 +++-
.../dialect/PostgreSQLSchemaMetaDataLoader.java | 10 ++-
.../dialect/SQLServerSchemaMetaDataLoader.java | 6 +-
.../schema/loader/spi/DataTypeLoaderFactory.java | 46 -----------
.../spi/DialectSchemaMetaDataLoaderFactory.java | 47 ------------
.../database/DatabaseRuleBuilderFactory.java | 70 -----------------
.../builder/database/DatabaseRulesBuilder.java | 18 +++--
...ultDatabaseRuleConfigurationBuilderFactory.java | 48 ------------
...faultGlobalRuleConfigurationBuilderFactory.java | 48 ------------
.../builder/global/GlobalRuleBuilderFactory.java | 61 ---------------
.../rule/builder/global/GlobalRulesBuilder.java | 12 +--
.../shortcut/YamlRuleConfigurationShortcuts.java | 4 +-
.../swapper/mode/YamlModeConfigurationSwapper.java | 10 ++-
...rsistRepositoryConfigurationSwapperFactory.java | 46 -----------
.../rule/YamlRuleConfigurationSwapperEngine.java | 19 +----
.../rule/YamlRuleConfigurationSwapperFactory.java | 70 -----------------
.../ShardingSphereAlgorithmFactoryTest.java | 9 +--
.../RuleConfigurationCheckerFactoryTest.java | 47 ------------
.../fixture/RuleConfigurationCheckerFixture.java | 43 -----------
.../database/type/DatabaseTypeEngineTest.java | 15 ++--
.../database/type/DatabaseTypeFactoryTest.java | 68 -----------------
.../infra/datanode/DataNodeBuilderFactoryTest.java | 42 ----------
.../DataSourcePoolActiveDetectorFactoryTest.java | 40 ----------
.../DataSourcePoolMetaDataFactoryTest.java | 38 ---------
...yTest.java => InstanceMetaDataFactoryTest.java} | 28 +------
...uleBasedSchemaMetaDataDecoratorFactoryTest.java | 37 ---------
.../RuleBasedSchemaMetaDataDecoratorFixture.java | 43 -----------
.../schema/loader/common/DataTypeLoaderTest.java | 50 ------------
.../loader/dialect/H2SchemaMetaDataLoaderTest.java | 7 +-
.../dialect/MySQLSchemaMetaDataLoaderTest.java | 7 +-
.../dialect/OracleSchemaMetaDataLoaderTest.java | 7 +-
.../PostgreSQLSchemaMetaDataLoaderTest.java | 7 +-
.../dialect/SQLServerSchemaMetaDataLoaderTest.java | 7 +-
.../DialectSchemaMetaDataLoaderFactoryTest.java | 38 ---------
.../database/DatabaseRuleBuilderFactoryTest.java | 58 --------------
...atabaseRuleConfigurationBuilderFactoryTest.java | 39 ----------
.../FixtureGlobalRuleConfigurationBuilder.java | 38 ---------
...tGlobalRuleConfigurationBuilderFactoryTest.java | 36 ---------
.../global/GlobalRuleBuilderFactoryTest.java | 56 --------------
...rsistRepositoryConfigurationSwapperFixture.java | 42 ----------
...tRepositoryConfigurationSwapperFactoryTest.java | 32 --------
.../YamlRuleConfigurationSwapperFactoryTest.java | 59 --------------
...ra.config.rule.checker.RuleConfigurationChecker | 18 -----
....decorator.spi.RuleBasedSchemaMetaDataDecorator | 18 -----
...er.global.DefaultGlobalRuleConfigurationBuilder | 18 -----
....mode.YamlPersistRepositoryConfigurationSwapper | 18 -----
.../context/refresher/MetaDataRefreshEngine.java | 3 +-
.../refresher/MetaDataRefresherFactory.java | 48 ------------
.../infra/datetime/DatetimeServiceFactory.java | 43 -----------
.../infra/datetime/DatetimeServiceFactoryTest.java | 32 --------
.../datetime/fixture/DatetimeServiceFixture.java | 30 --------
...e.shardingsphere.infra.datetime.DatetimeService | 18 -----
.../datetime/database/DatabaseDatetimeService.java | 7 +-
.../DatetimeLoadingSQLProviderFactory.java | 46 -----------
.../fixture/FixtureDatetimeLoadingSQLProvider.java | 33 --------
.../DatetimeLoadingSQLProviderFactoryTest.java | 33 --------
...me.database.provider.DatetimeLoadingSQLProvider | 18 -----
.../infra/executor/check/SQLCheckEngine.java | 10 +--
.../executor/check/checker/SQLCheckerFactory.java | 49 ------------
.../jdbc/sane/SaneQueryResultEngineFactory.java | 45 -----------
.../raw/callback/RawExecutorCallbackFactory.java | 45 -----------
.../raw/callback/RawSQLExecutorCallback.java | 5 +-
.../jdbc/type/memory/JDBCMemoryQueryResult.java | 7 +-
.../DialectQueryResultDataRowLoaderFactory.java | 47 ------------
.../executor/sql/hook/SPISQLExecutionHook.java | 3 +-
.../executor/sql/hook/SQLExecutionHookFactory.java | 44 -----------
.../prepare/AbstractExecutionPrepareEngine.java | 3 +-
.../prepare/ExecutionPrepareDecoratorFactory.java | 49 ------------
.../driver/DriverExecutionPrepareEngine.java | 3 +-
.../driver/SQLExecutionUnitBuilderFactory.java | 45 -----------
.../executor/sql/process/ExecuteProcessEngine.java | 14 ++--
.../process/spi/ExecuteProcessReporterFactory.java | 45 -----------
.../check/checker/SQLCheckerFactoryTest.java | 43 -----------
.../check/checker/fixture/SQLCheckerFixture.java | 61 ---------------
.../engine/jdbc/JDBCExecutorCallbackTest.java | 12 +--
.../sane/SaneQueryResultEngineFactoryTest.java | 34 ---------
.../fixture/FixtureExecutionPrepareDecorator.java | 44 -----------
.../sql/fixture/FixtureSaneQueryResultEngine.java | 38 ---------
.../ExecutionPrepareDecoratorFactoryTest.java | 36 ---------
.../driver/SQLExecutionUnitBuilderFactoryTest.java | 32 --------
.../driver/fixture/FixtureDriverExecutionUnit.java | 40 ----------
.../fixture/FixtureExecutorStatementManager.java | 37 ---------
.../fixture/FixtureSQLExecutionUnitBuilder.java | 37 ---------
.../fixture/FixtureStorageResourceOption.java | 23 ------
.../spi/ExecuteProcessReporterFactoryTest.java | 37 ---------
...gsphere.infra.executor.check.checker.SQLChecker | 18 -----
...e.engine.driver.jdbc.sane.SaneQueryResultEngine | 18 -----
....executor.sql.prepare.ExecutionPrepareDecorator | 18 -----
...utor.sql.prepare.driver.SQLExecutionUnitBuilder | 18 -----
.../shardingsphere/infra/merge/MergeEngine.java | 4 +-
.../merge/engine/ResultProcessEngineFactory.java | 49 ------------
.../engine/ResultProcessEngineFactoryTest.java | 45 -----------
.../merge/fixture/ResultProcessEngineFixture.java | 34 ---------
...ngsphere.infra.merge.engine.ResultProcessEngine | 1 -
.../infra/rewrite/SQLRewriteEntry.java | 4 +-
.../context/SQLRewriteContextDecoratorFactory.java | 49 ------------
.../infra/rewrite/SQLRewriteEntryTest.java | 10 +--
.../SQLRewriteContextDecoratorFactoryTest.java | 36 ---------
.../fixture/FixtureSQLRewriteContextDecorator.java | 41 ----------
...nfra.rewrite.context.SQLRewriteContextDecorator | 18 -----
.../infra/route/SQLRouterFactory.java | 49 ------------
.../route/engine/impl/PartialSQLRouteExecutor.java | 4 +-
.../infra/route/SQLRouterFactoryTest.java | 42 ----------
.../util/spi/ShardingSphereServiceLoader.java | 62 +++++++--------
.../ShardingSphereYamlConstructFactory.java | 41 ----------
.../constructor/ShardingSphereYamlConstructor.java | 9 ++-
.../representer/ShardingSphereYamlRepresenter.java | 11 ++-
.../ShardingSphereYamlTupleProcessorFactory.java | 44 -----------
.../ShardingSphereYamlShortcutsFactory.java | 46 -----------
.../util/spi/ShardingSphereServiceLoaderTest.java | 13 ++--
.../spi/type/optional/OptionalSPIRegistryTest.java | 5 --
.../spi/type/ordered/OrderedSPIRegistryTest.java | 5 --
.../ordered/cache/OrderedServicesCacheTest.java | 5 --
.../spi/type/required/RequiredSPIRegistryTest.java | 8 --
.../util/spi/type/typed/TypedSPIRegistryTest.java | 7 +-
.../ShardingSphereYamlConstructFactoryTest.java | 37 ---------
.../ShardingSphereYamlShortcutsFactoryTest.java | 37 ---------
.../core/datasource/ShardingSphereDataSource.java | 13 +++-
.../driver/state/DriverStateContext.java | 4 +-
.../driver/state/DriverStateFactory.java | 45 -----------
.../driver/executor/AbstractBaseExecutorTest.java | 6 +-
.../driver/state/DriverStateFactoryTest.java | 36 ---------
.../driver/state/fixture/DriverStateFixture.java | 37 ---------
....apache.shardingsphere.driver.state.DriverState | 18 -----
.../factory/AuthorityProviderAlgorithmFactory.java | 46 -----------
.../authority/rule/AuthorityRule.java | 4 +-
.../authority/checker/AuthorityCheckerTest.java | 8 +-
...sePermittedPrivilegesProviderAlgorithmTest.java | 11 +--
.../pipeline/api/config/ImporterConfiguration.java | 7 +-
...rdingSpherePipelineDataSourceConfiguration.java | 4 +-
.../StandardPipelineDataSourceConfiguration.java | 4 +-
.../barrier/PipelineDistributedBarrierFactory.java | 44 -----------
.../DataConsistencyCalculateAlgorithmFactory.java | 55 -------------
.../JdbcQueryPropertiesExtensionFactory.java | 46 -----------
.../CreateTableSQLGeneratorFactory.java | 45 -----------
.../pipeline/spi/importer/ImporterCreator.java | 3 +-
.../spi/importer/ImporterCreatorFactory.java | 44 -----------
.../channel/PipelineChannelCreatorFactory.java | 56 --------------
.../ingest/dumper/IncrementalDumperCreator.java | 3 +-
.../dumper/IncrementalDumperCreatorFactory.java | 56 --------------
.../position/PositionInitializerFactory.java | 45 -----------
.../data/pipeline/spi/job/JobTypeFactory.java | 3 +-
.../ratelimit/JobRateLimitAlgorithmFactory.java | 56 --------------
.../sharding/ShardingColumnsExtractorFactory.java | 43 -----------
.../CreateTableSQLGeneratorFactoryTest.java | 33 --------
.../fixture/CreateTableSQLGeneratorFixture.java | 37 ---------
...peline.spi.ddlgenerator.CreateTableSQLGenerator | 18 -----
.../data/pipeline/cdc/api/CDCJobAPIFactory.java | 40 ----------
.../data/pipeline/cdc/api/impl/CDCJobAPIImpl.java | 9 ++-
.../data/pipeline/cdc/core/job/CDCJob.java | 4 +-
.../pipeline/cdc/core/prepare/CDCJobPreparer.java | 4 +-
.../cdc/core/importer/CDCImporterCreatorTest.java | 7 +-
.../data/pipeline/core/api/PipelineAPIFactory.java | 5 --
.../pipeline/core/api/PipelineJobAPIFactory.java | 55 -------------
.../AbstractInventoryIncrementalJobAPIImpl.java | 17 +++--
.../core/api/impl/AbstractPipelineJobAPIImpl.java | 18 ++---
.../DataConsistencyCalculateAlgorithmChooser.java | 5 +-
...RC32MatchDataConsistencyCalculateAlgorithm.java | 8 +-
...DataMatchDataConsistencyCalculateAlgorithm.java | 19 +++--
.../datasource/AbstractDataSourceChecker.java | 10 +--
.../check/datasource/DataSourceCheckerFactory.java | 48 ------------
...AbstractInventoryIncrementalProcessContext.java | 9 +--
.../core/datasource/PipelineDataSourceFactory.java | 6 +-
.../creator/PipelineDataSourceCreatorFactory.java | 42 ----------
.../StandardPipelineDataSourceCreator.java | 2 +-
.../ShardingSphereDataScheduleCollector.java | 8 +-
.../pipeline/core/importer/DataSourceImporter.java | 6 +-
.../ingest/dumper/ColumnValueReaderFactory.java | 46 -----------
.../core/ingest/dumper/InventoryDumper.java | 9 ++-
.../pipeline/core/job/AbstractPipelineJob.java | 9 ++-
.../persist/PipelineJobProgressPersistService.java | 5 +-
...YamlJobItemIncrementalTasksProgressSwapper.java | 8 +-
.../metadata/generator/PipelineDDLGenerator.java | 5 +-
.../StandardPipelineTableMetaDataLoader.java | 11 +--
.../metadata/node/PipelineMetaDataNodeWatcher.java | 10 +--
...ineChangedJobConfigurationProcessorFactory.java | 47 ------------
...PipelineMetaDataChangedEventHandlerFactory.java | 41 ----------
.../impl/BarrierMetaDataChangedEventHandler.java | 5 +-
.../impl/ChangedJobConfigurationDispatcher.java | 7 +-
.../core/prepare/InventoryTaskSplitter.java | 10 ++-
.../core/prepare/PipelineJobPreparerUtils.java | 24 +++---
.../datasource/AbstractDataSourcePreparer.java | 6 +-
.../datasource/DataSourcePreparerFactory.java | 46 -----------
.../sqlbuilder/AbstractPipelineSQLBuilder.java | 5 +-
.../core/sqlbuilder/PipelineSQLBuilderFactory.java | 46 -----------
.../data/pipeline/core/task/IncrementalTask.java | 11 +--
.../core/task/InventoryIncrementalTasksRunner.java | 6 +-
.../data/pipeline/core/task/InventoryTask.java | 5 +-
...pi.datasource.creator.PipelineDataSourceCreator | 2 +-
...taConsistencyCalculateAlgorithmChooserTest.java | 16 ++--
...lineMetaDataChangedEventHandlerFactoryTest.java | 47 ------------
.../mysql/ingest/MySQLIncrementalDumper.java | 8 +-
.../column/value/MySQLDataTypeHandlerFactory.java | 46 -----------
.../MySQLJdbcQueryPropertiesExtensionTest.java | 4 +-
.../value/MySQLDataTypeHandlerFactoryTest.java | 70 -----------------
.../OpenGaussJdbcQueryPropertiesExtensionTest.java | 4 +-
...PostgreSQLJdbcQueryPropertiesExtensionTest.java | 4 +-
.../ShowMigrationCheckAlgorithmsResultSet.java | 6 +-
.../query/ShowMigrationJobStatusResultSet.java | 6 +-
.../handler/update/CommitMigrationUpdater.java | 6 +-
.../handler/update/RollbackMigrationUpdater.java | 7 +-
.../api/impl/ConsistencyCheckJobAPI.java | 6 +-
...tencyCheckChangedJobConfigurationProcessor.java | 5 +-
.../task/ConsistencyCheckTasksRunner.java | 7 +-
.../migration/api/impl/MigrationJobAPI.java | 20 ++---
.../MigrationChangedJobConfigurationProcessor.java | 4 +-
.../migration/prepare/MigrationJobPreparer.java | 5 +-
.../SingleSchemaMetaDataDecoratorTest.java | 5 +-
.../single/route/SingleSQLRouterTest.java | 9 ++-
.../DefaultSingleRuleConfigurationBuilderTest.java | 4 +-
.../single/rule/builder/SingleRuleBuilderTest.java | 6 +-
.../factory/SQLFederationExecutorFactory.java | 46 -----------
.../sqlfederation/rule/SQLFederationRule.java | 9 ++-
.../parser/OptimizerParserContextFactory.java | 8 +-
.../dialect/OptimizerSQLDialectBuilderFactory.java | 48 ------------
.../OptimizerSQLDialectBuilderFactoryTest.java | 41 ----------
.../factory/SQLTranslatorFactory.java | 46 -----------
.../sqltranslator/rule/SQLTranslatorRule.java | 5 +-
.../sqltranslator/jooq/JooQDialectRegistry.java | 14 ++--
.../traffic/factory/TrafficAlgorithmFactory.java | 57 --------------
.../TrafficLoadBalanceAlgorithmFactory.java | 57 --------------
.../TrafficLoadBalanceAlgorithmFactoryTest.java | 41 ----------
.../TrafficLoadBalanceAlgorithmFixture.java | 46 -----------
...gsphere.traffic.spi.TrafficLoadBalanceAlgorithm | 18 -----
.../shardingsphere/traffic/rule/TrafficRule.java | 8 +-
.../segment/SQLMatchTrafficAlgorithmTest.java | 5 +-
.../segment/SQLRegexTrafficAlgorithmTest.java | 5 +-
.../update/AlterTrafficRuleStatementUpdater.java | 11 +--
.../update/CreateTrafficRuleStatementUpdater.java | 13 ++--
.../ShardingSphereTransactionManagerFactory.java | 61 ---------------
.../ShardingSphereTransactionManagerEngine.java | 4 +-
...ShardingSphereTransactionManagerEngineTest.java | 5 +-
.../AlterTransactionRuleStatementUpdater.java | 13 ++--
.../AlterTransactionRuleStatementUpdaterTest.java | 11 +--
...eataATShardingSphereTransactionManagerTest.java | 5 +-
.../xa/XAShardingSphereTransactionManager.java | 10 ++-
.../jta/connection/XAConnectionWrapperFactory.java | 45 -----------
.../xa/jta/datasource/XADataSourceFactory.java | 45 -----------
.../xa/jta/datasource/XATransactionDataSource.java | 9 ++-
.../properties/XADataSourceDefinitionFactory.java | 45 -----------
.../swapper/DataSourcePropertyProviderFactory.java | 48 ------------
.../jta/datasource/swapper/DataSourceSwapper.java | 5 +-
.../XATransactionManagerProviderFactory.java | 60 ---------------
.../xa/XAShardingSphereTransactionManagerTest.java | 6 +-
.../transaction/xa/fixture/DataSourceUtils.java | 6 +-
.../connection/XAConnectionWrapperFactoryTest.java | 33 --------
.../dialect/H2XAConnectionWrapperTest.java | 13 ++--
.../dialect/MariaDBXAConnectionWrapperTest.java | 13 ++--
.../dialect/MySQLXAConnectionWrapperTest.java | 13 ++--
.../dialect/OpenGaussXAConnectionWrapperTest.java | 13 ++--
.../dialect/PostgreSQLXAConnectionWrapperTest.java | 13 ++--
.../xa/jta/datasource/XADataSourceFactoryTest.java | 67 ----------------
.../datasource/XATransactionDataSourceTest.java | 19 ++---
.../XADataSourceDefinitionFactoryTest.java | 33 --------
.../DataSourcePropertyProviderFactoryTest.java | 40 ----------
.../XATransactionManagerProviderFactoryTest.java | 37 ---------
.../xa/core/src/test/resources/logback-test.xml | 1 -
.../mode/manager/ContextManagerBuilderFactory.java | 46 -----------
.../ContextManagerLifecycleListenerFactory.java | 44 -----------
.../mode/metadata/MetaDataContexts.java | 9 ++-
.../manager/ContextManagerBuilderFactoryTest.java | 38 ---------
.../fixture/ContextManagerBuilderFixture.java | 42 ----------
...ardingsphere.mode.manager.ContextManagerBuilder | 18 -----
.../cluster/ClusterContextManagerBuilder.java | 16 +++-
.../registry/GovernanceWatcherFactory.java | 4 -
.../compute/service/ComputeNodeStatusService.java | 5 +-
.../watcher/ComputeNodeStateChangedWatcher.java | 4 +-
.../ClusterPersistRepositoryFactoryTest.java | 36 ---------
.../cluster/ClusterPersistRepositoryFactory.java | 48 ------------
.../creator/DistributedLockCreatorFactory.java | 45 -----------
.../cluster/lock/holder/DistributedLockHolder.java | 4 +-
.../StandaloneContextManagerBuilder.java | 9 ++-
.../StandalonePersistRepositoryFactoryTest.java | 40 ----------
.../StandalonePersistRepositoryFactory.java | 47 ------------
.../repository/standalone/jdbc/JDBCRepository.java | 6 +-
.../provider/JDBCRepositoryProviderFactory.java | 45 -----------
.../JDBCRepositoryProviderFactoryTest.java | 37 ---------
.../backend/communication/ProxySQLExecutor.java | 6 +-
.../callback/ProxyJDBCExecutorCallback.java | 6 +-
.../jdbc/statement/JDBCBackendStatement.java | 3 +-
...tementMemoryStrictlyFetchSizeSetterFactory.java | 46 -----------
.../backend/config/ProxyConfigurationLoader.java | 5 +-
.../handler/ProxyBackendHandlerFactory.java | 34 ---------
.../admin/DatabaseAdminBackendHandlerFactory.java | 8 +-
.../DatabaseAdminExecutorCreatorFactory.java | 47 ------------
.../ReplayRequiredSessionVariablesLoader.java | 47 ------------
.../mysql/DefaultMySQLSessionVariableHandler.java | 7 +-
.../mysql/MySQLSessionVariableHandlerFactory.java | 41 ----------
.../admin/mysql/MySQLSetVariableAdminExecutor.java | 8 +-
.../DefaultPostgreSQLSessionVariableHandler.java | 7 +-
.../PostgreSQLResetVariableAdminExecutor.java | 5 +-
.../PostgreSQLSessionVariableHandlerFactory.java | 44 -----------
.../PostgreSQLSetVariableAdminExecutor.java | 5 +-
.../backend/handler/cdc/CDCBackendHandler.java | 6 +-
...ueryableGlobalRuleRALBackendHandlerFactory.java | 51 -------------
.../distsql/ral/RALBackendHandlerFactory.java | 19 +++--
...pdatableGlobalRuleRALBackendHandlerFactory.java | 50 ------------
...aseDiscoveryRuleConfigurationImportChecker.java | 9 ++-
...iteSplittingRuleConfigurationImportChecker.java | 9 ++-
.../QueryableScalingRALBackendHandlerFactory.java | 48 ------------
.../update/UpdatableScalingRALBackendHandler.java | 5 +-
.../ExportDatabaseConfigurationHandler.java | 4 +-
.../ral/queryable/ShowMigrationRuleResultSet.java | 7 +-
.../AlterInventoryIncrementalRuleUpdater.java | 5 +-
.../rdl/rule/RuleDefinitionBackendHandler.java | 8 +-
.../distsql/rql/RQLBackendHandlerFactory.java | 7 +-
.../header/query/QueryHeaderBuilderEngine.java | 10 ++-
.../header/query/QueryHeaderBuilderFactory.java | 46 -----------
.../jdbc/DatabaseCommunicationEngineTest.java | 8 +-
...ntMemoryStrictlyFetchSizeSetterFactoryTest.java | 37 ---------
...tementMemoryStrictlyFetchSizeSetterFixture.java | 34 ---------
.../handler/ProxyBackendHandlerFactoryTest.java | 6 +-
.../DatabaseAdminExecutorCreatorFactoryTest.java | 38 ---------
.../ReplayRequiredSessionVariablesLoaderTest.java | 39 ----------
.../DatabaseAdminExecutorCreatorFixture.java | 49 ------------
.../FixtureReplayRequiredSessionVariables.java | 36 ---------
.../DefaultMySQLSessionVariableHandlerTest.java | 10 ++-
.../MySQLSessionVariableHandlerFactoryTest.java | 31 --------
...efaultPostgreSQLSessionVariableHandlerTest.java | 10 ++-
.../PostgreSQLResetVariableAdminExecutorTest.java | 7 +-
.../PostgreSQLSetVariableAdminExecutorTest.java | 7 +-
.../handler/cdc/fixture/FixtureCDCJobAPI.java | 2 +-
.../QueryableScalingFixtureRALStatement.java | 23 ------
.../fixture/QueryableScalingFixtureResultSet.java | 56 --------------
...eryableScalingRALBackendHandlerFactoryTest.java | 33 --------
.../query/QueryHeaderBuilderFactoryTest.java | 40 ----------
...here.distsql.handler.resultset.DistSQLResultSet | 18 -----
...tatement.StatementMemoryStrictlyFetchSizeSetter | 18 -----
...ler.admin.executor.DatabaseAdminExecutorCreator | 18 -----
...r.admin.executor.ReplayRequiredSessionVariables | 18 -----
.../proxy/initializer/BootstrapInitializer.java | 21 +++--
.../proxy/version/ShardingSphereProxyVersion.java | 7 +-
.../version/ShardingSphereProxyVersionTest.java | 9 ++-
.../netty/FrontendChannelInboundHandler.java | 5 +-
.../frontend/netty/ServerHandlerInitializer.java | 6 +-
.../DatabaseProtocolFrontendEngineFactory.java | 48 ------------
.../DatabaseProtocolFrontendEngineFactoryTest.java | 33 --------
.../execute/MySQLComStmtExecuteExecutor.java | 5 +-
.../prepare/MySQLComStmtPrepareExecutor.java | 5 +-
.../fieldlist/MySQLComFieldListPacketExecutor.java | 9 ++-
.../text/query/MySQLComQueryPacketExecutor.java | 10 +--
.../text/query/MySQLMultiStatementsHandler.java | 7 +-
.../query/simple/OpenGaussComQueryExecutor.java | 11 +--
.../query/simple/PostgreSQLComQueryExecutor.java | 11 +--
.../command/query/extended/PortalTest.java | 3 +-
.../DatabaseTypedSQLParserFacadeFactory.java | 45 -----------
.../core/database/parser/SQLParserExecutor.java | 3 +-
.../database/visitor/SQLVisitorFacadeFactory.java | 46 -----------
.../core/database/visitor/SQLVisitorFactory.java | 3 +-
.../DatabaseTypedSQLParserFacadeFactoryTest.java | 41 ----------
.../visitor/SQLVisitorFacadeFactoryTest.java | 31 --------
.../DatabaseTypedSQLParserFacadeFixture.java | 40 ----------
...ere.sql.parser.spi.DatabaseTypedSQLParserFacade | 18 -----
.../container/atomic/storage/impl/H2Container.java | 5 +-
.../atomic/storage/impl/MySQLContainer.java | 7 +-
.../atomic/storage/impl/OpenGaussContainer.java | 7 +-
.../atomic/storage/impl/PostgreSQLContainer.java | 7 +-
.../env/runtime/cluster/ClusterEnvironment.java | 4 +-
.../scenario/authority/AuthoritySQLSet.java | 4 +-
.../createtable/CreateTableSQLGeneratorIT.java | 10 ++-
.../param/array/E2ETestParameterGenerator.java | 4 +-
.../JdbcStandaloneTestParameterGenerator.java | 4 +-
.../test/it/optimize/SQLNodeConverterEngineIT.java | 9 ++-
.../sql/parser/external/ExternalSQLParserIT.java | 5 +-
.../SQLParseResultReporterCreatorFactory.java | 44 -----------
.../pipeline/api/PipelineJobAPIFactoryTest.java | 43 -----------
.../core/api/impl/MigrationJobAPITest.java | 9 ++-
...taConsistencyCalculateAlgorithmFactoryTest.java | 31 --------
.../PipelineDataSourceCreatorFactoryTest.java | 47 ------------
.../IncrementalDumperCreatorFactoryTest.java | 89 ----------------------
.../DataConsistencyCalculateAlgorithmFixture.java | 6 +-
.../core/importer/ImporterCreatorFactoryTest.java | 73 ------------------
.../dumper/ColumnValueReaderFactoryTest.java | 46 -----------
...hangedJobConfigurationProcessorFactoryTest.java | 45 -----------
.../sqlbuilder/PipelineSQLBuilderFactoryTest.java | 48 ------------
.../core/util/JobConfigurationBuilder.java | 6 +-
.../pipeline/core/util/PipelineContextUtil.java | 6 +-
.../datasource/DataSourceCheckerFactoryTest.java | 33 --------
.../position/PositionInitializerFactoryTest.java | 47 ------------
.../ShardingColumnsExtractorFactoryTest.java | 33 --------
.../it/rewrite/engine/AbstractSQLRewriterIT.java | 6 +-
548 files changed, 1471 insertions(+), 10863 deletions(-)
diff --git a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/spi/AgentServiceLoader.java b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/spi/AgentServiceLoader.java
index ef2f10603cb..9f712b4a25c 100644
--- a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/spi/AgentServiceLoader.java
+++ b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/spi/AgentServiceLoader.java
@@ -38,7 +38,7 @@ public final class AgentServiceLoader<T> {
private AgentServiceLoader(final Class<T> service) {
validate(service);
- this.services = register(service);
+ this.services = load(service);
}
private void validate(final Class<T> service) {
@@ -46,7 +46,7 @@ public final class AgentServiceLoader<T> {
Preconditions.checkArgument(service.isInterface(), "SPI class `%s` is not interface.", service);
}
- private Collection<T> register(final Class<T> service) {
+ private Collection<T> load(final Class<T> service) {
Collection<T> result = new LinkedList<>();
for (T each : ServiceLoader.load(service)) {
result.add(each);
diff --git a/agent/bootstrap/src/test/java/org/apache/shardingsphere/agent/bootstrap/transformer/AgentTransformerTest.java b/agent/bootstrap/src/test/java/org/apache/shardingsphere/agent/bootstrap/transformer/AgentTransformerTest.java
index df4855403d2..97817f4beaa 100644
--- a/agent/bootstrap/src/test/java/org/apache/shardingsphere/agent/bootstrap/transformer/AgentTransformerTest.java
+++ b/agent/bootstrap/src/test/java/org/apache/shardingsphere/agent/bootstrap/transformer/AgentTransformerTest.java
@@ -48,7 +48,7 @@ public final class AgentTransformerTest {
private static ResettableClassFileTransformer byteBuddyAgent;
@BeforeClass
- public static void setup() throws ReflectiveOperationException {
+ public static void setup() {
ByteBuddyAgent.install();
AgentClassLoader.init(Collections.emptyList());
AdvisorConfiguration advisorConfig = createAdvisorConfiguration();
diff --git a/dialect-exception/core/src/main/java/org/apache/shardingsphere/dialect/SQLExceptionTransformEngine.java b/dialect-exception/core/src/main/java/org/apache/shardingsphere/dialect/SQLExceptionTransformEngine.java
index 6b9e627f885..eb09ed73d3b 100644
--- a/dialect-exception/core/src/main/java/org/apache/shardingsphere/dialect/SQLExceptionTransformEngine.java
+++ b/dialect-exception/core/src/main/java/org/apache/shardingsphere/dialect/SQLExceptionTransformEngine.java
@@ -22,10 +22,10 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.dialect.exception.SQLDialectException;
import org.apache.shardingsphere.dialect.exception.protocol.DatabaseProtocolException;
import org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper;
-import org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapperFactory;
import org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.DatabaseProtocolSQLException;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnknownSQLException;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.sql.SQLException;
import java.util.Optional;
@@ -54,7 +54,7 @@ public final class SQLExceptionTransformEngine {
if (cause instanceof DatabaseProtocolException) {
return new DatabaseProtocolSQLException(cause.getMessage()).toSQLException();
}
- Optional<SQLDialectExceptionMapper> dialectExceptionMapper = SQLDialectExceptionMapperFactory.findInstance(databaseType);
+ Optional<SQLDialectExceptionMapper> dialectExceptionMapper = TypedSPIRegistry.findRegisteredService(SQLDialectExceptionMapper.class, databaseType);
if (dialectExceptionMapper.isPresent()) {
return dialectExceptionMapper.get().convert((SQLDialectException) cause);
}
diff --git a/dialect-exception/core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java b/dialect-exception/core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java
deleted file mode 100644
index 485b286f5c4..00000000000
--- a/dialect-exception/core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java
+++ /dev/null
@@ -1,46 +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.dialect.mapper;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-import java.util.Optional;
-
-/**
- * SQL dialect exception mapper factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class SQLDialectExceptionMapperFactory {
-
- static {
- ShardingSphereServiceLoader.register(SQLDialectExceptionMapper.class);
- }
-
- /**
- * Find instance of SQL dialect exception mapper.
- *
- * @param databaseType database type
- * @return found instance
- */
- public static Optional<SQLDialectExceptionMapper> findInstance(final String databaseType) {
- return TypedSPIRegistry.findRegisteredService(SQLDialectExceptionMapper.class, databaseType);
- }
-}
diff --git a/dialect-exception/core/src/test/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactoryTest.java b/dialect-exception/core/src/test/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactoryTest.java
deleted file mode 100644
index 1b48fa20533..00000000000
--- a/dialect-exception/core/src/test/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactoryTest.java
+++ /dev/null
@@ -1,34 +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.dialect.mapper;
-
-import org.apache.shardingsphere.dialect.mapper.fixture.FixtureSQLDialectExceptionMapper;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class SQLDialectExceptionMapperFactoryTest {
-
- @Test
- public void assertGetInstance() {
- assertTrue(SQLDialectExceptionMapperFactory.findInstance("FIXTURE").isPresent());
- assertThat(SQLDialectExceptionMapperFactory.findInstance("FIXTURE").get(), instanceOf(FixtureSQLDialectExceptionMapper.class));
- }
-}
diff --git a/dialect-exception/core/src/test/java/org/apache/shardingsphere/dialect/mapper/fixture/FixtureSQLDialectExceptionMapper.java b/dialect-exception/core/src/test/java/org/apache/shardingsphere/dialect/mapper/fixture/FixtureSQLDialectExceptionMapper.java
deleted file mode 100644
index 8f4adb3eb90..00000000000
--- a/dialect-exception/core/src/test/java/org/apache/shardingsphere/dialect/mapper/fixture/FixtureSQLDialectExceptionMapper.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.dialect.mapper.fixture;
-
-import org.apache.shardingsphere.dialect.exception.SQLDialectException;
-import org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper;
-
-import java.sql.SQLException;
-
-public final class FixtureSQLDialectExceptionMapper implements SQLDialectExceptionMapper {
-
- @Override
- public SQLException convert(final SQLDialectException sqlDialectException) {
- return new SQLException();
- }
-
- @Override
- public String getType() {
- return "FIXTURE";
- }
-}
diff --git a/dialect-exception/core/src/test/resources/META-INF/services/org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper b/dialect-exception/core/src/test/resources/META-INF/services/org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper
deleted file mode 100644
index c0efc2fbbd2..00000000000
--- a/dialect-exception/core/src/test/resources/META-INF/services/org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.dialect.mapper.fixture.FixtureSQLDialectExceptionMapper
diff --git a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/update/RALUpdaterFactory.java b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/update/RALUpdaterFactory.java
deleted file mode 100644
index 6c89ce5f548..00000000000
--- a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/update/RALUpdaterFactory.java
+++ /dev/null
@@ -1,45 +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.distsql.handler.update;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * RAL updater factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class RALUpdaterFactory {
-
- static {
- ShardingSphereServiceLoader.register(RALUpdater.class);
- }
-
- /**
- * Get instance of RAL updater.
- *
- * @param sqlStatementClass SQL statement class
- * @return got instance
- */
- @SuppressWarnings("rawtypes")
- public static RALUpdater getInstance(final Class<?> sqlStatementClass) {
- return TypedSPIRegistry.getRegisteredService(RALUpdater.class, sqlStatementClass.getCanonicalName());
- }
-}
diff --git a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/update/RuleDefinitionUpdaterFactory.java b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/update/RuleDefinitionUpdaterFactory.java
deleted file mode 100644
index 9d97b007516..00000000000
--- a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/update/RuleDefinitionUpdaterFactory.java
+++ /dev/null
@@ -1,46 +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.distsql.handler.update;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-
-/**
- * Rule definition updater factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class RuleDefinitionUpdaterFactory {
-
- static {
- ShardingSphereServiceLoader.register(RuleDefinitionUpdater.class);
- }
-
- /**
- * Get instance of rule definition updater.
- *
- * @param sqlStatement SQL statement
- * @return got instance
- */
- @SuppressWarnings("rawtypes")
- public static RuleDefinitionUpdater getInstance(final SQLStatement sqlStatement) {
- return TypedSPIRegistry.getRegisteredService(RuleDefinitionUpdater.class, sqlStatement.getClass().getCanonicalName());
- }
-}
diff --git a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/config/FixtureRuleConfiguration.java b/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/config/FixtureRuleConfiguration.java
deleted file mode 100644
index 0060535fe4b..00000000000
--- a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/config/FixtureRuleConfiguration.java
+++ /dev/null
@@ -1,29 +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.distsql.handler.fixture.config;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-
-@RequiredArgsConstructor
-@Getter
-public final class FixtureRuleConfiguration implements RuleConfiguration {
-
- private final String name;
-}
diff --git a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/statement/FixtureRALStatement.java b/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/statement/FixtureRALStatement.java
deleted file mode 100644
index 34cd3d426a4..00000000000
--- a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/statement/FixtureRALStatement.java
+++ /dev/null
@@ -1,23 +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.distsql.handler.fixture.statement;
-
-import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
-
-public final class FixtureRALStatement extends AbstractSQLStatement {
-}
diff --git a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/statement/FixtureRuleStatement.java b/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/statement/FixtureRuleStatement.java
deleted file mode 100644
index 2523fa2884a..00000000000
--- a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/statement/FixtureRuleStatement.java
+++ /dev/null
@@ -1,28 +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.distsql.handler.fixture.statement;
-
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-
-public final class FixtureRuleStatement implements SQLStatement {
-
- @Override
- public int getParameterCount() {
- return 0;
- }
-}
diff --git a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/updater/FixtureRALUpdater.java b/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/updater/FixtureRALUpdater.java
deleted file mode 100644
index 6a5673548bb..00000000000
--- a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/updater/FixtureRALUpdater.java
+++ /dev/null
@@ -1,33 +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.distsql.handler.fixture.updater;
-
-import org.apache.shardingsphere.distsql.handler.fixture.statement.FixtureRALStatement;
-import org.apache.shardingsphere.distsql.handler.update.RALUpdater;
-
-public final class FixtureRALUpdater implements RALUpdater<FixtureRALStatement> {
-
- @Override
- public void executeUpdate(final String databaseName, final FixtureRALStatement sqlStatement) {
- }
-
- @Override
- public String getType() {
- return FixtureRALStatement.class.getName();
- }
-}
diff --git a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/updater/FixtureRuleDefinitionUpdater.java b/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/updater/FixtureRuleDefinitionUpdater.java
deleted file mode 100644
index 1b28d5970aa..00000000000
--- a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/updater/FixtureRuleDefinitionUpdater.java
+++ /dev/null
@@ -1,40 +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.distsql.handler.fixture.updater;
-
-import org.apache.shardingsphere.distsql.handler.fixture.config.FixtureRuleConfiguration;
-import org.apache.shardingsphere.distsql.handler.fixture.statement.FixtureRuleStatement;
-import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-
-public final class FixtureRuleDefinitionUpdater implements RuleDefinitionUpdater<FixtureRuleStatement, FixtureRuleConfiguration> {
-
- @Override
- public void checkSQLStatement(final ShardingSphereDatabase database, final FixtureRuleStatement sqlStatement, final FixtureRuleConfiguration currentRuleConfig) {
- }
-
- @Override
- public Class<FixtureRuleConfiguration> getRuleConfigurationClass() {
- return FixtureRuleConfiguration.class;
- }
-
- @Override
- public String getType() {
- return FixtureRuleStatement.class.getName();
- }
-}
diff --git a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/update/RALUpdaterFactoryTest.java b/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/update/RALUpdaterFactoryTest.java
deleted file mode 100644
index 0dc67461d07..00000000000
--- a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/update/RALUpdaterFactoryTest.java
+++ /dev/null
@@ -1,33 +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.distsql.handler.update;
-
-import org.apache.shardingsphere.distsql.handler.fixture.statement.FixtureRALStatement;
-import org.apache.shardingsphere.distsql.handler.fixture.updater.FixtureRALUpdater;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class RALUpdaterFactoryTest {
-
- @Test
- public void assertGetInstance() {
- assertThat(RALUpdaterFactory.getInstance(FixtureRALStatement.class), instanceOf(FixtureRALUpdater.class));
- }
-}
diff --git a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/update/RuleDefinitionUpdaterFactoryTest.java b/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/update/RuleDefinitionUpdaterFactoryTest.java
deleted file mode 100644
index a95429da9c5..00000000000
--- a/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/update/RuleDefinitionUpdaterFactoryTest.java
+++ /dev/null
@@ -1,34 +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.distsql.handler.update;
-
-import org.apache.shardingsphere.distsql.handler.fixture.updater.FixtureRuleDefinitionUpdater;
-import org.apache.shardingsphere.distsql.handler.fixture.statement.FixtureRuleStatement;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-
-public final class RuleDefinitionUpdaterFactoryTest {
-
- @Test
- public void assertGetInstance() {
- assertThat(RuleDefinitionUpdaterFactory.getInstance(mock(FixtureRuleStatement.class)), instanceOf(FixtureRuleDefinitionUpdater.class));
- }
-}
diff --git a/distsql/handler/src/test/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RALUpdater b/distsql/handler/src/test/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RALUpdater
deleted file mode 100644
index b37f5675191..00000000000
--- a/distsql/handler/src/test/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RALUpdater
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.distsql.handler.fixture.updater.FixtureRALUpdater
diff --git a/distsql/handler/src/test/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater b/distsql/handler/src/test/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater
deleted file mode 100644
index 623a59f06c5..00000000000
--- a/distsql/handler/src/test/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.distsql.handler.fixture.updater.FixtureRuleDefinitionUpdater
diff --git a/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/featured/FeaturedDistSQLStatementParserEngine.java b/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/featured/FeaturedDistSQLStatementParserEngine.java
index add15f12701..996abad9e0b 100644
--- a/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/featured/FeaturedDistSQLStatementParserEngine.java
+++ b/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/featured/FeaturedDistSQLStatementParserEngine.java
@@ -22,6 +22,8 @@ import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
import org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade;
+import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
import org.apache.shardingsphere.sql.parser.core.SQLParserFactory;
@@ -45,7 +47,7 @@ public final class FeaturedDistSQLStatementParserEngine {
}
private FeaturedDistSQLParseASTNode parseToASTNode(final String sql) {
- for (FeaturedDistSQLStatementParserFacade each : FeaturedDistSQLStatementParserFacadeFactory.getAllInstances()) {
+ for (FeaturedDistSQLStatementParserFacade each : ShardingSphereServiceLoader.getServiceInstances(FeaturedDistSQLStatementParserFacade.class)) {
try {
ParseASTNode parseASTNode = (ParseASTNode) SQLParserFactory.newInstance(sql, each.getLexerClass(), each.getParserClass()).parse();
return new FeaturedDistSQLParseASTNode(each.getType(), parseASTNode);
@@ -58,7 +60,7 @@ public final class FeaturedDistSQLStatementParserEngine {
@SneakyThrows(ReflectiveOperationException.class)
@SuppressWarnings("rawtypes")
private SQLStatement getSQLStatement(final String sql, final String featureType, final ParseASTNode parseASTNode) {
- SQLVisitor visitor = FeaturedDistSQLStatementParserFacadeFactory.getInstance(featureType).getVisitorClass().getDeclaredConstructor().newInstance();
+ SQLVisitor visitor = TypedSPIRegistry.getRegisteredService(FeaturedDistSQLStatementParserFacade.class, featureType).getVisitorClass().getDeclaredConstructor().newInstance();
if (parseASTNode.getRootNode() instanceof ErrorNode) {
throw new SQLParsingException(sql);
}
diff --git a/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/featured/FeaturedDistSQLStatementParserFacadeFactory.java b/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/featured/FeaturedDistSQLStatementParserFacadeFactory.java
deleted file mode 100644
index 96ac003b5d4..00000000000
--- a/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/featured/FeaturedDistSQLStatementParserFacadeFactory.java
+++ /dev/null
@@ -1,56 +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.distsql.parser.core.featured;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-import java.util.Collection;
-
-/**
- * Featured DistSQL statement parser facade factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class FeaturedDistSQLStatementParserFacadeFactory {
-
- static {
- ShardingSphereServiceLoader.register(FeaturedDistSQLStatementParserFacade.class);
- }
-
- /**
- * Get instance of featured DistSQL statement parser facade.
- *
- * @param type feature type
- * @return got instance
- */
- public static FeaturedDistSQLStatementParserFacade getInstance(final String type) {
- return TypedSPIRegistry.getRegisteredService(FeaturedDistSQLStatementParserFacade.class, type);
- }
-
- /**
- * Get all instances of featured DistSQL statement parser facade.
- *
- * @return got instances
- */
- public static Collection<FeaturedDistSQLStatementParserFacade> getAllInstances() {
- return ShardingSphereServiceLoader.getServiceInstances(FeaturedDistSQLStatementParserFacade.class);
- }
-}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGeneratorFactory.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGeneratorFactory.java
index c572a147d99..9ce2c11a662 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGeneratorFactory.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGeneratorFactory.java
@@ -23,7 +23,6 @@ import freemarker.template.TemplateException;
import lombok.SneakyThrows;
import org.apache.shardingsphere.example.generator.core.yaml.config.YamlExampleConfiguration;
import org.apache.shardingsphere.example.generator.core.yaml.config.YamlExampleConfigurationValidator;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
@@ -44,10 +43,6 @@ public final class ExampleGeneratorFactory {
private final Configuration templateConfig;
- static {
- ShardingSphereServiceLoader.register(ExampleGenerator.class);
- }
-
public ExampleGeneratorFactory() throws IOException {
templateConfig = createTemplateConfiguration();
}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
index 77986a53688..6d11fbad5d9 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.example.generator.scenario;
import org.apache.shardingsphere.example.generator.scenario.feature.FeatureExampleScenario;
import org.apache.shardingsphere.example.generator.scenario.framework.FrameworkExampleScenario;
import org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.util.Arrays;
@@ -42,12 +41,6 @@ public final class ExampleScenarioFactory {
private final TransactionExampleScenario transactionScenario;
- static {
- ShardingSphereServiceLoader.register(FeatureExampleScenario.class);
- ShardingSphereServiceLoader.register(FrameworkExampleScenario.class);
- ShardingSphereServiceLoader.register(TransactionExampleScenario.class);
- }
-
public ExampleScenarioFactory(final String feature, final String framework, final String transaction) {
featureScenarios = getFeatureScenarios(feature);
frameworkScenario = getFrameworkScenario(framework);
diff --git a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/factory/DatabaseDiscoveryProviderAlgorithmFactory.java b/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/factory/DatabaseDiscoveryProviderAlgorithmFactory.java
deleted file mode 100644
index b88d4ea2514..00000000000
--- a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/factory/DatabaseDiscoveryProviderAlgorithmFactory.java
+++ /dev/null
@@ -1,57 +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.dbdiscovery.factory;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * Database discovery provider algorithm factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DatabaseDiscoveryProviderAlgorithmFactory {
-
- static {
- ShardingSphereServiceLoader.register(DatabaseDiscoveryProviderAlgorithm.class);
- }
-
- /**
- * Create new instance of database discovery provider algorithm.
- *
- * @param databaseDiscoveryProviderAlgorithmConfig database discovery provider algorithm configuration
- * @return created instance
- */
- public static DatabaseDiscoveryProviderAlgorithm newInstance(final AlgorithmConfiguration databaseDiscoveryProviderAlgorithmConfig) {
- return ShardingSphereAlgorithmFactory.createAlgorithm(databaseDiscoveryProviderAlgorithmConfig, DatabaseDiscoveryProviderAlgorithm.class);
- }
-
- /**
- * Judge whether contains database discovery provider algorithm.
- *
- * @param databaseDiscoveryProviderAlgorithmType database discovery provider algorithm type
- * @return contains database discovery provider algorithm or not
- */
- public static boolean contains(final String databaseDiscoveryProviderAlgorithmType) {
- return TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryProviderAlgorithm.class, databaseDiscoveryProviderAlgorithmType).isPresent();
- }
-}
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 86c94d7617b..918ac66c561 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
@@ -24,12 +24,11 @@ import org.apache.shardingsphere.dbdiscovery.algorithm.DatabaseDiscoveryEngine;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.factory.DatabaseDiscoveryProviderAlgorithmFactory;
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.rule.identifier.type.exportable.constant.ExportableConstants;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
@@ -37,6 +36,7 @@ import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
+import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
import org.apache.shardingsphere.infra.schedule.CronJob;
import org.apache.shardingsphere.infra.schedule.ScheduleContext;
import org.apache.shardingsphere.mode.metadata.storage.StorageNodeStatus;
@@ -90,7 +90,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(), DatabaseDiscoveryProviderAlgorithmFactory.newInstance(entry.getValue()));
+ result.put(entry.getKey(), ShardingSphereAlgorithmFactory.createAlgorithm(entry.getValue(), DatabaseDiscoveryProviderAlgorithm.class));
}
return result;
}
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java
index 4eda56eb4c6..935a1d929d6 100644
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java
+++ b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java
@@ -20,15 +20,11 @@ package org.apache.shardingsphere.dbdiscovery.checker;
import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
-import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationCheckerFactory;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.junit.Test;
import java.util.Collections;
-import java.util.Optional;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -38,10 +34,8 @@ public final class DatabaseDiscoveryRuleConfigurationCheckerTest {
@Test
public void assertValidCheck() {
DatabaseDiscoveryRuleConfiguration config = getValidConfiguration();
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(DatabaseDiscoveryRuleConfigurationChecker.class));
- checker.get().check("test", config, Collections.emptyMap(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, Collections.emptyMap(), Collections.emptyList());
}
private DatabaseDiscoveryRuleConfiguration getValidConfiguration() {
@@ -56,10 +50,8 @@ public final class DatabaseDiscoveryRuleConfigurationCheckerTest {
@Test(expected = IllegalStateException.class)
public void assertInvalidCheck() {
DatabaseDiscoveryRuleConfiguration config = getInvalidConfiguration();
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(DatabaseDiscoveryRuleConfigurationChecker.class));
- checker.get().check("test", config, Collections.emptyMap(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, Collections.emptyMap(), Collections.emptyList());
}
private DatabaseDiscoveryRuleConfiguration getInvalidConfiguration() {
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
index 0a3685dccf3..ab8e2a1a2c9 100644
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
+++ b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
@@ -34,10 +34,11 @@ import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.route.SQLRouterFactory;
+import org.apache.shardingsphere.infra.route.SQLRouter;
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.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
@@ -85,7 +86,7 @@ public final class DatabaseDiscoverySQLRouterTest {
InstanceContext instanceContext = mock(InstanceContext.class, RETURNS_DEEP_STUBS);
when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
rule = new DatabaseDiscoveryRule(DATA_SOURCE_NAME, Collections.singletonMap(PRIMARY_DATA_SOURCE, new MockedDataSource()), config, instanceContext);
- sqlRouter = (DatabaseDiscoverySQLRouter) SQLRouterFactory.getInstances(Collections.singleton(rule)).get(rule);
+ sqlRouter = (DatabaseDiscoverySQLRouter) OrderedSPIRegistry.getRegisteredServices(SQLRouter.class, Collections.singleton(rule)).get(rule);
}
@Test
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
index b2e661e516c..0084866db81 100644
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
+++ b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
import org.junit.Test;
@@ -46,14 +46,14 @@ public final class DatabaseDiscoveryRuleBuilderTest {
@Test
public void assertBuild() {
ScheduleContextFactory.newInstance(new ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class)));
- DatabaseDiscoveryRuleConfiguration config = new DatabaseDiscoveryRuleConfiguration(
+ DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(
Collections.singleton(new DatabaseDiscoveryDataSourceRuleConfiguration("name", Collections.singletonList("name"), "", "CORE.FIXTURE")),
Collections.singletonMap("ha_heartbeat", new DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
Collections.singletonMap("CORE.FIXTURE", new AlgorithmConfiguration("CORE.FIXTURE", new Properties())));
- DatabaseRuleBuilder builder = DatabaseRuleBuilderFactory.getInstanceMap(Collections.singletonList(config)).get(config);
+ DatabaseRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, Collections.singletonList(ruleConfig)).get(ruleConfig);
InstanceContext instanceContext = mock(InstanceContext.class, RETURNS_DEEP_STUBS);
when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
- assertThat(builder.build(config, "test_schema",
+ assertThat(builder.build(ruleConfig, "test_schema",
Collections.singletonMap("name", new MockedDataSource()), Collections.emptyList(), instanceContext), instanceOf(DatabaseDiscoveryRule.class));
}
}
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapperTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapperTest.java
index e7f08606a4a..2cb20506913 100644
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapperTest.java
+++ b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapperTest.java
@@ -22,7 +22,8 @@ import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDa
import org.apache.shardingsphere.dbdiscovery.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.yaml.config.rule.YamlDatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperFactory;
+import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
import org.junit.Test;
import java.util.Arrays;
@@ -85,7 +86,7 @@ public final class YamlDatabaseDiscoveryRuleConfigurationSwapperTest {
}
private YamlDatabaseDiscoveryRuleConfigurationSwapper getYamlDatabaseDiscoveryRuleConfigurationSwapper() {
- Optional<YamlDatabaseDiscoveryRuleConfigurationSwapper> result = YamlRuleConfigurationSwapperFactory.getAllInstances().stream()
+ Optional<YamlDatabaseDiscoveryRuleConfigurationSwapper> result = ShardingSphereServiceLoader.getServiceInstances(YamlRuleConfigurationSwapper.class).stream()
.filter(each -> each instanceof YamlDatabaseDiscoveryRuleConfigurationSwapper)
.map(each -> (YamlDatabaseDiscoveryRuleConfigurationSwapper) each)
.findFirst();
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
index 1cb497ae2b3..d748d39ef31 100644
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
+++ b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
@@ -24,16 +24,17 @@ import org.apache.shardingsphere.dbdiscovery.distsql.handler.converter.DatabaseD
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.AbstractDatabaseDiscoverySegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryDefinitionSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.factory.DatabaseDiscoveryProviderAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
import org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdater;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.util.Collection;
import java.util.Collections;
@@ -88,7 +89,7 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDef
Map<String, List<AbstractDatabaseDiscoverySegment>> segmentMap = sqlStatement.getRules().stream().collect(Collectors.groupingBy(each -> each.getClass().getSimpleName()));
Collection<String> invalidInput = segmentMap.getOrDefault(DatabaseDiscoveryDefinitionSegment.class.getSimpleName(), Collections.emptyList()).stream()
.map(each -> ((DatabaseDiscoveryDefinitionSegment) each).getDiscoveryType().getName()).distinct()
- .filter(each -> !DatabaseDiscoveryProviderAlgorithmFactory.contains(each)).collect(Collectors.toList());
+ .filter(each -> !TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryProviderAlgorithm.class, each).isPresent()).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(invalidInput.isEmpty(), () -> new InvalidAlgorithmConfigurationException("database discovery", invalidInput));
ShardingSpherePreconditions.checkState(invalidInput.isEmpty(), () -> new MissingRequiredAlgorithmException("database discovery", invalidInput));
}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java
index 3564092e569..978519eff71 100644
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java
+++ b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java
@@ -21,14 +21,15 @@ import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleCon
import org.apache.shardingsphere.dbdiscovery.distsql.handler.converter.DatabaseDiscoveryRuleStatementConverter;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryProviderAlgorithmSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryTypeStatement;
-import org.apache.shardingsphere.dbdiscovery.factory.DatabaseDiscoveryProviderAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
import org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
+import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdater;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.util.Collection;
import java.util.Map.Entry;
@@ -74,7 +75,7 @@ public final class AlterDatabaseDiscoveryTypeStatementUpdater implements RuleDef
private void checkInvalidDiscoverType(final AlterDatabaseDiscoveryTypeStatement sqlStatement) {
Collection<String> invalidType = sqlStatement.getProviders().stream().map(each -> each.getAlgorithm().getName()).distinct()
- .filter(each -> !DatabaseDiscoveryProviderAlgorithmFactory.contains(each)).collect(Collectors.toList());
+ .filter(each -> !TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryProviderAlgorithm.class, each).isPresent()).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(invalidType.isEmpty(), () -> new InvalidAlgorithmConfigurationException(RULE_TYPE, invalidType));
}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
index 456f5c5d19e..9082ce38fe8 100644
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
+++ b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
@@ -23,15 +23,16 @@ import org.apache.shardingsphere.dbdiscovery.distsql.handler.converter.DatabaseD
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.AbstractDatabaseDiscoverySegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryDefinitionSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.factory.DatabaseDiscoveryProviderAlgorithmFactory;
-import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
import org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
+import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
+import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpdater;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.util.Collection;
import java.util.Collections;
@@ -88,7 +89,7 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdater implements RuleDe
Map<String, List<AbstractDatabaseDiscoverySegment>> segmentMap = sqlStatement.getRules().stream().collect(Collectors.groupingBy(each -> each.getClass().getSimpleName()));
Collection<String> invalidInput = segmentMap.getOrDefault(DatabaseDiscoveryDefinitionSegment.class.getSimpleName(), Collections.emptyList()).stream()
.map(each -> ((DatabaseDiscoveryDefinitionSegment) each).getDiscoveryType().getName()).distinct()
- .filter(each -> !DatabaseDiscoveryProviderAlgorithmFactory.contains(each)).collect(Collectors.toList());
+ .filter(each -> !TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryProviderAlgorithm.class, each).isPresent()).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(invalidInput.isEmpty(), () -> new InvalidAlgorithmConfigurationException(RULE_TYPE.toLowerCase(), invalidInput));
ShardingSpherePreconditions.checkState(invalidInput.isEmpty(), () -> new MissingRequiredAlgorithmException(RULE_TYPE, databaseName, invalidInput));
}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java
index c896eca63d9..f6f14995f51 100644
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java
+++ b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java
@@ -21,13 +21,14 @@ import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleCon
import org.apache.shardingsphere.dbdiscovery.distsql.handler.converter.DatabaseDiscoveryRuleStatementConverter;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryProviderAlgorithmSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryTypeStatement;
-import org.apache.shardingsphere.dbdiscovery.factory.DatabaseDiscoveryProviderAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
import org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
+import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpdater;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.util.Collection;
import java.util.Map.Entry;
@@ -65,7 +66,7 @@ public final class CreateDatabaseDiscoveryTypeStatementUpdater implements RuleDe
private void checkInvalidDiscoverType(final CreateDatabaseDiscoveryTypeStatement sqlStatement) {
Collection<String> invalidType = sqlStatement.getProviders().stream().map(each -> each.getAlgorithm().getName()).distinct()
- .filter(each -> !DatabaseDiscoveryProviderAlgorithmFactory.contains(each)).collect(Collectors.toList());
+ .filter(each -> !TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryProviderAlgorithm.class, each).isPresent()).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(invalidType.isEmpty(), () -> new InvalidAlgorithmConfigurationException(RULE_TYPE, invalidType));
}
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 14d5525dcd7..c20571e190c 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
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.dbdiscovery.mysql.type;
-import org.apache.shardingsphere.dbdiscovery.factory.DatabaseDiscoveryProviderAlgorithmFactory;
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.junit.Test;
@@ -30,8 +30,8 @@ import java.util.Collections;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
@@ -44,7 +44,7 @@ public final class MGRDatabaseDiscoveryProviderAlgorithmTest {
public void assertCheckEnvironment() throws SQLException {
Properties props = new Properties();
props.setProperty("group-name", "foo_group");
- DatabaseDiscoveryProviderAlgorithm actual = DatabaseDiscoveryProviderAlgorithmFactory.newInstance(new AlgorithmConfiguration("MySQL.MGR", props));
+ DatabaseDiscoveryProviderAlgorithm actual = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MySQL.MGR", props), DatabaseDiscoveryProviderAlgorithm.class);
actual.checkEnvironment("foo_db", Collections.singletonList(mockEnvironmentAvailableDataSource()));
}
@@ -63,7 +63,8 @@ public final class MGRDatabaseDiscoveryProviderAlgorithmTest {
@Test
public void assertIsPrimaryInstance() throws SQLException {
- DatabaseDiscoveryProviderAlgorithm actual = DatabaseDiscoveryProviderAlgorithmFactory.newInstance(new AlgorithmConfiguration("MySQL.MGR", new Properties()));
+ DatabaseDiscoveryProviderAlgorithm actual = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("MySQL.MGR", new Properties()), DatabaseDiscoveryProviderAlgorithm.class);
assertTrue(actual.isPrimaryInstance(mockPrimaryDataSource()));
}
diff --git a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/factory/EncryptAlgorithmFactory.java b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/factory/EncryptAlgorithmFactory.java
deleted file mode 100644
index 1502b2fb9d5..00000000000
--- a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/factory/EncryptAlgorithmFactory.java
+++ /dev/null
@@ -1,57 +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.encrypt.factory;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * Encrypt algorithm factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class EncryptAlgorithmFactory {
-
- static {
- ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
- }
-
- /**
- * Create new instance of encrypt algorithm.
- *
- * @param encryptAlgorithmConfig encrypt algorithm configuration
- * @return created instance
- */
- public static EncryptAlgorithm newInstance(final AlgorithmConfiguration encryptAlgorithmConfig) {
- return ShardingSphereAlgorithmFactory.createAlgorithm(encryptAlgorithmConfig, EncryptAlgorithm.class);
- }
-
- /**
- * Judge whether contains encrypt algorithm.
- *
- * @param encryptAlgorithmType encrypt algorithm type
- * @return contains encrypt algorithm or not
- */
- public static boolean contains(final String encryptAlgorithmType) {
- return TypedSPIRegistry.findRegisteredService(EncryptAlgorithm.class, encryptAlgorithmType).isPresent();
- }
-}
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 1951e63c903..37b9a3d027f 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
@@ -23,9 +23,9 @@ import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.context.EncryptContextBuilder;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
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;
@@ -60,7 +60,7 @@ public final class EncryptRule implements DatabaseRule, TableContainedRule {
public EncryptRule(final EncryptRuleConfiguration ruleConfig) {
configuration = ruleConfig;
- ruleConfig.getEncryptors().forEach((key, value) -> putAllEncryptors(key, EncryptAlgorithmFactory.newInstance(value)));
+ ruleConfig.getEncryptors().forEach((key, value) -> putAllEncryptors(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, EncryptAlgorithm.class)));
ruleConfig.getTables().forEach(each -> tables.put(each.getName().toLowerCase(), new EncryptTable(each)));
queryWithCipherColumn = ruleConfig.isQueryWithCipherColumn();
}
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 963ec8757e1..7f77b1fc8a3 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
@@ -18,8 +18,9 @@
package org.apache.shardingsphere.encrypt.algorithm.encrypt;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
+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.junit.Before;
import org.junit.Test;
@@ -31,14 +32,13 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
-@SuppressWarnings("unchecked")
public final class AESEncryptAlgorithmTest {
private StandardEncryptAlgorithm<Object, String> encryptAlgorithm;
@Before
public void setUp() {
- encryptAlgorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("AES", createProperties()));
+ encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("AES", createProperties()), EncryptAlgorithm.class);
}
private Properties createProperties() {
@@ -49,7 +49,7 @@ public final class AESEncryptAlgorithmTest {
@Test(expected = IllegalArgumentException.class)
public void assertCreateNewInstanceWithoutAESKey() {
- EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("AES", new Properties()));
+ ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("AES", new Properties()), EncryptAlgorithm.class);
}
@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 e5a52ce1047..74bc23751fa 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
@@ -18,8 +18,9 @@
package org.apache.shardingsphere.encrypt.algorithm.encrypt;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
+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.junit.Before;
import org.junit.Test;
@@ -31,14 +32,14 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
-@SuppressWarnings("unchecked")
public final class MD5EncryptAlgorithmTest {
private StandardEncryptAlgorithm<Object, String> encryptAlgorithm;
@Before
public void setUp() {
- encryptAlgorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("MD5", new Properties()));
+
+ encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MD5", new Properties()), EncryptAlgorithm.class);
}
@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 f0969faa33f..5ac3cc3b6be 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
@@ -19,8 +19,9 @@ package org.apache.shardingsphere.encrypt.algorithm.encrypt;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
+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.junit.Before;
import org.junit.Test;
@@ -32,14 +33,13 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
-@SuppressWarnings("unchecked")
public final class RC4EncryptAlgorithmTest {
private StandardEncryptAlgorithm<Object, String> encryptAlgorithm;
@Before
public void setUp() {
- encryptAlgorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("Rc4", createProperties()));
+ encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("RC4", createProperties()), EncryptAlgorithm.class);
}
private Properties createProperties() {
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 7bfd9934240..254a6600fe0 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
@@ -18,8 +18,9 @@
package org.apache.shardingsphere.encrypt.algorithm.like;
import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
+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.junit.Before;
import org.junit.Test;
@@ -31,7 +32,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
-@SuppressWarnings("unchecked")
public final class CharDigestLikeEncryptAlgorithmTest {
private LikeEncryptAlgorithm<Object, String> englishLikeEncryptAlgorithm;
@@ -42,9 +42,9 @@ public final class CharDigestLikeEncryptAlgorithmTest {
@Before
public void setUp() {
- englishLikeEncryptAlgorithm = (LikeEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("CHAR_DIGEST_LIKE", new Properties()));
- chineseLikeEncryptAlgorithm = (LikeEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("CHAR_DIGEST_LIKE", new Properties()));
- koreanLikeEncryptAlgorithm = (LikeEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("CHAR_DIGEST_LIKE", createProperties()));
+ 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", createProperties()), EncryptAlgorithm.class);
}
private Properties createProperties() {
@@ -58,8 +58,7 @@ public final class CharDigestLikeEncryptAlgorithmTest {
public void assertEncrypt() {
assertThat(englishLikeEncryptAlgorithm.encrypt("1234567890%abcdefghijklmnopqrstuvwxyz%ABCDEFGHIJKLMNOPQRSTUVWXYZ",
mock(EncryptContext.class)), is("0145458981%`adedehihilmlmpqpqtutuxyxy%@ADEDEHIHILMLMPQPQTUTUXYXY"));
- assertThat(englishLikeEncryptAlgorithm.encrypt("_1234__5678__",
- mock(EncryptContext.class)), is("_0145__4589__"));
+ assertThat(englishLikeEncryptAlgorithm.encrypt("_1234__5678__", mock(EncryptContext.class)), is("_0145__4589__"));
}
@Test
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
index 1250a4caaa2..7694ba82182 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
@@ -22,16 +22,12 @@ import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfig
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
-import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationCheckerFactory;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
-import java.util.Optional;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,10 +37,8 @@ public final class EncryptRuleConfigurationCheckerTest {
@Test
public void assertCheckWhenConfigValidConfiguration() {
EncryptRuleConfiguration config = createValidConfiguration();
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(EncryptRuleConfigurationChecker.class));
- checker.get().check("test", config, Collections.emptyMap(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, Collections.emptyMap(), Collections.emptyList());
}
private EncryptRuleConfiguration createValidConfiguration() {
@@ -59,10 +53,8 @@ public final class EncryptRuleConfigurationCheckerTest {
@Test(expected = IllegalStateException.class)
public void assertCheckWhenConfigInvalidCipherColumn() {
EncryptRuleConfiguration config = createInvalidCipherColumnConfig();
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(EncryptRuleConfigurationChecker.class));
- checker.get().check("test", config, Collections.emptyMap(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, Collections.emptyMap(), Collections.emptyList());
}
private EncryptRuleConfiguration createInvalidCipherColumnConfig() {
@@ -77,10 +69,8 @@ public final class EncryptRuleConfigurationCheckerTest {
@Test(expected = IllegalStateException.class)
public void assertCheckWhenConfigInvalidAssistColumn() {
EncryptRuleConfiguration config = createInvalidAssistColumnConfig();
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(EncryptRuleConfigurationChecker.class));
- checker.get().check("test", config, Collections.emptyMap(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, Collections.emptyMap(), Collections.emptyList());
}
private EncryptRuleConfiguration createInvalidAssistColumnConfig() {
@@ -96,10 +86,8 @@ public final class EncryptRuleConfigurationCheckerTest {
@Test(expected = IllegalStateException.class)
public void assertCheckWhenConfigInvalidLikeColumn() {
EncryptRuleConfiguration config = createInvalidLikeColumnConfig();
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(EncryptRuleConfigurationChecker.class));
- checker.get().check("test", config, Collections.emptyMap(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, Collections.emptyMap(), Collections.emptyList());
}
private EncryptRuleConfiguration createInvalidLikeColumnConfig() {
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java
index 24dd8d6a9b0..16621b7783e 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java
@@ -25,10 +25,11 @@ import org.apache.shardingsphere.infra.binder.statement.dal.ExplainStatementCont
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.merge.engine.ResultProcessEngineFactory;
+import org.apache.shardingsphere.infra.merge.engine.ResultProcessEngine;
import org.apache.shardingsphere.infra.merge.engine.decorator.ResultDecorator;
import org.apache.shardingsphere.infra.merge.engine.decorator.impl.TransparentResultDecorator;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLExplainStatement;
import org.junit.Test;
@@ -55,7 +56,7 @@ public final class EncryptResultDecoratorEngineTest {
@Test
public void assertNewInstanceWithSelectStatement() {
- EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) ResultProcessEngineFactory.getInstances(Collections.singleton(rule)).get(rule);
+ EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) OrderedSPIRegistry.getRegisteredServices(ResultProcessEngine.class, Collections.singleton(rule)).get(rule);
ResultDecorator<?> actual = engine.newInstance(database, rule, mock(ConfigurationProperties.class), mock(SelectStatementContext.class, RETURNS_DEEP_STUBS));
assertThat(actual, instanceOf(EncryptDQLResultDecorator.class));
}
@@ -64,14 +65,14 @@ public final class EncryptResultDecoratorEngineTest {
public void assertNewInstanceWithDALStatement() {
SQLStatementContext<ExplainStatement> sqlStatementContext = mock(ExplainStatementContext.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(MySQLExplainStatement.class));
- EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) ResultProcessEngineFactory.getInstances(Collections.singleton(rule)).get(rule);
+ EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) OrderedSPIRegistry.getRegisteredServices(ResultProcessEngine.class, Collections.singleton(rule)).get(rule);
ResultDecorator<?> actual = engine.newInstance(database, rule, mock(ConfigurationProperties.class), sqlStatementContext);
assertThat(actual, instanceOf(EncryptDALResultDecorator.class));
}
@Test
public void assertNewInstanceWithOtherStatement() {
- EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) ResultProcessEngineFactory.getInstances(Collections.singleton(rule)).get(rule);
+ EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) OrderedSPIRegistry.getRegisteredServices(ResultProcessEngine.class, Collections.singleton(rule)).get(rule);
ResultDecorator<?> actual = engine.newInstance(database, rule, mock(ConfigurationProperties.class), mock(InsertStatementContext.class));
assertThat(actual, instanceOf(TransparentResultDecorator.class));
}
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 a8c8ee0193e..299cc4b53c5 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
@@ -18,9 +18,10 @@
package org.apache.shardingsphere.encrypt.merge.dql;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
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;
@@ -88,7 +89,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 = (StandardEncryptAlgorithm<?, ?>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("MD5", new Properties()));
+ encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MD5", new Properties()), EncryptAlgorithm.class);
}
@Test
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptSchemaMetaDataDecoratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptSchemaMetaDataDecoratorTest.java
index 58bbab1993f..ce0a8a96e14 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptSchemaMetaDataDecoratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptSchemaMetaDataDecoratorTest.java
@@ -21,11 +21,12 @@ import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial;
-import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecoratorFactory;
+import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.junit.Test;
import java.sql.Types;
@@ -81,6 +82,6 @@ public final class EncryptSchemaMetaDataDecoratorTest {
}
private EncryptSchemaMetaDataDecorator getEncryptMetaDataBuilder(final EncryptRule encryptRule, final Collection<ShardingSphereRule> rules) {
- return (EncryptSchemaMetaDataDecorator) RuleBasedSchemaMetaDataDecoratorFactory.getInstances(rules).get(encryptRule);
+ return (EncryptSchemaMetaDataDecorator) OrderedSPIRegistry.getRegisteredServices(RuleBasedSchemaMetaDataDecorator.class, rules).get(encryptRule);
}
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
index 53e8b9d5bbe..f976b31d554 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.junit.Test;
import java.util.Collections;
@@ -36,7 +36,7 @@ public final class EncryptRuleBuilderTest {
@Test
public void assertBuild() {
EncryptRuleConfiguration ruleConfig = mock(EncryptRuleConfiguration.class);
- DatabaseRuleBuilder builder = DatabaseRuleBuilderFactory.getInstanceMap(Collections.singletonList(ruleConfig)).get(ruleConfig);
+ DatabaseRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, Collections.singletonList(ruleConfig)).get(ruleConfig);
assertThat(builder.build(ruleConfig, "", Collections.emptyMap(), Collections.emptyList(), mock(InstanceContext.class)), instanceOf(EncryptRule.class));
}
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapperTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapperTest.java
index 82df45f6fb6..2827d124ed6 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapperTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapperTest.java
@@ -22,8 +22,9 @@ import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfigu
import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperFactory;
+import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
import org.junit.Test;
import java.util.Collection;
@@ -70,6 +71,6 @@ public final class YamlEncryptRuleConfigurationSwapperTest {
private YamlEncryptRuleConfigurationSwapper getSwapper() {
EncryptRuleConfiguration ruleConfig = mock(EncryptRuleConfiguration.class);
- return (YamlEncryptRuleConfigurationSwapper) YamlRuleConfigurationSwapperFactory.getInstanceMapByRuleConfigurations(Collections.singletonList(ruleConfig)).get(ruleConfig);
+ return (YamlEncryptRuleConfigurationSwapper) OrderedSPIRegistry.getRegisteredServices(YamlRuleConfigurationSwapper.class, Collections.singleton(ruleConfig)).get(ruleConfig);
}
}
diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
index 8682b45040f..b9a80bb6548 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
@@ -29,10 +29,11 @@ import org.apache.shardingsphere.encrypt.distsql.handler.converter.EncryptRuleSt
import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.util.Collection;
import java.util.Collections;
@@ -85,7 +86,7 @@ public final class AlterEncryptRuleStatementUpdater implements RuleDefinitionAlt
for (EncryptRuleSegment each : sqlStatement.getRules()) {
encryptors.addAll(each.getColumns().stream().map(column -> column.getEncryptor().getName()).collect(Collectors.toSet()));
}
- Collection<String> invalidEncryptors = encryptors.stream().filter(each -> !EncryptAlgorithmFactory.contains(each)).collect(Collectors.toList());
+ Collection<String> invalidEncryptors = encryptors.stream().filter(each -> !TypedSPIRegistry.findRegisteredService(EncryptAlgorithm.class, each).isPresent()).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(invalidEncryptors.isEmpty(), () -> new InvalidAlgorithmConfigurationException("encryptor", invalidEncryptors));
}
diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
index 5134ed3acd0..14b78cdd940 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
@@ -29,9 +29,10 @@ import org.apache.shardingsphere.encrypt.distsql.handler.converter.EncryptRuleSt
import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptRuleStatement;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.util.Collection;
import java.util.Collections;
@@ -78,7 +79,7 @@ public final class CreateEncryptRuleStatementUpdater implements RuleDefinitionCr
private void checkToBeCreatedEncryptors(final CreateEncryptRuleStatement sqlStatement) throws InvalidAlgorithmConfigurationException {
Collection<String> encryptors = new LinkedHashSet<>();
sqlStatement.getRules().forEach(each -> encryptors.addAll(each.getColumns().stream().map(column -> column.getEncryptor().getName()).collect(Collectors.toSet())));
- Collection<String> notExistedEncryptors = encryptors.stream().filter(each -> !EncryptAlgorithmFactory.contains(each)).collect(Collectors.toList());
+ Collection<String> notExistedEncryptors = encryptors.stream().filter(each -> !TypedSPIRegistry.findRegisteredService(EncryptAlgorithm.class, each).isPresent()).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(notExistedEncryptors.isEmpty(), () -> new InvalidAlgorithmConfigurationException("encryptor", notExistedEncryptors));
}
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 3df17d1c7a9..1ffbf8c0837 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
@@ -18,8 +18,9 @@
package org.apache.shardingsphere.encrypt.sm.algorithm;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
+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.junit.Before;
import org.junit.Test;
@@ -31,14 +32,13 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
-@SuppressWarnings("unchecked")
public final class SM3EncryptAlgorithmTest {
private StandardEncryptAlgorithm<Object, String> encryptAlgorithm;
@Before
public void setUp() {
- encryptAlgorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("SM3", createProperties()));
+ encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM3", createProperties()), EncryptAlgorithm.class);
}
private Properties createProperties() {
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 48ae24842b0..26e94349b64 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
@@ -18,8 +18,9 @@
package org.apache.shardingsphere.encrypt.sm.algorithm;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
+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.junit.Test;
@@ -30,12 +31,11 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
-@SuppressWarnings("unchecked")
public final class SM4EncryptAlgorithmTest {
@Test(expected = IllegalArgumentException.class)
public void assertInitWithoutKey() {
- StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("SM4", createECBProperties()));
+ StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
algorithm.init(createInvalidProperties());
}
@@ -48,25 +48,25 @@ public final class SM4EncryptAlgorithmTest {
@Test
public void assertEncryptNullValue() {
- StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("SM4", createECBProperties()));
+ StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
assertNull(algorithm.encrypt(null, mock(EncryptContext.class)));
}
@Test
public void assertEncryptWithECBMode() {
- StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("SM4", createECBProperties()));
+ StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
assertThat(algorithm.encrypt("test", mock(EncryptContext.class)), is("028654f2ca4f575dee9e1faae85dadde"));
}
@Test
public void assertDecryptNullValue() {
- StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("SM4", createECBProperties()));
+ StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
assertNull(algorithm.decrypt(null, mock(EncryptContext.class)));
}
@Test
public void assertDecryptWithECBMode() {
- StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("SM4", createECBProperties()));
+ StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
assertThat(algorithm.decrypt("028654f2ca4f575dee9e1faae85dadde", mock(EncryptContext.class)).toString(), is("test"));
}
@@ -80,13 +80,13 @@ public final class SM4EncryptAlgorithmTest {
@Test
public void assertEncryptWithCBCMode() {
- StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("SM4", createCBCProperties()));
+ StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createCBCProperties()), EncryptAlgorithm.class);
assertThat(algorithm.encrypt("test", mock(EncryptContext.class)), is("dca2127b57ba8cac36a0914e0208dc11"));
}
@Test
public void assertDecrypt() {
- StandardEncryptAlgorithm<Object, String> algorithm = (StandardEncryptAlgorithm<Object, String>) EncryptAlgorithmFactory.newInstance(new AlgorithmConfiguration("SM4", createCBCProperties()));
+ StandardEncryptAlgorithm<Object, String> algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SM4", createCBCProperties()), EncryptAlgorithm.class);
assertThat(algorithm.decrypt("dca2127b57ba8cac36a0914e0208dc11", mock(EncryptContext.class)).toString(), is("test"));
}
diff --git a/features/mask/api/src/main/java/org/apache/shardingsphere/mask/factory/MaskAlgorithmFactory.java b/features/mask/api/src/main/java/org/apache/shardingsphere/mask/factory/MaskAlgorithmFactory.java
deleted file mode 100644
index d05feaa7a72..00000000000
--- a/features/mask/api/src/main/java/org/apache/shardingsphere/mask/factory/MaskAlgorithmFactory.java
+++ /dev/null
@@ -1,59 +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.mask.factory;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
-
-/**
- * Mask algorithm factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MaskAlgorithmFactory {
-
- static {
- ShardingSphereServiceLoader.register(MaskAlgorithm.class);
- }
-
- /**
- * Create new instance of mask algorithm.
- *
- * @param maskAlgorithmConfig mask algorithm configuration
- * @param <I> type of plain value
- * @param <O> type of masked value
- * @return created instance
- */
- public static <I, O> MaskAlgorithm<I, O> newInstance(final AlgorithmConfiguration maskAlgorithmConfig) {
- return ShardingSphereAlgorithmFactory.createAlgorithm(maskAlgorithmConfig, MaskAlgorithm.class);
- }
-
- /**
- * Judge whether contains mask algorithm.
- *
- * @param maskAlgorithmType mask algorithm type
- * @return contains mask algorithm or not
- */
- public static boolean contains(final String maskAlgorithmType) {
- return TypedSPIRegistry.findRegisteredService(MaskAlgorithm.class, maskAlgorithmType).isPresent();
- }
-}
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 579c59f802a..ebaeacd6d85 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,11 +18,11 @@
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.mask.api.config.MaskRuleConfiguration;
-import org.apache.shardingsphere.mask.factory.MaskAlgorithmFactory;
import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import java.util.Collection;
@@ -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, MaskAlgorithmFactory.newInstance(value)));
+ ruleConfig.getMaskAlgorithms().forEach((key, value) -> maskAlgorithms.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, MaskAlgorithm.class)));
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/MaskResultDecoratorEngineTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/MaskResultDecoratorEngineTest.java
index b3c4b1e3ae4..34225938850 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/MaskResultDecoratorEngineTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/MaskResultDecoratorEngineTest.java
@@ -20,10 +20,11 @@ package org.apache.shardingsphere.mask.merge;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.merge.engine.ResultProcessEngineFactory;
+import org.apache.shardingsphere.infra.merge.engine.ResultProcessEngine;
import org.apache.shardingsphere.infra.merge.engine.decorator.ResultDecorator;
import org.apache.shardingsphere.infra.merge.engine.decorator.impl.TransparentResultDecorator;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.mask.merge.dql.MaskDQLResultDecorator;
import org.apache.shardingsphere.mask.rule.MaskRule;
import org.junit.Test;
@@ -49,14 +50,14 @@ public final class MaskResultDecoratorEngineTest {
@Test
public void assertNewInstanceWithSelectStatement() {
- MaskResultDecoratorEngine engine = (MaskResultDecoratorEngine) ResultProcessEngineFactory.getInstances(Collections.singleton(rule)).get(rule);
+ MaskResultDecoratorEngine engine = (MaskResultDecoratorEngine) OrderedSPIRegistry.getRegisteredServices(ResultProcessEngine.class, Collections.singleton(rule)).get(rule);
ResultDecorator<?> actual = engine.newInstance(database, rule, mock(ConfigurationProperties.class), mock(SelectStatementContext.class, RETURNS_DEEP_STUBS));
assertThat(actual, instanceOf(MaskDQLResultDecorator.class));
}
@Test
public void assertNewInstanceWithOtherStatement() {
- MaskResultDecoratorEngine engine = (MaskResultDecoratorEngine) ResultProcessEngineFactory.getInstances(Collections.singleton(rule)).get(rule);
+ MaskResultDecoratorEngine engine = (MaskResultDecoratorEngine) OrderedSPIRegistry.getRegisteredServices(ResultProcessEngine.class, Collections.singleton(rule)).get(rule);
ResultDecorator<?> actual = engine.newInstance(database, rule, mock(ConfigurationProperties.class), mock(InsertStatementContext.class));
assertThat(actual, instanceOf(TransparentResultDecorator.class));
}
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 e78587eea9c..11a2267fc79 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,13 @@
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.mask.factory.MaskAlgorithmFactory;
import org.apache.shardingsphere.mask.rule.MaskRule;
import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.junit.Before;
@@ -62,7 +62,7 @@ public final class MaskAlgorithmMetaDataTest {
@Before
public void setUp() {
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
- maskAlgorithm = MaskAlgorithmFactory.newInstance(new AlgorithmConfiguration("MD5", new Properties()));
+ maskAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MD5", new Properties()), MaskAlgorithm.class);
}
@SuppressWarnings("rawtypes")
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/builder/MaskRuleBuilderTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/builder/MaskRuleBuilderTest.java
index b94491d0e88..c2bf87fdfae 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/builder/MaskRuleBuilderTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/builder/MaskRuleBuilderTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.mask.rule.builder;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import org.apache.shardingsphere.mask.rule.MaskRule;
import org.junit.Test;
@@ -36,7 +36,7 @@ public final class MaskRuleBuilderTest {
@Test
public void assertBuild() {
MaskRuleConfiguration ruleConfig = mock(MaskRuleConfiguration.class);
- DatabaseRuleBuilder builder = DatabaseRuleBuilderFactory.getInstanceMap(Collections.singletonList(ruleConfig)).get(ruleConfig);
+ DatabaseRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig);
assertThat(builder.build(ruleConfig, "", Collections.emptyMap(), Collections.emptyList(), mock(InstanceContext.class)), instanceOf(MaskRule.class));
}
}
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskRuleConfigurationSwapperTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskRuleConfigurationSwapperTest.java
index 52f67389c6b..71e8e8215b5 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskRuleConfigurationSwapperTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskRuleConfigurationSwapperTest.java
@@ -18,8 +18,9 @@
package org.apache.shardingsphere.mask.yaml.swapper;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperFactory;
+import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
import org.apache.shardingsphere.mask.yaml.config.YamlMaskRuleConfiguration;
@@ -70,6 +71,6 @@ public final class YamlMaskRuleConfigurationSwapperTest {
private YamlMaskRuleConfigurationSwapper getSwapper() {
MaskRuleConfiguration ruleConfig = mock(MaskRuleConfiguration.class);
- return (YamlMaskRuleConfigurationSwapper) YamlRuleConfigurationSwapperFactory.getInstanceMapByRuleConfigurations(Collections.singletonList(ruleConfig)).get(ruleConfig);
+ return (YamlMaskRuleConfigurationSwapper) OrderedSPIRegistry.getRegisteredServices(YamlRuleConfigurationSwapper.class, Collections.singleton(ruleConfig)).get(ruleConfig);
}
}
diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdater.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdater.java
index 114c6037d27..29d937b00fb 100644
--- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdater.java
+++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdater.java
@@ -23,13 +23,14 @@ import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpda
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
import org.apache.shardingsphere.mask.distsql.handler.converter.MaskRuleStatementConverter;
import org.apache.shardingsphere.mask.distsql.parser.segment.MaskColumnSegment;
import org.apache.shardingsphere.mask.distsql.parser.segment.MaskRuleSegment;
import org.apache.shardingsphere.mask.distsql.parser.statement.CreateMaskRuleStatement;
-import org.apache.shardingsphere.mask.factory.MaskAlgorithmFactory;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import java.util.Collection;
import java.util.LinkedList;
@@ -57,7 +58,7 @@ public final class CreateMaskRuleStatementUpdater implements RuleDefinitionCreat
private void checkAlgorithms(final CreateMaskRuleStatement sqlStatement) {
Collection<MaskColumnSegment> columns = new LinkedList<>();
sqlStatement.getRules().forEach(each -> columns.addAll(each.getColumns()));
- columns.forEach(each -> ShardingSpherePreconditions.checkState(MaskAlgorithmFactory.contains(each.getAlgorithm().getName()),
+ columns.forEach(each -> ShardingSpherePreconditions.checkState(TypedSPIRegistry.findRegisteredService(MaskAlgorithm.class, each.getAlgorithm().getName()).isPresent(),
() -> new InvalidAlgorithmConfigurationException("mask", each.getAlgorithm().getName())));
}
diff --git a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/factory/ReadQueryLoadBalanceAlgorithmFactory.java b/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/factory/ReadQueryLoadBalanceAlgorithmFactory.java
deleted file mode 100644
index 746a4160e85..00000000000
--- a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/factory/ReadQueryLoadBalanceAlgorithmFactory.java
+++ /dev/null
@@ -1,67 +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.readwritesplitting.factory;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * Read query load-balance algorithm factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ReadQueryLoadBalanceAlgorithmFactory {
-
- static {
- ShardingSphereServiceLoader.register(ReadQueryLoadBalanceAlgorithm.class);
- }
-
- /**
- * Create new instance of read query load-balance algorithm.
- *
- * @return created instance
- */
- public static ReadQueryLoadBalanceAlgorithm newInstance() {
- return RequiredSPIRegistry.getRegisteredService(ReadQueryLoadBalanceAlgorithm.class);
- }
-
- /**
- * Create new instance of read query load-balance algorithm.
- *
- * @param readQueryLoadBalanceAlgorithmConfig read query load-balance algorithm configuration
- * @return created instance
- */
- public static ReadQueryLoadBalanceAlgorithm newInstance(final AlgorithmConfiguration readQueryLoadBalanceAlgorithmConfig) {
- return ShardingSphereAlgorithmFactory.createAlgorithm(readQueryLoadBalanceAlgorithmConfig, ReadQueryLoadBalanceAlgorithm.class);
- }
-
- /**
- * Judge whether contains read query load-balance algorithm.
- *
- * @param readQueryLoadBalanceAlgorithmType read query load-balance algorithm type
- * @return contains read query load-balance algorithm or not
- */
- public static boolean contains(final String readQueryLoadBalanceAlgorithmType) {
- return TypedSPIRegistry.findRegisteredService(ReadQueryLoadBalanceAlgorithm.class, readQueryLoadBalanceAlgorithmType).isPresent();
- }
-}
diff --git a/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/factory/ReplicaLoadBalanceAlgorithmFactoryTest.java b/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/factory/ReplicaLoadBalanceAlgorithmFactoryTest.java
deleted file mode 100644
index 024f14101ea..00000000000
--- a/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/factory/ReplicaLoadBalanceAlgorithmFactoryTest.java
+++ /dev/null
@@ -1,46 +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.readwritesplitting.factory;
-
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.readwritesplitting.factory.fixture.ReadQueryLoadBalanceAlgorithmFixture;
-import org.junit.Test;
-
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class ReplicaLoadBalanceAlgorithmFactoryTest {
-
- @Test
- public void assertNewInstance() {
- assertThat(ReadQueryLoadBalanceAlgorithmFactory.newInstance(), instanceOf(ReadQueryLoadBalanceAlgorithmFixture.class));
- }
-
- @Test
- public void assertNewInstanceWithAlgorithmConfiguration() {
- assertThat(ReadQueryLoadBalanceAlgorithmFactory.newInstance(new AlgorithmConfiguration("FIXTURE", new Properties())), instanceOf(ReadQueryLoadBalanceAlgorithmFixture.class));
- }
-
- @Test
- public void assertContains() {
- assertTrue(ReadQueryLoadBalanceAlgorithmFactory.contains("FIXTURE"));
- }
-}
diff --git a/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/factory/fixture/ReadQueryLoadBalanceAlgorithmFixture.java b/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/factory/fixture/ReadQueryLoadBalanceAlgorithmFixture.java
deleted file mode 100644
index 07a9d6b26ba..00000000000
--- a/features/readwrite-splitting/api/src/test/java/org/apache/shardingsphere/readwritesplitting/factory/fixture/ReadQueryLoadBalanceAlgorithmFixture.java
+++ /dev/null
@@ -1,46 +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.readwritesplitting.factory.fixture;
-
-import org.apache.shardingsphere.infra.context.transaction.TransactionConnectionContext;
-import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
-
-import java.util.List;
-import java.util.Properties;
-
-public final class ReadQueryLoadBalanceAlgorithmFixture implements ReadQueryLoadBalanceAlgorithm {
-
- @Override
- public String getDataSource(final String name, final String writeDataSourceName, final List<String> readDataSourceNames, final TransactionConnectionContext context) {
- return null;
- }
-
- @Override
- public Properties getProps() {
- return null;
- }
-
- @Override
- public void init(final Properties props) {
- }
-
- @Override
- public String getType() {
- return "FIXTURE";
- }
-}
diff --git a/features/readwrite-splitting/api/src/test/resources/META-INF/services/org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm b/features/readwrite-splitting/api/src/test/resources/META-INF/services/org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm
deleted file mode 100644
index 5e354ef41d8..00000000000
--- a/features/readwrite-splitting/api/src/test/resources/META-INF/services/org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.readwritesplitting.factory.fixture.ReadQueryLoadBalanceAlgorithmFixture
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 7ca6b14d08e..5cb5a06633e 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,6 +19,7 @@ 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;
@@ -31,7 +32,6 @@ import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingD
import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingOrder;
-import org.apache.shardingsphere.readwritesplitting.factory.ReadQueryLoadBalanceAlgorithmFactory;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import javax.sql.DataSource;
@@ -143,7 +143,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, ReadQueryLoadBalanceAlgorithmFactory.newInstance(value)));
+ config.getLoadBalancers().forEach((key, value) -> result.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, ReadQueryLoadBalanceAlgorithm.class)));
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 6a9583c4e6e..78c00624491 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,9 +19,8 @@ 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.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
@@ -30,14 +29,16 @@ import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedR
import org.apache.shardingsphere.infra.rule.identifier.type.StaticDataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.StorageConnectorReusableRule;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
+import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
+import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
import org.apache.shardingsphere.infra.util.expr.InlineExpressionParser;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
import org.apache.shardingsphere.mode.metadata.storage.StorageNodeStatus;
import org.apache.shardingsphere.mode.metadata.storage.event.StorageNodeDataSourceChangedEvent;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
-import org.apache.shardingsphere.readwritesplitting.factory.ReadQueryLoadBalanceAlgorithmFactory;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import org.apache.shardingsphere.readwritesplitting.strategy.type.DynamicReadwriteSplittingStrategy;
import org.apache.shardingsphere.readwritesplitting.strategy.type.StaticReadwriteSplittingStrategy;
@@ -67,7 +68,7 @@ public final class ReadwriteSplittingRule implements DatabaseRule, DataSourceCon
configuration = ruleConfig;
ruleConfig.getDataSources().stream().filter(each -> null != ruleConfig.getLoadBalancers().get(each.getLoadBalancerName()))
.forEach(each -> loadBalancers.put(each.getName() + "." + each.getLoadBalancerName(),
- ReadQueryLoadBalanceAlgorithmFactory.newInstance(ruleConfig.getLoadBalancers().get(each.getLoadBalancerName()))));
+ ShardingSphereAlgorithmFactory.createAlgorithm(ruleConfig.getLoadBalancers().get(each.getLoadBalancerName()), ReadQueryLoadBalanceAlgorithm.class)));
dataSourceRules = new HashMap<>(ruleConfig.getDataSources().size(), 1);
for (ReadwriteSplittingDataSourceRuleConfiguration each : ruleConfig.getDataSources()) {
dataSourceRules.putAll(createReadwriteSplittingDataSourceRules(each, builtRules));
@@ -76,7 +77,8 @@ public final class ReadwriteSplittingRule implements DatabaseRule, DataSourceCon
private Map<String, ReadwriteSplittingDataSourceRule> createReadwriteSplittingDataSourceRules(final ReadwriteSplittingDataSourceRuleConfiguration config,
final Collection<ShardingSphereRule> builtRules) {
- ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = loadBalancers.getOrDefault(config.getName() + "." + config.getLoadBalancerName(), ReadQueryLoadBalanceAlgorithmFactory.newInstance());
+ ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = loadBalancers.getOrDefault(
+ config.getName() + "." + config.getLoadBalancerName(), RequiredSPIRegistry.getRegisteredService(ReadQueryLoadBalanceAlgorithm.class));
return null == config.getStaticStrategy()
? createDynamicReadwriteSplittingDataSourceRules(config, builtRules, loadBalanceAlgorithm)
: createStaticReadwriteSplittingDataSourceRules(config, builtRules, loadBalanceAlgorithm);
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 7775adb13f1..baf03c1ebb8 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,10 @@
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.readwritesplitting.factory.ReadQueryLoadBalanceAlgorithmFactory;
+import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -47,7 +48,8 @@ public final class FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetSingleReadDataSourceInTransaction() {
- FixedReplicaWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = createReadQueryLoadBalanceAlgorithm(createSingleDataSourceProperties());
+ FixedReplicaWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("FIXED_REPLICA_WEIGHT", createSingleDataSourceProperties()), ReadQueryLoadBalanceAlgorithm.class);
TransactionConnectionContext context = new TransactionConnectionContext();
context.setInTransaction(true);
String routeDataSource = loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", Collections.singletonList("test_read_ds_1"), context);
@@ -63,7 +65,8 @@ public final class FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetMultipleReadDataSourcesWithoutTransaction() {
- FixedReplicaWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = createReadQueryLoadBalanceAlgorithm(createMultipleDataSourcesProperties());
+ FixedReplicaWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("FIXED_REPLICA_WEIGHT", createMultipleDataSourcesProperties()), ReadQueryLoadBalanceAlgorithm.class);
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
@@ -78,7 +81,8 @@ public final class FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetMultipleReadDataSourcesInTransaction() {
- FixedReplicaWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = createReadQueryLoadBalanceAlgorithm(createMultipleDataSourcesProperties());
+ FixedReplicaWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("FIXED_REPLICA_WEIGHT", createMultipleDataSourcesProperties()), ReadQueryLoadBalanceAlgorithm.class);
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
@@ -98,16 +102,13 @@ public final class FixedReplicaWeightReadQueryLoadBalanceAlgorithmTest {
return result;
}
- private FixedReplicaWeightReadQueryLoadBalanceAlgorithm createReadQueryLoadBalanceAlgorithm(final Properties props) {
- return (FixedReplicaWeightReadQueryLoadBalanceAlgorithm) ReadQueryLoadBalanceAlgorithmFactory.newInstance(new AlgorithmConfiguration("FIXED_REPLICA_WEIGHT", props));
- }
-
@Test
public void assertGetDataSourceWhenReadDataSourceChanged() {
Properties props = new Properties();
props.setProperty("test_read_ds_1", "1");
props.setProperty("test_read_ds_2", "2");
- FixedReplicaWeightReadQueryLoadBalanceAlgorithm algorithm = createReadQueryLoadBalanceAlgorithm(props);
+ FixedReplicaWeightReadQueryLoadBalanceAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("FIXED_REPLICA_WEIGHT", props), 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"));
}
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 acfe7767f4b..5b31c690018 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,10 @@
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.readwritesplitting.factory.ReadQueryLoadBalanceAlgorithmFactory;
+import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -47,7 +48,8 @@ public final class TransactionWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetSingleReadDataSource() {
- TransactionWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = createReadQueryLoadBalanceAlgorithm(createSingleDataSourceProperties());
+ TransactionWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("TRANSACTION_WEIGHT", createSingleDataSourceProperties()), ReadQueryLoadBalanceAlgorithm.class);
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"));
@@ -61,7 +63,8 @@ public final class TransactionWeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetMultipleReadDataSources() {
- TransactionWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = createReadQueryLoadBalanceAlgorithm(createMultipleDataSourcesProperties());
+ TransactionWeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("TRANSACTION_WEIGHT", createMultipleDataSourcesProperties()), ReadQueryLoadBalanceAlgorithm.class);
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
@@ -80,8 +83,4 @@ public final class TransactionWeightReadQueryLoadBalanceAlgorithmTest {
result.setProperty("test_read_ds_2", "5");
return result;
}
-
- private TransactionWeightReadQueryLoadBalanceAlgorithm createReadQueryLoadBalanceAlgorithm(final Properties props) {
- return (TransactionWeightReadQueryLoadBalanceAlgorithm) ReadQueryLoadBalanceAlgorithmFactory.newInstance(new AlgorithmConfiguration("TRANSACTION_WEIGHT", props));
- }
}
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 4cb627af7e0..65bfef1a4b9 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,10 @@
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.readwritesplitting.factory.ReadQueryLoadBalanceAlgorithmFactory;
+import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import org.junit.Test;
import java.util.Arrays;
@@ -35,19 +36,20 @@ public final class WeightReadQueryLoadBalanceAlgorithmTest {
@Test
public void assertGetSingleReadDataSource() {
- WeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = createReadQueryLoadBalanceAlgorithm(createSingleDataSourceProperties());
+ Properties props = new Properties();
+ props.setProperty("test_read_ds_1", "5");
+ WeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("WEIGHT", props), ReadQueryLoadBalanceAlgorithm.class);
assertThat(loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", Collections.singletonList("test_read_ds_1"), new TransactionConnectionContext()), is("test_read_ds_1"));
}
- private Properties createSingleDataSourceProperties() {
- Properties result = new Properties();
- result.setProperty("test_read_ds_1", "5");
- return result;
- }
-
@Test
public void assertGetMultipleReadDataSources() {
- WeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = createReadQueryLoadBalanceAlgorithm(createMultipleDataSourcesProperties());
+ Properties props = new Properties();
+ props.setProperty("test_read_ds_1", "5");
+ props.setProperty("test_read_ds_2", "5");
+ WeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("WEIGHT", props), ReadQueryLoadBalanceAlgorithm.class);
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
@@ -57,20 +59,13 @@ public final class WeightReadQueryLoadBalanceAlgorithmTest {
assertThat(loadBalanceAlgorithm.getDataSource("ds", writeDataSourceName, readDataSourceNames, new TransactionConnectionContext()), notNullValue());
}
- private Properties createMultipleDataSourcesProperties() {
- Properties result = new Properties();
- result.setProperty("test_read_ds_1", "5");
- result.setProperty("test_read_ds_2", "5");
- return result;
- }
-
- private WeightReadQueryLoadBalanceAlgorithm createReadQueryLoadBalanceAlgorithm(final Properties props) {
- return (WeightReadQueryLoadBalanceAlgorithm) ReadQueryLoadBalanceAlgorithmFactory.newInstance(new AlgorithmConfiguration("WEIGHT", props));
- }
-
@Test
public void assertGetReadDataSourceInTransaction() {
- WeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = createReadQueryLoadBalanceAlgorithm(createMultipleDataSourcesProperties());
+ Properties props = new Properties();
+ props.setProperty("test_read_ds_1", "5");
+ props.setProperty("test_read_ds_2", "5");
+ WeightReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("WEIGHT", props), ReadQueryLoadBalanceAlgorithm.class);
String writeDataSourceName = "test_write_ds";
String readDataSourceName1 = "test_read_ds_1";
String readDataSourceName2 = "test_read_ds_2";
@@ -85,7 +80,7 @@ public final class WeightReadQueryLoadBalanceAlgorithmTest {
Properties props = new Properties();
props.setProperty("test_read_ds_1", "1");
props.setProperty("test_read_ds_2", "2");
- WeightReadQueryLoadBalanceAlgorithm algorithm = createReadQueryLoadBalanceAlgorithm(props);
+ WeightReadQueryLoadBalanceAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("WEIGHT", props), 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"));
}
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
index a9b623d2a31..bc7cffed31d 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
@@ -19,9 +19,9 @@ package org.apache.shardingsphere.readwritesplitting.checker;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
-import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationCheckerFactory;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
@@ -34,12 +34,8 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.Properties;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -50,10 +46,8 @@ public final class ReadwriteSplittingRuleConfigurationCheckerTest {
@Test
public void assertValidCheck() {
ReadwriteSplittingRuleConfiguration config = createValidConfiguration();
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(ReadwriteSplittingRuleConfigurationChecker.class));
- checker.get().check("test", config, Collections.emptyMap(), Collections.singleton(mock(DynamicDataSourceContainedRule.class)));
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, Collections.emptyMap(), Collections.singleton(mock(DynamicDataSourceContainedRule.class)));
}
private ReadwriteSplittingRuleConfiguration createValidConfiguration() {
@@ -69,10 +63,8 @@ public final class ReadwriteSplittingRuleConfigurationCheckerTest {
@Test(expected = IllegalStateException.class)
public void assertInvalidCheck() {
ReadwriteSplittingRuleConfiguration config = createInvalidConfiguration();
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(ReadwriteSplittingRuleConfigurationChecker.class));
- checker.get().check("test", config, Collections.emptyMap(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, Collections.emptyMap(), Collections.emptyList());
}
private ReadwriteSplittingRuleConfiguration createInvalidConfiguration() {
@@ -90,10 +82,8 @@ public final class ReadwriteSplittingRuleConfigurationCheckerTest {
List<ReadwriteSplittingDataSourceRuleConfiguration> configurations = Arrays.asList(createDataSourceRuleConfig(
"write_ds_0", Arrays.asList("ds_0", "ds_1")), createDataSourceRuleConfig("write_ds_1", Arrays.asList("ds_2", "ds_3")));
when(config.getDataSources()).thenReturn(configurations);
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(ReadwriteSplittingRuleConfigurationChecker.class));
- checker.get().check("test", config, mockDataSources(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, mockDataSources(), Collections.emptyList());
}
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -103,10 +93,8 @@ public final class ReadwriteSplittingRuleConfigurationCheckerTest {
List<ReadwriteSplittingDataSourceRuleConfiguration> configurations = Arrays.asList(createDataSourceRuleConfig(
"write_ds_0", Arrays.asList("read_ds_0", "read_ds_0")), createDataSourceRuleConfig("write_ds_1", Arrays.asList("read_ds_0", "read_ds_0")));
when(config.getDataSources()).thenReturn(configurations);
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(ReadwriteSplittingRuleConfigurationChecker.class));
- checker.get().check("test", config, mockDataSources(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, mockDataSources(), Collections.emptyList());
}
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -120,22 +108,18 @@ public final class ReadwriteSplittingRuleConfigurationCheckerTest {
props.setProperty("read_ds_1", "2");
AlgorithmConfiguration algorithm = new AlgorithmConfiguration("WEIGHT", props);
when(config.getLoadBalancers()).thenReturn(Collections.singletonMap("weight_ds", algorithm));
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(ReadwriteSplittingRuleConfigurationChecker.class));
- checker.get().check("test", config, mockDataSources(), Collections.emptyList());
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
+ checker.check("test", config, mockDataSources(), Collections.emptyList());
}
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertCheckWhenConfigOtherRulesDatasource() {
ReadwriteSplittingRuleConfiguration config = createContainsOtherRulesDatasourceConfig();
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(ReadwriteSplittingRuleConfigurationChecker.class));
+ RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
DataSourceContainedRule dataSourceContainedRule = mock(DataSourceContainedRule.class, RETURNS_DEEP_STUBS);
when(dataSourceContainedRule.getDataSourceMapper().containsKey("otherDatasourceName")).thenReturn(true);
- checker.get().check("test", config, mockDataSources(), Collections.singleton(dataSourceContainedRule));
+ checker.check("test", config, mockDataSources(), Collections.singleton(dataSourceContainedRule));
}
private ReadwriteSplittingRuleConfiguration createContainsOtherRulesDatasourceConfig() {
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java
index bae26bf5639..3b762f6c87d 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java
@@ -28,11 +28,12 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.route.SQLRouterFactory;
+import org.apache.shardingsphere.infra.route.SQLRouter;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
@@ -72,7 +73,7 @@ public final class ReadwriteSplittingSQLRouterTest {
private static final String READ_DATASOURCE = "read";
- private ReadwriteSplittingRule rule;
+ private ReadwriteSplittingRule staticRule;
private ReadwriteSplittingRule dynamicRule;
@@ -85,26 +86,26 @@ public final class ReadwriteSplittingSQLRouterTest {
@Before
public void setUp() {
- rule = new ReadwriteSplittingRule(new ReadwriteSplittingRuleConfiguration(Collections.singleton(new ReadwriteSplittingDataSourceRuleConfiguration(DATASOURCE_NAME,
+ staticRule = new ReadwriteSplittingRule(new ReadwriteSplittingRuleConfiguration(Collections.singleton(new ReadwriteSplittingDataSourceRuleConfiguration(DATASOURCE_NAME,
new StaticReadwriteSplittingStrategyConfiguration(WRITE_DATASOURCE, Collections.singletonList(READ_DATASOURCE)), null, "")),
Collections.emptyMap()), Collections.emptyList());
- sqlRouter = (ReadwriteSplittingSQLRouter) SQLRouterFactory.getInstances(Collections.singleton(rule)).get(rule);
+ sqlRouter = (ReadwriteSplittingSQLRouter) OrderedSPIRegistry.getRegisteredServices(SQLRouter.class, Collections.singleton(staticRule)).get(staticRule);
DynamicDataSourceContainedRule dynamicDataSourceRule = mock(DynamicDataSourceContainedRule.class, RETURNS_DEEP_STUBS);
when(dynamicDataSourceRule.getPrimaryDataSourceName("readwrite_ds")).thenReturn(WRITE_DATASOURCE);
when(dynamicDataSourceRule.getReplicaDataSourceNames("readwrite_ds")).thenReturn(Collections.emptyList());
dynamicRule = new ReadwriteSplittingRule(new ReadwriteSplittingRuleConfiguration(Collections.singleton(new ReadwriteSplittingDataSourceRuleConfiguration(DATASOURCE_NAME, null,
new DynamicReadwriteSplittingStrategyConfiguration("readwrite_ds", "true"), "")), Collections.emptyMap()),
Collections.singleton(dynamicDataSourceRule));
- dynamicSqlRouter = (ReadwriteSplittingSQLRouter) SQLRouterFactory.getInstances(Collections.singleton(dynamicRule)).get(dynamicRule);
+ dynamicSqlRouter = (ReadwriteSplittingSQLRouter) OrderedSPIRegistry.getRegisteredServices(SQLRouter.class, Collections.singleton(dynamicRule)).get(dynamicRule);
}
@Test
public void assertCreateRouteContextToPrimaryWithoutRouteUnits() {
QueryContext queryContext = new QueryContext(mock(SQLStatementContext.class), "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyMap());
- RouteContext actual = sqlRouter.createRouteContext(queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ RouteContext actual = sqlRouter.createRouteContext(queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
assertThat(actual.getRouteUnits().size(), is(1));
RouteUnit routeUnit = actual.getRouteUnits().iterator().next();
assertThat(routeUnit.getDataSourceMapper().getLogicName(), is(DATASOURCE_NAME));
@@ -117,10 +118,10 @@ public final class ReadwriteSplittingSQLRouterTest {
public void assertDecorateRouteContextToPrimaryDataSource() {
RouteContext actual = mockRouteContext();
QueryContext queryContext = new QueryContext(mock(SQLStatementContext.class), "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyMap());
- sqlRouter.decorateRouteContext(actual, queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ sqlRouter.decorateRouteContext(actual, queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_READWRITE_SPLITTING_DATASOURCE_NAME));
assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE));
@@ -132,10 +133,10 @@ public final class ReadwriteSplittingSQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.empty());
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyMap());
- RouteContext actual = sqlRouter.createRouteContext(queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ RouteContext actual = sqlRouter.createRouteContext(queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
assertThat(actual.getRouteUnits().size(), is(1));
RouteUnit routeUnit = actual.getRouteUnits().iterator().next();
assertThat(routeUnit.getDataSourceMapper().getLogicName(), is(DATASOURCE_NAME));
@@ -151,10 +152,10 @@ public final class ReadwriteSplittingSQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.empty());
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyMap());
- sqlRouter.decorateRouteContext(actual, queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ sqlRouter.decorateRouteContext(actual, queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_READWRITE_SPLITTING_DATASOURCE_NAME));
assertThat(routedDataSourceNames.next(), is(READ_DATASOURCE));
@@ -166,10 +167,10 @@ public final class ReadwriteSplittingSQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.of(mock(LockSegment.class)));
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyMap());
- RouteContext actual = sqlRouter.createRouteContext(queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ RouteContext actual = sqlRouter.createRouteContext(queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE));
}
@@ -181,10 +182,10 @@ public final class ReadwriteSplittingSQLRouterTest {
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.of(mock(LockSegment.class)));
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyMap());
- sqlRouter.decorateRouteContext(actual, queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ sqlRouter.decorateRouteContext(actual, queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_READWRITE_SPLITTING_DATASOURCE_NAME));
assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE));
@@ -194,10 +195,10 @@ public final class ReadwriteSplittingSQLRouterTest {
public void assertCreateRouteContextToPrimaryDataSource() {
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(InsertStatement.class));
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyMap());
- RouteContext actual = sqlRouter.createRouteContext(queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ RouteContext actual = sqlRouter.createRouteContext(queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE));
}
@@ -207,17 +208,17 @@ public final class ReadwriteSplittingSQLRouterTest {
MySQLInsertStatement insertStatement = mock(MySQLInsertStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(insertStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyMap());
- RouteContext actual = sqlRouter.createRouteContext(queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ RouteContext actual = sqlRouter.createRouteContext(queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE));
MySQLSelectStatement selectStatement = mock(MySQLSelectStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
when(selectStatement.getLock()).thenReturn(Optional.empty());
queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- actual = sqlRouter.createRouteContext(queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ actual = sqlRouter.createRouteContext(queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(READ_DATASOURCE));
}
@@ -230,10 +231,10 @@ public final class ReadwriteSplittingSQLRouterTest {
when(sqlStatementContext.isHintWriteRouteOnly()).thenReturn(true);
when(sqlStatementContext.getProjectionsContext().isContainsLastInsertIdProjection()).thenReturn(false);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyMap());
- RouteContext actual = sqlRouter.createRouteContext(queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
+ RouteContext actual = sqlRouter.createRouteContext(queryContext, database, staticRule, new ConfigurationProperties(new Properties()), new ConnectionContext());
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE));
}
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
index 32bfda6716d..a276ba5f8b0 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.readwritesplitting.rule.builder;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
@@ -42,7 +42,7 @@ public final class ReadwriteSplittingRuleBuilderTest {
new StaticReadwriteSplittingStrategyConfiguration("writeDataSourceName", Collections.singletonList("readDataSourceName")),
null, "loadBalancerName")),
Collections.emptyMap());
- DatabaseRuleBuilder builder = DatabaseRuleBuilderFactory.getInstanceMap(Collections.singletonList(ruleConfig)).get(ruleConfig);
+ DatabaseRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig);
assertThat(builder.build(ruleConfig, "", Collections.emptyMap(), Collections.emptyList(), mock(InstanceContext.class)), instanceOf(ReadwriteSplittingRule.class));
}
}
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/swapper/YamlReadwriteSplittingRuleConfigurationSwapperTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/swapper/YamlReadwriteSplittingRuleConfigurationSwapperTest.java
index 5ef26c302f2..8e907d520b9 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/swapper/YamlReadwriteSplittingRuleConfigurationSwapperTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/swapper/YamlReadwriteSplittingRuleConfigurationSwapperTest.java
@@ -18,7 +18,8 @@
package org.apache.shardingsphere.readwritesplitting.swapper;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperFactory;
+import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
@@ -33,9 +34,9 @@ import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
public final class YamlReadwriteSplittingRuleConfigurationSwapperTest {
@@ -101,7 +102,7 @@ public final class YamlReadwriteSplittingRuleConfigurationSwapperTest {
}
private YamlReadwriteSplittingRuleConfigurationSwapper getYamlReadwriteSplittingRuleConfigurationSwapper() {
- Optional<YamlReadwriteSplittingRuleConfigurationSwapper> result = YamlRuleConfigurationSwapperFactory.getAllInstances().stream()
+ Optional<YamlReadwriteSplittingRuleConfigurationSwapper> result = ShardingSphereServiceLoader.getServiceInstances(YamlRuleConfigurationSwapper.class).stream()
.filter(each -> each instanceof YamlReadwriteSplittingRuleConfigurationSwapper)
.map(each -> (YamlReadwriteSplittingRuleConfigurationSwapper) each)
.findFirst();
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
index abb311e4053..144fa45f4cc 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
@@ -29,10 +29,11 @@ import org.apache.shardingsphere.infra.rule.identifier.type.exportable.Exportabl
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.RuleExportEngine;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
-import org.apache.shardingsphere.readwritesplitting.factory.ReadQueryLoadBalanceAlgorithmFactory;
+import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import java.util.Collection;
import java.util.Collections;
@@ -222,7 +223,7 @@ public final class ReadwriteSplittingRuleStatementChecker {
private static void checkLoadBalancers(final Collection<ReadwriteSplittingRuleSegment> segments) {
Collection<String> notExistedLoadBalancers = segments.stream().map(ReadwriteSplittingRuleSegment::getLoadBalancer).filter(Objects::nonNull).distinct()
- .filter(each -> !ReadQueryLoadBalanceAlgorithmFactory.contains(each)).collect(Collectors.toSet());
+ .filter(each -> !TypedSPIRegistry.findRegisteredService(ReadQueryLoadBalanceAlgorithm.class, each).isPresent()).collect(Collectors.toSet());
ShardingSpherePreconditions.checkState(notExistedLoadBalancers.isEmpty(), () -> new InvalidAlgorithmConfigurationException("Load balancers", notExistedLoadBalancers));
}
}
diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
index f3b4a494136..af833c08da5 100644
--- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
+++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
@@ -25,13 +25,12 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.CreateReadwriteSplittingRuleStatement;
-import org.apache.shardingsphere.readwritesplitting.factory.ReadQueryLoadBalanceAlgorithmFactory;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import org.junit.Before;
import org.junit.Test;
@@ -47,6 +46,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
@@ -136,11 +136,10 @@ public final class CreateReadwriteSplittingRuleStatementUpdaterTest {
ExportableRule exportableRule = mock(ExportableRule.class);
when(exportableRule.getExportData()).thenReturn(Collections.singletonMap(ExportableConstants.EXPORT_DB_DISCOVERY_PRIMARY_DATA_SOURCES, Collections.singletonMap("ms_group", "ds_0")));
when(database.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singleton(exportableRule));
- try (MockedStatic<ReadQueryLoadBalanceAlgorithmFactory> mockedFactory = mockStatic(ReadQueryLoadBalanceAlgorithmFactory.class)) {
- mockedFactory.when(() -> ReadQueryLoadBalanceAlgorithmFactory.contains("TEST")).thenReturn(true);
+ try (MockedStatic<TypedSPIRegistry> typedSPIRegistry = mockStatic(TypedSPIRegistry.class)) {
+ typedSPIRegistry.when(() -> TypedSPIRegistry.findRegisteredService(ReadQueryLoadBalanceAlgorithm.class, "TEST")).thenReturn(Optional.of(mock(ReadQueryLoadBalanceAlgorithm.class)));
ReadwriteSplittingRuleSegment dynamicSegment = new ReadwriteSplittingRuleSegment("dynamic_rule", "ms_group", "false", "TEST", new Properties());
ReadwriteSplittingRuleSegment staticSegment = new ReadwriteSplittingRuleSegment("static_rule", "write_ds_0", Arrays.asList("read_ds_0", "read_ds_1"), "TEST", new Properties());
- ShardingSphereServiceLoader.register(ReadQueryLoadBalanceAlgorithm.class);
CreateReadwriteSplittingRuleStatement statement = createSQLStatement(false, dynamicSegment, staticSegment);
updater.checkSQLStatement(database, statement, null);
ReadwriteSplittingRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(statement);
diff --git a/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/factory/ShadowAlgorithmFactory.java b/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/factory/ShadowAlgorithmFactory.java
deleted file mode 100644
index a80edd5b38a..00000000000
--- a/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/factory/ShadowAlgorithmFactory.java
+++ /dev/null
@@ -1,57 +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.shadow.factory;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * Shadow algorithm factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShadowAlgorithmFactory {
-
- static {
- ShardingSphereServiceLoader.register(ShadowAlgorithm.class);
- }
-
- /**
- * Create new instance of shadow algorithm.
- *
- * @param shadowAlgorithmConfig shadow algorithm configuration
- * @return created instance
- */
- public static ShadowAlgorithm newInstance(final AlgorithmConfiguration shadowAlgorithmConfig) {
- return ShardingSphereAlgorithmFactory.createAlgorithm(shadowAlgorithmConfig, ShadowAlgorithm.class);
- }
-
- /**
- * Judge whether contains shadow algorithm.
- *
- * @param shadowAlgorithmType shadow algorithm type
- * @return contains shadow algorithm or not
- */
- public static boolean contains(final String shadowAlgorithmType) {
- return TypedSPIRegistry.findRegisteredService(ShadowAlgorithm.class, shadowAlgorithmType).isPresent();
- }
-}
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 4ea70199e30..e371db88069 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,6 +18,7 @@
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;
@@ -28,7 +29,6 @@ import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguratio
import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.hint.HintShadowAlgorithm;
-import org.apache.shardingsphere.shadow.factory.ShadowAlgorithmFactory;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Collection;
@@ -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 = ShadowAlgorithmFactory.newInstance(value);
+ ShadowAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(value, ShadowAlgorithm.class);
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 8f48882cf03..f033e5cb149 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,9 +17,10 @@
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.shadow.exception.data.UnsupportedShadowColumnTypeException;
-import org.apache.shardingsphere.shadow.factory.ShadowAlgorithmFactory;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.junit.Test;
import java.util.Properties;
@@ -31,21 +32,17 @@ public final class ColumnRegexMatchShadowAlgorithmTest extends AbstractColumnSha
@Test
public void assertIsShadow() {
- ColumnRegexMatchedShadowAlgorithm shadowAlgorithm = createShadowAlgorithm();
+ ColumnRegexMatchedShadowAlgorithm shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("REGEX_MATCH", createProperties()), ShadowAlgorithm.class);
createPreciseColumnShadowValuesFalseCase().forEach(each -> assertFalse(shadowAlgorithm.isShadow(each)));
createPreciseColumnShadowValuesTrueCase().forEach(each -> assertTrue(shadowAlgorithm.isShadow(each)));
}
@Test(expected = UnsupportedShadowColumnTypeException.class)
public void assertExceptionCase() {
- ColumnRegexMatchedShadowAlgorithm shadowAlgorithm = createShadowAlgorithm();
+ ColumnRegexMatchedShadowAlgorithm shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("REGEX_MATCH", createProperties()), ShadowAlgorithm.class);
createPreciseColumnShadowValuesExceptionCase().forEach(each -> assertFalse(shadowAlgorithm.isShadow(each)));
}
- private ColumnRegexMatchedShadowAlgorithm createShadowAlgorithm() {
- return (ColumnRegexMatchedShadowAlgorithm) ShadowAlgorithmFactory.newInstance(new AlgorithmConfiguration("REGEX_MATCH", createProperties()));
- }
-
private Properties createProperties() {
Properties result = new Properties();
result.setProperty("column", SHADOW_COLUMN);
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 9e8aa5f0aa2..0f59baffee0 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,9 +17,10 @@
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.shadow.exception.data.UnsupportedShadowColumnTypeException;
-import org.apache.shardingsphere.shadow.factory.ShadowAlgorithmFactory;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.junit.Test;
import java.util.Properties;
@@ -31,21 +32,17 @@ public final class ColumnValueMatchShadowAlgorithmTest extends AbstractColumnSha
@Test
public void assertIsShadow() {
- ColumnValueMatchedShadowAlgorithm shadowAlgorithm = createShadowAlgorithm();
+ ColumnValueMatchedShadowAlgorithm shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("VALUE_MATCH", createProperties()), ShadowAlgorithm.class);
createPreciseColumnShadowValuesTrueCase().forEach(each -> assertTrue(shadowAlgorithm.isShadow(each)));
createPreciseColumnShadowValuesFalseCase().forEach(each -> assertFalse(shadowAlgorithm.isShadow(each)));
}
@Test(expected = UnsupportedShadowColumnTypeException.class)
public void assertExceptionCase() {
- ColumnValueMatchedShadowAlgorithm shadowAlgorithm = createShadowAlgorithm();
+ ColumnValueMatchedShadowAlgorithm shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("VALUE_MATCH", createProperties()), ShadowAlgorithm.class);
createPreciseColumnShadowValuesExceptionCase().forEach(each -> assertFalse(shadowAlgorithm.isShadow(each)));
}
- private ColumnValueMatchedShadowAlgorithm createShadowAlgorithm() {
- return (ColumnValueMatchedShadowAlgorithm) ShadowAlgorithmFactory.newInstance(new AlgorithmConfiguration("VALUE_MATCH", createProperties()));
- }
-
private Properties createProperties() {
Properties result = new Properties();
result.setProperty("column", SHADOW_COLUMN);
diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithmTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithmTest.java
index cbfd72d9c88..d5a64769a37 100644
--- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithmTest.java
+++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithmTest.java
@@ -17,10 +17,11 @@
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.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.hint.PreciseHintShadowValue;
-import org.apache.shardingsphere.shadow.factory.ShadowAlgorithmFactory;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.junit.Before;
import org.junit.Test;
@@ -36,7 +37,7 @@ public final class SimpleHintShadowAlgorithmTest {
@Before
public void init() {
- shadowAlgorithm = (SimpleHintShadowAlgorithm) ShadowAlgorithmFactory.newInstance(new AlgorithmConfiguration("SIMPLE_HINT", createProperties()));
+ shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SIMPLE_HINT", createProperties()), ShadowAlgorithm.class);
}
private Properties createProperties() {
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 14ec1264d06..5d8fcd1d4fb 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,12 +17,12 @@
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.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.factory.ShadowAlgorithmFactory;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.junit.Test;
import java.util.Collections;
@@ -34,12 +34,8 @@ public final class ColumnShadowAlgorithmDeterminerTest {
@Test
public void assertIsShadow() {
- assertTrue(ColumnShadowAlgorithmDeterminer.isShadow(createColumnShadowAlgorithms(), createShadowDetermineCondition()));
- }
-
- @SuppressWarnings("unchecked")
- private ColumnShadowAlgorithm<Comparable<?>> createColumnShadowAlgorithms() {
- return (ColumnShadowAlgorithm<Comparable<?>>) ShadowAlgorithmFactory.newInstance(new AlgorithmConfiguration("REGEX_MATCH", createProperties()));
+ assertTrue(ColumnShadowAlgorithmDeterminer.isShadow(
+ ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("REGEX_MATCH", createProperties()), ShadowAlgorithm.class), createShadowDetermineCondition()));
}
private Properties createProperties() {
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 0b7fb4da4d4..c9ed5b31532 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,6 +17,7 @@
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.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
@@ -24,8 +25,8 @@ import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguratio
import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.hint.HintShadowAlgorithm;
import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
-import org.apache.shardingsphere.shadow.factory.ShadowAlgorithmFactory;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.junit.Test;
import java.util.Collection;
@@ -40,15 +41,10 @@ public final class HintShadowAlgorithmDeterminerTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertIsShadow() {
- HintShadowAlgorithm hintShadowAlgorithm = (HintShadowAlgorithm) ShadowAlgorithmFactory.newInstance(createHintShadowAlgorithm());
+ HintShadowAlgorithm hintShadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SIMPLE_HINT", createProperties()), ShadowAlgorithm.class);
assertTrue(HintShadowAlgorithmDeterminer.isShadow(hintShadowAlgorithm, createShadowDetermineCondition(), new ShadowRule(createShadowRuleConfiguration())));
}
- @SuppressWarnings({"rawtypes", "unchecked"})
- private AlgorithmConfiguration createHintShadowAlgorithm() {
- return new AlgorithmConfiguration("SIMPLE_HINT", createProperties());
- }
-
private Properties createProperties() {
Properties result = new Properties();
result.setProperty("foo", "foo_value");
@@ -59,7 +55,7 @@ public final class HintShadowAlgorithmDeterminerTest {
ShadowRuleConfiguration result = new ShadowRuleConfiguration();
result.setDataSources(createDataSources());
result.setTables(Collections.singletonMap("t_order", new ShadowTableConfiguration(Collections.singletonList("shadow-data-source-0"), Collections.singleton("simple-hint-algorithm"))));
- result.setShadowAlgorithms(Collections.singletonMap("simple-hint-algorithm", createHintShadowAlgorithm()));
+ result.setShadowAlgorithms(Collections.singletonMap("simple-hint-algorithm", new AlgorithmConfiguration("SIMPLE_HINT", createProperties())));
return result;
}
diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java
index 0b2ce46a2cd..3f49b9e471d 100644
--- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java
+++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.shadow.rule.builder;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.junit.Test;
@@ -36,7 +36,7 @@ public final class ShadowRuleBuilderTest {
@Test
public void assertBuild() {
ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration();
- DatabaseRuleBuilder builder = DatabaseRuleBuilderFactory.getInstanceMap(Collections.singletonList(ruleConfig)).get(ruleConfig);
+ DatabaseRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig);
assertThat(builder.build(ruleConfig, "", Collections.emptyMap(), Collections.emptyList(), mock(InstanceContext.class)), instanceOf(ShadowRule.class));
}
}
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmStatementUpdater.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmStatementUpdater.java
index 8e7d385c3dc..3b1a66d4da5 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmStatementUpdater.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmStatementUpdater.java
@@ -18,18 +18,19 @@
package org.apache.shardingsphere.shadow.distsql.handler.update;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdater;
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatementChecker;
import org.apache.shardingsphere.shadow.distsql.parser.statement.AlterDefaultShadowAlgorithmStatement;
-import org.apache.shardingsphere.shadow.factory.ShadowAlgorithmFactory;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Collection;
import java.util.Collections;
@@ -51,8 +52,8 @@ public final class AlterDefaultShadowAlgorithmStatementUpdater implements RuleDe
}
private Map<String, AlgorithmConfiguration> buildAlgorithmMap(final AlterDefaultShadowAlgorithmStatement sqlStatement) {
- return Collections.singletonMap(DEFAULT_ALGORITHM_NAME, new AlgorithmConfiguration(sqlStatement.getShadowAlgorithmSegment().getAlgorithmSegment().getName(),
- sqlStatement.getShadowAlgorithmSegment().getAlgorithmSegment().getProps()));
+ return Collections.singletonMap(DEFAULT_ALGORITHM_NAME,
+ new AlgorithmConfiguration(sqlStatement.getShadowAlgorithmSegment().getAlgorithmSegment().getName(), sqlStatement.getShadowAlgorithmSegment().getAlgorithmSegment().getProps()));
}
@Override
@@ -71,8 +72,8 @@ public final class AlterDefaultShadowAlgorithmStatementUpdater implements RuleDe
checkAlgorithmCompleteness(algorithmSegment);
checkAlgorithmType(algorithmSegment);
Collection<String> requiredAlgorithmNames = Collections.singleton(DEFAULT_ALGORITHM_NAME);
- ShadowRuleStatementChecker.checkExisted(requiredAlgorithmNames, currentRuleConfig.getShadowAlgorithms().keySet(),
- notExistedAlgorithms -> new MissingRequiredAlgorithmException("shadow", databaseName, notExistedAlgorithms));
+ ShadowRuleStatementChecker.checkExisted(requiredAlgorithmNames,
+ currentRuleConfig.getShadowAlgorithms().keySet(), notExistedAlgorithms -> new MissingRequiredAlgorithmException("shadow", databaseName, notExistedAlgorithms));
}
private static void checkAlgorithmCompleteness(final AlgorithmSegment algorithmSegment) {
@@ -82,7 +83,8 @@ public final class AlterDefaultShadowAlgorithmStatementUpdater implements RuleDe
private void checkAlgorithmType(final AlgorithmSegment algorithmSegment) {
String shadowAlgorithmType = algorithmSegment.getName();
- ShardingSpherePreconditions.checkState(ShadowAlgorithmFactory.contains(shadowAlgorithmType), () -> new InvalidAlgorithmConfigurationException("shadow", shadowAlgorithmType));
+ ShardingSpherePreconditions.checkState(
+ TypedSPIRegistry.findRegisteredService(ShadowAlgorithm.class, shadowAlgorithmType).isPresent(), () -> new InvalidAlgorithmConfigurationException("shadow", shadowAlgorithmType));
}
@Override
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java
index bb3dbc3ed58..726d8562953 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdat
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
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;
@@ -34,7 +35,7 @@ import org.apache.shardingsphere.shadow.distsql.handler.supporter.ShadowRuleStat
import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowRuleSegment;
import org.apache.shardingsphere.shadow.distsql.parser.statement.AlterShadowRuleStatement;
-import org.apache.shardingsphere.shadow.factory.ShadowAlgorithmFactory;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Collection;
import java.util.Map;
@@ -88,7 +89,8 @@ public final class AlterShadowRuleStatementUpdater implements RuleDefinitionAlte
private void checkAlgorithmType(final AlterShadowRuleStatement sqlStatement) {
Collection<String> invalidAlgorithmTypes = sqlStatement.getRules().stream().flatMap(each -> each.getShadowTableRules().values().stream()).flatMap(Collection::stream)
- .map(each -> each.getAlgorithmSegment().getName()).collect(Collectors.toSet()).stream().filter(each -> !ShadowAlgorithmFactory.contains(each)).collect(Collectors.toSet());
+ .map(each -> each.getAlgorithmSegment().getName()).collect(Collectors.toSet()).stream()
+ .filter(each -> !TypedSPIRegistry.findRegisteredService(ShadowAlgorithm.class, each).isPresent()).collect(Collectors.toSet());
ShardingSpherePreconditions.checkState(invalidAlgorithmTypes.isEmpty(), () -> new InvalidAlgorithmConfigurationException("shadow", invalidAlgorithmTypes));
}
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
index e52d8e1b948..229b49399d0 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
@@ -25,15 +25,17 @@ import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.distsql.parser.statement.CreateDefaultShadowAlgorithmStatement;
-import org.apache.shardingsphere.shadow.factory.ShadowAlgorithmFactory;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Create default shadow algorithm statement updater.
@@ -76,7 +78,7 @@ public final class CreateDefaultShadowAlgorithmStatementUpdater implements RuleD
private static Collection<String> getIdentical(final ShadowRuleConfiguration currentRuleConfig) {
Collection<String> currentAlgorithmNames = null == currentRuleConfig ? Collections.emptyList() : currentRuleConfig.getShadowAlgorithms().keySet();
- return Collections.singleton(DEFAULT_ALGORITHM_NAME).stream().filter(currentAlgorithmNames::contains).collect(Collectors.toSet());
+ return Stream.of(DEFAULT_ALGORITHM_NAME).filter(currentAlgorithmNames::contains).collect(Collectors.toSet());
}
private void checkExist(final String databaseName, final ShadowRuleConfiguration currentRuleConfig) {
@@ -86,7 +88,8 @@ public final class CreateDefaultShadowAlgorithmStatementUpdater implements RuleD
private void checkAlgorithmType(final CreateDefaultShadowAlgorithmStatement sqlStatement) {
String shadowAlgorithmType = sqlStatement.getShadowAlgorithmSegment().getAlgorithmSegment().getName();
- ShardingSpherePreconditions.checkState(ShadowAlgorithmFactory.contains(shadowAlgorithmType), () -> new InvalidAlgorithmConfigurationException(SHADOW, shadowAlgorithmType));
+ ShardingSpherePreconditions.checkState(
+ TypedSPIRegistry.findRegisteredService(ShadowAlgorithm.class, shadowAlgorithmType).isPresent(), () -> new InvalidAlgorithmConfigurationException(SHADOW, shadowAlgorithmType));
}
private static void checkAlgorithmCompleteness(final Collection<AlgorithmSegment> algorithmSegments) {
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java
index 5ec6d5e73b3..4af3dbd5aa1 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpda
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatementChecker;
@@ -30,7 +31,7 @@ import org.apache.shardingsphere.shadow.distsql.handler.converter.ShadowRuleStat
import org.apache.shardingsphere.shadow.distsql.handler.supporter.ShadowRuleStatementSupporter;
import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowRuleSegment;
import org.apache.shardingsphere.shadow.distsql.parser.statement.CreateShadowRuleStatement;
-import org.apache.shardingsphere.shadow.factory.ShadowAlgorithmFactory;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Collection;
import java.util.LinkedList;
@@ -97,7 +98,8 @@ public final class CreateShadowRuleStatementUpdater implements RuleDefinitionCre
private void checkAlgorithmType(final Collection<ShadowRuleSegment> segments) {
Collection<String> invalidAlgorithmTypes = segments.stream().flatMap(each -> each.getShadowTableRules().values().stream()).flatMap(Collection::stream)
- .map(each -> each.getAlgorithmSegment().getName()).collect(Collectors.toSet()).stream().filter(each -> !ShadowAlgorithmFactory.contains(each)).collect(Collectors.toSet());
+ .map(each -> each.getAlgorithmSegment().getName()).collect(Collectors.toSet())
+ .stream().filter(each -> !TypedSPIRegistry.findRegisteredService(ShadowAlgorithm.class, each).isPresent()).collect(Collectors.toSet());
ShardingSpherePreconditions.checkState(invalidAlgorithmTypes.isEmpty(), () -> new InvalidAlgorithmConfigurationException("shadow", invalidAlgorithmTypes));
}
diff --git a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/factory/KeyGenerateAlgorithmFactory.java b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/factory/KeyGenerateAlgorithmFactory.java
deleted file mode 100644
index 30d518bada7..00000000000
--- a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/factory/KeyGenerateAlgorithmFactory.java
+++ /dev/null
@@ -1,67 +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.sharding.factory;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * Key generate algorithm factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class KeyGenerateAlgorithmFactory {
-
- static {
- ShardingSphereServiceLoader.register(KeyGenerateAlgorithm.class);
- }
-
- /**
- * Create new instance of key generate algorithm.
- *
- * @return created instance
- */
- public static KeyGenerateAlgorithm newInstance() {
- return RequiredSPIRegistry.getRegisteredService(KeyGenerateAlgorithm.class);
- }
-
- /**
- * Create new instance of key generate algorithm.
- *
- * @param keyGenerateAlgorithmConfig key generate algorithm configuration
- * @return created instance
- */
- public static KeyGenerateAlgorithm newInstance(final AlgorithmConfiguration keyGenerateAlgorithmConfig) {
- return ShardingSphereAlgorithmFactory.createAlgorithm(keyGenerateAlgorithmConfig, KeyGenerateAlgorithm.class);
- }
-
- /**
- * Judge whether contains key generate algorithm.
- *
- * @param keyGenerateAlgorithmType key generate algorithm type
- * @return contains key generate algorithm or not
- */
- public static boolean contains(final String keyGenerateAlgorithmType) {
- return TypedSPIRegistry.findRegisteredService(KeyGenerateAlgorithm.class, keyGenerateAlgorithmType).isPresent();
- }
-}
diff --git a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/factory/ShardingAlgorithmFactory.java b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/factory/ShardingAlgorithmFactory.java
deleted file mode 100644
index f6e5e611a29..00000000000
--- a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/factory/ShardingAlgorithmFactory.java
+++ /dev/null
@@ -1,57 +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.sharding.factory;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * Sharding algorithm factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShardingAlgorithmFactory {
-
- static {
- ShardingSphereServiceLoader.register(ShardingAlgorithm.class);
- }
-
- /**
- * Create new instance of sharding algorithm.
- *
- * @param shardingAlgorithmConfig sharding algorithm configuration
- * @return created instance
- */
- public static ShardingAlgorithm newInstance(final AlgorithmConfiguration shardingAlgorithmConfig) {
- return ShardingSphereAlgorithmFactory.createAlgorithm(shardingAlgorithmConfig, ShardingAlgorithm.class);
- }
-
- /**
- * Judge whether contains sharding algorithm.
- *
- * @param shardingAlgorithmType sharding algorithm type
- * @return contains sharding algorithm or not
- */
- public static boolean contains(final String shardingAlgorithmType) {
- return TypedSPIRegistry.findRegisteredService(ShardingAlgorithm.class, shardingAlgorithmType).isPresent();
- }
-}
diff --git a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/factory/ShardingAuditAlgorithmFactory.java b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/factory/ShardingAuditAlgorithmFactory.java
deleted file mode 100644
index e18a6158bb6..00000000000
--- a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/factory/ShardingAuditAlgorithmFactory.java
+++ /dev/null
@@ -1,57 +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.sharding.factory;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.sharding.spi.ShardingAuditAlgorithm;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * Sharding audit algorithm factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShardingAuditAlgorithmFactory {
-
- static {
- ShardingSphereServiceLoader.register(ShardingAuditAlgorithm.class);
- }
-
- /**
- * Create new instance of sharding audit algorithm.
- *
- * @param shardingAuditAlgorithmConfig sharding audit algorithm configuration
- * @return created instance
- */
- public static ShardingAuditAlgorithm newInstance(final AlgorithmConfiguration shardingAuditAlgorithmConfig) {
- return ShardingSphereAlgorithmFactory.createAlgorithm(shardingAuditAlgorithmConfig, ShardingAuditAlgorithm.class);
- }
-
- /**
- * Judge whether contains sharding audit algorithm.
- *
- * @param shardingAuditAlgorithmType sharding audit algorithm type
- * @return contains sharding audit algorithm or not
- */
- public static boolean contains(final String shardingAuditAlgorithmType) {
- return TypedSPIRegistry.findRegisteredService(ShardingAuditAlgorithm.class, shardingAuditAlgorithmType).isPresent();
- }
-}
diff --git a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/factory/KeyGenerateAlgorithmFactoryTest.java b/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/factory/KeyGenerateAlgorithmFactoryTest.java
deleted file mode 100644
index 8fef7cbcf8f..00000000000
--- a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/factory/KeyGenerateAlgorithmFactoryTest.java
+++ /dev/null
@@ -1,46 +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.sharding.factory;
-
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.sharding.fixture.KeyGenerateAlgorithmFixture;
-import org.junit.Test;
-
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class KeyGenerateAlgorithmFactoryTest {
-
- @Test
- public void assertNewInstance() {
- assertThat(KeyGenerateAlgorithmFactory.newInstance(), instanceOf(KeyGenerateAlgorithmFixture.class));
- }
-
- @Test
- public void assertNewInstanceWithAlgorithmConfiguration() {
- assertThat(KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("FIXTURE", new Properties())), instanceOf(KeyGenerateAlgorithmFixture.class));
- }
-
- @Test
- public void assertContains() {
- assertTrue(KeyGenerateAlgorithmFactory.contains("FIXTURE"));
- }
-}
diff --git a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/factory/ShardingAlgorithmFactoryTest.java b/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/factory/ShardingAlgorithmFactoryTest.java
deleted file mode 100644
index b7962edb650..00000000000
--- a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/factory/ShardingAlgorithmFactoryTest.java
+++ /dev/null
@@ -1,41 +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.sharding.factory;
-
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.sharding.fixture.ShardingAlgorithmFixture;
-import org.junit.Test;
-
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class ShardingAlgorithmFactoryTest {
-
- @Test
- public void assertNewInstance() {
- assertThat(ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("FIXTURE", new Properties())), instanceOf(ShardingAlgorithmFixture.class));
- }
-
- @Test
- public void assertContains() {
- assertTrue(ShardingAlgorithmFactory.contains("FIXTURE"));
- }
-}
diff --git a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/factory/ShardingAuditAlgorithmFactoryTest.java b/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/factory/ShardingAuditAlgorithmFactoryTest.java
deleted file mode 100644
index ac733d0137a..00000000000
--- a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/factory/ShardingAuditAlgorithmFactoryTest.java
+++ /dev/null
@@ -1,41 +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.sharding.factory;
-
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.sharding.fixture.ShardingAuditAlgorithmFixture;
-import org.junit.Test;
-
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class ShardingAuditAlgorithmFactoryTest {
-
- @Test
- public void assertNewInstance() {
- assertThat(ShardingAuditAlgorithmFactory.newInstance(new AlgorithmConfiguration("FIXTURE", new Properties())), instanceOf(ShardingAuditAlgorithmFixture.class));
- }
-
- @Test
- public void assertContains() {
- assertTrue(ShardingAuditAlgorithmFactory.contains("FIXTURE"));
- }
-}
diff --git a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/fixture/KeyGenerateAlgorithmFixture.java b/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/fixture/KeyGenerateAlgorithmFixture.java
deleted file mode 100644
index 96868af751a..00000000000
--- a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/fixture/KeyGenerateAlgorithmFixture.java
+++ /dev/null
@@ -1,44 +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.sharding.fixture;
-
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-
-import java.util.Properties;
-
-public final class KeyGenerateAlgorithmFixture implements KeyGenerateAlgorithm {
-
- @Override
- public void init(final Properties props) {
- }
-
- @Override
- public Properties getProps() {
- return new Properties();
- }
-
- @Override
- public Comparable<?> generateKey() {
- return null;
- }
-
- @Override
- public String getType() {
- return "FIXTURE";
- }
-}
diff --git a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/fixture/ShardingAlgorithmFixture.java b/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/fixture/ShardingAlgorithmFixture.java
deleted file mode 100644
index 11d1080cae9..00000000000
--- a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/fixture/ShardingAlgorithmFixture.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.sharding.fixture;
-
-import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
-
-import java.util.Properties;
-
-public final class ShardingAlgorithmFixture implements ShardingAlgorithm {
-
- @Override
- public Properties getProps() {
- return new Properties();
- }
-
- @Override
- public void init(final Properties props) {
- }
-
- @Override
- public String getType() {
- return "FIXTURE";
- }
-}
diff --git a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/fixture/ShardingAuditAlgorithmFixture.java b/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/fixture/ShardingAuditAlgorithmFixture.java
deleted file mode 100644
index 79147266af6..00000000000
--- a/features/sharding/api/src/test/java/org/apache/shardingsphere/sharding/fixture/ShardingAuditAlgorithmFixture.java
+++ /dev/null
@@ -1,47 +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.sharding.fixture;
-
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.sharding.spi.ShardingAuditAlgorithm;
-
-import java.util.List;
-import java.util.Properties;
-
-public final class ShardingAuditAlgorithmFixture implements ShardingAuditAlgorithm {
-
- @Override
- public void init(final Properties props) {
- }
-
- @Override
- public void check(final SQLStatementContext<?> sqlStatementContext, final List<Object> params, final Grantee grantee, final ShardingSphereDatabase database) {
- }
-
- @Override
- public Properties getProps() {
- return new Properties();
- }
-
- @Override
- public String getType() {
- return "FIXTURE";
- }
-}
diff --git a/features/sharding/api/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm b/features/sharding/api/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm
deleted file mode 100644
index da7b2a000f6..00000000000
--- a/features/sharding/api/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.sharding.fixture.KeyGenerateAlgorithmFixture
diff --git a/features/sharding/api/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm b/features/sharding/api/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm
deleted file mode 100644
index cf5d2a56371..00000000000
--- a/features/sharding/api/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.sharding.fixture.ShardingAlgorithmFixture
diff --git a/features/sharding/api/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAuditAlgorithm b/features/sharding/api/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAuditAlgorithm
deleted file mode 100644
index 35e9e19632a..00000000000
--- a/features/sharding/api/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAuditAlgorithm
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.sharding.fixture.ShardingAuditAlgorithmFixture
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
index f910a39096f..2f224aebd56 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
@@ -25,8 +25,8 @@ import org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueC
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.datetime.DatetimeService;
-import org.apache.shardingsphere.infra.datetime.DatetimeServiceFactory;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
import org.apache.shardingsphere.sharding.exception.data.NullShardingValueException;
import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils;
import org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition;
@@ -112,7 +112,7 @@ public final class InsertClauseShardingConditionEngine implements ShardingCondit
generateShardingCondition((CommonExpressionSegment) each, result, shardingColumn.get(), tableName);
} else if (ExpressionConditionUtils.isNowExpression(each)) {
if (null == datetimeService) {
- datetimeService = DatetimeServiceFactory.getInstance();
+ datetimeService = RequiredSPIRegistry.getRegisteredService(DatetimeService.class);
}
result.getValues().add(new ListShardingConditionValue<>(shardingColumn.get(), tableName, Collections.singletonList(datetimeService.getDatetime())));
} else if (ExpressionConditionUtils.isNullExpression(each)) {
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java
index aacae251ab7..a484d0b17ce 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java
@@ -18,7 +18,8 @@
package org.apache.shardingsphere.sharding.route.engine.condition.generator.impl;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.datetime.DatetimeServiceFactory;
+import org.apache.shardingsphere.infra.datetime.DatetimeService;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
import org.apache.shardingsphere.sharding.route.engine.condition.Column;
import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils;
import org.apache.shardingsphere.sharding.route.engine.condition.generator.ConditionValue;
@@ -51,7 +52,7 @@ public final class ConditionValueBetweenOperatorGenerator implements ConditionVa
return Optional.of(new RangeShardingConditionValue<>(column.getName(), column.getTableName(), SafeNumberOperationUtil.safeClosed(betweenValue.get(), andValue.get()),
parameterMarkerIndexes));
}
- Date datetime = DatetimeServiceFactory.getInstance().getDatetime();
+ Date datetime = RequiredSPIRegistry.getRegisteredService(DatetimeService.class).getDatetime();
if (!betweenValue.isPresent() && ExpressionConditionUtils.isNowExpression(predicate.getBetweenExpr())) {
betweenValue = Optional.of(datetime);
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
index bf0eb940878..20212c7426c 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
@@ -18,7 +18,8 @@
package org.apache.shardingsphere.sharding.route.engine.condition.generator.impl;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.infra.datetime.DatetimeServiceFactory;
+import org.apache.shardingsphere.infra.datetime.DatetimeService;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
import org.apache.shardingsphere.sharding.route.engine.condition.Column;
import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils;
import org.apache.shardingsphere.sharding.route.engine.condition.generator.ConditionValue;
@@ -68,7 +69,7 @@ public final class ConditionValueCompareOperatorGenerator implements ConditionVa
return generate(value.get(), column, operator, conditionValue.getParameterMarkerIndex().orElse(-1));
}
if (ExpressionConditionUtils.isNowExpression(valueExpression)) {
- return generate(DatetimeServiceFactory.getInstance().getDatetime(), column, operator, -1);
+ return generate(RequiredSPIRegistry.getRegisteredService(DatetimeService.class).getDatetime(), column, operator, -1);
}
return Optional.empty();
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
index fd33e54601e..d6ba47be1c1 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.route.engine.condition.generator.impl;
import org.apache.shardingsphere.infra.datetime.DatetimeService;
-import org.apache.shardingsphere.infra.datetime.DatetimeServiceFactory;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
import org.apache.shardingsphere.sharding.route.engine.condition.Column;
import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils;
import org.apache.shardingsphere.sharding.route.engine.condition.generator.ConditionValue;
@@ -42,7 +42,7 @@ public final class ConditionValueInOperatorGenerator implements ConditionValueGe
public Optional<ShardingConditionValue> generate(final InExpression predicate, final Column column, final List<Object> params) {
List<Comparable<?>> shardingConditionValues = new LinkedList<>();
List<Integer> parameterMarkerIndexes = new ArrayList<>(predicate.getExpressionList().size());
- DatetimeService datetimeService = DatetimeServiceFactory.getInstance();
+ DatetimeService datetimeService = RequiredSPIRegistry.getRegisteredService(DatetimeService.class);
for (ExpressionSegment each : predicate.getExpressionList()) {
ConditionValue conditionValue = new ConditionValue(each, params);
Optional<Comparable<?>> value = conditionValue.getValue();
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 8f932309690..01f87aabef1 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
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
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;
@@ -35,6 +36,7 @@ import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRul
import org.apache.shardingsphere.infra.rule.identifier.type.TableContainedRule;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.expr.InlineExpressionParser;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
@@ -48,9 +50,6 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardS
import org.apache.shardingsphere.sharding.api.sharding.ShardingAutoTableAlgorithm;
import org.apache.shardingsphere.sharding.exception.algorithm.GenerateKeyStrategyNotFoundException;
import org.apache.shardingsphere.sharding.exception.metadata.ShardingRuleNotFoundException;
-import org.apache.shardingsphere.sharding.factory.KeyGenerateAlgorithmFactory;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
-import org.apache.shardingsphere.sharding.factory.ShardingAuditAlgorithmFactory;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.apache.shardingsphere.sharding.spi.ShardingAuditAlgorithm;
@@ -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, ShardingAlgorithmFactory.newInstance(value)));
- ruleConfig.getKeyGenerators().forEach((key, value) -> keyGenerators.put(key, KeyGenerateAlgorithmFactory.newInstance(value)));
- ruleConfig.getAuditors().forEach((key, value) -> auditors.put(key, ShardingAuditAlgorithmFactory.newInstance(value)));
+ 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)));
tableRules.putAll(createTableRules(ruleConfig.getTables(), ruleConfig.getDefaultKeyGenerateStrategy()));
tableRules.putAll(createAutoTableRules(ruleConfig.getAutoTables(), ruleConfig.getDefaultKeyGenerateStrategy()));
broadcastTables = createBroadcastTables(ruleConfig.getBroadcastTables());
@@ -129,7 +128,7 @@ public final class ShardingRule implements DatabaseRule, DataNodeContainedRule,
defaultTableShardingStrategyConfig = null == ruleConfig.getDefaultTableShardingStrategy() ? new NoneShardingStrategyConfiguration() : ruleConfig.getDefaultTableShardingStrategy();
defaultAuditStrategy = null == ruleConfig.getDefaultAuditStrategy() ? new ShardingAuditStrategyConfiguration(Collections.emptyList(), true) : ruleConfig.getDefaultAuditStrategy();
defaultKeyGenerateAlgorithm = null == ruleConfig.getDefaultKeyGenerateStrategy()
- ? KeyGenerateAlgorithmFactory.newInstance()
+ ? RequiredSPIRegistry.getRegisteredService(KeyGenerateAlgorithm.class)
: keyGenerators.get(ruleConfig.getDefaultKeyGenerateStrategy().getKeyGeneratorName());
defaultShardingColumn = ruleConfig.getDefaultShardingColumn();
shardingTableDataNodes = createShardingTableDataNodes(tableRules);
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 fc76a728af7..db9d54290d1 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,13 @@
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.check.exception.SQLCheckException;
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.sharding.factory.ShardingAuditAlgorithmFactory;
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;
@@ -52,7 +52,7 @@ public final class DMLShardingConditionsShardingAuditAlgorithmTest {
@Before
public void setUp() {
- shardingAuditAlgorithm = ShardingAuditAlgorithmFactory.newInstance(new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));
+ shardingAuditAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()), ShardingAuditAlgorithm.class);
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 51819d39b9e..23f7be55c58 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,6 +18,7 @@
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;
@@ -29,7 +30,6 @@ import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.sharding.algorithm.keygen.fixture.FixedTimeService;
import org.apache.shardingsphere.sharding.algorithm.keygen.fixture.WorkerIdGeneratorFixture;
-import org.apache.shardingsphere.sharding.factory.KeyGenerateAlgorithmFactory;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.junit.Test;
import org.mockito.internal.configuration.plugins.Plugins;
@@ -70,7 +70,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
int threadNumber = Runtime.getRuntime().availableProcessors() * 2;
ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
int taskNumber = threadNumber * 4;
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -84,7 +84,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKeyWithSingleThread() {
SnowflakeKeyGenerateAlgorithm.setTimeService(new FixedTimeService(1));
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -101,7 +101,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
SnowflakeKeyGenerateAlgorithm.setTimeService(new FixedTimeService(5));
Properties props = new Properties();
props.setProperty("max-vibration-offset", "3");
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", props));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -117,7 +117,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
Properties props = new Properties();
SnowflakeKeyGenerateAlgorithm.setTimeService(new TimeService());
props.setProperty("max-vibration-offset", String.valueOf(3));
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", props));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -141,7 +141,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
public void assertGenerateKeyWithClockCallBack() {
TimeService timeService = new FixedTimeService(1);
SnowflakeKeyGenerateAlgorithm.setTimeService(timeService);
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -160,7 +160,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
SnowflakeKeyGenerateAlgorithm.setTimeService(timeService);
Properties props = new Properties();
props.setProperty("max-tolerate-time-difference-milliseconds", String.valueOf(0));
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", props));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -176,7 +176,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
public void assertGenerateKeyBeyondMaxSequencePerMilliSecond() {
TimeService timeService = new FixedTimeService(2);
SnowflakeKeyGenerateAlgorithm.setTimeService(timeService);
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -202,7 +202,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test(expected = IllegalArgumentException.class)
public void assertSetWorkerIdFailureWhenNegative() {
- SnowflakeKeyGenerateAlgorithm algorithm = (SnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
+ SnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
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);
@@ -213,12 +213,12 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
public void assertSetMaxVibrationOffsetFailureWhenNegative() {
Properties props = new Properties();
props.setProperty("max-vibration-offset", String.valueOf(-1));
- KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", props)).generateKey();
+ ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class)).generateKey();
}
@Test(expected = IllegalArgumentException.class)
public void assertSetWorkerIdFailureWhenOutOfRange() {
- SnowflakeKeyGenerateAlgorithm algorithm = (SnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
+ SnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
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);
@@ -229,14 +229,14 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
public void assertSetMaxVibrationOffsetFailureWhenOutOfRange() {
Properties props = new Properties();
props.setProperty("max-vibration-offset", String.valueOf(4096));
- KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", props)).generateKey();
+ ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class)).generateKey();
}
@Test
public void assertSetMaxTolerateTimeDifferenceMilliseconds() throws ReflectiveOperationException {
Properties props = new Properties();
props.setProperty("max-tolerate-time-difference-milliseconds", String.valueOf(1));
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("SNOWFLAKE", props));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class);
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 9f661a0e01c..34066363024 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,6 +18,7 @@
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.sharding.api.sharding.complex.ComplexKeysShardingValue;
@@ -25,10 +26,10 @@ import org.apache.shardingsphere.sharding.api.sharding.hint.HintShardingValue;
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.ShardingAlgorithmClassImplementationException;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
import org.apache.shardingsphere.sharding.fixture.ClassBasedComplexKeysShardingAlgorithmFixture;
import org.apache.shardingsphere.sharding.fixture.ClassBasedHintShardingAlgorithmFixture;
import org.apache.shardingsphere.sharding.fixture.ClassBasedStandardShardingAlgorithmFixture;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Test;
import java.util.Arrays;
@@ -44,21 +45,21 @@ public final class ClassBasedShardingAlgorithmTest {
public void assertInitWithNullStrategy() {
Properties props = new Properties();
props.setProperty("strategy", null);
- ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("CLASS_BASED", props));
+ ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test(expected = IllegalArgumentException.class)
public void assertInitWithWrongStrategy() {
Properties props = new Properties();
props.setProperty("strategy", "wrong");
- ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("CLASS_BASED", props));
+ ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test(expected = NullPointerException.class)
public void assertInitWithNullClass() {
Properties props = new Properties();
props.setProperty("strategy", "standard");
- ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("CLASS_BASED", props));
+ ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test(expected = ClassNotFoundException.class)
@@ -66,7 +67,7 @@ public final class ClassBasedShardingAlgorithmTest {
Properties props = new Properties();
props.setProperty("strategy", "standard");
props.setProperty("algorithmClassName", "org.apache.shardingsphere.sharding.UndefinedClass");
- ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("CLASS_BASED", props));
+ ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test(expected = ShardingAlgorithmClassImplementationException.class)
@@ -74,21 +75,19 @@ public final class ClassBasedShardingAlgorithmTest {
Properties props = new Properties();
props.setProperty("strategy", "standard");
props.setProperty("algorithmClassName", ClassBasedComplexKeysShardingAlgorithmFixture.class.getName());
- ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("CLASS_BASED", props));
+ ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test
public void assertPreciseDoSharding() {
- ClassBasedShardingAlgorithm algorithm = (ClassBasedShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("CLASS_BASED", createStandardProperties()));
+ ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", createStandardProperties()), ShardingAlgorithm.class);
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() {
- ClassBasedShardingAlgorithm algorithm = (ClassBasedShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("CLASS_BASED", createStandardProperties()));
+ ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", createStandardProperties()), ShardingAlgorithm.class);
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));
@@ -96,7 +95,7 @@ public final class ClassBasedShardingAlgorithmTest {
@Test
public void assertComplexKeysDoSharding() {
- ClassBasedShardingAlgorithm algorithm = (ClassBasedShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("CLASS_BASED", createComplexProperties()));
+ ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", createComplexProperties()), ShardingAlgorithm.class);
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));
@@ -104,7 +103,7 @@ public final class ClassBasedShardingAlgorithmTest {
@Test
public void assertHintDoSharding() {
- ClassBasedShardingAlgorithm algorithm = (ClassBasedShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("CLASS_BASED", createHintProperties()));
+ ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", createHintProperties()), ShardingAlgorithm.class);
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 0adfab961ad..e1f709d3e9d 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,9 +18,10 @@
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.sharding.api.sharding.complex.ComplexKeysShardingValue;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Test;
import java.util.Arrays;
@@ -42,8 +43,8 @@ public final class ComplexInlineShardingAlgorithmTest {
sharingValueMap.put("type", Collections.singletonList(2));
sharingValueMap.put("order_id", Collections.singletonList(2));
ComplexKeysShardingValue<Comparable<?>> shardingValue = new ComplexKeysShardingValue<>("t_order", sharingValueMap, Collections.emptyMap());
- ComplexInlineShardingAlgorithm algorithm = (ComplexInlineShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("COMPLEX_INLINE", createDisallowRangeQueryProperties()));
+ ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("COMPLEX_INLINE", createDisallowRangeQueryProperties()), ShardingAlgorithm.class);
Collection<String> actual = algorithm.doSharding(availableTargetNames, shardingValue);
assertTrue(1 == actual.size() && actual.contains("t_order_0_0"));
}
@@ -55,8 +56,8 @@ public final class ComplexInlineShardingAlgorithmTest {
sharingValueMap.put("type", Arrays.asList(1, 2));
sharingValueMap.put("order_id", Arrays.asList(1, 2));
ComplexKeysShardingValue<Comparable<?>> shardingValue = new ComplexKeysShardingValue<>("t_order", sharingValueMap, Collections.emptyMap());
- ComplexInlineShardingAlgorithm algorithm = (ComplexInlineShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("COMPLEX_INLINE", createDisallowRangeQueryProperties()));
+ ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("COMPLEX_INLINE", createDisallowRangeQueryProperties()), ShardingAlgorithm.class);
Collection<String> actual = algorithm.doSharding(availableTargetNames, shardingValue);
assertTrue(actual.containsAll(availableTargetNames));
}
@@ -72,8 +73,8 @@ public final class ComplexInlineShardingAlgorithmTest {
public void assertDoShardingWithRangeValue() {
List<String> availableTargetNames = Arrays.asList("t_order_0_0", "t_order_0_1", "t_order_1_0", "t_order_1_1");
ComplexKeysShardingValue<Comparable<?>> shardingValue = new ComplexKeysShardingValue<>("t_order", Collections.emptyMap(), Collections.singletonMap("type", Range.all()));
- ComplexInlineShardingAlgorithm algorithm = (ComplexInlineShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("COMPLEX_INLINE", createAllowRangeQueryProperties()));
+ ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("COMPLEX_INLINE", createAllowRangeQueryProperties()), ShardingAlgorithm.class);
Collection<String> actual = algorithm.doSharding(availableTargetNames, shardingValue);
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 07758ce3646..2366ed392d7 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,11 +18,12 @@
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.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Before;
import org.junit.Test;
@@ -166,6 +167,6 @@ public final class AutoIntervalShardingAlgorithmTest {
}
private AutoIntervalShardingAlgorithm createAutoIntervalShardingAlgorithm(final Properties props) {
- return (AutoIntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("AUTO_INTERVAL", 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 0bd0bc1d5e5..c933f287131 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,11 +19,12 @@ 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.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Before;
import org.junit.Test;
@@ -47,8 +48,8 @@ import java.util.LinkedList;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
public final class IntervalShardingAlgorithmTest {
@@ -104,7 +105,7 @@ public final class IntervalShardingAlgorithmTest {
}
private void initShardStrategyByQuarter() {
- shardingAlgorithmByQuarter = (IntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("INTERVAL", createQuarterProperties()));
+ shardingAlgorithmByQuarter = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createQuarterProperties()), ShardingAlgorithm.class);
for (int i = 2016; i <= 2020; i++) {
for (int j = 1; j <= 4; j++) {
availableTablesForQuarterDataSources.add(String.format("t_order_%04d%02d", i, j));
@@ -124,7 +125,7 @@ public final class IntervalShardingAlgorithmTest {
}
private void initShardStrategyByMonth() {
- shardingAlgorithmByMonth = (IntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("INTERVAL", createMonthProperties()));
+ shardingAlgorithmByMonth = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createMonthProperties()), ShardingAlgorithm.class);
for (int i = 2016; i <= 2020; i++) {
for (int j = 1; j <= 12; j++) {
availableTablesForMonthDataSources.add(String.format("t_order_%04d%02d", i, j));
@@ -145,8 +146,7 @@ public final class IntervalShardingAlgorithmTest {
private void initShardingStrategyByDay() {
int stepAmount = 2;
- shardingAlgorithmByDay = (IntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("INTERVAL", createDayProperties(stepAmount)));
+ shardingAlgorithmByDay = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createDayProperties(stepAmount)), ShardingAlgorithm.class);
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));
@@ -166,8 +166,8 @@ public final class IntervalShardingAlgorithmTest {
private void initShardStrategyByDayWithMillisecond() {
int stepAmount = 2;
- shardingAlgorithmByDayWithMillisecond = (IntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("INTERVAL", createDayWithMillisecondProperties(stepAmount)));
+ shardingAlgorithmByDayWithMillisecond = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("INTERVAL", createDayWithMillisecondProperties(stepAmount)), ShardingAlgorithm.class);
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));
@@ -188,8 +188,7 @@ public final class IntervalShardingAlgorithmTest {
private void initShardingStrategyByJDBCDate() {
int stepAmount = 2;
- shardingAlgorithmByJDBCDate = (IntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("INTERVAL", createJDBCDateProperties(stepAmount)));
+ shardingAlgorithmByJDBCDate = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createJDBCDateProperties(stepAmount)), ShardingAlgorithm.class);
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));
@@ -209,8 +208,7 @@ public final class IntervalShardingAlgorithmTest {
private void initShardingStrategyByJDBCTime() {
int stepAmount = 2;
- shardingAlgorithmByJDBCTime = (IntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("INTERVAL", createJDBCTimeProperties(stepAmount)));
+ shardingAlgorithmByJDBCTime = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createJDBCTimeProperties(stepAmount)), ShardingAlgorithm.class);
for (int i = 2; i < 13; i++) {
availableTablesForJDBCTimeDataSources.add(String.format("t_order_%02d%02d", i, 0));
}
@@ -229,8 +227,7 @@ public final class IntervalShardingAlgorithmTest {
private void initShardingStrategyByYear() {
int stepAmount = 2;
- shardingAlgorithmByYear = (IntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("INTERVAL", createYearProperties(stepAmount)));
+ shardingAlgorithmByYear = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createYearProperties(stepAmount)), ShardingAlgorithm.class);
for (int i = 2000; i < 2023; i++) {
availableTablesForYearDataSources.add(String.format("t_order_%04d", i));
}
@@ -249,8 +246,7 @@ public final class IntervalShardingAlgorithmTest {
private void initShardingStrategyByYearMonth() {
int stepAmount = 2;
- shardingAlgorithmByYearMonth = (IntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("INTERVAL", createYearMonthProperties(stepAmount)));
+ shardingAlgorithmByYearMonth = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createYearMonthProperties(stepAmount)), ShardingAlgorithm.class);
for (int i = 2016; i <= 2021; i++) {
for (int j = 1; j <= 12; j++) {
availableTablesForYearMonthDataSources.add(String.format("t_order_%04d%02d", i, j));
@@ -271,8 +267,7 @@ public final class IntervalShardingAlgorithmTest {
private void initShardingStrategyByMonthInJSR310() {
int stepAmount = 2;
- shardingAlgorithmByMonthInJSR310 = (IntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("INTERVAL", createMonthInJSR310Properties(stepAmount)));
+ shardingAlgorithmByMonthInJSR310 = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createMonthInJSR310Properties(stepAmount)), ShardingAlgorithm.class);
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 f385a28d126..420e9937d67 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,9 +17,10 @@
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.sharding.api.sharding.hint.HintShardingValue;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Before;
import org.junit.Test;
@@ -39,7 +40,7 @@ public final class HintInlineShardingAlgorithmTest {
@Before
public void setUp() {
- hintInlineShardingAlgorithm = (HintInlineShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("HINT_INLINE", createProperties()));
+ hintInlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("HINT_INLINE", createProperties()), ShardingAlgorithm.class);
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 7444822c9c7..de814d9019f 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,12 +19,13 @@ 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.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.exception.algorithm.MismatchedInlineShardingAlgorithmExpressionAndColumnException;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Before;
import org.junit.Test;
@@ -51,10 +52,10 @@ public final class InlineShardingAlgorithmTest {
@Before
public void setUp() {
- inlineShardingAlgorithm = (InlineShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("INLINE", createAllowRangeQueryProperties()));
- inlineShardingAlgorithmWithSimplified = (InlineShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("INLINE", createDisallowRangeQueryProperties()));
- negativeNumberInlineShardingAlgorithm = (InlineShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("INLINE", createNegativeAllowRangeQueryProperties()));
+ inlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", createAllowRangeQueryProperties()), ShardingAlgorithm.class);
+ inlineShardingAlgorithmWithSimplified = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", createDisallowRangeQueryProperties()), ShardingAlgorithm.class);
+ negativeNumberInlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("INLINE", createNegativeAllowRangeQueryProperties()), ShardingAlgorithm.class);
}
private Properties createAllowRangeQueryProperties() {
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 f4064a193d0..cbfacdc4c46 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,11 +18,12 @@
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.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Before;
import org.junit.Test;
@@ -42,7 +43,7 @@ public final class HashModShardingAlgorithmTest {
@Before
public void setup() {
- shardingAlgorithm = (HashModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("HASH_MOD", createProperties()));
+ shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("HASH_MOD", createProperties()), ShardingAlgorithm.class);
}
private Properties createProperties() {
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 76d43719dff..466a70a9d3c 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,11 +18,12 @@
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.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Test;
import java.util.Arrays;
@@ -39,26 +40,26 @@ public final class ModShardingAlgorithmTest {
@Test
public void assertPreciseDoShardingWithIntShardingValue() {
- ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", createProperties()));
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
assertThat(algorithm.doSharding(createAvailableTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, 17)), is("t_order_1"));
}
@Test
public void assertPreciseDoShardingWithBigIntegerShardingValue() {
- ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", createProperties()));
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
assertThat(algorithm.doSharding(createAvailableTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_12"));
}
@Test
public void assertRangeDoShardingWithAllTargets() {
- ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", createProperties()));
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
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 = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", createProperties()));
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
Collection<String> actual = algorithm.doSharding(createAvailableTargetNames(),
new RangeShardingValue<>("t_order", "order_id", DATA_NODE_INFO, Range.closed(1L, 2L)));
assertThat(actual.size(), is(2));
@@ -79,13 +80,13 @@ public final class ModShardingAlgorithmTest {
@Test
public void assertPreciseDoShardingWithValueIsBigIntegerAndZeroPadding() {
- ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", createZeroPaddingProperties()));
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createZeroPaddingProperties()), ShardingAlgorithm.class);
assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07"));
}
@Test
public void assertRangeDoShardingWithAllTargetsZeroPadding() {
- ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", createZeroPaddingProperties()));
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createZeroPaddingProperties()), ShardingAlgorithm.class);
Collection<String> actual = algorithm.doSharding(createAvailableIncludeZeroTargetNames(),
new RangeShardingValue<>("t_order", "order_id", DATA_NODE_INFO, Range.closed(1L, 16L)));
assertThat(actual.size(), is(16));
@@ -95,7 +96,7 @@ public final class ModShardingAlgorithmTest {
public void assertRangeDoShardingWithWrongArgumentForStartOffset() {
Properties props = createZeroPaddingProperties();
props.setProperty("start-offset", "-1");
- ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", props));
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", props), ShardingAlgorithm.class);
assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07"));
}
@@ -103,7 +104,7 @@ public final class ModShardingAlgorithmTest {
public void assertRangeDoShardingWithWrongArgumentForStopOffset() {
Properties props = createZeroPaddingProperties();
props.setProperty("stop-offset", "-1");
- ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", props));
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", props), ShardingAlgorithm.class);
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 31383aded7f..7fb1b0de79d 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,11 +18,12 @@
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.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +44,7 @@ public final class BoundaryBasedRangeShardingAlgorithmTest {
@Before
public void setUp() {
- shardingAlgorithm = (BoundaryBasedRangeShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("BOUNDARY_RANGE", createProperties()));
+ shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("BOUNDARY_RANGE", createProperties()), ShardingAlgorithm.class);
}
private Properties createProperties() {
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 5a9f66b815b..802c0728d06 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,11 +18,12 @@
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.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +44,7 @@ public final class VolumeBasedRangeShardingAlgorithmTest {
@Before
public void setUp() {
- shardingAlgorithm = (VolumeBasedRangeShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("VOLUME_RANGE", createProperties()));
+ shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("VOLUME_RANGE", createProperties()), ShardingAlgorithm.class);
}
private Properties createProperties() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationCheckerTest.java
index 195110340eb..9163213784e 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationCheckerTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationCheckerTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.sharding.checker;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
-import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationCheckerFactory;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -29,14 +29,13 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingS
import org.junit.Test;
import java.util.Collections;
-import java.util.Optional;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public final class ShardingRuleConfigurationCheckerTest {
+ @SuppressWarnings("unchecked")
@Test
public void assertCheckSuccess() {
ShardingRuleConfiguration ruleConfig = createRuleConfiguration();
@@ -44,15 +43,20 @@ public final class ShardingRuleConfigurationCheckerTest {
ShardingStrategyConfiguration shardingStrategyConfig = createShardingStrategyConfiguration();
ruleConfig.setTables(Collections.singleton(createShardingTableRuleConfiguration(shardingStrategyConfig, shardingAuditStrategyConfig, ruleConfig.getDefaultKeyGenerateStrategy())));
ruleConfig.setAutoTables(Collections.singleton(createShardingAutoTableRuleConfiguration(shardingStrategyConfig, shardingAuditStrategyConfig, ruleConfig.getDefaultKeyGenerateStrategy())));
- getChecker(ruleConfig).check("foo_db", ruleConfig, Collections.emptyMap(), Collections.emptyList());
+ RuleConfigurationChecker<ShardingRuleConfiguration> checker = OrderedSPIRegistry.getRegisteredServicesByClass(
+ RuleConfigurationChecker.class, Collections.singleton(ruleConfig.getClass())).get(ruleConfig.getClass());
+ checker.check("foo_db", ruleConfig, Collections.emptyMap(), Collections.emptyList());
}
+ @SuppressWarnings("unchecked")
@Test(expected = IllegalStateException.class)
public void assertCheckTableConfigurationFailed() {
ShardingRuleConfiguration ruleConfig = createRuleConfiguration();
ruleConfig.setTables(Collections.singletonList(createShardingTableRuleConfiguration(null, null, null)));
ruleConfig.setAutoTables(Collections.singleton(createShardingAutoTableRuleConfiguration(null, null, null)));
- getChecker(ruleConfig).check("foo_db", ruleConfig, Collections.emptyMap(), Collections.emptyList());
+ RuleConfigurationChecker<ShardingRuleConfiguration> checker = OrderedSPIRegistry.getRegisteredServicesByClass(
+ RuleConfigurationChecker.class, Collections.singleton(ruleConfig.getClass())).get(ruleConfig.getClass());
+ checker.check("foo_db", ruleConfig, Collections.emptyMap(), Collections.emptyList());
}
private ShardingRuleConfiguration createRuleConfiguration() {
@@ -90,11 +94,4 @@ public final class ShardingRuleConfigurationCheckerTest {
when(result.getKeyGenerateStrategy()).thenReturn(null == keyGenerateStrategyConfig ? mock(KeyGenerateStrategyConfiguration.class) : keyGenerateStrategyConfig);
return result;
}
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- private RuleConfigurationChecker<ShardingRuleConfiguration> getChecker(final ShardingRuleConfiguration ruleConfig) {
- Optional<RuleConfigurationChecker> result = RuleConfigurationCheckerFactory.findInstance(ruleConfig);
- assertTrue(result.isPresent());
- return result.get();
- }
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java
index b8095a00e15..7ba1be3d59f 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java
@@ -22,12 +22,13 @@ import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementConte
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.merge.engine.merger.impl.TransparentResultMerger;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.merge.dal.ShardingDALResultMerger;
import org.apache.shardingsphere.sharding.merge.ddl.ShardingDDLResultMerger;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
@@ -92,7 +93,7 @@ public final class ShardingResultMergerEngineTest {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext sqlStatementContext = new SelectStatementContext(createShardingSphereMetaData(database),
Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
- assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"), null, props,
+ assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"), null, props,
sqlStatementContext), instanceOf(ShardingDQLResultMerger.class));
}
@@ -104,7 +105,7 @@ public final class ShardingResultMergerEngineTest {
public void assertNewInstanceWithDALStatement() {
ConfigurationProperties props = new ConfigurationProperties(new Properties());
CommonSQLStatementContext<PostgreSQLShowStatement> sqlStatementContext = new CommonSQLStatementContext<>(new PostgreSQLShowStatement(""));
- assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"), null, props,
+ assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"), null, props,
sqlStatementContext), instanceOf(ShardingDALResultMerger.class));
}
@@ -116,7 +117,7 @@ public final class ShardingResultMergerEngineTest {
insertStatement.setInsertColumns(insertColumnsSegment);
InsertStatementContext sqlStatementContext = createInsertStatementContext(insertStatement);
ConfigurationProperties props = new ConfigurationProperties(new Properties());
- assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"), null, props,
+ assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"), null, props,
sqlStatementContext), instanceOf(TransparentResultMerger.class));
}
@@ -130,7 +131,7 @@ public final class ShardingResultMergerEngineTest {
public void assertNewInstanceWithDDLStatement() {
ConfigurationProperties props = new ConfigurationProperties(new Properties());
CommonSQLStatementContext<OpenGaussFetchStatement> sqlStatementContext = new CommonSQLStatementContext<>(new OpenGaussFetchStatement());
- assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"), null, props,
+ assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"), null, props,
sqlStatementContext), instanceOf(ShardingDDLResultMerger.class));
}
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java
index 896699a6255..8484de23e3b 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java
@@ -21,12 +21,13 @@ import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementConte
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
@@ -64,7 +65,7 @@ public final class IteratorStreamMergedResultTest {
@Test
public void assertNextForResultSetsAllEmpty() throws SQLException {
List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, database, mock(ConnectionContext.class));
@@ -77,7 +78,7 @@ public final class IteratorStreamMergedResultTest {
for (QueryResult each : queryResults) {
when(each.next()).thenReturn(true, false);
}
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, database, mock(ConnectionContext.class));
@@ -91,7 +92,7 @@ public final class IteratorStreamMergedResultTest {
public void assertNextForFirstResultSetsNotEmptyOnly() throws SQLException {
List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
when(queryResults.get(0).next()).thenReturn(true, false);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, database, mock(ConnectionContext.class));
@@ -103,7 +104,7 @@ public final class IteratorStreamMergedResultTest {
public void assertNextForMiddleResultSetsNotEmpty() throws SQLException {
List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
when(queryResults.get(1).next()).thenReturn(true, false);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, database, mock(ConnectionContext.class));
@@ -115,7 +116,7 @@ public final class IteratorStreamMergedResultTest {
public void assertNextForLastResultSetsNotEmptyOnly() throws SQLException {
List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
when(queryResults.get(2).next()).thenReturn(true, false);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, database, mock(ConnectionContext.class));
@@ -130,7 +131,7 @@ public final class IteratorStreamMergedResultTest {
when(queryResults.get(1).next()).thenReturn(true, false);
when(queryResults.get(3).next()).thenReturn(true, false);
when(queryResults.get(5).next()).thenReturn(true, false);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, database, mock(ConnectionContext.class));
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java
index 038bda5c26a..1eab362aa58 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -32,6 +31,7 @@ import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRule
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.merge.common.IteratorStreamMergedResult;
import org.apache.shardingsphere.sharding.merge.dql.groupby.GroupByMemoryMergedResult;
import org.apache.shardingsphere.sharding.merge.dql.groupby.GroupByStreamMergedResult;
@@ -82,7 +82,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildIteratorStreamMergedResult() throws SQLException {
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
SelectStatement selectStatement = buildSelectStatement(new MySQLSelectStatement());
@@ -94,7 +94,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildIteratorStreamMergedResultWithLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
@@ -107,7 +107,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildIteratorStreamMergedResultWithMySQLLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
@@ -121,7 +121,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildIteratorStreamMergedResultWithOracleLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"));
final ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
OracleSelectStatement selectStatement = (OracleSelectStatement) buildSelectStatement(new OracleSelectStatement());
selectStatement.setProjections(new ProjectionsSegment(0, 0));
@@ -151,7 +151,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildIteratorStreamMergedResultWithSQLServerLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement());
@@ -165,7 +165,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildOrderByStreamMergedResult() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
@@ -178,7 +178,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildOrderByStreamMergedResultWithMySQLLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
@@ -194,7 +194,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildOrderByStreamMergedResultWithOracleLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"));
final ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
WhereSegment whereSegment = mock(WhereSegment.class);
BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class);
@@ -226,7 +226,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildOrderByStreamMergedResultWithSQLServerLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement());
@@ -242,7 +242,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByStreamMergedResult() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
@@ -256,7 +256,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByStreamMergedResultWithMySQLLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
@@ -273,7 +273,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByStreamMergedResultWithOracleLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"));
final ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
WhereSegment whereSegment = mock(WhereSegment.class);
BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class);
@@ -306,7 +306,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByStreamMergedResultWithSQLServerLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement());
@@ -323,7 +323,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByMemoryMergedResult() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
@@ -336,7 +336,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByMemoryMergedResultWithMySQLLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
@@ -352,7 +352,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByMemoryMergedResultWithOracleLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"));
final ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
WhereSegment whereSegment = mock(WhereSegment.class);
BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class);
@@ -384,7 +384,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByMemoryMergedResultWithSQLServerLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement());
@@ -402,7 +402,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByMemoryMergedResultWithAggregationOnly() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
@@ -425,7 +425,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
- DatabaseType databaseType = DatabaseTypeFactory.getInstance("MySQL");
+ DatabaseType databaseType = TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL");
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(databaseType);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
@@ -434,7 +434,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"));
final ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
WhereSegment whereSegment = mock(WhereSegment.class);
BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class);
@@ -467,7 +467,7 @@ public final class ShardingDQLResultMergerTest {
@Test
public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithSQLServerLimit() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement());
@@ -510,7 +510,7 @@ public final class ShardingDQLResultMergerTest {
ShardingSphereColumn column3 = new ShardingSphereColumn("col3", 0, false, false, false, true, false);
ShardingSphereTable table = new ShardingSphereTable("tbl", Arrays.asList(column1, column2, column3), Collections.emptyList(), Collections.emptyList());
ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap());
- return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"), mock(ShardingSphereResourceMetaData.class),
+ return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"), mock(ShardingSphereResourceMetaData.class),
mock(ShardingSphereRuleMetaData.class), Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema));
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java
index 1ce423d71f3..17af190cbd2 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementConte
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -29,6 +29,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.enums.NullsOrderType;
@@ -73,7 +74,7 @@ public final class GroupByMemoryMergedResultTest {
@Test
public void assertNextForResultSetsAllEmpty() throws SQLException {
when(database.getName()).thenReturn("db_schema");
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult()), createSelectStatementContext(), database, mock(ConnectionContext.class));
assertTrue(actual.next());
assertThat(actual.getValue(1, Object.class), is(0));
@@ -99,7 +100,7 @@ public final class GroupByMemoryMergedResultTest {
when(queryResult3.getValue(3, Object.class)).thenReturn(2, 3);
when(queryResult3.getValue(4, Object.class)).thenReturn(2, 2, 3);
when(queryResult3.getValue(5, Object.class)).thenReturn(20, 20, 30);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), database, mock(ConnectionContext.class));
assertTrue(actual.next());
assertThat(actual.getValue(1, Object.class), is(new BigDecimal(30)));
@@ -164,7 +165,7 @@ public final class GroupByMemoryMergedResultTest {
when(queryResult3.getValue(3, Object.class)).thenReturn(2, 3);
when(queryResult3.getValue(4, Object.class)).thenReturn(2, 2, 3);
when(queryResult3.getValue(5, Object.class)).thenReturn(20, 20, 30);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), database, mock(ConnectionContext.class));
assertTrue(actual.next());
assertThat(actual.getValue(1, Object.class), is(new BigDecimal(30)));
@@ -206,7 +207,7 @@ public final class GroupByMemoryMergedResultTest {
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
when(database.getSchemas()).thenReturn(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema));
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
- ShardingDQLResultMerger merger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger merger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = merger.merge(Arrays.asList(queryResult, queryResult, queryResult), createSelectStatementContext(database), database, mock(ConnectionContext.class));
assertFalse(actual.next());
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
index 8ab8e023f4b..9b8301befec 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementConte
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -31,6 +31,7 @@ import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRule
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.enums.NullsOrderType;
@@ -54,8 +55,8 @@ import java.util.Collections;
import java.util.Date;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -65,7 +66,7 @@ public final class GroupByStreamMergedResultTest {
@Test
public void assertNextForResultSetsAllEmpty() throws SQLException {
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult()),
createSelectStatementContext(), createDatabase(), mock(ConnectionContext.class));
assertFalse(actual.next());
@@ -90,7 +91,7 @@ public final class GroupByStreamMergedResultTest {
when(queryResult3.getValue(4, Object.class)).thenReturn(new Date(0L));
when(queryResult3.getValue(5, Object.class)).thenReturn(2, 2, 3);
when(queryResult3.getValue(6, Object.class)).thenReturn(20, 20, 30);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), createDatabase(), mock(ConnectionContext.class));
assertTrue(actual.next());
assertThat(actual.getValue(1, Object.class), is(new BigDecimal(40)));
@@ -132,7 +133,7 @@ public final class GroupByStreamMergedResultTest {
when(queryResult3.getValue(3, Object.class)).thenReturn(1, 1, 1, 1, 3);
when(queryResult3.getValue(5, Object.class)).thenReturn(1, 1, 3);
when(queryResult3.getValue(6, Object.class)).thenReturn(10, 10, 30);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), createDatabase(), mock(ConnectionContext.class));
assertTrue(actual.next());
assertThat(actual.getValue(1, Object.class), is(new BigDecimal(10)));
@@ -186,7 +187,7 @@ public final class GroupByStreamMergedResultTest {
ShardingSphereColumn column3 = new ShardingSphereColumn("col3", 0, false, false, false, true, false);
ShardingSphereTable table = new ShardingSphereTable("tbl", Arrays.asList(column1, column2, column3), Collections.emptyList(), Collections.emptyList());
ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap());
- return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"),
+ return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"),
mock(ShardingSphereResourceMetaData.class), mock(ShardingSphereRuleMetaData.class), Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema));
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java
index 91777c0de49..331f8b796d3 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementConte
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
@@ -32,6 +32,7 @@ import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRule
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.enums.NullsOrderType;
import org.apache.shardingsphere.sql.parser.sql.common.enums.OrderDirection;
@@ -85,7 +86,7 @@ public final class OrderByStreamMergedResultTest {
@Test
public void assertNextForResultSetsAllEmpty() throws SQLException {
List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertFalse(actual.next());
}
@@ -99,7 +100,7 @@ public final class OrderByStreamMergedResultTest {
when(metaData.getColumnName(1)).thenReturn("col1");
when(metaData.getColumnName(2)).thenReturn("col2");
}
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
when(queryResults.get(0).next()).thenReturn(true, false);
when(queryResults.get(0).getValue(1, Object.class)).thenReturn("2");
when(queryResults.get(2).next()).thenReturn(true, true, false);
@@ -123,7 +124,7 @@ public final class OrderByStreamMergedResultTest {
when(metaData.getColumnName(1)).thenReturn("col1");
when(metaData.getColumnName(2)).thenReturn("col2");
}
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
when(queryResults.get(0).next()).thenReturn(true, false);
when(queryResults.get(0).getValue(1, Object.class)).thenReturn("2");
when(queryResults.get(1).next()).thenReturn(true, true, true, false);
@@ -161,7 +162,7 @@ public final class OrderByStreamMergedResultTest {
when(queryResults.get(1).getValue(1, Object.class)).thenReturn("B", "B", "a", "a");
when(queryResults.get(2).next()).thenReturn(true, false);
when(queryResults.get(2).getValue(1, Object.class)).thenReturn("A");
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertTrue(actual.next());
assertThat(actual.getValue(1, Object.class).toString(), is("A"));
@@ -189,7 +190,7 @@ public final class OrderByStreamMergedResultTest {
when(queryResults.get(1).getValue(2, Object.class)).thenReturn("a", "a", "B", "B");
when(queryResults.get(2).next()).thenReturn(true, false);
when(queryResults.get(2).getValue(2, Object.class)).thenReturn("A");
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertTrue(actual.next());
assertThat(actual.getValue(2, Object.class).toString(), is("a"));
@@ -208,7 +209,7 @@ public final class OrderByStreamMergedResultTest {
ShardingSphereTable table = new ShardingSphereTable("tbl", Arrays.asList(column1, column2), Collections.emptyList(), Collections.emptyList());
ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap());
return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
- DatabaseTypeFactory.getInstance("MySQL"), mock(ShardingSphereResourceMetaData.class), mock(ShardingSphereRuleMetaData.class),
+ TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"), mock(ShardingSphereResourceMetaData.class), mock(ShardingSphereRuleMetaData.class),
Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema));
}
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java
index c633214b392..ed24945bac5 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java
@@ -21,12 +21,13 @@ import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementConte
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.LimitSegment;
@@ -54,7 +55,7 @@ public final class LimitDecoratorMergedResultTest {
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, Integer.MAX_VALUE), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
mock(ConnectionContext.class));
assertFalse(actual.next());
@@ -68,7 +69,7 @@ public final class LimitDecoratorMergedResultTest {
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
mock(ConnectionContext.class));
for (int i = 0; i < 6; i++) {
@@ -85,7 +86,7 @@ public final class LimitDecoratorMergedResultTest {
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2), new NumberLiteralLimitValueSegment(0, 0, 2)));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
mock(ConnectionContext.class));
assertTrue(actual.next());
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
index b5538070ab7..9082c89b21b 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
@@ -21,12 +21,13 @@ import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementConte
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
@@ -77,7 +78,7 @@ public final class RowNumberDecoratorMergedResultTest {
when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment);
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
@@ -88,7 +89,7 @@ public final class RowNumberDecoratorMergedResultTest {
@Test
public void assertNextWithoutOffsetWithoutRowCount() throws SQLException {
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
OracleSelectStatement selectStatement = new OracleSelectStatement();
selectStatement.setProjections(new ProjectionsSegment(0, 0));
@@ -125,7 +126,7 @@ public final class RowNumberDecoratorMergedResultTest {
when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment);
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
@@ -159,7 +160,7 @@ public final class RowNumberDecoratorMergedResultTest {
when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment);
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java
index 7ab6dcde034..d3668d364a8 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java
@@ -21,13 +21,14 @@ import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementConte
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.LimitSegment;
@@ -64,7 +65,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, Integer.MAX_VALUE, true), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockShardingSphereDatabase(), mock(ConnectionContext.class));
assertFalse(actual.next());
@@ -72,7 +73,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
public void assertNextWithoutOffsetWithRowCount() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
@@ -95,7 +96,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, true), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
- ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockShardingSphereDatabase(), mock(ConnectionContext.class));
for (int i = 0; i < 7; i++) {
@@ -106,7 +107,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
public void assertNextWithOffsetBoundOpenedFalse() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
final ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
@@ -122,7 +123,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
public void assertNextWithOffsetBoundOpenedTrue() throws SQLException {
- final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
+ final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/ShardingSchemaMetaDataDecoratorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/ShardingSchemaMetaDataDecoratorTest.java
index db7a644e7b0..7505893af8b 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/ShardingSchemaMetaDataDecoratorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/ShardingSchemaMetaDataDecoratorTest.java
@@ -19,11 +19,12 @@ package org.apache.shardingsphere.sharding.metadata;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial;
-import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecoratorFactory;
+import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.junit.Test;
@@ -51,7 +52,7 @@ public final class ShardingSchemaMetaDataDecoratorTest {
ShardingRule shardingRule = mock(ShardingRule.class);
when(shardingRule.findLogicTableByActualTable(TABLE_NAME)).thenReturn(Optional.of(TABLE_NAME));
Collection<ShardingSphereRule> rules = Collections.singletonList(shardingRule);
- ShardingSchemaMetaDataDecorator builder = (ShardingSchemaMetaDataDecorator) RuleBasedSchemaMetaDataDecoratorFactory.getInstances(rules).get(shardingRule);
+ ShardingSchemaMetaDataDecorator builder = (ShardingSchemaMetaDataDecorator) OrderedSPIRegistry.getRegisteredServices(RuleBasedSchemaMetaDataDecorator.class, rules).get(shardingRule);
Collection<TableMetaData> tableMetaDataList = new LinkedList<>();
tableMetaDataList.add(createTableMetaData());
GenericSchemaBuilderMaterial material = mock(GenericSchemaBuilderMaterial.class);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
index 0fa13cabc63..9f430c47749 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -35,6 +35,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.
import org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngine;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.engine.SQLRouteEngine;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.route.engine.fixture.AbstractRoutingEngineTest;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.single.rule.SingleRule;
@@ -64,7 +65,8 @@ public abstract class AbstractSQLRouteTest extends AbstractRoutingEngineTest {
ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Arrays.asList(shardingRule, singleRule));
ShardingSphereResourceMetaData resourceMetaData = mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS);
when(resourceMetaData.getStorageTypes()).thenReturn(Collections.singletonMap("ds_0", new MySQLDatabaseType()));
- ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"), resourceMetaData, ruleMetaData, schemas);
+ ShardingSphereDatabase database = new ShardingSphereDatabase(
+ DefaultDatabase.LOGIC_NAME, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"), resourceMetaData, ruleMetaData, schemas);
SQLStatementContext<?> sqlStatementContext =
SQLStatementContextFactory.newInstance(createShardingSphereMetaData(database), params, sqlStatementParserEngine.parse(sql, false), DefaultDatabase.LOGIC_NAME);
QueryContext queryContext = new QueryContext(sqlStatementContext, sql, params);
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 d4fa834897a..6c0a1a42c4f 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,6 +17,7 @@
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;
@@ -38,11 +39,11 @@ import org.apache.shardingsphere.sharding.exception.syntax.DMLWithMultipleShardi
import org.apache.shardingsphere.sharding.exception.syntax.InsertSelectTableViolationException;
import org.apache.shardingsphere.sharding.exception.syntax.MissingGenerateKeyColumnWithInsertSelectException;
import org.apache.shardingsphere.sharding.exception.syntax.UnsupportedUpdatingShardingValueException;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
import org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions;
import org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingInsertStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -225,7 +226,7 @@ public final class ShardingInsertStatementValidatorTest {
when(databaseStrategyConfig.getShardingAlgorithmName()).thenReturn("database_inline");
when(shardingRule.getDatabaseShardingStrategyConfiguration(tableRule)).thenReturn(databaseStrategyConfig);
when(shardingRule.getShardingAlgorithms()).thenReturn(
- Collections.singletonMap("database_inline", ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("INLINE", createProperties()))));
+ Collections.singletonMap("database_inline", ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", createProperties()), ShardingAlgorithm.class)));
}
private Properties createProperties() {
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 7149bd70ddb..3dacf33b1c0 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,6 +17,7 @@
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;
@@ -29,7 +30,6 @@ import org.apache.shardingsphere.infra.route.context.RouteUnit;
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;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
import org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingUpdateStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
@@ -136,7 +136,7 @@ public final class ShardingUpdateStatementValidatorTest {
}
private Map<String, ShardingAlgorithm> createShardingAlgorithmMap() {
- return Collections.singletonMap("database_inline", ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("INLINE", createProperties())));
+ return Collections.singletonMap("database_inline", ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", createProperties()), ShardingAlgorithm.class));
}
private Properties createProperties() {
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 08a2e0811a6..4cbc6c962d8 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,6 +17,7 @@
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;
@@ -27,7 +28,7 @@ import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerate
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.exception.metadata.DataNodesMissedWithShardingTableException;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Test;
import java.util.Arrays;
@@ -40,8 +41,8 @@ import java.util.Map;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public final class TableRuleTest {
@@ -80,7 +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 = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", createProperties()));
+ ModShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
TableRule actual = new TableRule(tableRuleConfig, Arrays.asList("ds0", "ds1", "ds2"), shardingAlgorithm, null);
assertThat(actual.getLogicTable(), is("LOGIC_TABLE"));
assertThat(actual.getActualDataNodes().size(), is(4));
@@ -94,7 +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 = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("MOD", createProperties()));
+ ModShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
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/core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java
index 818bdb3349c..f37800d57cf 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.sharding.rule.builder;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.junit.Before;
@@ -43,7 +43,7 @@ public final class ShardingRuleBuilderTest {
@Before
public void setUp() {
ruleConfig = new ShardingRuleConfiguration();
- builder = DatabaseRuleBuilderFactory.getInstanceMap(Collections.singletonList(ruleConfig)).get(ruleConfig);
+ builder = OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig);
}
@SuppressWarnings("unchecked")
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 ab387d3b6dd..3e3c2c6c00e 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
@@ -26,12 +26,14 @@ import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleExc
import org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
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;
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.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
@@ -51,12 +53,11 @@ import org.apache.shardingsphere.sharding.distsql.parser.segment.table.AbstractT
import org.apache.shardingsphere.sharding.distsql.parser.segment.table.AutoTableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.table.TableRuleSegment;
import org.apache.shardingsphere.sharding.exception.metadata.ShardingRuleNotFoundException;
-import org.apache.shardingsphere.sharding.factory.KeyGenerateAlgorithmFactory;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
-import org.apache.shardingsphere.sharding.factory.ShardingAuditAlgorithmFactory;
import org.apache.shardingsphere.sharding.rule.BindingTableCheckedConfiguration;
import org.apache.shardingsphere.sharding.rule.TableRule;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.sharding.spi.ShardingAuditAlgorithm;
import java.util.Arrays;
import java.util.Collection;
@@ -142,7 +143,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, ShardingAlgorithmFactory.newInstance(value)));
+ checkedConfig.getShardingAlgorithms().forEach((key, value) -> shardingAlgorithms.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, ShardingAlgorithm.class)));
tableRules.putAll(createTableRules(checkedConfig.getTables(), checkedConfig.getDefaultKeyGenerateStrategy(), allDataSourceNames));
tableRules.putAll(createAutoTableRules(checkedConfig.getAutoTables(), shardingAlgorithms, checkedConfig.getDefaultKeyGenerateStrategy(), allDataSourceNames));
Collection<String> broadcastTables = createBroadcastTables(checkedConfig.getBroadcastTables());
@@ -258,7 +259,8 @@ public final class ShardingTableRuleStatementChecker {
.filter(optional -> null == currentRuleConfig || !currentRuleConfig.getKeyGenerators().containsKey(optional)).ifPresent(notExistKeyGenerator::add))
.filter(each -> !each.getKeyGenerateAlgorithmName().isPresent()).forEach(each -> requiredKeyGenerators.add(each.getKeyGenerateAlgorithmSegment().getName()));
ShardingSpherePreconditions.checkState(notExistKeyGenerator.isEmpty(), () -> new MissingRequiredAlgorithmException("key generator", notExistKeyGenerator));
- Collection<String> invalidKeyGenerators = requiredKeyGenerators.stream().distinct().filter(each -> !KeyGenerateAlgorithmFactory.contains(each)).collect(Collectors.toList());
+ Collection<String> invalidKeyGenerators = requiredKeyGenerators.stream()
+ .distinct().filter(each -> !TypedSPIRegistry.findRegisteredService(KeyGenerateAlgorithm.class, each).isPresent()).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(invalidKeyGenerators.isEmpty(), () -> new InvalidAlgorithmConfigurationException("key generator", invalidKeyGenerators));
}
@@ -269,7 +271,8 @@ public final class ShardingTableRuleStatementChecker {
requiredAuditors.addAll(each.getAuditorSegments().stream()
.map(ShardingAuditorSegment::getAlgorithmSegment).collect(Collectors.toList()).stream().map(AlgorithmSegment::getName).collect(Collectors.toList()));
}
- Collection<String> invalidAuditors = requiredAuditors.stream().distinct().filter(each -> !ShardingAuditAlgorithmFactory.contains(each)).collect(Collectors.toList());
+ Collection<String> invalidAuditors = requiredAuditors.stream()
+ .distinct().filter(each -> !TypedSPIRegistry.findRegisteredService(ShardingAuditAlgorithm.class, each).isPresent()).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(invalidAuditors.isEmpty(), () -> new InvalidAlgorithmConfigurationException("auditor", invalidAuditors));
}
@@ -283,10 +286,10 @@ public final class ShardingTableRuleStatementChecker {
private static void checkAutoTableShardingAlgorithms(final Collection<AutoTableRuleSegment> rules) {
rules.forEach(each -> {
- ShardingSpherePreconditions.checkState(ShardingAlgorithmFactory.contains(each.getShardingAlgorithmSegment().getName()),
+ ShardingSpherePreconditions.checkState(TypedSPIRegistry.findRegisteredService(ShardingAlgorithm.class, each.getShardingAlgorithmSegment().getName()).isPresent(),
() -> new InvalidAlgorithmConfigurationException("sharding", each.getShardingAlgorithmSegment().getName()));
- ShardingAlgorithm shardingAlgorithm = ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration(each.getShardingAlgorithmSegment().getName(), each.getShardingAlgorithmSegment().getProps()));
+ ShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration(each.getShardingAlgorithmSegment().getName(), each.getShardingAlgorithmSegment().getProps()), ShardingAlgorithm.class);
ShardingSpherePreconditions.checkState(shardingAlgorithm instanceof ShardingAutoTableAlgorithm, () -> new InvalidAlgorithmConfigurationException("sharding", shardingAlgorithm.getType(),
String.format("auto sharding algorithm is required for rule `%s`", each.getLogicTable())));
});
@@ -307,7 +310,8 @@ public final class ShardingTableRuleStatementChecker {
if (databaseStrategySegment.isPresent()) {
AlgorithmSegment databaseShardingAlgorithm = databaseStrategySegment.get().getShardingAlgorithm();
if (null != databaseShardingAlgorithm) {
- ShardingAlgorithm shardingAlgorithm = ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration(databaseShardingAlgorithm.getName(), databaseShardingAlgorithm.getProps()));
+ ShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration(databaseShardingAlgorithm.getName(), databaseShardingAlgorithm.getProps()), ShardingAlgorithm.class);
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())));
@@ -320,7 +324,8 @@ public final class ShardingTableRuleStatementChecker {
if (tableStrategySegment.isPresent()) {
AlgorithmSegment tableShardingAlgorithm = tableStrategySegment.get().getShardingAlgorithm();
if (null != tableShardingAlgorithm) {
- ShardingAlgorithm shardingAlgorithm = ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration(tableShardingAlgorithm.getName(), tableShardingAlgorithm.getProps()));
+ ShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration(tableShardingAlgorithm.getName(), tableShardingAlgorithm.getProps()), ShardingAlgorithm.class);
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/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableNodesResultSet.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableNodesResultSet.java
index ec658a9884b..5fbf9c77569 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableNodesResultSet.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableNodesResultSet.java
@@ -18,17 +18,18 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
+import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.expr.InlineExpressionParser;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.sharding.ShardingAutoTableAlgorithm;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableNodesStatement;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -94,8 +95,8 @@ public final class ShardingTableNodesResultSet implements DatabaseDistSQLResultS
if (null == algorithmConfig) {
return 0;
}
- if (ShardingAlgorithmFactory.contains(algorithmConfig.getType())) {
- ShardingAlgorithm shardingAlgorithm = ShardingAlgorithmFactory.newInstance(algorithmConfig);
+ if (TypedSPIRegistry.findRegisteredService(ShardingAlgorithm.class, algorithmConfig.getType()).isPresent()) {
+ ShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(algorithmConfig, ShardingAlgorithm.class);
if (shardingAlgorithm instanceof ShardingAutoTableAlgorithm) {
shardingAlgorithm.init(algorithmConfig.getProps());
return ((ShardingAutoTableAlgorithm) shardingAlgorithm).getAutoTablesAmount();
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
index 66f38fde0ee..6c9d161f973 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
@@ -19,16 +19,17 @@ package org.apache.shardingsphere.sharding.distsql.update;
import lombok.SneakyThrows;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
-import org.apache.shardingsphere.distsql.parser.core.featured.FeaturedDistSQLStatementParserFacadeFactory;
+import org.apache.shardingsphere.distsql.handler.exception.DistSQLException;
+import org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.distsql.parser.statement.DistSQLStatement;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.distsql.handler.exception.DistSQLException;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -262,7 +263,7 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
private DistSQLStatement getDistSQLStatement(final String sql) {
ShardingDistSQLStatementParserFacade facade = new ShardingDistSQLStatementParserFacade();
ParseASTNode parseASTNode = (ParseASTNode) SQLParserFactory.newInstance(sql, facade.getLexerClass(), facade.getParserClass()).parse();
- SQLVisitor visitor = FeaturedDistSQLStatementParserFacadeFactory.getInstance(facade.getType()).getVisitorClass().getDeclaredConstructor().newInstance();
+ SQLVisitor visitor = TypedSPIRegistry.getRegisteredService(FeaturedDistSQLStatementParserFacade.class, facade.getType()).getVisitorClass().getDeclaredConstructor().newInstance();
return (DistSQLStatement) ((ParseTreeVisitor) visitor).visit(parseASTNode.getRootNode());
}
diff --git a/features/sharding/plugin/cache/src/main/java/org/apache/shardingsphere/sharding/cache/checker/algorithm/CacheableShardingAlgorithmChecker.java b/features/sharding/plugin/cache/src/main/java/org/apache/shardingsphere/sharding/cache/checker/algorithm/CacheableShardingAlgorithmChecker.java
index 02de8fbc8d0..cda0d2082ef 100644
--- a/features/sharding/plugin/cache/src/main/java/org/apache/shardingsphere/sharding/cache/checker/algorithm/CacheableShardingAlgorithmChecker.java
+++ b/features/sharding/plugin/cache/src/main/java/org/apache/shardingsphere/sharding/cache/checker/algorithm/CacheableShardingAlgorithmChecker.java
@@ -33,7 +33,6 @@ public final class CacheableShardingAlgorithmChecker {
static {
Collection<Class<? extends ShardingAlgorithm>> result = new HashSet<>();
- ShardingSphereServiceLoader.register(CacheableShardingAlgorithmClassProvider.class);
for (CacheableShardingAlgorithmClassProvider each : ShardingSphereServiceLoader.getServiceInstances(CacheableShardingAlgorithmClassProvider.class)) {
result.addAll(each.getCacheableShardingAlgorithmClasses());
}
diff --git a/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java b/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
index a592fb5dfde..fc613be96c5 100644
--- a/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
+++ b/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -34,6 +34,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
import org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngine;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -167,8 +168,9 @@ public final class ShardingRouteCacheableCheckerTest {
new ShardingSphereColumn("warehouse_id", Types.INTEGER, false, false, false, true, false),
new ShardingSphereColumn("order_broadcast_table_id", Types.INTEGER, true, false, false, true, false)),
Collections.emptyList(), Collections.emptyList()));
- return new ShardingSphereDatabase(DATABASE_NAME, DatabaseTypeFactory.getInstance("PostgreSQL"), new ShardingSphereResourceMetaData(DATABASE_NAME, Collections.emptyMap()),
- new ShardingSphereRuleMetaData(Arrays.asList(shardingRule, shardingCacheRule)), Collections.singletonMap(SCHEMA_NAME, schema));
+ return new ShardingSphereDatabase(DATABASE_NAME, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "PostgreSQL"),
+ new ShardingSphereResourceMetaData(DATABASE_NAME, Collections.emptyMap()), new ShardingSphereRuleMetaData(Arrays.asList(shardingRule, shardingCacheRule)),
+ Collections.singletonMap(SCHEMA_NAME, schema));
}
private QueryContext prepareQueryContext(final ShardingSphereDatabase database, final String sql, final List<Object> params) {
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 49af96ee9b2..9ddef2028ff 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,9 +26,9 @@ 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.sharding.cosid.algorithm.CosIdAlgorithmConstants;
-import org.apache.shardingsphere.sharding.factory.KeyGenerateAlgorithmFactory;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.junit.Test;
@@ -37,8 +37,8 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
public final class CosIdKeyGenerateAlgorithmTest {
@@ -47,7 +47,7 @@ public final class CosIdKeyGenerateAlgorithmTest {
String idName = "test-cosid";
DefaultSegmentId defaultSegmentId = new DefaultSegmentId(new IdSegmentDistributor.Mock());
DefaultIdGeneratorProvider.INSTANCE.set(idName, defaultSegmentId);
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("COSID", createAsLongProperties(idName)));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", createAsLongProperties(idName)), KeyGenerateAlgorithm.class);
assertThat(algorithm.generateKey(), is(1L));
assertThat(algorithm.generateKey(), is(2L));
}
@@ -62,7 +62,7 @@ public final class CosIdKeyGenerateAlgorithmTest {
public void assertGenerateKeyWhenNotSetIdName() {
DefaultSegmentId defaultSegmentId = new DefaultSegmentId(new IdSegmentDistributor.Mock());
DefaultIdGeneratorProvider.INSTANCE.setShare(defaultSegmentId);
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("COSID", new Properties()));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", new Properties()), KeyGenerateAlgorithm.class);
assertThat(algorithm.generateKey(), is(1L));
assertThat(algorithm.generateKey(), is(2L));
}
@@ -70,7 +70,7 @@ public final class CosIdKeyGenerateAlgorithmTest {
@Test(expected = NotFoundIdGeneratorException.class)
public void assertGenerateKeyWhenIdProviderIsEmpty() {
DefaultIdGeneratorProvider.INSTANCE.clear();
- KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("COSID", new Properties())).generateKey();
+ ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", new Properties()), KeyGenerateAlgorithm.class)).generateKey();
}
@Test
@@ -79,7 +79,7 @@ public final class CosIdKeyGenerateAlgorithmTest {
String prefix = "test_";
IdGenerator idGeneratorDecorator = new StringIdGeneratorDecorator(new MillisecondSnowflakeId(1, 0), new PrefixIdConverter(prefix, Radix62IdConverter.INSTANCE));
DefaultIdGeneratorProvider.INSTANCE.set(idName, idGeneratorDecorator);
- KeyGenerateAlgorithm algorithm = KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("COSID", createAsStringProperties(idName)));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", createAsStringProperties(idName)), KeyGenerateAlgorithm.class);
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 d8415e626c8..175e3d61904 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,6 +22,7 @@ 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;
@@ -31,7 +32,7 @@ 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.sharding.cosid.algorithm.keygen.fixture.WorkerIdGeneratorFixture;
-import org.apache.shardingsphere.sharding.factory.KeyGenerateAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.junit.Test;
import java.util.Properties;
@@ -40,8 +41,8 @@ import java.util.concurrent.locks.LockSupport;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.closeTo;
import static org.mockito.Mockito.mock;
public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@@ -58,8 +59,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKey() {
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()));
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
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();
@@ -75,7 +75,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKeyModUniformity() {
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()));
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
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;
@@ -118,8 +118,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
public void assertGenerateKeyAsString() {
Properties props = new Properties();
props.setProperty(CosIdSnowflakeKeyGenerateAlgorithm.AS_STRING_KEY, Boolean.TRUE.toString());
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("COSID_SNOWFLAKE", props));
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", props), KeyGenerateAlgorithm.class);
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));
@@ -135,13 +134,12 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test(expected = NullPointerException.class)
public void assertGenerateKeyWhenNoneInstanceContext() {
- KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties())).generateKey();
+ ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class)).generateKey();
}
@Test(expected = IllegalArgumentException.class)
public void assertGenerateKeyWhenNegative() {
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()));
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
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,8 +147,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test(expected = IllegalArgumentException.class)
public void assertGenerateKeyWhenGreaterThen1023() {
- CosIdSnowflakeKeyGenerateAlgorithm algorithm = (CosIdSnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()));
+ CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()), KeyGenerateAlgorithm.class);
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 3cc63921250..d557cd3497c 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,14 +20,15 @@ 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.sharding.cosid.algorithm.CosIdAlgorithmConstants;
-import org.apache.shardingsphere.sharding.cosid.algorithm.keygen.CosIdSnowflakeKeyGenerateAlgorithm;
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;
+import org.apache.shardingsphere.sharding.cosid.algorithm.keygen.CosIdSnowflakeKeyGenerateAlgorithm;
import org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.fixture.IntervalShardingAlgorithmDataFixture;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -75,8 +76,8 @@ public final class CosIdSnowflakeIntervalShardingAlgorithmTest {
@Test
public void assertDoSharding() {
- CosIdSnowflakeIntervalShardingAlgorithm algorithm = (CosIdSnowflakeIntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("COSID_INTERVAL_SNOWFLAKE", createProperties()));
+ CosIdSnowflakeIntervalShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("COSID_INTERVAL_SNOWFLAKE", createProperties()), ShardingAlgorithm.class);
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);
@@ -99,8 +100,8 @@ public final class CosIdSnowflakeIntervalShardingAlgorithmTest {
@Test
public void assertDoSharding() {
- CosIdSnowflakeIntervalShardingAlgorithm algorithm = (CosIdSnowflakeIntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(
- new AlgorithmConfiguration("COSID_INTERVAL_SNOWFLAKE", createProperties()));
+ CosIdSnowflakeIntervalShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("COSID_INTERVAL_SNOWFLAKE", createProperties()), ShardingAlgorithm.class);
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 fdf4f5086a7..d96417df1d4 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
@@ -18,18 +18,20 @@
package org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.fixture;
import com.google.common.collect.Range;
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
-import java.util.Properties;
-import java.util.function.Function;
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.sharding.cosid.algorithm.Arguments;
import org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
import org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.CosIdIntervalShardingAlgorithm;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.Properties;
+import java.util.function.Function;
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class IntervalShardingAlgorithmDataFixture {
@@ -124,7 +126,7 @@ public final class IntervalShardingAlgorithmDataFixture {
* @return CosIdIntervalShardingAlgorithm
*/
public static CosIdIntervalShardingAlgorithm createShardingAlgorithm() {
- return (CosIdIntervalShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("COSID_INTERVAL", createProperties()));
+ return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_INTERVAL", createProperties()), ShardingAlgorithm.class);
}
private static Properties createProperties() {
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 ead08b7e974..21fe8bba6b5 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,13 +20,14 @@ 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.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.cosid.algorithm.Arguments;
import org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
-import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -51,9 +52,8 @@ 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() {
- return (CosIdModShardingAlgorithm<Long>) ShardingAlgorithmFactory.newInstance(new AlgorithmConfiguration("COSID_MOD", createProperties()));
+ return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_MOD", createProperties()), ShardingAlgorithm.class);
}
private static Properties createProperties() {
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 ce5ac6d14fa..0522a0f4c3a 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,8 +17,9 @@
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.sharding.factory.KeyGenerateAlgorithmFactory;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.junit.Test;
import java.util.Properties;
@@ -30,6 +31,7 @@ public final class NanoIdKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKey() {
- assertThat(((String) KeyGenerateAlgorithmFactory.newInstance(new AlgorithmConfiguration("NANOID", new Properties())).generateKey()).length(), is(21));
+ KeyGenerateAlgorithm generateAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("NANOID", new Properties()), KeyGenerateAlgorithm.class);
+ assertThat(generateAlgorithm.generateKey().toString().length(), is(21));
}
}
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/decider/SQLFederationDeciderFactory.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/decider/SQLFederationDeciderFactory.java
deleted file mode 100644
index 756e1e92417..00000000000
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/decider/SQLFederationDeciderFactory.java
+++ /dev/null
@@ -1,49 +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.binder.decider;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * SQL federation decider factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class SQLFederationDeciderFactory {
-
- static {
- ShardingSphereServiceLoader.register(SQLFederationDecider.class);
- }
-
- /**
- * Get instances of SQL federation decider.
- *
- * @param rules rules
- * @return got instances
- */
- @SuppressWarnings("rawtypes")
- public static Map<ShardingSphereRule, SQLFederationDecider> getInstances(final Collection<ShardingSphereRule> rules) {
- return OrderedSPIRegistry.getRegisteredServices(SQLFederationDecider.class, rules);
- }
-}
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/decider/engine/SQLFederationDeciderEngine.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/decider/engine/SQLFederationDeciderEngine.java
index 173d36188fd..58e33194c06 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/decider/engine/SQLFederationDeciderEngine.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/decider/engine/SQLFederationDeciderEngine.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.infra.binder.decider.engine;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.decider.SQLFederationDecider;
-import org.apache.shardingsphere.infra.binder.decider.SQLFederationDeciderFactory;
import org.apache.shardingsphere.infra.binder.decider.context.SQLFederationDeciderContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
@@ -28,6 +27,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.util.SystemSchemaUtil;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import java.util.Collection;
import java.util.Map;
@@ -45,7 +45,7 @@ public final class SQLFederationDeciderEngine {
public SQLFederationDeciderEngine(final Collection<ShardingSphereRule> rules, final ConfigurationProperties props) {
this.props = props;
- deciders = SQLFederationDeciderFactory.getInstances(rules);
+ deciders = OrderedSPIRegistry.getRegisteredServices(SQLFederationDecider.class, rules);
}
/**
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/CommonSQLStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/CommonSQLStatementContext.java
index cfc6f1bebc5..7a897f210aa 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/CommonSQLStatementContext.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/CommonSQLStatementContext.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.infra.binder.statement;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.hint.SQLHintExtractor;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.OpenGaussStatement;
@@ -59,22 +59,22 @@ public class CommonSQLStatementContext<T extends SQLStatement> implements SQLSta
private DatabaseType getDatabaseType(final SQLStatement sqlStatement) {
if (sqlStatement instanceof MySQLStatement) {
- return DatabaseTypeFactory.getInstance("MySQL");
+ return TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL");
}
if (sqlStatement instanceof PostgreSQLStatement) {
- return DatabaseTypeFactory.getInstance("PostgreSQL");
+ return TypedSPIRegistry.getRegisteredService(DatabaseType.class, "PostgreSQL");
}
if (sqlStatement instanceof OracleStatement) {
- return DatabaseTypeFactory.getInstance("Oracle");
+ return TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle");
}
if (sqlStatement instanceof SQLServerStatement) {
- return DatabaseTypeFactory.getInstance("SQLServer");
- }
- if (sqlStatement instanceof SQL92Statement) {
- return DatabaseTypeFactory.getInstance("SQL92");
+ return TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer");
}
if (sqlStatement instanceof OpenGaussStatement) {
- return DatabaseTypeFactory.getInstance("openGauss");
+ return TypedSPIRegistry.getRegisteredService(DatabaseType.class, "openGauss");
+ }
+ if (sqlStatement instanceof SQL92Statement) {
+ return TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQL92");
}
throw new UnsupportedSQLOperationException(sqlStatement.getClass().getName());
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
index 90a4d276709..ce375dde024 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
@@ -26,9 +26,9 @@ import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.Par
import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ShorthandProjection;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.exception.SchemaNotFoundException;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.enums.JoinType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -244,7 +244,7 @@ public final class ProjectionEngineTest {
public void assertCreateProjectionWhenShorthandProjectionContainsJoinUsingColumnForPostgreSQL() {
when(schema.getVisibleColumnNames("t_order")).thenReturn(Arrays.asList("order_id", "user_id", "status", "merchant_id", "remark", "creation_date"));
when(schema.getVisibleColumnNames("t_order_item")).thenReturn(Arrays.asList("item_id", "order_id", "user_id", "product_id", "quantity", "creation_date"));
- Optional<Projection> actual = new ProjectionEngine("public", Collections.singletonMap("public", schema), DatabaseTypeFactory.getInstance("PostgreSQL"))
+ Optional<Projection> actual = new ProjectionEngine("public", Collections.singletonMap("public", schema), TypedSPIRegistry.getRegisteredService(DatabaseType.class, "PostgreSQL"))
.createProjection(createJoinTableSegmentWithUsingColumn(), new ShorthandProjectionSegment(0, 0));
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShorthandProjection.class));
@@ -257,8 +257,8 @@ public final class ProjectionEngineTest {
when(schema.getVisibleColumnNames("t_order")).thenReturn(Arrays.asList("order_id", "user_id", "status", "merchant_id", "remark", "creation_date"));
when(schema.getVisibleColumnNames("t_order_item")).thenReturn(Arrays.asList("item_id", "order_id", "user_id", "product_id", "quantity", "creation_date"));
Optional<Projection> actual = new ProjectionEngine(DefaultDatabase.LOGIC_NAME,
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema), DatabaseTypeFactory.getInstance("MySQL")).createProjection(createJoinTableSegmentWithUsingColumn(),
- new ShorthandProjectionSegment(0, 0));
+ Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema),
+ TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL")).createProjection(createJoinTableSegmentWithUsingColumn(), new ShorthandProjectionSegment(0, 0));
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShorthandProjection.class));
assertThat(((ShorthandProjection) actual.get()).getActualColumns().size(), is(9));
@@ -271,8 +271,8 @@ public final class ProjectionEngineTest {
ShorthandProjectionSegment projectionSegment = new ShorthandProjectionSegment(0, 0);
projectionSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("o")));
Optional<Projection> actual =
- new ProjectionEngine("public", Collections.singletonMap("public", schema), DatabaseTypeFactory.getInstance("PostgreSQL")).createProjection(createJoinTableSegmentWithUsingColumn(),
- projectionSegment);
+ new ProjectionEngine("public", Collections.singletonMap("public", schema),
+ TypedSPIRegistry.getRegisteredService(DatabaseType.class, "PostgreSQL")).createProjection(createJoinTableSegmentWithUsingColumn(), projectionSegment);
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShorthandProjection.class));
assertThat(((ShorthandProjection) actual.get()).getActualColumns().size(), is(6));
@@ -284,8 +284,8 @@ public final class ProjectionEngineTest {
when(schema.getVisibleColumnNames("t_order")).thenReturn(Arrays.asList("order_id", "user_id", "status", "merchant_id", "remark", "creation_date"));
ShorthandProjectionSegment projectionSegment = new ShorthandProjectionSegment(0, 0);
projectionSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("o")));
- Optional<Projection> actual = new ProjectionEngine(DefaultDatabase.LOGIC_NAME,
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema), DatabaseTypeFactory.getInstance("MySQL")).createProjection(createJoinTableSegmentWithUsingColumn(), projectionSegment);
+ Optional<Projection> actual = new ProjectionEngine(DefaultDatabase.LOGIC_NAME, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema),
+ TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL")).createProjection(createJoinTableSegmentWithUsingColumn(), projectionSegment);
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShorthandProjection.class));
assertThat(((ShorthandProjection) actual.get()).getActualColumns().size(), is(6));
@@ -349,7 +349,7 @@ public final class ProjectionEngineTest {
public void assertCreateProjectionWhenShorthandProjectionContainsNaturalJoinForPostgreSQL() {
when(schema.getVisibleColumnNames("t_order")).thenReturn(Arrays.asList("order_id", "user_id", "status", "merchant_id", "remark", "creation_date"));
when(schema.getVisibleColumnNames("t_order_item")).thenReturn(Arrays.asList("item_id", "order_id", "user_id", "product_id", "quantity", "creation_date"));
- Optional<Projection> actual = new ProjectionEngine("public", Collections.singletonMap("public", schema), DatabaseTypeFactory.getInstance("PostgreSQL"))
+ Optional<Projection> actual = new ProjectionEngine("public", Collections.singletonMap("public", schema), TypedSPIRegistry.getRegisteredService(DatabaseType.class, "PostgreSQL"))
.createProjection(createJoinTableSegmentWithNaturalJoin(), new ShorthandProjectionSegment(0, 0));
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShorthandProjection.class));
@@ -361,9 +361,8 @@ public final class ProjectionEngineTest {
public void assertCreateProjectionWhenShorthandProjectionContainsNaturalJoinForMySQL() {
when(schema.getVisibleColumnNames("t_order")).thenReturn(Arrays.asList("order_id", "user_id", "status", "merchant_id", "remark", "creation_date"));
when(schema.getVisibleColumnNames("t_order_item")).thenReturn(Arrays.asList("item_id", "order_id", "user_id", "product_id", "quantity", "creation_date"));
- Optional<Projection> actual = new ProjectionEngine(DefaultDatabase.LOGIC_NAME,
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema), DatabaseTypeFactory.getInstance("MySQL")).createProjection(createJoinTableSegmentWithNaturalJoin(),
- new ShorthandProjectionSegment(0, 0));
+ Optional<Projection> actual = new ProjectionEngine(DefaultDatabase.LOGIC_NAME, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema),
+ TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL")).createProjection(createJoinTableSegmentWithNaturalJoin(), new ShorthandProjectionSegment(0, 0));
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShorthandProjection.class));
assertThat(((ShorthandProjection) actual.get()).getActualColumns().size(), is(9));
@@ -376,8 +375,8 @@ public final class ProjectionEngineTest {
ShorthandProjectionSegment projectionSegment = new ShorthandProjectionSegment(0, 0);
projectionSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("o")));
Optional<Projection> actual =
- new ProjectionEngine("public", Collections.singletonMap("public", schema), DatabaseTypeFactory.getInstance("PostgreSQL")).createProjection(createJoinTableSegmentWithNaturalJoin(),
- projectionSegment);
+ new ProjectionEngine("public", Collections.singletonMap("public", schema),
+ TypedSPIRegistry.getRegisteredService(DatabaseType.class, "PostgreSQL")).createProjection(createJoinTableSegmentWithNaturalJoin(), projectionSegment);
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShorthandProjection.class));
assertThat(((ShorthandProjection) actual.get()).getActualColumns().size(), is(6));
@@ -389,8 +388,8 @@ public final class ProjectionEngineTest {
when(schema.getVisibleColumnNames("t_order")).thenReturn(Arrays.asList("order_id", "user_id", "status", "merchant_id", "remark", "creation_date"));
ShorthandProjectionSegment projectionSegment = new ShorthandProjectionSegment(0, 0);
projectionSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("o")));
- Optional<Projection> actual = new ProjectionEngine(DefaultDatabase.LOGIC_NAME,
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema), DatabaseTypeFactory.getInstance("MySQL")).createProjection(createJoinTableSegmentWithNaturalJoin(), projectionSegment);
+ Optional<Projection> actual = new ProjectionEngine(DefaultDatabase.LOGIC_NAME, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema),
+ TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL")).createProjection(createJoinTableSegmentWithNaturalJoin(), projectionSegment);
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShorthandProjection.class));
assertThat(((ShorthandProjection) actual.get()).getActualColumns().size(), is(6));
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/checker/RuleConfigurationCheckerFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/checker/RuleConfigurationCheckerFactory.java
deleted file mode 100644
index 49e12fcc663..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/checker/RuleConfigurationCheckerFactory.java
+++ /dev/null
@@ -1,51 +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.config.rule.checker;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * Rule configuration checker factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class RuleConfigurationCheckerFactory {
-
- static {
- ShardingSphereServiceLoader.register(RuleConfigurationChecker.class);
- }
-
- /**
- * Find instance of rule configuration checker.
- *
- * @param config rule configuration
- * @return found instance
- */
- @SuppressWarnings("rawtypes")
- public static Optional<RuleConfigurationChecker> findInstance(final RuleConfiguration config) {
- Map<Class<?>, RuleConfigurationChecker> checkers = OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass()));
- return Optional.ofNullable(checkers.get(config.getClass()));
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
index da1444ec74b..cb9ded916f6 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
@@ -24,6 +24,8 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.datasource.state.DataSourceStateManager;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.wrapper.SQLWrapperException;
+import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -97,7 +99,8 @@ public final class DatabaseTypeEngine {
* @return database type
*/
public static DatabaseType getDatabaseType(final String url) {
- return DatabaseTypeFactory.getInstances().stream().filter(each -> matchURLs(url, each)).findAny().orElseGet(() -> DatabaseTypeFactory.getInstance("SQL92"));
+ return ShardingSphereServiceLoader.getServiceInstances(DatabaseType.class)
+ .stream().filter(each -> matchURLs(url, each)).findAny().orElseGet(() -> TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQL92"));
}
/**
@@ -107,7 +110,7 @@ public final class DatabaseTypeEngine {
* @return storage type
*/
public static DatabaseType getStorageType(final Collection<DataSource> dataSources) {
- return dataSources.isEmpty() ? DatabaseTypeFactory.getInstance(DEFAULT_DATABASE_TYPE) : getStorageType(dataSources.iterator().next());
+ return dataSources.isEmpty() ? TypedSPIRegistry.getRegisteredService(DatabaseType.class, DEFAULT_DATABASE_TYPE) : getStorageType(dataSources.iterator().next());
}
private static DatabaseType getStorageType(final DataSource dataSource) {
@@ -134,7 +137,7 @@ public final class DatabaseTypeEngine {
* @return trunk database type
*/
public static DatabaseType getTrunkDatabaseType(final String name) {
- DatabaseType databaseType = DatabaseTypeFactory.getInstance(name);
+ DatabaseType databaseType = TypedSPIRegistry.getRegisteredService(DatabaseType.class, name);
return databaseType instanceof BranchDatabaseType ? ((BranchDatabaseType) databaseType).getTrunkDatabaseType() : databaseType;
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeFactory.java
deleted file mode 100644
index 04a8fc3be72..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeFactory.java
+++ /dev/null
@@ -1,55 +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.database.type;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-import java.util.Collection;
-
-/**
- * Database type factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DatabaseTypeFactory {
-
- static {
- ShardingSphereServiceLoader.register(DatabaseType.class);
- }
-
- /**
- * Get instance of database type.
- *
- * @param name name of database type
- * @return got instance
- */
- public static DatabaseType getInstance(final String name) {
- return TypedSPIRegistry.getRegisteredService(DatabaseType.class, name);
- }
-
- /**
- * Get instances of database type.
- *
- * @return got instances
- */
- public static Collection<DatabaseType> getInstances() {
- return ShardingSphereServiceLoader.getServiceInstances(DatabaseType.class);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseType.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseType.java
index 321b432538f..6851773a69a 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseType.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseType.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.H2DataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.BranchDatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sql.parser.sql.common.enums.QuoteCharacter;
import java.util.Collection;
@@ -49,7 +49,7 @@ public final class H2DatabaseType implements BranchDatabaseType {
@Override
public DatabaseType getTrunkDatabaseType() {
- return DatabaseTypeFactory.getInstance("MySQL");
+ return TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL");
}
@Override
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseType.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseType.java
index 2e544ece84b..fcddeeefcd7 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseType.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseType.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.MariaDBDataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.BranchDatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.sql.parser.sql.common.enums.QuoteCharacter;
import java.util.Collection;
@@ -49,7 +49,7 @@ public final class MariaDBDatabaseType implements BranchDatabaseType {
@Override
public DatabaseType getTrunkDatabaseType() {
- return DatabaseTypeFactory.getInstance("MySQL");
+ return TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL");
}
@Override
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactory.java
deleted file mode 100644
index 550a05b4ff8..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactory.java
+++ /dev/null
@@ -1,49 +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.datanode;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Data node builder factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DataNodeBuilderFactory {
-
- static {
- ShardingSphereServiceLoader.register(DataNodeBuilder.class);
- }
-
- /**
- * Get instances of data node builder.
- *
- * @param rules rules
- * @return got instances
- */
- @SuppressWarnings("rawtypes")
- public static Map<ShardingSphereRule, DataNodeBuilder> getInstances(final Collection<ShardingSphereRule> rules) {
- return OrderedSPIRegistry.getRegisteredServices(DataNodeBuilder.class, rules);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
index 106cd538587..743f863ec16 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.infra.datanode;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import java.util.Collection;
import java.util.Collections;
@@ -41,7 +42,7 @@ public final class DataNodes {
public DataNodes(final Collection<ShardingSphereRule> rules) {
this.rules = rules;
- dataNodeBuilders = DataNodeBuilderFactory.getInstances(rules);
+ dataNodeBuilders = OrderedSPIRegistry.getRegisteredServices(DataNodeBuilder.class, rules);
}
/**
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreator.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreator.java
index d48ef1bb960..be6dc55ee24 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreator.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreator.java
@@ -21,11 +21,11 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
-import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaDataFactory;
import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaDataReflection;
import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import org.apache.shardingsphere.infra.datasource.props.custom.CustomDataSourceProperties;
import org.apache.shardingsphere.infra.datasource.registry.GlobalDataSourceRegistry;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.util.LinkedHashMap;
@@ -72,7 +72,7 @@ public final class DataSourcePoolCreator {
*/
public static DataSource create(final DataSourceProperties dataSourceProps) {
DataSource result = createDataSource(dataSourceProps.getDataSourceClassName());
- Optional<DataSourcePoolMetaData> poolMetaData = DataSourcePoolMetaDataFactory.findInstance(dataSourceProps.getDataSourceClassName());
+ Optional<DataSourcePoolMetaData> poolMetaData = TypedSPIRegistry.findRegisteredService(DataSourcePoolMetaData.class, dataSourceProps.getDataSourceClassName());
DataSourceReflection dataSourceReflection = new DataSourceReflection(result);
if (poolMetaData.isPresent()) {
setDefaultFields(dataSourceReflection, poolMetaData.get());
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourceReflection.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourceReflection.java
index c29033291a1..fcad398a8f0 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourceReflection.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourceReflection.java
@@ -22,9 +22,9 @@ import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
-import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaDataFactory;
import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaDataReflection;
import org.apache.shardingsphere.infra.datasource.pool.metadata.type.DefaultDataSourcePoolFieldMetaData;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.lang.reflect.Method;
@@ -159,7 +159,8 @@ public final class DataSourceReflection {
*/
public void addDefaultDataSourceProperties() {
DataSourcePoolMetaDataReflection dataSourcePoolMetaDataReflection = new DataSourcePoolMetaDataReflection(dataSource,
- DataSourcePoolMetaDataFactory.findInstance(dataSource.getClass().getName()).map(DataSourcePoolMetaData::getFieldMetaData).orElseGet(DefaultDataSourcePoolFieldMetaData::new));
+ TypedSPIRegistry.findRegisteredService(DataSourcePoolMetaData.class, dataSource.getClass().getName())
+ .map(DataSourcePoolMetaData::getFieldMetaData).orElseGet(DefaultDataSourcePoolFieldMetaData::new));
Optional<String> jdbcUrl = dataSourcePoolMetaDataReflection.getJdbcUrl();
Optional<Properties> jdbcConnectionProps = dataSourcePoolMetaDataReflection.getJdbcConnectionProperties();
if (!jdbcUrl.isPresent() || !jdbcConnectionProps.isPresent()) {
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyer.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyer.java
index 58c3f5efd3b..1bb1d0c9044 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyer.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyer.java
@@ -20,7 +20,8 @@ package org.apache.shardingsphere.infra.datasource.pool.destroyer;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.DataSourcePoolActiveDetector;
-import org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.DataSourcePoolActiveDetectorFactory;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.util.concurrent.ExecutorService;
@@ -53,7 +54,8 @@ public final class DataSourcePoolDestroyer {
}
private void waitUntilActiveConnectionComplete() {
- DataSourcePoolActiveDetector dataSourcePoolActiveDetector = DataSourcePoolActiveDetectorFactory.getInstance(dataSource.getClass().getName());
+ DataSourcePoolActiveDetector dataSourcePoolActiveDetector = TypedSPIRegistry.findRegisteredService(DataSourcePoolActiveDetector.class, dataSource.getClass().getName())
+ .orElseGet(() -> RequiredSPIRegistry.getRegisteredService(DataSourcePoolActiveDetector.class));
while (dataSourcePoolActiveDetector.containsActiveConnection(dataSource)) {
try {
Thread.sleep(10L);
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/detector/DataSourcePoolActiveDetectorFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/detector/DataSourcePoolActiveDetectorFactory.java
deleted file mode 100644
index bb5aec9984a..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/detector/DataSourcePoolActiveDetectorFactory.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.datasource.pool.destroyer.detector;
-
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * Data source pool active detector factory.
- */
-public final class DataSourcePoolActiveDetectorFactory {
-
- static {
- ShardingSphereServiceLoader.register(DataSourcePoolActiveDetector.class);
- }
-
- /**
- * Get instance of data source pool active detector.
- *
- * @param dataSourceClassName data source class name
- * @return got instance
- */
- public static DataSourcePoolActiveDetector getInstance(final String dataSourceClassName) {
- return TypedSPIRegistry.findRegisteredService(DataSourcePoolActiveDetector.class, dataSourceClassName)
- .orElseGet(() -> RequiredSPIRegistry.getRegisteredService(DataSourcePoolActiveDetector.class));
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/DataSourcePoolMetaDataFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/DataSourcePoolMetaDataFactory.java
deleted file mode 100644
index 8e29f8877be..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/DataSourcePoolMetaDataFactory.java
+++ /dev/null
@@ -1,46 +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.datasource.pool.metadata;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-import java.util.Optional;
-
-/**
- * Data source pool meta data factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DataSourcePoolMetaDataFactory {
-
- static {
- ShardingSphereServiceLoader.register(DataSourcePoolMetaData.class);
- }
-
- /**
- * Find instance of data source pool meta data.
- *
- * @param dataSourceClassName data source class name
- * @return found instance
- */
- public static Optional<DataSourcePoolMetaData> findInstance(final String dataSourceClassName) {
- return TypedSPIRegistry.findRegisteredService(DataSourcePoolMetaData.class, dataSourceClassName);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourceProperties.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourceProperties.java
index 0dd2d1ef53e..e0f7f6339bf 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourceProperties.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourceProperties.java
@@ -20,10 +20,10 @@ package org.apache.shardingsphere.infra.datasource.props;
import com.google.common.base.Objects;
import lombok.Getter;
import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
-import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaDataFactory;
import org.apache.shardingsphere.infra.datasource.props.custom.CustomDataSourceProperties;
import org.apache.shardingsphere.infra.datasource.props.synonym.ConnectionPropertySynonyms;
import org.apache.shardingsphere.infra.datasource.props.synonym.PoolPropertySynonyms;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.util.Collection;
import java.util.Collections;
@@ -49,7 +49,7 @@ public final class DataSourceProperties {
public DataSourceProperties(final String dataSourceClassName, final Map<String, Object> props) {
this.dataSourceClassName = dataSourceClassName;
- Optional<DataSourcePoolMetaData> poolMetaData = DataSourcePoolMetaDataFactory.findInstance(dataSourceClassName);
+ Optional<DataSourcePoolMetaData> poolMetaData = TypedSPIRegistry.findRegisteredService(DataSourcePoolMetaData.class, dataSourceClassName);
Map<String, String> propertySynonyms = poolMetaData.isPresent() ? poolMetaData.get().getPropertySynonyms() : Collections.emptyMap();
connectionPropertySynonyms = new ConnectionPropertySynonyms(props, propertySynonyms);
poolPropertySynonyms = new PoolPropertySynonyms(props, propertySynonyms);
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesCreator.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesCreator.java
index 4952f04bdf8..a51e7e7b2d2 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesCreator.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesCreator.java
@@ -22,7 +22,7 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.datasource.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourceReflection;
import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
-import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaDataFactory;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.util.LinkedHashMap;
@@ -77,7 +77,7 @@ public final class DataSourcePropertiesCreator {
private static Map<String, Object> createProperties(final DataSource dataSource) {
Map<String, Object> result = new LinkedHashMap<>();
- Optional<DataSourcePoolMetaData> poolMetaData = DataSourcePoolMetaDataFactory.findInstance(dataSource.getClass().getName());
+ Optional<DataSourcePoolMetaData> poolMetaData = TypedSPIRegistry.findRegisteredService(DataSourcePoolMetaData.class, dataSource.getClass().getName());
for (Entry<String, Object> entry : new DataSourceReflection(dataSource).convertToProperties().entrySet()) {
String propertyName = entry.getKey();
Object propertyValue = entry.getValue();
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
index b336edede86..456422caf26 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.infra.datasource.props;
import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator;
import org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer;
import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
-import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaDataFactory;
import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolPropertiesValidator;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -56,7 +56,7 @@ public final class DataSourcePropertiesValidator {
}
private void validateProperties(final String dataSourceName, final DataSourceProperties dataSourceProps) throws InvalidDataSourcePropertiesException {
- Optional<DataSourcePoolMetaData> poolMetaData = DataSourcePoolMetaDataFactory.findInstance(dataSourceProps.getDataSourceClassName());
+ Optional<DataSourcePoolMetaData> poolMetaData = TypedSPIRegistry.findRegisteredService(DataSourcePoolMetaData.class, dataSourceProps.getDataSourceClassName());
if (!poolMetaData.isPresent()) {
return;
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactory.java
similarity index 71%
rename from infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilderFactory.java
rename to infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactory.java
index e15c31795f0..01d5f491d0e 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilderFactory.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactory.java
@@ -21,29 +21,12 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.instance.metadata.jdbc.JDBCInstanceMetaData;
import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
/**
- * Instance meta data builder factory.
+ * Instance meta data factory.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class InstanceMetaDataBuilderFactory {
-
- static {
- ShardingSphereServiceLoader.register(InstanceMetaDataBuilder.class);
- }
-
- /**
- * Create instance meta data.
- *
- * @param type type
- * @param port port
- * @return created instance meta data
- */
- public static InstanceMetaData create(final String type, final int port) {
- return TypedSPIRegistry.getRegisteredService(InstanceMetaDataBuilder.class, type).build(port);
- }
+public final class InstanceMetaDataFactory {
/**
* Create instance meta data.
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilderFactory.java
deleted file mode 100644
index 6527715ac4c..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilderFactory.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.data.builder;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-import java.util.Optional;
-
-/**
- * ShardingSphere data builder factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShardingSphereDataBuilderFactory {
-
- static {
- ShardingSphereServiceLoader.register(ShardingSphereDataBuilder.class);
- }
-
- /**
- * Find instance of dialect ShardingSphere data builder.
- *
- * @param databaseType database type
- * @return found instance
- */
- public static Optional<ShardingSphereDataBuilder> getInstance(final DatabaseType databaseType) {
- String type = databaseType instanceof OpenGaussDatabaseType ? "PostgreSQL" : databaseType.getType();
- return TypedSPIRegistry.findRegisteredService(ShardingSphereDataBuilder.class, type);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/collector/ShardingSphereDataCollectorFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/collector/ShardingSphereDataCollectorFactory.java
deleted file mode 100644
index 70c26f49f34..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/collector/ShardingSphereDataCollectorFactory.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.data.collector;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-import java.util.Optional;
-
-/**
- * ShardingSphere data collector factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShardingSphereDataCollectorFactory {
-
- static {
- ShardingSphereServiceLoader.register(ShardingSphereDataCollector.class);
- }
-
- /**
- * Find instance of rule altered detector.
- *
- * @param tableName table name
- * @return found instance
- */
- public static Optional<ShardingSphereDataCollector> findInstance(final String tableName) {
- return TypedSPIRegistry.findRegisteredService(ShardingSphereDataCollector.class, tableName);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java
index d29122bdbd4..a4247e8ad90 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java
@@ -26,7 +26,6 @@ import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator;
-import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecoratorFactory;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.SchemaMetaDataLoaderEngine;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.SchemaMetaDataLoaderMaterial;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
@@ -37,6 +36,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.Tab
import org.apache.shardingsphere.infra.metadata.database.schema.util.SchemaMetaDataUtil;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.identifier.type.TableContainedRule;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import java.sql.SQLException;
import java.util.Collection;
@@ -118,7 +118,7 @@ public final class GenericSchemaBuilder {
@SuppressWarnings({"unchecked", "rawtypes"})
private static Map<String, ShardingSphereSchema> decorate(final Map<String, SchemaMetaData> schemaMetaDataMap, final GenericSchemaBuilderMaterial material) {
Map<String, SchemaMetaData> result = new LinkedHashMap<>(schemaMetaDataMap);
- for (Entry<ShardingSphereRule, RuleBasedSchemaMetaDataDecorator> entry : RuleBasedSchemaMetaDataDecoratorFactory.getInstances(material.getRules()).entrySet()) {
+ for (Entry<ShardingSphereRule, RuleBasedSchemaMetaDataDecorator> entry : OrderedSPIRegistry.getRegisteredServices(RuleBasedSchemaMetaDataDecorator.class, material.getRules()).entrySet()) {
if (!(entry.getKey() instanceof TableContainedRule)) {
continue;
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/decorator/spi/RuleBasedSchemaMetaDataDecoratorFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/decorator/spi/RuleBasedSchemaMetaDataDecoratorFactory.java
deleted file mode 100644
index 069552beb63..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/decorator/spi/RuleBasedSchemaMetaDataDecoratorFactory.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi;
-
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Rule based schema meta data decorator factory.
- */
-public final class RuleBasedSchemaMetaDataDecoratorFactory {
-
- static {
- ShardingSphereServiceLoader.register(RuleBasedSchemaMetaDataDecorator.class);
- }
-
- /**
- * Get instances of rule based schema meta data decorator.
- *
- * @param rules rules
- * @return got instances
- */
- @SuppressWarnings("rawtypes")
- public static Map<ShardingSphereRule, RuleBasedSchemaMetaDataDecorator> getInstances(final Collection<ShardingSphereRule> rules) {
- return OrderedSPIRegistry.getRegisteredServices(RuleBasedSchemaMetaDataDecorator.class, rules);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/SchemaMetaDataLoaderEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/SchemaMetaDataLoaderEngine.java
index af44fc41f27..26e6c784fb4 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/SchemaMetaDataLoaderEngine.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/SchemaMetaDataLoaderEngine.java
@@ -25,8 +25,8 @@ import org.apache.shardingsphere.infra.metadata.database.schema.loader.common.Ta
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoaderFactory;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnknownSQLException;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import java.sql.SQLException;
import java.util.Collection;
@@ -76,7 +76,7 @@ public final class SchemaMetaDataLoaderEngine {
}
private static Collection<SchemaMetaData> load(final SchemaMetaDataLoaderMaterial material) throws SQLException {
- Optional<DialectSchemaMetaDataLoader> dialectSchemaMetaDataLoader = DialectSchemaMetaDataLoaderFactory.findInstance(material.getStorageType());
+ Optional<DialectSchemaMetaDataLoader> dialectSchemaMetaDataLoader = TypedSPIRegistry.findRegisteredService(DialectSchemaMetaDataLoader.class, material.getStorageType().getType());
if (dialectSchemaMetaDataLoader.isPresent()) {
try {
return dialectSchemaMetaDataLoader.get().load(material.getDataSource(), material.getActualTableNames(), material.getDefaultSchemaName());
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/H2SchemaMetaDataLoader.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/H2SchemaMetaDataLoader.java
index 34dc87c2e9f..dddc336e405 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/H2SchemaMetaDataLoader.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/H2SchemaMetaDataLoader.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoaderFactory;
+import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoader;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -82,7 +82,7 @@ public final class H2SchemaMetaDataLoader implements DialectSchemaMetaDataLoader
private Map<String, Collection<ColumnMetaData>> loadColumnMetaDataMap(final Connection connection, final Collection<String> tables) throws SQLException {
Map<String, Collection<ColumnMetaData>> result = new HashMap<>();
try (PreparedStatement preparedStatement = connection.prepareStatement(getTableMetaDataSQL(tables))) {
- Map<String, Integer> dataTypes = DataTypeLoaderFactory.getInstance(DatabaseTypeFactory.getInstance("H2")).load(connection.getMetaData());
+ Map<String, Integer> dataTypes = RequiredSPIRegistry.getRegisteredService(DataTypeLoader.class).load(connection.getMetaData());
Map<String, Collection<String>> tablePrimaryKeys = loadTablePrimaryKeys(connection, tables);
Map<String, Map<String, Boolean>> tableGenerated = loadTableGenerated(connection, tables);
preparedStatement.setString(1, connection.getCatalog());
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/MySQLSchemaMetaDataLoader.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/MySQLSchemaMetaDataLoader.java
index da9ec92948c..63679f1182d 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/MySQLSchemaMetaDataLoader.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/MySQLSchemaMetaDataLoader.java
@@ -17,15 +17,17 @@
package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.datasource.registry.GlobalDataSourceRegistry;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ConstraintMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoaderFactory;
+import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoader;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -39,6 +41,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.stream.Collectors;
/**
@@ -104,7 +107,9 @@ public final class MySQLSchemaMetaDataLoader implements DialectSchemaMetaDataLoa
try (
Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(getTableMetaDataSQL(tables))) {
- Map<String, Integer> dataTypes = DataTypeLoaderFactory.getInstance(DatabaseTypeFactory.getInstance("MySQL")).load(connection.getMetaData());
+ Optional<DataTypeLoader> loader = TypedSPIRegistry.findRegisteredService(DataTypeLoader.class, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL").getType());
+ Preconditions.checkState(loader.isPresent());
+ Map<String, Integer> dataTypes = loader.get().load(connection.getMetaData());
String databaseName = "".equals(connection.getCatalog()) ? GlobalDataSourceRegistry.getInstance().getCachedDatabaseTables().get(tables.iterator().next()) : connection.getCatalog();
preparedStatement.setString(1, databaseName);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OpenGaussSchemaMetaDataLoader.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OpenGaussSchemaMetaDataLoader.java
index c1d582fbdeb..4ecebc681f4 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OpenGaussSchemaMetaDataLoader.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OpenGaussSchemaMetaDataLoader.java
@@ -19,14 +19,16 @@ package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.common.SchemaMetaDataLoader;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoaderFactory;
+import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoader;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -62,7 +64,7 @@ public final class OpenGaussSchemaMetaDataLoader implements DialectSchemaMetaDat
@Override
public Collection<SchemaMetaData> load(final DataSource dataSource, final Collection<String> tables, final String defaultSchemaName) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
- Collection<String> schemaNames = SchemaMetaDataLoader.loadSchemaNames(connection, DatabaseTypeFactory.getInstance(getType()));
+ Collection<String> schemaNames = SchemaMetaDataLoader.loadSchemaNames(connection, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "openGauss"));
Map<String, Multimap<String, IndexMetaData>> schemaIndexMetaDataMap = loadIndexMetaDataMap(connection, schemaNames);
Map<String, Multimap<String, ColumnMetaData>> schemaColumnMetaDataMap = loadColumnMetaDataMap(connection, tables, schemaNames);
Collection<SchemaMetaData> result = new LinkedList<>();
@@ -97,7 +99,7 @@ public final class OpenGaussSchemaMetaDataLoader implements DialectSchemaMetaDat
final Collection<String> schemaNames) throws SQLException {
Map<String, Multimap<String, ColumnMetaData>> result = new LinkedHashMap<>();
try (PreparedStatement preparedStatement = connection.prepareStatement(getColumnMetaDataSQL(schemaNames, tables)); ResultSet resultSet = preparedStatement.executeQuery()) {
- Map<String, Integer> dataTypes = DataTypeLoaderFactory.getInstance(DatabaseTypeFactory.getInstance("openGauss")).load(connection.getMetaData());
+ Map<String, Integer> dataTypes = RequiredSPIRegistry.getRegisteredService(DataTypeLoader.class).load(connection.getMetaData());
Collection<String> primaryKeys = loadPrimaryKeys(connection, schemaNames);
while (resultSet.next()) {
String tableName = resultSet.getString("table_name");
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OracleSchemaMetaDataLoader.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OracleSchemaMetaDataLoader.java
index 03bc4ebbae4..6b1565c6ed5 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OracleSchemaMetaDataLoader.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OracleSchemaMetaDataLoader.java
@@ -17,15 +17,17 @@
package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.adapter.MetaDataLoaderConnectionAdapter;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoaderFactory;
+import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoader;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -41,6 +43,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.stream.Collectors;
/**
@@ -75,7 +78,7 @@ public final class OracleSchemaMetaDataLoader implements DialectSchemaMetaDataLo
public Collection<SchemaMetaData> load(final DataSource dataSource, final Collection<String> tables, final String defaultSchemaName) throws SQLException {
Map<String, Collection<ColumnMetaData>> columnMetaDataMap = new HashMap<>(tables.size(), 1);
Map<String, Collection<IndexMetaData>> indexMetaDataMap = new HashMap<>(tables.size(), 1);
- try (Connection connection = new MetaDataLoaderConnectionAdapter(DatabaseTypeFactory.getInstance("Oracle"), dataSource.getConnection())) {
+ try (Connection connection = new MetaDataLoaderConnectionAdapter(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle"), dataSource.getConnection())) {
for (List<String> each : Lists.partition(new ArrayList<>(tables), MAX_EXPRESSION_SIZE)) {
columnMetaDataMap.putAll(loadColumnMetaDataMap(connection, each));
indexMetaDataMap.putAll(loadIndexMetaData(connection, each));
@@ -92,7 +95,9 @@ public final class OracleSchemaMetaDataLoader implements DialectSchemaMetaDataLo
private Map<String, Collection<ColumnMetaData>> loadColumnMetaDataMap(final Connection connection, final Collection<String> tables) throws SQLException {
Map<String, Collection<ColumnMetaData>> result = new HashMap<>(tables.size(), 1);
try (PreparedStatement preparedStatement = connection.prepareStatement(getTableMetaDataSQL(tables, connection.getMetaData()))) {
- Map<String, Integer> dataTypes = DataTypeLoaderFactory.getInstance(DatabaseTypeFactory.getInstance("Oracle")).load(connection.getMetaData());
+ Optional<DataTypeLoader> loader = TypedSPIRegistry.findRegisteredService(DataTypeLoader.class, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle").getType());
+ Preconditions.checkState(loader.isPresent());
+ Map<String, Integer> dataTypes = loader.get().load(connection.getMetaData());
Map<String, Collection<String>> tablePrimaryKeys = loadTablePrimaryKeys(connection, tables);
preparedStatement.setString(1, connection.getSchema());
try (ResultSet resultSet = preparedStatement.executeQuery()) {
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/PostgreSQLSchemaMetaDataLoader.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/PostgreSQLSchemaMetaDataLoader.java
index 1b5573e4375..1ba5201af74 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/PostgreSQLSchemaMetaDataLoader.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/PostgreSQLSchemaMetaDataLoader.java
@@ -19,15 +19,17 @@ package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.common.SchemaMetaDataLoader;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ConstraintMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoaderFactory;
+import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoader;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -72,7 +74,7 @@ public final class PostgreSQLSchemaMetaDataLoader implements DialectSchemaMetaDa
@Override
public Collection<SchemaMetaData> load(final DataSource dataSource, final Collection<String> tables, final String defaultSchemaName) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
- Collection<String> schemaNames = SchemaMetaDataLoader.loadSchemaNames(connection, DatabaseTypeFactory.getInstance(getType()));
+ Collection<String> schemaNames = SchemaMetaDataLoader.loadSchemaNames(connection, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "PostgreSQL"));
Map<String, Multimap<String, IndexMetaData>> schemaIndexMetaDataMap = loadIndexMetaDataMap(connection, schemaNames);
Map<String, Multimap<String, ColumnMetaData>> schemaColumnMetaDataMap = loadColumnMetaDataMap(connection, tables, schemaNames);
Map<String, Multimap<String, ConstraintMetaData>> schemaConstraintMetaDataMap = loadConstraintMetaDataMap(connection, schemaNames);
@@ -110,7 +112,7 @@ public final class PostgreSQLSchemaMetaDataLoader implements DialectSchemaMetaDa
Map<String, Multimap<String, ColumnMetaData>> result = new LinkedHashMap<>();
Collection<String> roleTableGrants = loadRoleTableGrants(connection, tables);
try (PreparedStatement preparedStatement = connection.prepareStatement(getColumnMetaDataSQL(schemaNames, tables)); ResultSet resultSet = preparedStatement.executeQuery()) {
- Map<String, Integer> dataTypes = DataTypeLoaderFactory.getInstance(DatabaseTypeFactory.getInstance("PostgreSQL")).load(connection.getMetaData());
+ Map<String, Integer> dataTypes = RequiredSPIRegistry.getRegisteredService(DataTypeLoader.class).load(connection.getMetaData());
Collection<String> primaryKeys = loadPrimaryKeys(connection, schemaNames);
while (resultSet.next()) {
String tableName = resultSet.getString("table_name");
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/SQLServerSchemaMetaDataLoader.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/SQLServerSchemaMetaDataLoader.java
index d75662c3f56..9e65727cc28 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/SQLServerSchemaMetaDataLoader.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/SQLServerSchemaMetaDataLoader.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoaderFactory;
+import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoader;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -80,7 +80,7 @@ public final class SQLServerSchemaMetaDataLoader implements DialectSchemaMetaDat
try (
Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(getTableMetaDataSQL(tables, connection.getMetaData()))) {
- Map<String, Integer> dataTypes = DataTypeLoaderFactory.getInstance(DatabaseTypeFactory.getInstance("SQLServer")).load(connection.getMetaData());
+ Map<String, Integer> dataTypes = RequiredSPIRegistry.getRegisteredService(DataTypeLoader.class).load(connection.getMetaData());
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String tableName = resultSet.getString("TABLE_NAME");
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/spi/DataTypeLoaderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/spi/DataTypeLoaderFactory.java
deleted file mode 100644
index 5cacc4818d7..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/spi/DataTypeLoaderFactory.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.database.schema.loader.spi;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * Data type loader.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DataTypeLoaderFactory {
-
- static {
- ShardingSphereServiceLoader.register(DataTypeLoader.class);
- }
-
- /**
- * Get instance of dialect data type loader.
- *
- * @param databaseType database type
- * @return found instance
- */
- public static DataTypeLoader getInstance(final DatabaseType databaseType) {
- return TypedSPIRegistry.findRegisteredService(DataTypeLoader.class, databaseType.getType()).orElseGet(() -> RequiredSPIRegistry.getRegisteredService(DataTypeLoader.class));
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/spi/DialectSchemaMetaDataLoaderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/spi/DialectSchemaMetaDataLoaderFactory.java
deleted file mode 100644
index ac9136ef44f..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/spi/DialectSchemaMetaDataLoaderFactory.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.database.schema.loader.spi;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-import java.util.Optional;
-
-/**
- * Dialect schema meta data loader factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DialectSchemaMetaDataLoaderFactory {
-
- static {
- ShardingSphereServiceLoader.register(DialectSchemaMetaDataLoader.class);
- }
-
- /**
- * Find instance of dialect schema meta data loader.
- *
- * @param databaseType database type
- * @return found instance
- */
- public static Optional<DialectSchemaMetaDataLoader> findInstance(final DatabaseType databaseType) {
- return TypedSPIRegistry.findRegisteredService(DialectSchemaMetaDataLoader.class, databaseType.getType());
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactory.java
deleted file mode 100644
index becfedca1ac..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactory.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.builder.database;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Map;
-
-/**
- * Database rule builder factory.
- */
-@SuppressWarnings("rawtypes")
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DatabaseRuleBuilderFactory {
-
- static {
- ShardingSphereServiceLoader.register(DatabaseRuleBuilder.class);
- }
-
- /**
- * Get instances of database rule builder.
- *
- * @return got instances
- */
- public static Collection<DatabaseRuleBuilder> getInstances() {
- return OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class);
- }
-
- /**
- * Get instance map of database rule builder.
- *
- * @param ruleConfigs rule configurations
- * @return got instance map
- */
- public static Map<RuleConfiguration, DatabaseRuleBuilder> getInstanceMap(final Collection<RuleConfiguration> ruleConfigs) {
- return OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, ruleConfigs);
- }
-
- /**
- * Get instance map of database rule builder.
- *
- * @param ruleConfigs rule configurations
- * @param orderComparator order comparator
- * @return got instance map
- */
- public static Map<RuleConfiguration, DatabaseRuleBuilder> getInstanceMap(final Collection<RuleConfiguration> ruleConfigs, final Comparator<Integer> orderComparator) {
- return OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, ruleConfigs, orderComparator);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilder.java
index 03bc863589c..eeac3450fe8 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilder.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilder.java
@@ -21,14 +21,16 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationCheckerFactory;
+import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
import org.apache.shardingsphere.infra.config.rule.function.DistributedRuleConfiguration;
import org.apache.shardingsphere.infra.config.rule.function.EnhancedRuleConfiguration;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -54,7 +56,11 @@ public final class DatabaseRulesBuilder {
public static Collection<ShardingSphereRule> build(final String databaseName, final DatabaseConfiguration databaseConfig, final InstanceContext instanceContext) {
Collection<ShardingSphereRule> result = new LinkedList<>();
for (Entry<RuleConfiguration, DatabaseRuleBuilder> entry : getRuleBuilderMap(databaseConfig).entrySet()) {
- RuleConfigurationCheckerFactory.findInstance(entry.getKey()).ifPresent(optional -> optional.check(databaseName, entry.getKey(), databaseConfig.getDataSources(), result));
+ RuleConfigurationChecker configChecker = OrderedSPIRegistry.getRegisteredServicesByClass(
+ RuleConfigurationChecker.class, Collections.singleton(entry.getKey().getClass())).get(entry.getKey().getClass());
+ if (null != configChecker) {
+ configChecker.check(databaseName, entry.getKey(), databaseConfig.getDataSources(), result);
+ }
result.add(entry.getValue().build(entry.getKey(), databaseName, databaseConfig.getDataSources(), result, instanceContext));
}
return result;
@@ -72,13 +78,13 @@ public final class DatabaseRulesBuilder {
@SuppressWarnings("rawtypes")
private static Map<RuleConfiguration, DatabaseRuleBuilder> getDistributedRuleBuilderMap(final Collection<RuleConfiguration> ruleConfigs) {
Collection<RuleConfiguration> distributedRuleConfigs = ruleConfigs.stream().filter(each -> isAssignableFrom(each, DistributedRuleConfiguration.class)).collect(Collectors.toList());
- return DatabaseRuleBuilderFactory.getInstanceMap(distributedRuleConfigs, Comparator.reverseOrder());
+ return OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, distributedRuleConfigs, Comparator.reverseOrder());
}
@SuppressWarnings("rawtypes")
private static Map<RuleConfiguration, DatabaseRuleBuilder> getEnhancedRuleBuilderMap(final Collection<RuleConfiguration> ruleConfigs) {
Collection<RuleConfiguration> enhancedRuleConfigs = ruleConfigs.stream().filter(each -> isAssignableFrom(each, EnhancedRuleConfiguration.class)).collect(Collectors.toList());
- return DatabaseRuleBuilderFactory.getInstanceMap(enhancedRuleConfigs);
+ return OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class, enhancedRuleConfigs);
}
private static boolean isAssignableFrom(final RuleConfiguration ruleConfig, final Class<? extends RuleConfiguration> ruleConfigClass) {
@@ -89,7 +95,7 @@ public final class DatabaseRulesBuilder {
private static Map<RuleConfiguration, DatabaseRuleBuilder> getMissedDefaultRuleBuilderMap(final Collection<DatabaseRuleBuilder> configuredBuilders) {
Map<RuleConfiguration, DatabaseRuleBuilder> result = new LinkedHashMap<>();
Map<DatabaseRuleBuilder, DefaultDatabaseRuleConfigurationBuilder> defaultBuilders =
- DefaultDatabaseRuleConfigurationBuilderFactory.getInstances(getMissedDefaultRuleBuilders(configuredBuilders));
+ OrderedSPIRegistry.getRegisteredServices(DefaultDatabaseRuleConfigurationBuilder.class, getMissedDefaultRuleBuilders(configuredBuilders));
// TODO consider about order for new put items
for (Entry<DatabaseRuleBuilder, DefaultDatabaseRuleConfigurationBuilder> entry : defaultBuilders.entrySet()) {
result.put(entry.getValue().build(), entry.getKey());
@@ -100,6 +106,6 @@ public final class DatabaseRulesBuilder {
@SuppressWarnings({"unchecked", "rawtypes"})
private static Collection<DatabaseRuleBuilder> getMissedDefaultRuleBuilders(final Collection<DatabaseRuleBuilder> configuredBuilders) {
Collection<Class<DatabaseRuleBuilder>> configuredBuilderClasses = configuredBuilders.stream().map(each -> (Class<DatabaseRuleBuilder>) each.getClass()).collect(Collectors.toSet());
- return DatabaseRuleBuilderFactory.getInstances().stream().filter(each -> !configuredBuilderClasses.contains(each.getClass())).collect(Collectors.toList());
+ return OrderedSPIRegistry.getRegisteredServices(DatabaseRuleBuilder.class).stream().filter(each -> !configuredBuilderClasses.contains(each.getClass())).collect(Collectors.toList());
}
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DefaultDatabaseRuleConfigurationBuilderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DefaultDatabaseRuleConfigurationBuilderFactory.java
deleted file mode 100644
index 20b82bdca69..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DefaultDatabaseRuleConfigurationBuilderFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.builder.database;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Default database rule configuration builder factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DefaultDatabaseRuleConfigurationBuilderFactory {
-
- static {
- ShardingSphereServiceLoader.register(DefaultDatabaseRuleConfigurationBuilder.class);
- }
-
- /**
- * Get instances of database rule builder.
- *
- * @param builders database rule builders
- * @return got instances
- */
- @SuppressWarnings("rawtypes")
- public static Map<DatabaseRuleBuilder, DefaultDatabaseRuleConfigurationBuilder> getInstances(final Collection<DatabaseRuleBuilder> builders) {
- return OrderedSPIRegistry.getRegisteredServices(DefaultDatabaseRuleConfigurationBuilder.class, builders);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactory.java
deleted file mode 100644
index e7bd0e5dc3c..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.builder.global;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Default global rule configuration builder factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DefaultGlobalRuleConfigurationBuilderFactory {
-
- static {
- ShardingSphereServiceLoader.register(DefaultGlobalRuleConfigurationBuilder.class);
- }
-
- /**
- * Get instance default global rule configuration builder.
- *
- * @param globalRuleBuilders global rule builders
- * @return got instance
- */
- @SuppressWarnings("rawtypes")
- public static Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> getInstance(final Collection<GlobalRuleBuilder> globalRuleBuilders) {
- return OrderedSPIRegistry.getRegisteredServices(DefaultGlobalRuleConfigurationBuilder.class, globalRuleBuilders);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilderFactory.java
deleted file mode 100644
index 87f8e6a015c..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilderFactory.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.builder.global;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * Global rule builder factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class GlobalRuleBuilderFactory {
-
- static {
- ShardingSphereServiceLoader.register(GlobalRuleBuilder.class);
- }
-
- /**
- * Get instance map of global rule builder.
- *
- * @param ruleConfigs rule configurations
- * @return got instance map
- */
- @SuppressWarnings("rawtypes")
- public static Map<RuleConfiguration, GlobalRuleBuilder> getInstanceMap(final Collection<RuleConfiguration> ruleConfigs) {
- return OrderedSPIRegistry.getRegisteredServices(GlobalRuleBuilder.class, ruleConfigs);
- }
-
- /**
- * Get instances of global rule builder.
- *
- * @param builderClasses builder classes
- * @return got instances
- */
- @SuppressWarnings("rawtypes")
- public static Collection<GlobalRuleBuilder> getInstances(final Collection<Class<GlobalRuleBuilder>> builderClasses) {
- return OrderedSPIRegistry.getRegisteredServices(GlobalRuleBuilder.class).stream().filter(each -> !builderClasses.contains(each.getClass())).collect(Collectors.toList());
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
index 961b7aada91..a32811c7fb1 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import java.util.Collection;
import java.util.LinkedHashMap;
@@ -46,8 +47,8 @@ public final class GlobalRulesBuilder {
* @return built rules
*/
@SuppressWarnings({"unchecked", "rawtypes"})
- public static Collection<ShardingSphereRule> buildRules(final Collection<RuleConfiguration> globalRuleConfigs, final Map<String, ShardingSphereDatabase> databases,
- final ConfigurationProperties props) {
+ public static Collection<ShardingSphereRule> buildRules(final Collection<RuleConfiguration> globalRuleConfigs,
+ final Map<String, ShardingSphereDatabase> databases, final ConfigurationProperties props) {
Collection<ShardingSphereRule> result = new LinkedList<>();
for (Entry<RuleConfiguration, GlobalRuleBuilder> entry : getRuleBuilderMap(globalRuleConfigs).entrySet()) {
result.add(entry.getValue().build(entry.getKey(), databases, props));
@@ -58,7 +59,7 @@ public final class GlobalRulesBuilder {
@SuppressWarnings("rawtypes")
private static Map<RuleConfiguration, GlobalRuleBuilder> getRuleBuilderMap(final Collection<RuleConfiguration> globalRuleConfigs) {
Map<RuleConfiguration, GlobalRuleBuilder> result = new LinkedHashMap<>();
- result.putAll(GlobalRuleBuilderFactory.getInstanceMap(globalRuleConfigs));
+ result.putAll(OrderedSPIRegistry.getRegisteredServices(GlobalRuleBuilder.class, globalRuleConfigs));
result.putAll(getMissedDefaultRuleBuilderMap(result));
return result;
}
@@ -66,7 +67,8 @@ public final class GlobalRulesBuilder {
@SuppressWarnings("rawtypes")
private static Map<RuleConfiguration, GlobalRuleBuilder> getMissedDefaultRuleBuilderMap(final Map<RuleConfiguration, GlobalRuleBuilder> builders) {
Map<RuleConfiguration, GlobalRuleBuilder> result = new LinkedHashMap<>();
- Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> defaultBuilders = DefaultGlobalRuleConfigurationBuilderFactory.getInstance(getMissedDefaultRuleBuilders(builders.values()));
+ Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> defaultBuilders = OrderedSPIRegistry.getRegisteredServices(
+ DefaultGlobalRuleConfigurationBuilder.class, getMissedDefaultRuleBuilders(builders.values()));
for (Entry<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> entry : defaultBuilders.entrySet()) {
result.put(entry.getValue().build(), entry.getKey());
}
@@ -76,6 +78,6 @@ public final class GlobalRulesBuilder {
@SuppressWarnings({"unchecked", "rawtypes"})
private static Collection<GlobalRuleBuilder> getMissedDefaultRuleBuilders(final Collection<GlobalRuleBuilder> configuredBuilders) {
Collection<Class<GlobalRuleBuilder>> configuredBuilderClasses = configuredBuilders.stream().map(each -> (Class<GlobalRuleBuilder>) each.getClass()).collect(Collectors.toSet());
- return GlobalRuleBuilderFactory.getInstances(configuredBuilderClasses);
+ return OrderedSPIRegistry.getRegisteredServices(GlobalRuleBuilder.class).stream().filter(each -> !configuredBuilderClasses.contains(each.getClass())).collect(Collectors.toList());
}
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/shortcut/YamlRuleConfigurationShortcuts.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/shortcut/YamlRuleConfigurationShortcuts.java
index eeed27c192c..021aa337646 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/shortcut/YamlRuleConfigurationShortcuts.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/shortcut/YamlRuleConfigurationShortcuts.java
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.infra.yaml.config.shortcut;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.util.yaml.shortcuts.ShardingSphereYamlShortcuts;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
-import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperFactory;
import java.lang.reflect.ParameterizedType;
import java.util.Collection;
@@ -36,7 +36,7 @@ public final class YamlRuleConfigurationShortcuts implements ShardingSphereYamlS
@Override
@SneakyThrows(ReflectiveOperationException.class)
public Map<String, Class<?>> getYamlShortcuts() {
- Collection<YamlRuleConfigurationSwapper> swappers = YamlRuleConfigurationSwapperFactory.getAllInstances();
+ Collection<YamlRuleConfigurationSwapper> swappers = ShardingSphereServiceLoader.getServiceInstances(YamlRuleConfigurationSwapper.class);
Map<String, Class<?>> result = new HashMap<>(swappers.size(), 1);
for (YamlRuleConfigurationSwapper each : swappers) {
Class<?> yamlRuleConfigurationClass = Class.forName(((ParameterizedType) each.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0].getTypeName());
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/YamlModeConfigurationSwapper.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/YamlModeConfigurationSwapper.java
index ea80d324777..f748004499d 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/YamlModeConfigurationSwapper.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/YamlModeConfigurationSwapper.java
@@ -19,12 +19,14 @@ package org.apache.shardingsphere.infra.yaml.config.swapper.mode;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlModeConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
+import org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlModeConfiguration;
/**
* YAML mode configuration swapper.
*/
+@SuppressWarnings("unchecked")
public final class YamlModeConfigurationSwapper implements YamlConfigurationSwapper<YamlModeConfiguration, ModeConfiguration> {
@Override
@@ -32,7 +34,8 @@ public final class YamlModeConfigurationSwapper implements YamlConfigurationSwap
YamlModeConfiguration result = new YamlModeConfiguration();
result.setType(data.getType());
if (null != data.getRepository()) {
- YamlPersistRepositoryConfigurationSwapper<PersistRepositoryConfiguration> swapper = YamlPersistRepositoryConfigurationSwapperFactory.getInstance(data.getType());
+ YamlPersistRepositoryConfigurationSwapper<PersistRepositoryConfiguration> swapper = TypedSPIRegistry.getRegisteredService(
+ YamlPersistRepositoryConfigurationSwapper.class, data.getType());
result.setRepository(swapper.swapToYamlConfiguration(data.getRepository()));
}
return result;
@@ -43,7 +46,8 @@ public final class YamlModeConfigurationSwapper implements YamlConfigurationSwap
if (null == yamlConfig.getRepository()) {
return new ModeConfiguration(yamlConfig.getType(), null);
}
- YamlPersistRepositoryConfigurationSwapper<PersistRepositoryConfiguration> swapper = YamlPersistRepositoryConfigurationSwapperFactory.getInstance(yamlConfig.getType());
+ YamlPersistRepositoryConfigurationSwapper<PersistRepositoryConfiguration> swapper = TypedSPIRegistry.getRegisteredService(
+ YamlPersistRepositoryConfigurationSwapper.class, yamlConfig.getType());
return new ModeConfiguration(yamlConfig.getType(), swapper.swapToObject(yamlConfig.getRepository()));
}
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/YamlPersistRepositoryConfigurationSwapperFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/YamlPersistRepositoryConfigurationSwapperFactory.java
deleted file mode 100644
index 9417c03c077..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/mode/YamlPersistRepositoryConfigurationSwapperFactory.java
+++ /dev/null
@@ -1,46 +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.yaml.config.swapper.mode;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
-
-/**
- * YAML persist repository configuration swapper factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class YamlPersistRepositoryConfigurationSwapperFactory {
-
- static {
- ShardingSphereServiceLoader.register(YamlPersistRepositoryConfigurationSwapper.class);
- }
-
- /**
- * Get instance of YAML persist repository configuration swapper.
- *
- * @param type swapper type
- * @return got instance
- */
- @SuppressWarnings("unchecked")
- public static YamlPersistRepositoryConfigurationSwapper<PersistRepositoryConfiguration> getInstance(final String type) {
- return TypedSPIRegistry.getRegisteredService(YamlPersistRepositoryConfigurationSwapper.class, type);
- }
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperEngine.java
index 365e759aad2..9f302690930 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperEngine.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperEngine.java
@@ -18,10 +18,10 @@
package org.apache.shardingsphere.infra.yaml.config.swapper.rule;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.stream.Collectors;
@@ -39,7 +39,7 @@ public final class YamlRuleConfigurationSwapperEngine {
*/
@SuppressWarnings("unchecked")
public Collection<YamlRuleConfiguration> swapToYamlRuleConfigurations(final Collection<RuleConfiguration> ruleConfigs) {
- return YamlRuleConfigurationSwapperFactory.getInstanceMapByRuleConfigurations(ruleConfigs).entrySet().stream()
+ return OrderedSPIRegistry.getRegisteredServices(YamlRuleConfigurationSwapper.class, ruleConfigs).entrySet().stream()
.map(entry -> (YamlRuleConfiguration) entry.getValue().swapToYamlConfiguration(entry.getKey())).collect(Collectors.toList());
}
@@ -53,7 +53,7 @@ public final class YamlRuleConfigurationSwapperEngine {
public Collection<RuleConfiguration> swapToRuleConfigurations(final Collection<YamlRuleConfiguration> yamlRuleConfigs) {
Collection<RuleConfiguration> result = new LinkedList<>();
Collection<Class<?>> ruleConfigTypes = yamlRuleConfigs.stream().map(YamlRuleConfiguration::getRuleConfigurationType).collect(Collectors.toList());
- for (Entry<Class<?>, YamlRuleConfigurationSwapper> entry : YamlRuleConfigurationSwapperFactory.getInstanceMapByRuleConfigurationClasses(ruleConfigTypes).entrySet()) {
+ for (Entry<Class<?>, YamlRuleConfigurationSwapper> entry : OrderedSPIRegistry.getRegisteredServicesByClass(YamlRuleConfigurationSwapper.class, ruleConfigTypes).entrySet()) {
result.addAll(swapToRuleConfigurations(yamlRuleConfigs, entry.getKey(), entry.getValue()));
}
return result;
@@ -65,17 +65,4 @@ public final class YamlRuleConfigurationSwapperEngine {
return yamlRuleConfigs.stream()
.filter(each -> each.getRuleConfigurationType().equals(ruleConfigType)).map(each -> (RuleConfiguration) swapper.swapToObject(each)).collect(Collectors.toList());
}
-
- /**
- * Swap from YAML rule configuration to rule configuration.
- *
- * @param yamlRuleConfig YAML rule configuration
- * @return rule configuration
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public RuleConfiguration swapToRuleConfiguration(final YamlRuleConfiguration yamlRuleConfig) {
- Collection<Class<?>> types = Collections.singletonList(yamlRuleConfig.getRuleConfigurationType());
- YamlRuleConfigurationSwapper swapper = YamlRuleConfigurationSwapperFactory.getInstanceMapByRuleConfigurationClasses(types).get(yamlRuleConfig.getRuleConfigurationType());
- return (RuleConfiguration) swapper.swapToObject(yamlRuleConfig);
- }
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperFactory.java
deleted file mode 100644
index f86a88c4819..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperFactory.java
+++ /dev/null
@@ -1,70 +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.yaml.config.swapper.rule;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * YAML rule configuration swapper factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class YamlRuleConfigurationSwapperFactory {
-
- static {
- ShardingSphereServiceLoader.register(YamlRuleConfigurationSwapper.class);
- }
-
- /**
- * Get instance map of YAML rule configuration swapper.
- *
- * @param ruleConfigs rule configurations
- * @return instance map of rule configuration and YAML rule configuration swapper
- */
- @SuppressWarnings("rawtypes")
- public static Map<RuleConfiguration, YamlRuleConfigurationSwapper> getInstanceMapByRuleConfigurations(final Collection<RuleConfiguration> ruleConfigs) {
- return OrderedSPIRegistry.getRegisteredServices(YamlRuleConfigurationSwapper.class, ruleConfigs);
- }
-
- /**
- * Get instance map of YAML rule configuration swapper.
- *
- * @param ruleConfigTypes rule configurations types
- * @return got instance map
- */
- @SuppressWarnings("rawtypes")
- public static Map<Class<?>, YamlRuleConfigurationSwapper> getInstanceMapByRuleConfigurationClasses(final Collection<Class<?>> ruleConfigTypes) {
- return OrderedSPIRegistry.getRegisteredServicesByClass(YamlRuleConfigurationSwapper.class, ruleConfigTypes);
- }
-
- /**
- * Get all instances of all YAML rule configuration swappers.
- *
- * @return got instances
- */
- @SuppressWarnings("rawtypes")
- public static Collection<YamlRuleConfigurationSwapper> getAllInstances() {
- return ShardingSphereServiceLoader.getServiceInstances(YamlRuleConfigurationSwapper.class);
- }
-}
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
index 0f3ad219371..a2941a294a8 100644
--- 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
@@ -17,10 +17,8 @@
package org.apache.shardingsphere.infra.algorithm;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.algorithm.fixture.ShardingSphereAlgorithmFixture;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.junit.BeforeClass;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.junit.Test;
import java.util.Properties;
@@ -31,11 +29,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
public final class ShardingSphereAlgorithmFactoryTest {
- @BeforeClass
- public static void setUp() {
- ShardingSphereServiceLoader.register(ShardingSphereAlgorithm.class);
- }
-
@Test
public void assertCreateAlgorithm() {
Properties props = new Properties();
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/RuleConfigurationCheckerFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/RuleConfigurationCheckerFactoryTest.java
deleted file mode 100644
index 42475672bb5..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/RuleConfigurationCheckerFactoryTest.java
+++ /dev/null
@@ -1,47 +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.config.rule.checker;
-
-import org.apache.shardingsphere.infra.config.rule.checker.fixture.RuleConfigurationCheckerFixture;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration;
-import org.junit.Test;
-
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertFalse;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class RuleConfigurationCheckerFactoryTest {
-
- @SuppressWarnings("rawtypes")
- @Test
- public void assertFindInstance() {
- Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(new FixtureRuleConfiguration());
- assertTrue(checker.isPresent());
- assertThat(checker.get(), instanceOf(RuleConfigurationCheckerFixture.class));
- }
-
- @Test
- public void assertFindInstanceWithoutChecker() {
- assertFalse(RuleConfigurationCheckerFactory.findInstance(mock(RuleConfiguration.class)).isPresent());
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/fixture/RuleConfigurationCheckerFixture.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/fixture/RuleConfigurationCheckerFixture.java
deleted file mode 100644
index ec91693bf30..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/fixture/RuleConfigurationCheckerFixture.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.config.rule.checker.fixture;
-
-import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
-import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.Map;
-
-public final class RuleConfigurationCheckerFixture implements RuleConfigurationChecker<FixtureRuleConfiguration> {
-
- @Override
- public void check(final String databaseName, final FixtureRuleConfiguration config, final Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> rules) {
- }
-
- @Override
- public int getOrder() {
- return -10;
- }
-
- @Override
- public Class<FixtureRuleConfiguration> getTypeClass() {
- return FixtureRuleConfiguration.class;
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
index f0f22e15ee0..a2471bae54f 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.wrapper.SQLWrapperException;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
import org.junit.Test;
@@ -58,7 +59,7 @@ public final class DatabaseTypeEngineTest {
@Test
public void assertGetProtocolTypeFromDataSource() throws SQLException {
- DataSource datasource = mockDataSource(DatabaseTypeFactory.getInstance("PostgreSQL"));
+ DataSource datasource = mockDataSource(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "PostgreSQL"));
DatabaseConfiguration databaseConfig = new DataSourceProvidedDatabaseConfiguration(Collections.singletonMap("foo_ds", datasource), Collections.singleton(new FixtureRuleConfiguration()));
assertThat(DatabaseTypeEngine.getProtocolType("sharding_db", databaseConfig, new ConfigurationProperties(new Properties())), instanceOf(PostgreSQLDatabaseType.class));
assertThat(DatabaseTypeEngine.getProtocolType(Collections.singletonMap("foo_db", databaseConfig), new ConfigurationProperties(new Properties())), instanceOf(PostgreSQLDatabaseType.class));
@@ -66,7 +67,7 @@ public final class DatabaseTypeEngineTest {
@Test
public void assertGetStorageTypes() throws SQLException {
- DataSource datasource = mockDataSource(DatabaseTypeFactory.getInstance("MySQL"));
+ DataSource datasource = mockDataSource(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL"));
DatabaseConfiguration databaseConfig = new DataSourceProvidedDatabaseConfiguration(Collections.singletonMap("foo_db", datasource), Collections.singletonList(new FixtureRuleConfiguration()));
assertTrue(DatabaseTypeEngine.getStorageTypes("foo_db", databaseConfig).containsKey("foo_db"));
assertThat(DatabaseTypeEngine.getStorageTypes("foo_db", databaseConfig).get("foo_db"), instanceOf(MySQLDatabaseType.class));
@@ -79,13 +80,15 @@ public final class DatabaseTypeEngineTest {
@Test
public void assertGetStorageTypeWithDataSources() throws SQLException {
- Collection<DataSource> dataSources = Arrays.asList(mockDataSource(DatabaseTypeFactory.getInstance("H2")), mockDataSource(DatabaseTypeFactory.getInstance("H2")));
+ Collection<DataSource> dataSources = Arrays.asList(mockDataSource(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "H2")),
+ mockDataSource(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "H2")));
assertThat(DatabaseTypeEngine.getStorageType(dataSources).getType(), is("H2"));
}
@Test
public void assertGetStorageTypeWithDifferentDataSourceTypes() throws SQLException {
- Collection<DataSource> dataSources = Arrays.asList(mockDataSource(DatabaseTypeFactory.getInstance("H2")), mockDataSource(DatabaseTypeFactory.getInstance("MySQL")));
+ Collection<DataSource> dataSources = Arrays.asList(mockDataSource(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "H2")),
+ mockDataSource(TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL")));
assertThat(DatabaseTypeEngine.getStorageType(dataSources).getType(), is("H2"));
}
@@ -147,9 +150,9 @@ public final class DatabaseTypeEngineTest {
@Test
public void assertGetDefaultSchemaName() {
- DatabaseType schemaSupportDatabaseType = DatabaseTypeFactory.getInstance("openGauss");
+ DatabaseType schemaSupportDatabaseType = TypedSPIRegistry.getRegisteredService(DatabaseType.class, "openGauss");
assertThat(DatabaseTypeEngine.getDefaultSchemaName(schemaSupportDatabaseType, ""), is("public"));
- DatabaseType schemaNoSupportDatabaseType = DatabaseTypeFactory.getInstance("MySQL");
+ DatabaseType schemaNoSupportDatabaseType = TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL");
assertThat(DatabaseTypeEngine.getDefaultSchemaName(schemaNoSupportDatabaseType, "MySQL"), is("mysql"));
}
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeFactoryTest.java
deleted file mode 100644
index 5d0ddb93623..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeFactoryTest.java
+++ /dev/null
@@ -1,68 +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.database.type;
-
-import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.MariaDBDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.OracleDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.SQL92DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.SQLServerDatabaseType;
-import org.apache.shardingsphere.infra.fixture.InfraDatabaseTypeFixture;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class DatabaseTypeFactoryTest {
-
- @Test
- public void assertGetInstance() {
- assertThat(DatabaseTypeFactory.getInstance("INFRA.FIXTURE"), instanceOf(InfraDatabaseTypeFixture.class));
- assertThat(DatabaseTypeFactory.getInstance("SQL92"), instanceOf(SQL92DatabaseType.class));
- assertThat(DatabaseTypeFactory.getInstance("MySQL"), instanceOf(MySQLDatabaseType.class));
- assertThat(DatabaseTypeFactory.getInstance("MariaDB"), instanceOf(MariaDBDatabaseType.class));
- assertThat(DatabaseTypeFactory.getInstance("PostgreSQL"), instanceOf(PostgreSQLDatabaseType.class));
- assertThat(DatabaseTypeFactory.getInstance("OpenGauss"), instanceOf(OpenGaussDatabaseType.class));
- assertThat(DatabaseTypeFactory.getInstance("Oracle"), instanceOf(OracleDatabaseType.class));
- assertThat(DatabaseTypeFactory.getInstance("SQLServer"), instanceOf(SQLServerDatabaseType.class));
- assertThat(DatabaseTypeFactory.getInstance("H2"), instanceOf(H2DatabaseType.class));
- }
-
- @Test
- public void assertGetInstances() {
- Collection<DatabaseType> actual = DatabaseTypeFactory.getInstances();
- assertThat(actual.size(), is(9));
- Iterator<DatabaseType> iterator = actual.iterator();
- assertThat(iterator.next(), instanceOf(InfraDatabaseTypeFixture.class));
- assertThat(iterator.next(), instanceOf(SQL92DatabaseType.class));
- assertThat(iterator.next(), instanceOf(MySQLDatabaseType.class));
- assertThat(iterator.next(), instanceOf(MariaDBDatabaseType.class));
- assertThat(iterator.next(), instanceOf(PostgreSQLDatabaseType.class));
- assertThat(iterator.next(), instanceOf(OpenGaussDatabaseType.class));
- assertThat(iterator.next(), instanceOf(OracleDatabaseType.class));
- assertThat(iterator.next(), instanceOf(SQLServerDatabaseType.class));
- assertThat(iterator.next(), instanceOf(H2DatabaseType.class));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactoryTest.java
deleted file mode 100644
index 5eadc60b25a..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactoryTest.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.datanode;
-
-import org.apache.shardingsphere.infra.fixture.DataNodeBuilderFixture;
-import org.apache.shardingsphere.infra.fixture.FixtureRule;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class DataNodeBuilderFactoryTest {
-
- @SuppressWarnings("rawtypes")
- @Test
- public void assertGetInstances() {
- FixtureRule rule = new FixtureRule();
- Map<ShardingSphereRule, DataNodeBuilder> actual = DataNodeBuilderFactory.getInstances(Collections.singleton(rule));
- assertThat(actual.size(), is(1));
- assertThat(actual.get(rule), instanceOf(DataNodeBuilderFixture.class));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/detector/DataSourcePoolActiveDetectorFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/detector/DataSourcePoolActiveDetectorFactoryTest.java
deleted file mode 100644
index 50197132e3e..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/detector/DataSourcePoolActiveDetectorFactoryTest.java
+++ /dev/null
@@ -1,40 +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.datasource.pool.destroyer.detector;
-
-import com.zaxxer.hikari.HikariDataSource;
-import org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.type.DefaultDataSourcePoolActiveDetector;
-import org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.type.HikariDataSourcePoolActiveDetector;
-import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class DataSourcePoolActiveDetectorFactoryTest {
-
- @Test
- public void assertGetDefaultInstance() {
- assertThat(DataSourcePoolActiveDetectorFactory.getInstance(MockedDataSource.class.getName()), instanceOf(DefaultDataSourcePoolActiveDetector.class));
- }
-
- @Test
- public void assertGetHikariInstance() {
- assertThat(DataSourcePoolActiveDetectorFactory.getInstance(HikariDataSource.class.getName()), instanceOf(HikariDataSourcePoolActiveDetector.class));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/metadata/DataSourcePoolMetaDataFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/metadata/DataSourcePoolMetaDataFactoryTest.java
deleted file mode 100644
index 479340f8098..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/metadata/DataSourcePoolMetaDataFactoryTest.java
+++ /dev/null
@@ -1,38 +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.datasource.pool.metadata;
-
-import org.apache.shardingsphere.infra.datasource.pool.metadata.fixture.MockedDataSourcePoolMetaData;
-import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
-import org.junit.Test;
-
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class DataSourcePoolMetaDataFactoryTest {
-
- @Test
- public void assertFindInstance() {
- Optional<DataSourcePoolMetaData> actual = DataSourcePoolMetaDataFactory.findInstance(MockedDataSource.class.getName());
- assertTrue(actual.isPresent());
- assertThat(actual.get(), instanceOf(MockedDataSourcePoolMetaData.class));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilderFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactoryTest.java
similarity index 62%
rename from infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilderFactoryTest.java
rename to infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactoryTest.java
index 9f84b78853e..8456a46d5cf 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataBuilderFactoryTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/metadata/InstanceMetaDataFactoryTest.java
@@ -20,35 +20,15 @@ package org.apache.shardingsphere.infra.instance.metadata;
import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotNull;
-public final class InstanceMetaDataBuilderFactoryTest {
-
- @Test
- public void assertCreateJDBCInstanceMetaDataWithoutInstanceId() {
- InstanceMetaData actual = InstanceMetaDataBuilderFactory.create("JDBC", -1);
- assertNotNull(actual.getId());
- assertNotNull(actual.getIp());
- assertThat(actual.getAttributes(), is(""));
- assertThat(actual.getType(), is(InstanceType.JDBC));
- }
-
- @Test
- public void assertCreateProxyInstanceMetaDataWithoutInstanceId() {
- ProxyInstanceMetaData actual = (ProxyInstanceMetaData) InstanceMetaDataBuilderFactory.create("Proxy", 3307);
- assertNotNull(actual.getId());
- assertNotNull(actual.getIp());
- assertThat(actual.getPort(), is(3307));
- assertThat(actual.getAttributes(), endsWith("@3307"));
- assertThat(actual.getType(), is(InstanceType.PROXY));
- }
+public final class InstanceMetaDataFactoryTest {
@Test
public void assertCreateJDBCInstanceMetaDataWithInstanceId() {
- InstanceMetaData actual = InstanceMetaDataBuilderFactory.create("foo_id", InstanceType.JDBC, "", "foo_version");
+ InstanceMetaData actual = InstanceMetaDataFactory.create("foo_id", InstanceType.JDBC, "", "foo_version");
assertThat(actual.getId(), is("foo_id"));
assertNotNull(actual.getIp());
assertThat(actual.getAttributes(), is(""));
@@ -58,7 +38,7 @@ public final class InstanceMetaDataBuilderFactoryTest {
@Test
public void assertCreateProxyInstanceMetaDataWithInstanceId() {
- ProxyInstanceMetaData actual = (ProxyInstanceMetaData) InstanceMetaDataBuilderFactory.create("foo_id", InstanceType.PROXY, "127.0.0.1@3307", "foo_version");
+ ProxyInstanceMetaData actual = (ProxyInstanceMetaData) InstanceMetaDataFactory.create("foo_id", InstanceType.PROXY, "127.0.0.1@3307", "foo_version");
assertThat(actual.getId(), is("foo_id"));
assertThat(actual.getIp(), is("127.0.0.1"));
assertThat(actual.getPort(), is(3307));
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/spi/RuleBasedSchemaMetaDataDecoratorFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/spi/RuleBasedSchemaMetaDataDecoratorFactoryTest.java
deleted file mode 100644
index d30739743f7..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/spi/RuleBasedSchemaMetaDataDecoratorFactoryTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.database.schema.builder.spi;
-
-import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecoratorFactory;
-import org.apache.shardingsphere.infra.metadata.database.schema.fixture.loader.RuleBasedSchemaMetaDataDecoratorFixture;
-import org.apache.shardingsphere.infra.metadata.database.schema.fixture.rule.TableContainedFixtureRule;
-import org.junit.Test;
-
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class RuleBasedSchemaMetaDataDecoratorFactoryTest {
-
- @Test
- public void assertGetInstances() {
- TableContainedFixtureRule rule = new TableContainedFixtureRule();
- assertThat(RuleBasedSchemaMetaDataDecoratorFactory.getInstances(Collections.singleton(rule)).get(rule), instanceOf(RuleBasedSchemaMetaDataDecoratorFixture.class));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/RuleBasedSchemaMetaDataDecoratorFixture.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/RuleBasedSchemaMetaDataDecoratorFixture.java
deleted file mode 100644
index e304b656b1f..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/RuleBasedSchemaMetaDataDecoratorFixture.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.metadata.database.schema.fixture.loader;
-
-import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial;
-import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator;
-import org.apache.shardingsphere.infra.metadata.database.schema.fixture.rule.TableContainedFixtureRule;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
-
-import java.util.Map;
-
-public final class RuleBasedSchemaMetaDataDecoratorFixture implements RuleBasedSchemaMetaDataDecorator<TableContainedFixtureRule> {
-
- @Override
- public Map<String, SchemaMetaData> decorate(final Map<String, SchemaMetaData> schemaMetaDataMap, final TableContainedFixtureRule rule, final GenericSchemaBuilderMaterial material) {
- return schemaMetaDataMap;
- }
-
- @Override
- public int getOrder() {
- return 1;
- }
-
- @Override
- public Class<TableContainedFixtureRule> getTypeClass() {
- return TableContainedFixtureRule.class;
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/common/DataTypeLoaderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/common/DataTypeLoaderTest.java
deleted file mode 100644
index cfbb3eaffcd..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/common/DataTypeLoaderTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.database.schema.loader.common;
-
-import org.apache.shardingsphere.infra.fixture.InfraDatabaseTypeFixture;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DataTypeLoaderFactory;
-import org.junit.Test;
-
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class DataTypeLoaderTest {
-
- @Test
- public void assertLoad() throws SQLException {
- ResultSet resultSet = mock(ResultSet.class);
- when(resultSet.next()).thenReturn(true, true, false);
- when(resultSet.getString("TYPE_NAME")).thenReturn("int", "varchar");
- when(resultSet.getInt("DATA_TYPE")).thenReturn(Types.INTEGER, Types.VARCHAR);
- DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
- when(databaseMetaData.getTypeInfo()).thenReturn(resultSet);
- Map<String, Integer> actual = DataTypeLoaderFactory.getInstance(new InfraDatabaseTypeFixture()).load(databaseMetaData);
- assertThat(actual.size(), is(2));
- assertThat(actual.get("INT"), is(Types.INTEGER));
- assertThat(actual.get("VARCHAR"), is(Types.VARCHAR));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/H2SchemaMetaDataLoaderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/H2SchemaMetaDataLoaderTest.java
index 8db6a2f5004..0d9151d6835 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/H2SchemaMetaDataLoaderTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/H2SchemaMetaDataLoaderTest.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoaderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.junit.Test;
import javax.sql.DataSource;
@@ -147,7 +147,8 @@ public final class H2SchemaMetaDataLoaderTest {
}
private DialectSchemaMetaDataLoader getDialectTableMetaDataLoader() {
- Optional<DialectSchemaMetaDataLoader> result = DialectSchemaMetaDataLoaderFactory.findInstance(DatabaseTypeFactory.getInstance("H2"));
+ Optional<DialectSchemaMetaDataLoader> result = TypedSPIRegistry.findRegisteredService(
+ DialectSchemaMetaDataLoader.class, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "H2").getType());
assertTrue(result.isPresent());
return result.get();
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/MySQLSchemaMetaDataLoaderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/MySQLSchemaMetaDataLoaderTest.java
index eb8cb60269e..55f589ef9df 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/MySQLSchemaMetaDataLoaderTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/MySQLSchemaMetaDataLoaderTest.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoaderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.junit.Test;
import javax.sql.DataSource;
@@ -108,7 +108,8 @@ public final class MySQLSchemaMetaDataLoaderTest {
}
private DialectSchemaMetaDataLoader getDialectTableMetaDataLoader() {
- Optional<DialectSchemaMetaDataLoader> result = DialectSchemaMetaDataLoaderFactory.findInstance(DatabaseTypeFactory.getInstance("MySQL"));
+ Optional<DialectSchemaMetaDataLoader> result = TypedSPIRegistry.findRegisteredService(
+ DialectSchemaMetaDataLoader.class, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "MySQL").getType());
assertTrue(result.isPresent());
return result.get();
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OracleSchemaMetaDataLoaderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OracleSchemaMetaDataLoaderTest.java
index 4ebae45e5f1..b6450f61c88 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OracleSchemaMetaDataLoaderTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/OracleSchemaMetaDataLoaderTest.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoaderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.junit.Test;
import javax.sql.DataSource;
@@ -228,7 +228,8 @@ public final class OracleSchemaMetaDataLoaderTest {
}
private DialectSchemaMetaDataLoader getDialectTableMetaDataLoader() {
- Optional<DialectSchemaMetaDataLoader> result = DialectSchemaMetaDataLoaderFactory.findInstance(DatabaseTypeFactory.getInstance("Oracle"));
+ Optional<DialectSchemaMetaDataLoader> result = TypedSPIRegistry.findRegisteredService(
+ DialectSchemaMetaDataLoader.class, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "Oracle").getType());
assertTrue(result.isPresent());
return result.get();
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/PostgreSQLSchemaMetaDataLoaderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/PostgreSQLSchemaMetaDataLoaderTest.java
index 227cbab4abf..312f4850b6d 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/PostgreSQLSchemaMetaDataLoaderTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/PostgreSQLSchemaMetaDataLoaderTest.java
@@ -17,14 +17,14 @@
package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ConstraintMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoaderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.junit.Test;
import javax.sql.DataSource;
@@ -173,7 +173,8 @@ public final class PostgreSQLSchemaMetaDataLoaderTest {
}
private DialectSchemaMetaDataLoader getDialectTableMetaDataLoader() {
- Optional<DialectSchemaMetaDataLoader> result = DialectSchemaMetaDataLoaderFactory.findInstance(DatabaseTypeFactory.getInstance("PostgreSQL"));
+ Optional<DialectSchemaMetaDataLoader> result = TypedSPIRegistry.findRegisteredService(
+ DialectSchemaMetaDataLoader.class, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "PostgreSQL").getType());
assertTrue(result.isPresent());
return result.get();
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/SQLServerSchemaMetaDataLoaderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/SQLServerSchemaMetaDataLoaderTest.java
index 84362f2fbfd..34d686dcc57 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/SQLServerSchemaMetaDataLoaderTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/SQLServerSchemaMetaDataLoaderTest.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoader;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.spi.DialectSchemaMetaDataLoaderFactory;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
import org.junit.Test;
import javax.sql.DataSource;
@@ -190,7 +190,8 @@ public final class SQLServerSchemaMetaDataLoaderTest {
}
private DialectSchemaMetaDataLoader getDialectTableMetaDataLoader() {
- Optional<DialectSchemaMetaDataLoader> result = DialectSchemaMetaDataLoaderFactory.findInstance(DatabaseTypeFactory.getInstance("SQLServer"));
+ Optional<DialectSchemaMetaDataLoader> result = TypedSPIRegistry.findRegisteredService(
+ DialectSchemaMetaDataLoader.class, TypedSPIRegistry.getRegisteredService(DatabaseType.class, "SQLServer").getType());
assertTrue(result.isPresent());
return result.get();
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/spi/DialectSchemaMetaDataLoaderFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/spi/DialectSchemaMetaDataLoaderFactoryTest.java
deleted file mode 100644
index 63cc646caa1..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/spi/DialectSchemaMetaDataLoaderFactoryTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.database.schema.loader.spi;
-
-import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
-import org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect.H2SchemaMetaDataLoader;
-import org.junit.Test;
-
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class DialectSchemaMetaDataLoaderFactoryTest {
-
- @Test
- public void assertFindInstance() {
- Optional<DialectSchemaMetaDataLoader> actual = DialectSchemaMetaDataLoaderFactory.findInstance(new H2DatabaseType());
- assertTrue(actual.isPresent());
- assertThat(actual.get(), instanceOf(H2SchemaMetaDataLoader.class));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactoryTest.java
deleted file mode 100644
index d6e8516f9ab..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactoryTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.builder.database;
-
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration;
-import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureDatabaseRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureDatabaseRuleConfiguration;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertFalse;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class DatabaseRuleBuilderFactoryTest {
-
- @SuppressWarnings("rawtypes")
- @Test
- public void assertGetInstances() {
- Iterator<DatabaseRuleBuilder> actual = DatabaseRuleBuilderFactory.getInstances().iterator();
- assertThat(actual.next(), instanceOf(FixtureDatabaseRuleBuilder.class));
- assertFalse(actual.hasNext());
- }
-
- @Test
- public void assertGetInstanceMap() {
- FixtureDatabaseRuleConfiguration ruleConfig = new FixtureDatabaseRuleConfiguration();
- assertThat(DatabaseRuleBuilderFactory.getInstanceMap(Collections.singleton(ruleConfig)).get(ruleConfig), instanceOf(FixtureDatabaseRuleBuilder.class));
- }
-
- @Test
- public void assertGetInstanceMapWithComparator() {
- Iterator<RuleConfiguration> actual = DatabaseRuleBuilderFactory.getInstanceMap(
- Arrays.asList(new FixtureDatabaseRuleConfiguration(), new FixtureRuleConfiguration()), Comparator.naturalOrder()).keySet().iterator();
- assertThat(actual.next(), instanceOf(FixtureDatabaseRuleConfiguration.class));
- assertFalse(actual.hasNext());
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DefaultDatabaseRuleConfigurationBuilderFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DefaultDatabaseRuleConfigurationBuilderFactoryTest.java
deleted file mode 100644
index ffd5be6f5b0..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DefaultDatabaseRuleConfigurationBuilderFactoryTest.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.rule.builder.database;
-
-import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureDatabaseRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureDatabaseRuleConfigurationBuilder;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class DefaultDatabaseRuleConfigurationBuilderFactoryTest {
-
- @Test
- @SuppressWarnings("rawtypes")
- public void assertGetInstances() {
- FixtureDatabaseRuleBuilder builder = new FixtureDatabaseRuleBuilder();
- Map<DatabaseRuleBuilder, DefaultDatabaseRuleConfigurationBuilder> actual = DefaultDatabaseRuleConfigurationBuilderFactory.getInstances(Collections.singleton(builder));
- assertThat(actual.get(builder), instanceOf(FixtureDatabaseRuleConfigurationBuilder.class));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleConfigurationBuilder.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleConfigurationBuilder.java
deleted file mode 100644
index 35806255bc8..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleConfigurationBuilder.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.builder.fixture;
-
-import org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder;
-
-public final class FixtureGlobalRuleConfigurationBuilder implements DefaultGlobalRuleConfigurationBuilder<FixtureGlobalRuleConfiguration, FixtureGlobalRuleBuilder> {
-
- @Override
- public FixtureGlobalRuleConfiguration build() {
- return new FixtureGlobalRuleConfiguration();
- }
-
- @Override
- public int getOrder() {
- return 0;
- }
-
- @Override
- public Class<FixtureGlobalRuleBuilder> getTypeClass() {
- return FixtureGlobalRuleBuilder.class;
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactoryTest.java
deleted file mode 100644
index 9458baa9dd3..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactoryTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.builder.global;
-
-import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleConfigurationBuilder;
-import org.junit.Test;
-
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class DefaultGlobalRuleConfigurationBuilderFactoryTest {
-
- @Test
- public void assertGetInstance() {
- FixtureGlobalRuleBuilder builder = new FixtureGlobalRuleBuilder();
- assertThat(DefaultGlobalRuleConfigurationBuilderFactory.getInstance(Collections.singleton(builder)).get(builder), instanceOf(FixtureGlobalRuleConfigurationBuilder.class));
- }
-}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilderFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilderFactoryTest.java
deleted file mode 100644
index da17e52c8f0..00000000000
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilderFactoryTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.builder.global;
-
-import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleBuilder;
-import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleConfiguration;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class GlobalRuleBuilderFactoryTest {
-
- @Test
- public void assertGetInstanceMap() {
- FixtureGlobalRuleConfiguration ruleConfig = new FixtureGlobalRuleConfiguration();
- assertThat(GlobalRuleBuilderFactory.getInstanceMap(Collections.singletonList(ruleConfig)).get(ruleConfig), instanceOf(FixtureGlobalRuleBuilder.class));
- }
-
- @SuppressWarnings("rawtypes")
- @Test
- public void assertGetInstancesWithoutAssignedGlobalRuleBuilderClasses() {
- Collection<GlobalRuleBuilder> actual = GlobalRuleBuilderFactory.getInstances(Collections.emptyList());
- assertThat(actual.size(), is(1));
- assertThat(actual.iterator().next(), instanceOf(FixtureGlobalRuleBuilder.class));
... 13259 lines suppressed ...