Repository: apache/incubator-shardingsphere
Pull request #5015 (2020-03-31 06:21:01)

Establish ShardingSphereServiceLoader
For #3691.



Patch:
diff --git a/encrypt-core/encrypt-core-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/Encryptor.java b/encrypt-core/encrypt-core-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/Encryptor.java
index 5b7a53aeb1d..854f32b33d9 100644
--- a/encrypt-core/encrypt-core-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/Encryptor.java
+++ b/encrypt-core/encrypt-core-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/Encryptor.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.encrypt.strategy.spi;
 
-import org.apache.shardingsphere.spi.TypeBasedSPI;
+import org.apache.shardingsphere.spi.type.TypeBasedSPI;
 
 /**
  * Encryptor.
diff --git a/encrypt-core/encrypt-core-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/loader/EncryptorServiceLoader.java b/encrypt-core/encrypt-core-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/loader/EncryptorServiceLoader.java
index 7dfc8bda54d..598986486cb 100644
--- a/encrypt-core/encrypt-core-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/loader/EncryptorServiceLoader.java
+++ b/encrypt-core/encrypt-core-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/loader/EncryptorServiceLoader.java
@@ -17,8 +17,8 @@
 
 package org.apache.shardingsphere.encrypt.strategy.spi.loader;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
-import org.apache.shardingsphere.spi.TypeBasedSPIServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.TypeBasedSPIServiceLoader;
 import org.apache.shardingsphere.encrypt.strategy.spi.Encryptor;
 
 /**
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.encrypt.strategy.spi.Encryptor;
 public final class EncryptorServiceLoader extends TypeBasedSPIServiceLoader<Encryptor> {
     
     static {
-        NewInstanceServiceLoader.register(Encryptor.class);
+        ShardingSphereServiceLoader.register(Encryptor.class);
     }
     
     public EncryptorServiceLoader() {
diff --git a/encrypt-core/encrypt-core-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java b/encrypt-core/encrypt-core-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
index 3d0840de28a..d70e802b9ac 100644
--- a/encrypt-core/encrypt-core-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
+++ b/encrypt-core/encrypt-core-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.underlying.common.config.properties.Configurati
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContext;
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContextDecorator;
 import org.apache.shardingsphere.underlying.rewrite.parameter.rewriter.ParameterRewriter;
+import org.apache.shardingsphere.underlying.route.context.RouteContext;
 
 /**
  * SQL rewrite context decorator for encrypt.
@@ -33,7 +34,7 @@ public final class EncryptSQLRewriteContextDecorator implements SQLRewriteContex
     
     @SuppressWarnings("unchecked")
     @Override
-    public void decorate(final EncryptRule encryptRule, final ConfigurationProperties properties, final SQLRewriteContext sqlRewriteContext) {
+    public void decorate(final EncryptRule encryptRule, final ConfigurationProperties properties, final SQLRewriteContext sqlRewriteContext, final RouteContext routeContext) {
         boolean isQueryWithCipherColumn = properties.<Boolean>getValue(ConfigurationPropertyKey.QUERY_WITH_CIPHER_COLUMN);
         for (ParameterRewriter each : new EncryptParameterRewriterBuilder(encryptRule, isQueryWithCipherColumn).getParameterRewriters(sqlRewriteContext.getSchemaMetaData())) {
             if (!sqlRewriteContext.getParameters().isEmpty() && each.isNeedRewrite(sqlRewriteContext.getSqlStatementContext())) {
diff --git a/shadow-core/shadow-core-rewrite/src/main/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecorator.java b/shadow-core/shadow-core-rewrite/src/main/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecorator.java
index 30cb5b7f119..bac64cc211a 100644
--- a/shadow-core/shadow-core-rewrite/src/main/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecorator.java
+++ b/shadow-core/shadow-core-rewrite/src/main/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecorator.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.underlying.common.config.properties.Configurati
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContext;
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContextDecorator;
 import org.apache.shardingsphere.underlying.rewrite.parameter.rewriter.ParameterRewriter;
+import org.apache.shardingsphere.underlying.route.context.RouteContext;
 
 /**
  * SQL rewrite context decorator for shadow.
@@ -32,7 +33,7 @@ public final class ShadowSQLRewriteContextDecorator implements SQLRewriteContext
     
     @SuppressWarnings("unchecked")
     @Override
-    public void decorate(final ShadowRule shadowRule, final ConfigurationProperties properties, final SQLRewriteContext sqlRewriteContext) {
+    public void decorate(final ShadowRule shadowRule, final ConfigurationProperties properties, final SQLRewriteContext sqlRewriteContext, final RouteContext routeContext) {
         for (ParameterRewriter each : new ShadowParameterRewriterBuilder(shadowRule).getParameterRewriters(sqlRewriteContext.getSchemaMetaData())) {
             if (!sqlRewriteContext.getParameters().isEmpty() && each.isNeedRewrite(sqlRewriteContext.getSqlStatementContext())) {
                 each.rewrite(sqlRewriteContext.getParameterBuilder(), sqlRewriteContext.getSqlStatementContext(), sqlRewriteContext.getParameters());
diff --git a/sharding-core/database-time-service/src/main/java/org/apache/shardingsphere/route/time/spi/SPIDataBaseSQLEntry.java b/sharding-core/database-time-service/src/main/java/org/apache/shardingsphere/route/time/spi/SPIDataBaseSQLEntry.java
index 8d344c94372..c4442cf662a 100644
--- a/sharding-core/database-time-service/src/main/java/org/apache/shardingsphere/route/time/spi/SPIDataBaseSQLEntry.java
+++ b/sharding-core/database-time-service/src/main/java/org/apache/shardingsphere/route/time/spi/SPIDataBaseSQLEntry.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.route.time.spi;
 
 import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.route.time.exception.NoDatabaseSQLEntrySupportException;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 
 import java.util.Collection;
 
@@ -30,10 +30,10 @@ import java.util.Collection;
 public final class SPIDataBaseSQLEntry implements DatabaseSQLEntry {
     
     static {
-        NewInstanceServiceLoader.register(DatabaseSQLEntry.class);
+        ShardingSphereServiceLoader.register(DatabaseSQLEntry.class);
     }
     
-    private final Collection<DatabaseSQLEntry> sqlEntries = NewInstanceServiceLoader.newServiceInstances(DatabaseSQLEntry.class);
+    private final Collection<DatabaseSQLEntry> sqlEntries = ShardingSphereServiceLoader.newServiceInstances(DatabaseSQLEntry.class);
     
     private final String driverClassName;
     
diff --git a/sharding-core/sharding-core-api/src/main/java/org/apache/shardingsphere/spi/keygen/KeyGenerateAlgorithm.java b/sharding-core/sharding-core-api/src/main/java/org/apache/shardingsphere/spi/keygen/KeyGenerateAlgorithm.java
index 96d795c6b51..df123044691 100644
--- a/sharding-core/sharding-core-api/src/main/java/org/apache/shardingsphere/spi/keygen/KeyGenerateAlgorithm.java
+++ b/sharding-core/sharding-core-api/src/main/java/org/apache/shardingsphere/spi/keygen/KeyGenerateAlgorithm.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.spi.keygen;
 
-import org.apache.shardingsphere.spi.TypeBasedSPI;
+import org.apache.shardingsphere.spi.type.TypeBasedSPI;
 
 /**
  * Key generate algorithm.
diff --git a/sharding-core/sharding-core-api/src/main/java/org/apache/shardingsphere/spi/masterslave/MasterSlaveLoadBalanceAlgorithm.java b/sharding-core/sharding-core-api/src/main/java/org/apache/shardingsphere/spi/masterslave/MasterSlaveLoadBalanceAlgorithm.java
index c6e40b8e840..05c483e9390 100644
--- a/sharding-core/sharding-core-api/src/main/java/org/apache/shardingsphere/spi/masterslave/MasterSlaveLoadBalanceAlgorithm.java
+++ b/sharding-core/sharding-core-api/src/main/java/org/apache/shardingsphere/spi/masterslave/MasterSlaveLoadBalanceAlgorithm.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.spi.masterslave;
 
-import org.apache.shardingsphere.spi.TypeBasedSPI;
+import org.apache.shardingsphere.spi.type.TypeBasedSPI;
 
 import java.util.List;
 
diff --git a/sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/spi/algorithm/keygen/KeyGenerateAlgorithmServiceLoader.java b/sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/spi/algorithm/keygen/KeyGenerateAlgorithmServiceLoader.java
index 4b2b5aa1fc8..0863258b16a 100644
--- a/sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/spi/algorithm/keygen/KeyGenerateAlgorithmServiceLoader.java
+++ b/sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/spi/algorithm/keygen/KeyGenerateAlgorithmServiceLoader.java
@@ -17,9 +17,9 @@
 
 package org.apache.shardingsphere.spi.algorithm.keygen;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
-import org.apache.shardingsphere.spi.TypeBasedSPIServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.spi.keygen.KeyGenerateAlgorithm;
+import org.apache.shardingsphere.spi.type.TypeBasedSPIServiceLoader;
 
 /**
  * Key generate algorithm service loader.
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.spi.keygen.KeyGenerateAlgorithm;
 public final class KeyGenerateAlgorithmServiceLoader extends TypeBasedSPIServiceLoader<KeyGenerateAlgorithm> {
     
     static {
-        NewInstanceServiceLoader.register(KeyGenerateAlgorithm.class);
+        ShardingSphereServiceLoader.register(KeyGenerateAlgorithm.class);
     }
     
     public KeyGenerateAlgorithmServiceLoader() {
diff --git a/sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/spi/algorithm/masterslave/MasterSlaveLoadBalanceAlgorithmServiceLoader.java b/sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/spi/algorithm/masterslave/MasterSlaveLoadBalanceAlgorithmServiceLoader.java
index 528f654d766..cd5b9817f44 100644
--- a/sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/spi/algorithm/masterslave/MasterSlaveLoadBalanceAlgorithmServiceLoader.java
+++ b/sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/spi/algorithm/masterslave/MasterSlaveLoadBalanceAlgorithmServiceLoader.java
@@ -17,8 +17,8 @@
 
 package org.apache.shardingsphere.spi.algorithm.masterslave;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
-import org.apache.shardingsphere.spi.TypeBasedSPIServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.TypeBasedSPIServiceLoader;
 import org.apache.shardingsphere.spi.masterslave.MasterSlaveLoadBalanceAlgorithm;
 
 /**
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.spi.masterslave.MasterSlaveLoadBalanceAlgorithm
 public final class MasterSlaveLoadBalanceAlgorithmServiceLoader extends TypeBasedSPIServiceLoader<MasterSlaveLoadBalanceAlgorithm> {
     
     static {
-        NewInstanceServiceLoader.register(MasterSlaveLoadBalanceAlgorithm.class);
+        ShardingSphereServiceLoader.register(MasterSlaveLoadBalanceAlgorithm.class);
     }
     
     public MasterSlaveLoadBalanceAlgorithmServiceLoader() {
diff --git a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java
index 8f687e6271a..c7d620bccdc 100644
--- a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java
+++ b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java
@@ -25,20 +25,17 @@ import org.apache.shardingsphere.underlying.common.config.properties.Configurati
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContext;
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContextDecorator;
 import org.apache.shardingsphere.underlying.rewrite.parameter.rewriter.ParameterRewriter;
-import org.apache.shardingsphere.underlying.rewrite.sql.token.generator.aware.RouteContextAware;
 import org.apache.shardingsphere.underlying.route.context.RouteContext;
 
 /**
  * SQL rewrite context decorator for sharding.
  */
 @Setter
-public final class ShardingSQLRewriteContextDecorator implements SQLRewriteContextDecorator<ShardingRule>, RouteContextAware {
-    
-    private RouteContext routeContext;
+public final class ShardingSQLRewriteContextDecorator implements SQLRewriteContextDecorator<ShardingRule> {
     
     @SuppressWarnings("unchecked")
     @Override
-    public void decorate(final ShardingRule shardingRule, final ConfigurationProperties properties, final SQLRewriteContext sqlRewriteContext) {
+    public void decorate(final ShardingRule shardingRule, final ConfigurationProperties properties, final SQLRewriteContext sqlRewriteContext, final RouteContext routeContext) {
         for (ParameterRewriter each : new ShardingParameterRewriterBuilder(shardingRule, routeContext).getParameterRewriters(sqlRewriteContext.getSchemaMetaData())) {
             if (!sqlRewriteContext.getParameters().isEmpty() && each.isNeedRewrite(sqlRewriteContext.getSqlStatementContext())) {
                 each.rewrite(sqlRewriteContext.getParameterBuilder(), sqlRewriteContext.getSqlStatementContext(), sqlRewriteContext.getParameters());
diff --git a/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/sharding/route/spi/SPITimeService.java b/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/sharding/route/spi/SPITimeService.java
index f70adcd00cb..0c63567906f 100644
--- a/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/sharding/route/spi/SPITimeService.java
+++ b/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/sharding/route/spi/SPITimeService.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.sharding.route.spi;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 
 import java.util.Collection;
 import java.util.Date;
@@ -27,10 +27,10 @@ import java.util.Date;
  */
 public final class SPITimeService implements TimeService {
     
-    private final Collection<TimeService> timeServices = NewInstanceServiceLoader.newServiceInstances(TimeService.class);
+    private final Collection<TimeService> timeServices = ShardingSphereServiceLoader.newServiceInstances(TimeService.class);
     
     static {
-        NewInstanceServiceLoader.register(TimeService.class);
+        ShardingSphereServiceLoader.register(TimeService.class);
     }
     
     @Override
diff --git a/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/EncryptDataSource.java b/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/EncryptDataSource.java
index 70530e29759..92f39bf32a6 100644
--- a/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/EncryptDataSource.java
+++ b/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/EncryptDataSource.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.encrypt.rule.EncryptRule;
 import org.apache.shardingsphere.shardingjdbc.jdbc.adapter.AbstractDataSourceAdapter;
 import org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.EncryptConnection;
 import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.EncryptRuntimeContext;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.underlying.merge.engine.ResultProcessEngine;
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContextDecorator;
 
@@ -39,8 +39,8 @@ public class EncryptDataSource extends AbstractDataSourceAdapter {
     private final EncryptRuntimeContext runtimeContext;
     
     static {
-        NewInstanceServiceLoader.register(SQLRewriteContextDecorator.class);
-        NewInstanceServiceLoader.register(ResultProcessEngine.class);
+        ShardingSphereServiceLoader.register(SQLRewriteContextDecorator.class);
+        ShardingSphereServiceLoader.register(ResultProcessEngine.class);
     }
     
     public EncryptDataSource(final DataSource dataSource, final EncryptRule encryptRule, final Properties props) throws SQLException {
diff --git a/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/MasterSlaveDataSource.java b/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/MasterSlaveDataSource.java
index 33bf673a576..f0709b767bf 100644
--- a/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/MasterSlaveDataSource.java
+++ b/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/MasterSlaveDataSource.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.core.rule.MasterSlaveRule;
 import org.apache.shardingsphere.shardingjdbc.jdbc.adapter.AbstractDataSourceAdapter;
 import org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.MasterSlaveConnection;
 import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.MasterSlaveRuntimeContext;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.underlying.route.decorator.RouteDecorator;
 
 import javax.sql.DataSource;
@@ -39,7 +39,7 @@ public class MasterSlaveDataSource extends AbstractDataSourceAdapter {
     private final MasterSlaveRuntimeContext runtimeContext;
     
     static {
-        NewInstanceServiceLoader.register(RouteDecorator.class);
+        ShardingSphereServiceLoader.register(RouteDecorator.class);
     }
     
     public MasterSlaveDataSource(final Map<String, DataSource> dataSourceMap, final MasterSlaveRule masterSlaveRule, final Properties props) throws SQLException {
diff --git a/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/ShardingDataSource.java
index d8ed12c0fb5..f922f9be800 100644
--- a/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/ShardingDataSource.java
+++ b/sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/ShardingDataSource.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.core.rule.ShardingRule;
 import org.apache.shardingsphere.shardingjdbc.jdbc.adapter.AbstractDataSourceAdapter;
 import org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.ShardingConnection;
 import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.ShardingRuntimeContext;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
 import org.apache.shardingsphere.underlying.merge.engine.ResultProcessEngine;
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContextDecorator;
@@ -43,9 +43,9 @@ public class ShardingDataSource extends AbstractDataSourceAdapter {
     private final ShardingRuntimeContext runtimeContext;
     
     static {
-        NewInstanceServiceLoader.register(RouteDecorator.class);
-        NewInstanceServiceLoader.register(SQLRewriteContextDecorator.class);
-        NewInstanceServiceLoader.register(ResultProcessEngine.class);
+        ShardingSphereServiceLoader.register(RouteDecorator.class);
+        ShardingSphereServiceLoader.register(SQLRewriteContextDecorator.class);
+        ShardingSphereServiceLoader.register(ResultProcessEngine.class);
     }
     
     public ShardingDataSource(final Map<String, DataSource> dataSourceMap, final ShardingRule shardingRule, final Properties props) throws SQLException {
diff --git a/sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-api/src/main/java/org/apache/shardingsphere/orchestration/center/CenterRepository.java b/sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-api/src/main/java/org/apache/shardingsphere/orchestration/center/CenterRepository.java
index ca6e39c775e..0c3ada09e85 100644
--- a/sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-api/src/main/java/org/apache/shardingsphere/orchestration/center/CenterRepository.java
+++ b/sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-api/src/main/java/org/apache/shardingsphere/orchestration/center/CenterRepository.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.orchestration.center;
 
 import org.apache.shardingsphere.orchestration.center.listener.DataChangedEventListener;
-import org.apache.shardingsphere.spi.TypeBasedSPI;
+import org.apache.shardingsphere.spi.type.TypeBasedSPI;
 import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration;
 
 import java.util.List;
diff --git a/sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterRepositoryServiceLoader.java b/sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterRepositoryServiceLoader.java
index c21bdf7d120..be591e04913 100644
--- a/sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterRepositoryServiceLoader.java
+++ b/sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterRepositoryServiceLoader.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.orchestration.core.configcenter;
 import com.google.common.base.Preconditions;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
-import org.apache.shardingsphere.spi.TypeBasedSPIServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.TypeBasedSPIServiceLoader;
 import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration;
 
 /**
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration
 public final class ConfigCenterRepositoryServiceLoader extends TypeBasedSPIServiceLoader<ConfigCenterRepository> {
 
     static {
-        NewInstanceServiceLoader.register(ConfigCenterRepository.class);
+        ShardingSphereServiceLoader.register(ConfigCenterRepository.class);
     }
 
     public ConfigCenterRepositoryServiceLoader() {
diff --git a/sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-registrycenter/src/main/java/org/apache/shardingsphere/orchestration/core/registrycenter/RegistryCenterRepositoryServiceLoader.java b/sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-registrycenter/src/main/java/org/apache/shardingsphere/orchestration/core/registrycenter/RegistryCenterRepositoryServiceLoader.java
index c33962e2278..2e63798e220 100644
--- a/sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-registrycenter/src/main/java/org/apache/shardingsphere/orchestration/core/registrycenter/RegistryCenterRepositoryServiceLoader.java
+++ b/sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-registrycenter/src/main/java/org/apache/shardingsphere/orchestration/core/registrycenter/RegistryCenterRepositoryServiceLoader.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.orchestration.core.registrycenter;
 import com.google.common.base.Preconditions;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.orchestration.center.RegistryCenterRepository;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
-import org.apache.shardingsphere.spi.TypeBasedSPIServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.TypeBasedSPIServiceLoader;
 import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration;
 
 /**
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration
 public final class RegistryCenterRepositoryServiceLoader extends TypeBasedSPIServiceLoader<RegistryCenterRepository> {
     
     static {
-        NewInstanceServiceLoader.register(RegistryCenterRepository.class);
+        ShardingSphereServiceLoader.register(RegistryCenterRepository.class);
     }
     
     public RegistryCenterRepositoryServiceLoader() {
diff --git a/sharding-proxy/sharding-proxy-bootstrap/src/main/java/org/apache/shardingsphere/shardingproxy/Bootstrap.java b/sharding-proxy/sharding-proxy-bootstrap/src/main/java/org/apache/shardingsphere/shardingproxy/Bootstrap.java
index 0d388c31833..39e69258d89 100644
--- a/sharding-proxy/sharding-proxy-bootstrap/src/main/java/org/apache/shardingsphere/shardingproxy/Bootstrap.java
+++ b/sharding-proxy/sharding-proxy-bootstrap/src/main/java/org/apache/shardingsphere/shardingproxy/Bootstrap.java
@@ -42,7 +42,7 @@ import org.apache.shardingsphere.shardingproxy.config.yaml.YamlProxyServerConfig
 import org.apache.shardingsphere.shardingproxy.context.ShardingProxyContext;
 import org.apache.shardingsphere.shardingproxy.frontend.bootstrap.ShardingProxy;
 import org.apache.shardingsphere.shardingproxy.util.DataSourceConverter;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.underlying.common.config.DataSourceConfiguration;
 import org.apache.shardingsphere.underlying.common.config.RuleConfiguration;
 import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
@@ -89,9 +89,9 @@ public final class Bootstrap {
     }
     
     private static void registerDecorator() {
-        NewInstanceServiceLoader.register(RouteDecorator.class);
-        NewInstanceServiceLoader.register(SQLRewriteContextDecorator.class);
-        NewInstanceServiceLoader.register(ResultProcessEngine.class);
+        ShardingSphereServiceLoader.register(RouteDecorator.class);
+        ShardingSphereServiceLoader.register(SQLRewriteContextDecorator.class);
+        ShardingSphereServiceLoader.register(ResultProcessEngine.class);
     }
     
     private static int getPort(final String[] args) {
diff --git a/sharding-proxy/sharding-proxy-frontend/sharding-proxy-frontend-core/src/main/java/org/apache/shardingsphere/shardingproxy/frontend/DatabaseProtocolFrontendEngineFactory.java b/sharding-proxy/sharding-proxy-frontend/sharding-proxy-frontend-core/src/main/java/org/apache/shardingsphere/shardingproxy/frontend/DatabaseProtocolFrontendEngineFactory.java
index c7505eef5e7..127bdfaa176 100644
--- a/sharding-proxy/sharding-proxy-frontend/sharding-proxy-frontend-core/src/main/java/org/apache/shardingsphere/shardingproxy/frontend/DatabaseProtocolFrontendEngineFactory.java
+++ b/sharding-proxy/sharding-proxy-frontend/sharding-proxy-frontend-core/src/main/java/org/apache/shardingsphere/shardingproxy/frontend/DatabaseProtocolFrontendEngineFactory.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.shardingproxy.frontend;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.underlying.common.database.type.DatabaseTypes;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.shardingproxy.frontend.spi.DatabaseProtocolFrontendEngine;
 import org.apache.shardingsphere.spi.database.type.DatabaseType;
 
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.spi.database.type.DatabaseType;
 public final class DatabaseProtocolFrontendEngineFactory {
     
     static {
-        NewInstanceServiceLoader.register(DatabaseProtocolFrontendEngine.class);
+        ShardingSphereServiceLoader.register(DatabaseProtocolFrontendEngine.class);
     }
     
     /**
@@ -41,7 +41,7 @@ public final class DatabaseProtocolFrontendEngineFactory {
      * @return new instance of database protocol frontend engine
      */
     public static DatabaseProtocolFrontendEngine newInstance(final DatabaseType databaseType) {
-        for (DatabaseProtocolFrontendEngine each : NewInstanceServiceLoader.newServiceInstances(DatabaseProtocolFrontendEngine.class)) {
+        for (DatabaseProtocolFrontendEngine each : ShardingSphereServiceLoader.newServiceInstances(DatabaseProtocolFrontendEngine.class)) {
             if (DatabaseTypes.getActualDatabaseType(each.getDatabaseType()) == databaseType) {
                 return each;
             }
diff --git a/sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/spi/ScalingEntryLoader.java b/sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/spi/ScalingEntryLoader.java
index e0fffb9eb5f..81ee5f507b8 100644
--- a/sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/spi/ScalingEntryLoader.java
+++ b/sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/spi/ScalingEntryLoader.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.shardingscaling.core.spi;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -29,8 +29,8 @@ public final class ScalingEntryLoader {
     private static final Map<String, ScalingEntry> SCALING_ENTRY_MAP = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
     
     static {
-        NewInstanceServiceLoader.register(ScalingEntry.class);
-        for (ScalingEntry each : NewInstanceServiceLoader.newServiceInstances(ScalingEntry.class)) {
+        ShardingSphereServiceLoader.register(ScalingEntry.class);
+        for (ScalingEntry each : ShardingSphereServiceLoader.newServiceInstances(ScalingEntry.class)) {
             SCALING_ENTRY_MAP.put(each.getDatabaseType(), each);
         }
     }
diff --git a/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/org/apache/shardingsphere/shardingjdbc/spring/namespace/factorybean/KeyGenerateAlgorithmFactoryBean.java b/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/org/apache/shardingsphere/shardingjdbc/spring/namespace/factorybean/KeyGenerateAlgorithmFactoryBean.java
index fa279a5da83..6969efc723a 100644
--- a/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/org/apache/shardingsphere/shardingjdbc/spring/namespace/factorybean/KeyGenerateAlgorithmFactoryBean.java
+++ b/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/org/apache/shardingsphere/shardingjdbc/spring/namespace/factorybean/KeyGenerateAlgorithmFactoryBean.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.shardingjdbc.spring.namespace.factorybean;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
-import java.util.Properties;
 import lombok.Getter;
 import lombok.Setter;
 import org.apache.shardingsphere.spi.algorithm.keygen.KeyGenerateAlgorithmServiceLoader;
@@ -27,6 +26,8 @@ import org.apache.shardingsphere.spi.keygen.KeyGenerateAlgorithm;
 import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.InitializingBean;
 
+import java.util.Properties;
+
 /**
  * key generate algorithm FactoryBean.
  */
@@ -39,7 +40,7 @@ public class KeyGenerateAlgorithmFactoryBean implements FactoryBean<KeyGenerateA
     private Properties properties;
     
     @Override
-    public KeyGenerateAlgorithm getObject() throws Exception {
+    public KeyGenerateAlgorithm getObject() {
         return new KeyGenerateAlgorithmServiceLoader().newService(type, properties);
     }
     
@@ -54,7 +55,7 @@ public class KeyGenerateAlgorithmFactoryBean implements FactoryBean<KeyGenerateA
     }
     
     @Override
-    public void afterPropertiesSet() throws Exception {
+    public void afterPropertiesSet() {
         Preconditions.checkArgument(!Strings.isNullOrEmpty(type), "The type of keyGenerateAlgorithm is required.");
     }
 }
diff --git a/sharding-spring/sharding-spring-boot-util/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourcePropertiesSetterHolder.java b/sharding-spring/sharding-spring-boot-util/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourcePropertiesSetterHolder.java
index f1f54f847e6..daf7646100c 100644
--- a/sharding-spring/sharding-spring-boot-util/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourcePropertiesSetterHolder.java
+++ b/sharding-spring/sharding-spring-boot-util/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourcePropertiesSetterHolder.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.spring.boot.datasource;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -31,8 +31,8 @@ public final class DataSourcePropertiesSetterHolder {
     private static final Map<String, DataSourcePropertiesSetter> DATA_SOURCE_PROPERTIES_SETTER_MAP = new HashMap<>();
     
     static {
-        NewInstanceServiceLoader.register(DataSourcePropertiesSetter.class);
-        for (DataSourcePropertiesSetter each : NewInstanceServiceLoader.newServiceInstances(DataSourcePropertiesSetter.class)) {
+        ShardingSphereServiceLoader.register(DataSourcePropertiesSetter.class);
+        for (DataSourcePropertiesSetter each : ShardingSphereServiceLoader.newServiceInstances(DataSourcePropertiesSetter.class)) {
             DATA_SOURCE_PROPERTIES_SETTER_MAP.put(each.getType(), each);
         }
     }
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/NewInstanceServiceLoader.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoader.java
similarity index 76%
rename from shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/NewInstanceServiceLoader.java
rename to shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoader.java
index d16c1de2f4f..bfcf7cf404e 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/NewInstanceServiceLoader.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoader.java
@@ -19,20 +19,21 @@ package org.apache.shardingsphere.spi;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
+import org.apache.shardingsphere.spi.exception.ServiceLoaderException;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
-import java.util.LinkedList;
 import java.util.Map;
 import java.util.ServiceLoader;
+import java.util.stream.Collectors;
 
 /**
- * SPI service loader for new instance for every call.
+ * ShardingSphere service loader.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class NewInstanceServiceLoader {
+public final class ShardingSphereServiceLoader {
     
     private static final Map<Class, Collection<Class<?>>> SERVICE_MAP = new HashMap<>();
     
@@ -65,16 +66,16 @@ public final class NewInstanceServiceLoader {
      * @param <T> type of service
      * @return service instances
      */
-    @SneakyThrows
     @SuppressWarnings("unchecked")
     public static <T> Collection<T> newServiceInstances(final Class<T> service) {
-        Collection<T> result = new LinkedList<>();
-        if (null == SERVICE_MAP.get(service)) {
-            return result;
-        }
-        for (Class<?> each : SERVICE_MAP.get(service)) {
-            result.add((T) each.newInstance());
+        return SERVICE_MAP.containsKey(service) ? SERVICE_MAP.get(service).stream().map(each -> (T) newServiceInstance(each)).collect(Collectors.toList()) : Collections.emptyList();
+    }
+    
+    private static Object newServiceInstance(final Class<?> clazz) {
+        try {
+            return clazz.newInstance();
+        } catch (final InstantiationException | IllegalAccessException ex) {
+            throw new ServiceLoaderException(clazz, ex);
         }
-        return result;
     }
 }
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/exception/ServiceLoaderException.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/exception/ServiceLoaderException.java
new file mode 100644
index 00000000000..f1b39bf54fb
--- /dev/null
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/exception/ServiceLoaderException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.spi.exception;
+
+/**
+ * Service loader exception.
+ */
+public final class ServiceLoaderException extends RuntimeException {
+    
+    private static final long serialVersionUID = 6261274443437676201L;
+    
+    public ServiceLoaderException(final Class<?> clazz, final Exception cause) {
+        super(String.format("Can not find public default constructor for SPI class `%s`", clazz), cause);
+    }
+}
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderAware.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderBasedSPI.java
similarity index 95%
rename from shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderAware.java
rename to shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderBasedSPI.java
index b87b3f93c9f..4ea10badb41 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderAware.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderBasedSPI.java
@@ -18,11 +18,11 @@
 package org.apache.shardingsphere.spi.order;
 
 /**
- * Order aware.
+ * Order based SPI.
  * 
  * @param <T> type
  */
-public interface OrderAware<T> {
+public interface OrderBasedSPI<T> {
     
     /**
      * Get order of load.
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderedRegistry.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderedSPIRegistry.java
similarity index 61%
rename from shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderedRegistry.java
rename to shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderedSPIRegistry.java
index e8859657f23..e5ee758c8fd 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderedRegistry.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/order/OrderedSPIRegistry.java
@@ -17,30 +17,30 @@
 
 package org.apache.shardingsphere.spi.order;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 
 import java.util.Collection;
 import java.util.Map;
 import java.util.TreeMap;
 
 /**
- * Ordered registry.
+ * Ordered SPI registry.
  */
-public final class OrderedRegistry {
+public final class OrderedSPIRegistry {
     
     /**
-     * Get registered classes.
+     * Get registered services.
      * 
-     * @param orderAwareClass class of order aware
-     * @param <T> type of order aware class
-     * @return registered classes
+     * @param orderBasedClass class of order based
+     * @param <T> type of order based class
+     * @return registered services
      */
-    @SuppressWarnings("unchecked")
-    public static <T extends OrderAware> Collection<Class<T>> getRegisteredClasses(final Class<T> orderAwareClass) {
-        Map<Integer, Class<T>> result = new TreeMap<>();
-        for (T each : NewInstanceServiceLoader.newServiceInstances(orderAwareClass)) {
-            result.put(each.getOrder(), (Class<T>) each.getClass());
+    public static <T extends OrderBasedSPI> Collection<T> getRegisteredServices(final Class<T> orderBasedClass) {
+        Map<Integer, T> result = new TreeMap<>();
+        for (T each : ShardingSphereServiceLoader.newServiceInstances(orderBasedClass)) {
+            result.put(each.getOrder(), each);
         }
         return result.values();
     }
 }
+
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/TypeBasedSPI.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/TypeBasedSPI.java
similarity index 86%
rename from shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/TypeBasedSPI.java
rename to shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/TypeBasedSPI.java
index 0bf2c4b4c74..447c6103e87 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/TypeBasedSPI.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/TypeBasedSPI.java
@@ -15,17 +15,17 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.spi;
+package org.apache.shardingsphere.spi.type;
 
 import java.util.Properties;
 
 /**
- * Base algorithm SPI.
+ * Type based SPI.
  */
 public interface TypeBasedSPI {
     
     /**
-     * Get algorithm type.
+     * Get type.
      * 
      * @return type
      */
@@ -34,14 +34,14 @@ public interface TypeBasedSPI {
     /**
      * Get properties.
      * 
-     * @return properties of algorithm
+     * @return properties
      */
     Properties getProperties();
     
     /**
      * Set properties.
      * 
-     * @param properties properties of algorithm
+     * @param properties properties
      */
     void setProperties(Properties properties);
 }
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/TypeBasedSPIServiceLoader.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/TypeBasedSPIServiceLoader.java
similarity index 87%
rename from shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/TypeBasedSPIServiceLoader.java
rename to shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/TypeBasedSPIServiceLoader.java
index 8664c2f412f..0f222841e46 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/TypeBasedSPIServiceLoader.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/TypeBasedSPIServiceLoader.java
@@ -15,10 +15,11 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.spi;
+package org.apache.shardingsphere.spi.type;
 
 import com.google.common.collect.Collections2;
 import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 
 import java.util.Collection;
 import java.util.Properties;
@@ -62,11 +63,11 @@ public abstract class TypeBasedSPIServiceLoader<T extends TypeBasedSPI> {
     }
     
     private Collection<T> loadTypeBasedServices(final String type) {
-        return Collections2.filter(NewInstanceServiceLoader.newServiceInstances(classType), input -> type.equalsIgnoreCase(input.getType()));
+        return Collections2.filter(ShardingSphereServiceLoader.newServiceInstances(classType), input -> type.equalsIgnoreCase(input.getType()));
     }
     
     private T loadFirstTypeBasedService() {
-        Collection<T> instances = NewInstanceServiceLoader.newServiceInstances(classType);
+        Collection<T> instances = ShardingSphereServiceLoader.newServiceInstances(classType);
         if (instances.isEmpty()) {
             throw new RuntimeException(String.format("Invalid `%s` SPI, no implementation class load from SPI.", classType.getName()));
         }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/parser/SQLParserFactory.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/parser/SQLParserFactory.java
index d76fd73bf42..ca0feb977d0 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/parser/SQLParserFactory.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/parser/SQLParserFactory.java
@@ -25,7 +25,7 @@ import org.antlr.v4.runtime.CharStreams;
 import org.antlr.v4.runtime.CommonTokenStream;
 import org.antlr.v4.runtime.Lexer;
 import org.antlr.v4.runtime.TokenStream;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
 import org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration;
 
@@ -36,7 +36,7 @@ import org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration;
 public final class SQLParserFactory {
     
     static {
-        NewInstanceServiceLoader.register(SQLParserConfiguration.class);
+        ShardingSphereServiceLoader.register(SQLParserConfiguration.class);
     }
     
     /** 
@@ -47,7 +47,7 @@ public final class SQLParserFactory {
      * @return SQL parser
      */
     public static SQLParser newInstance(final String databaseTypeName, final String sql) {
-        for (SQLParserConfiguration each : NewInstanceServiceLoader.newServiceInstances(SQLParserConfiguration.class)) {
+        for (SQLParserConfiguration each : ShardingSphereServiceLoader.newServiceInstances(SQLParserConfiguration.class)) {
             if (each.getDatabaseTypeName().equals(databaseTypeName)) {
                 return createSQLParser(sql, each);
             }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/ParseTreeVisitorFactory.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/ParseTreeVisitorFactory.java
index 42fe2128566..48be72932ca 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/ParseTreeVisitorFactory.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/ParseTreeVisitorFactory.java
@@ -21,7 +21,7 @@ import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.SneakyThrows;
 import org.antlr.v4.runtime.tree.ParseTreeVisitor;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
 import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
 import org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration;
@@ -41,7 +41,7 @@ public final class ParseTreeVisitorFactory {
      * @return parse tree visitor
      */
     public static ParseTreeVisitor newInstance(final String databaseTypeName, final VisitorRule visitorRule) {
-        for (SQLParserConfiguration each : NewInstanceServiceLoader.newServiceInstances(SQLParserConfiguration.class)) {
+        for (SQLParserConfiguration each : ShardingSphereServiceLoader.newServiceInstances(SQLParserConfiguration.class)) {
             if (each.getDatabaseTypeName().equals(databaseTypeName)) {
                 return createParseTreeVisitor(each, visitorRule.getType());
             }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/hook/SPIParsingHook.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/hook/SPIParsingHook.java
index bed1bcd69c5..f481ca462c2 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/hook/SPIParsingHook.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/hook/SPIParsingHook.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.sql.parser.hook;
 
 import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 
 import java.util.Collection;
 
@@ -27,10 +27,10 @@ import java.util.Collection;
  */
 public final class SPIParsingHook implements ParsingHook {
     
-    private final Collection<ParsingHook> parsingHooks = NewInstanceServiceLoader.newServiceInstances(ParsingHook.class);
+    private final Collection<ParsingHook> parsingHooks = ShardingSphereServiceLoader.newServiceInstances(ParsingHook.class);
     
     static {
-        NewInstanceServiceLoader.register(ParsingHook.class);
+        ShardingSphereServiceLoader.register(ParsingHook.class);
     }
     
     @Override
diff --git a/shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/hook/SPIRootInvokeHook.java b/shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/hook/SPIRootInvokeHook.java
index b1123074a71..dcfd4deafb4 100644
--- a/shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/hook/SPIRootInvokeHook.java
+++ b/shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/hook/SPIRootInvokeHook.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.underlying.common.hook;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 
 import java.util.Collection;
 
@@ -26,10 +26,10 @@ import java.util.Collection;
  */
 public final class SPIRootInvokeHook implements RootInvokeHook {
     
-    private final Collection<RootInvokeHook> rootInvokeHooks = NewInstanceServiceLoader.newServiceInstances(RootInvokeHook.class);
+    private final Collection<RootInvokeHook> rootInvokeHooks = ShardingSphereServiceLoader.newServiceInstances(RootInvokeHook.class);
     
     static {
-        NewInstanceServiceLoader.register(RootInvokeHook.class);
+        ShardingSphereServiceLoader.register(RootInvokeHook.class);
     }
     
     @Override
diff --git a/shardingsphere-underlying/shardingsphere-executor/src/main/java/org/apache/shardingsphere/underlying/executor/hook/SPISQLExecutionHook.java b/shardingsphere-underlying/shardingsphere-executor/src/main/java/org/apache/shardingsphere/underlying/executor/hook/SPISQLExecutionHook.java
index a90daa855da..bebac7f4132 100644
--- a/shardingsphere-underlying/shardingsphere-executor/src/main/java/org/apache/shardingsphere/underlying/executor/hook/SPISQLExecutionHook.java
+++ b/shardingsphere-underlying/shardingsphere-executor/src/main/java/org/apache/shardingsphere/underlying/executor/hook/SPISQLExecutionHook.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.underlying.executor.hook;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.spi.database.metadata.DataSourceMetaData;
 
 import java.util.Collection;
@@ -29,10 +29,10 @@ import java.util.Map;
  */
 public final class SPISQLExecutionHook implements SQLExecutionHook {
     
-    private final Collection<SQLExecutionHook> sqlExecutionHooks = NewInstanceServiceLoader.newServiceInstances(SQLExecutionHook.class);
+    private final Collection<SQLExecutionHook> sqlExecutionHooks = ShardingSphereServiceLoader.newServiceInstances(SQLExecutionHook.class);
     
     static {
-        NewInstanceServiceLoader.register(SQLExecutionHook.class);
+        ShardingSphereServiceLoader.register(SQLExecutionHook.class);
     }
     
     @Override
diff --git a/shardingsphere-underlying/shardingsphere-merge/src/main/java/org/apache/shardingsphere/underlying/merge/engine/ResultProcessEngine.java b/shardingsphere-underlying/shardingsphere-merge/src/main/java/org/apache/shardingsphere/underlying/merge/engine/ResultProcessEngine.java
index c3cff605b55..b8f559fee37 100644
--- a/shardingsphere-underlying/shardingsphere-merge/src/main/java/org/apache/shardingsphere/underlying/merge/engine/ResultProcessEngine.java
+++ b/shardingsphere-underlying/shardingsphere-merge/src/main/java/org/apache/shardingsphere/underlying/merge/engine/ResultProcessEngine.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.underlying.merge.engine;
 
-import org.apache.shardingsphere.spi.order.OrderAware;
+import org.apache.shardingsphere.spi.order.OrderBasedSPI;
 import org.apache.shardingsphere.underlying.common.rule.BaseRule;
 
 /**
@@ -25,5 +25,5 @@ import org.apache.shardingsphere.underlying.common.rule.BaseRule;
  * 
  * @param <T> type of rule
  */
-public interface ResultProcessEngine<T extends BaseRule> extends OrderAware<Class<T>> {
+public interface ResultProcessEngine<T extends BaseRule> extends OrderBasedSPI<Class<T>> {
 }
diff --git a/shardingsphere-underlying/shardingsphere-pluggable/src/main/java/org/apache/shardingsphere/underlying/pluggble/merge/MergeEngine.java b/shardingsphere-underlying/shardingsphere-pluggable/src/main/java/org/apache/shardingsphere/underlying/pluggble/merge/MergeEngine.java
index e84396e0533..f3a964caba6 100644
--- a/shardingsphere-underlying/shardingsphere-pluggable/src/main/java/org/apache/shardingsphere/underlying/pluggble/merge/MergeEngine.java
+++ b/shardingsphere-underlying/shardingsphere-pluggable/src/main/java/org/apache/shardingsphere/underlying/pluggble/merge/MergeEngine.java
@@ -18,11 +18,10 @@
 package org.apache.shardingsphere.underlying.pluggble.merge;
 
 import org.apache.shardingsphere.spi.database.type.DatabaseType;
-import org.apache.shardingsphere.spi.order.OrderedRegistry;
+import org.apache.shardingsphere.spi.order.OrderedSPIRegistry;
 import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
 import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.underlying.common.exception.ShardingSphereException;
 import org.apache.shardingsphere.underlying.common.rule.BaseRule;
 import org.apache.shardingsphere.underlying.executor.QueryResult;
 import org.apache.shardingsphere.underlying.merge.MergeEntry;
@@ -62,20 +61,11 @@ public final class MergeEngine {
     }
     
     private void registerMergeDecorator() {
-        for (Class<? extends ResultProcessEngine> each : OrderedRegistry.getRegisteredClasses(ResultProcessEngine.class)) {
-            ResultProcessEngine processEngine = createProcessEngine(each);
-            Class<?> ruleClass = (Class<?>) processEngine.getType();
+        for (ResultProcessEngine each : OrderedSPIRegistry.getRegisteredServices(ResultProcessEngine.class)) {
+            Class<?> ruleClass = (Class<?>) each.getType();
             // FIXME rule.getClass().getSuperclass() == ruleClass for orchestration, should decouple extend between orchestration rule and sharding rule
             rules.stream().filter(rule -> rule.getClass() == ruleClass || rule.getClass().getSuperclass() == ruleClass).collect(Collectors.toList())
-                    .forEach(rule -> merger.registerProcessEngine(rule, processEngine));
-        }
-    }
-    
-    private ResultProcessEngine createProcessEngine(final Class<? extends ResultProcessEngine> processEngine) {
-        try {
-            return processEngine.newInstance();
-        } catch (final InstantiationException | IllegalAccessException ex) {
-            throw new ShardingSphereException(String.format("Can not find public default constructor for result process engine `%s`", processEngine), ex);
+                    .forEach(rule -> merger.registerProcessEngine(rule, each));
         }
     }
 }
diff --git a/shardingsphere-underlying/shardingsphere-pluggable/src/main/java/org/apache/shardingsphere/underlying/pluggble/prepare/BasePrepareEngine.java b/shardingsphere-underlying/shardingsphere-pluggable/src/main/java/org/apache/shardingsphere/underlying/pluggble/prepare/BasePrepareEngine.java
index 732a7234221..e31232b6f9b 100644
--- a/shardingsphere-underlying/shardingsphere-pluggable/src/main/java/org/apache/shardingsphere/underlying/pluggble/prepare/BasePrepareEngine.java
+++ b/shardingsphere-underlying/shardingsphere-pluggable/src/main/java/org/apache/shardingsphere/underlying/pluggble/prepare/BasePrepareEngine.java
@@ -18,11 +18,10 @@
 package org.apache.shardingsphere.underlying.pluggble.prepare;
 
 import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.spi.order.OrderedRegistry;
+import org.apache.shardingsphere.spi.order.OrderedSPIRegistry;
 import org.apache.shardingsphere.sql.parser.SQLParserEngine;
 import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
 import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.underlying.common.exception.ShardingSphereException;
 import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.underlying.common.rule.BaseRule;
 import org.apache.shardingsphere.underlying.executor.context.ExecutionContext;
@@ -97,20 +96,11 @@ public abstract class BasePrepareEngine {
     }
     
     private void registerRouteDecorator() {
-        for (Class<? extends RouteDecorator> each : OrderedRegistry.getRegisteredClasses(RouteDecorator.class)) {
-            RouteDecorator routeDecorator = createRouteDecorator(each);
-            Class<?> ruleClass = (Class<?>) routeDecorator.getType();
+        for (RouteDecorator each : OrderedSPIRegistry.getRegisteredServices(RouteDecorator.class)) {
+            Class<?> ruleClass = (Class<?>) each.getType();
             // FIXME rule.getClass().getSuperclass() == ruleClass for orchestration, should decouple extend between orchestration rule and sharding rule
             rules.stream().filter(rule -> rule.getClass() == ruleClass || rule.getClass().getSuperclass() == ruleClass).collect(Collectors.toList())
-                    .forEach(rule -> router.registerDecorator(rule, routeDecorator));
-        }
-    }
-    
-    private RouteDecorator createRouteDecorator(final Class<? extends RouteDecorator> decorator) {
-        try {
-            return decorator.newInstance();
-        } catch (final InstantiationException | IllegalAccessException ex) {
-            throw new ShardingSphereException(String.format("Can not find public default constructor for route decorator `%s`", decorator), ex);
+                    .forEach(rule -> router.registerDecorator(rule, each));
         }
     }
     
@@ -123,20 +113,11 @@ public abstract class BasePrepareEngine {
     }
     
     private void registerRewriteDecorator() {
-        for (Class<? extends SQLRewriteContextDecorator> each : OrderedRegistry.getRegisteredClasses(SQLRewriteContextDecorator.class)) {
-            SQLRewriteContextDecorator rewriteContextDecorator = createRewriteDecorator(each);
-            Class<?> ruleClass = (Class<?>) rewriteContextDecorator.getType();
+        for (SQLRewriteContextDecorator each : OrderedSPIRegistry.getRegisteredServices(SQLRewriteContextDecorator.class)) {
+            Class<?> ruleClass = (Class<?>) each.getType();
             // FIXME rule.getClass().getSuperclass() == ruleClass for orchestration, should decouple extend between orchestration rule and sharding rule
             rules.stream().filter(rule -> rule.getClass() == ruleClass || rule.getClass().getSuperclass() == ruleClass).collect(Collectors.toList())
-                    .forEach(rule -> rewriter.registerDecorator(rule, rewriteContextDecorator));
-        }
-    }
-    
-    private SQLRewriteContextDecorator createRewriteDecorator(final Class<? extends SQLRewriteContextDecorator> decorator) {
-        try {
-            return decorator.newInstance();
-        } catch (final InstantiationException | IllegalAccessException ex) {
-            throw new ShardingSphereException(String.format("Can not find public default constructor for rewrite decorator `%s`", decorator), ex);
+                    .forEach(rule -> rewriter.registerDecorator(rule, each));
         }
     }
     
diff --git a/shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/SQLRewriteEntry.java b/shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/SQLRewriteEntry.java
index c1b0b9ce734..886056afae8 100644
--- a/shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/SQLRewriteEntry.java
+++ b/shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/SQLRewriteEntry.java
@@ -24,13 +24,11 @@ import org.apache.shardingsphere.underlying.common.config.properties.Configurati
 import org.apache.shardingsphere.underlying.common.rule.BaseRule;
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContext;
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContextDecorator;
-import org.apache.shardingsphere.underlying.rewrite.sql.token.generator.aware.RouteContextAware;
 import org.apache.shardingsphere.underlying.route.context.RouteContext;
 
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 
 /**
  * SQL rewrite entry.
@@ -72,13 +70,6 @@ public final class SQLRewriteEntry {
     
     @SuppressWarnings("unchecked")
     private void decorate(final Map<BaseRule, SQLRewriteContextDecorator> decorators, final SQLRewriteContext sqlRewriteContext, final RouteContext routeContext) {
-        for (Entry<BaseRule, SQLRewriteContextDecorator> entry : decorators.entrySet()) {
-            BaseRule rule = entry.getKey();
-            SQLRewriteContextDecorator decorator = entry.getValue();
-            if (decorator instanceof RouteContextAware) {
-                ((RouteContextAware) decorator).setRouteContext(routeContext);
-            }
-            decorator.decorate(rule, properties, sqlRewriteContext);
-        }
+        decorators.forEach((key, value) -> value.decorate(key, properties, sqlRewriteContext, routeContext));
     }
 }
diff --git a/shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/context/SQLRewriteContextDecorator.java b/shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/context/SQLRewriteContextDecorator.java
index 2d5ac461950..962636c1a1a 100644
--- a/shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/context/SQLRewriteContextDecorator.java
+++ b/shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/context/SQLRewriteContextDecorator.java
@@ -17,16 +17,17 @@
 
 package org.apache.shardingsphere.underlying.rewrite.context;
 
-import org.apache.shardingsphere.spi.order.OrderAware;
+import org.apache.shardingsphere.spi.order.OrderBasedSPI;
 import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
 import org.apache.shardingsphere.underlying.common.rule.BaseRule;
+import org.apache.shardingsphere.underlying.route.context.RouteContext;
 
 /**
  * SQL rewrite context decorator.
  *
  * @param <T> type of rule
  */
-public interface SQLRewriteContextDecorator<T extends BaseRule> extends OrderAware<Class<T>> {
+public interface SQLRewriteContextDecorator<T extends BaseRule> extends OrderBasedSPI<Class<T>> {
     
     /**
      * Decorate SQL rewrite context.
@@ -34,6 +35,7 @@ public interface SQLRewriteContextDecorator<T extends BaseRule> extends OrderAwa
      * @param rule rule
      * @param properties ShardingSphere properties
      * @param sqlRewriteContext SQL rewrite context to be decorated
+     * @param routeContext route context
      */
-    void decorate(T rule, ConfigurationProperties properties, SQLRewriteContext sqlRewriteContext);
+    void decorate(T rule, ConfigurationProperties properties, SQLRewriteContext sqlRewriteContext, RouteContext routeContext);
 }
diff --git a/shardingsphere-underlying/shardingsphere-route/src/main/java/org/apache/shardingsphere/underlying/route/decorator/RouteDecorator.java b/shardingsphere-underlying/shardingsphere-route/src/main/java/org/apache/shardingsphere/underlying/route/decorator/RouteDecorator.java
index 7cc5f3813c8..fb1fab9cd4e 100644
--- a/shardingsphere-underlying/shardingsphere-route/src/main/java/org/apache/shardingsphere/underlying/route/decorator/RouteDecorator.java
+++ b/shardingsphere-underlying/shardingsphere-route/src/main/java/org/apache/shardingsphere/underlying/route/decorator/RouteDecorator.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.underlying.route.decorator;
 
-import org.apache.shardingsphere.spi.order.OrderAware;
+import org.apache.shardingsphere.spi.order.OrderBasedSPI;
 import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
 import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.underlying.common.rule.BaseRule;
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.underlying.route.context.RouteContext;
  * 
  * @param <T> type of rule
  */
-public interface RouteDecorator<T extends BaseRule> extends OrderAware<Class<T>> {
+public interface RouteDecorator<T extends BaseRule> extends OrderBasedSPI<Class<T>> {
     
     /**
      * Decorate route context.
diff --git a/shardingsphere-underlying/shardingsphere-route/src/main/java/org/apache/shardingsphere/underlying/route/hook/SPIRoutingHook.java b/shardingsphere-underlying/shardingsphere-route/src/main/java/org/apache/shardingsphere/underlying/route/hook/SPIRoutingHook.java
index b4d2c0da219..1dac7010edc 100644
--- a/shardingsphere-underlying/shardingsphere-route/src/main/java/org/apache/shardingsphere/underlying/route/hook/SPIRoutingHook.java
+++ b/shardingsphere-underlying/shardingsphere-route/src/main/java/org/apache/shardingsphere/underlying/route/hook/SPIRoutingHook.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.underlying.route.hook;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
 import org.apache.shardingsphere.underlying.route.context.RouteContext;
 
@@ -28,10 +28,10 @@ import java.util.Collection;
  */
 public final class SPIRoutingHook implements RoutingHook {
     
-    private final Collection<RoutingHook> routingHooks = NewInstanceServiceLoader.newServiceInstances(RoutingHook.class);
+    private final Collection<RoutingHook> routingHooks = ShardingSphereServiceLoader.newServiceInstances(RoutingHook.class);
     
     static {
-        NewInstanceServiceLoader.register(RoutingHook.class);
+        ShardingSphereServiceLoader.register(RoutingHook.class);
     }
     
     @Override


Test patch:
diff --git a/encrypt-core/encrypt-core-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java b/encrypt-core/encrypt-core-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java
index 922c10a5f56..fd27246f75c 100644
--- a/encrypt-core/encrypt-core-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java
+++ b/encrypt-core/encrypt-core-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java
@@ -30,8 +30,8 @@ import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
 import org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties;
 import org.apache.shardingsphere.underlying.common.yaml.engine.YamlEngine;
 import org.apache.shardingsphere.underlying.rewrite.context.SQLRewriteContext;
-import org.apache.shardingsphere.underlying.rewrite.engine.SQLRewriteResult;
 import org.apache.shardingsphere.underlying.rewrite.engine.SQLRewriteEngine;
+import org.apache.shardingsphere.underlying.rewrite.engine.SQLRewriteResult;
 import org.apache.shardingsphere.underlying.rewrite.parameterized.engine.AbstractSQLRewriterParameterizedTest;
 import org.apache.shardingsphere.underlying.rewrite.parameterized.engine.parameter.SQLRewriteEngineTestParameters;
 import org.apache.shardingsphere.underlying.rewrite.parameterized.engine.parameter.SQLRewriteEngineTestParametersBuilder;
@@ -65,7 +65,7 @@ public final class EncryptSQLRewriterParameterizedTest extends AbstractSQLRewrit
         YamlRootEncryptRuleConfiguration ruleConfiguration = createRuleConfiguration();
         EncryptRule encryptRule = new EncryptRule(new EncryptRuleConfigurationYamlSwapper().swap(ruleConfiguration.getEncryptRule()));
         SQLRewriteContext sqlRewriteContext = createSQLRewriteContext();
-        new EncryptSQLRewriteContextDecorator().decorate(encryptRule, new ConfigurationProperties(ruleConfiguration.getProps()), sqlRewriteContext);
+        new EncryptSQLRewriteContextDecorator().decorate(encryptRule, new ConfigurationProperties(ruleConfiguration.getProps()), sqlRewriteContext, null);
         sqlRewriteContext.generateSQLTokens();
         return Collections.singletonList(new SQLRewriteEngine().rewrite(sqlRewriteContext));
     }
diff --git a/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java b/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java
index 23b02a63ade..ff0512e7b0f 100644
--- a/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java
+++ b/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java
@@ -84,9 +84,8 @@ public final class MixSQLRewriterParameterizedTest extends AbstractSQLRewriterPa
         SQLRewriteContext sqlRewriteContext = new SQLRewriteContext(
                 mock(SchemaMetaData.class), routeContext.getSqlStatementContext(), getTestParameters().getInputSQL(), getTestParameters().getInputParameters());
         ShardingSQLRewriteContextDecorator shardingSQLRewriteContextDecorator = new ShardingSQLRewriteContextDecorator();
-        shardingSQLRewriteContextDecorator.setRouteContext(routeContext);
-        shardingSQLRewriteContextDecorator.decorate(shardingRule, properties, sqlRewriteContext);
-        new EncryptSQLRewriteContextDecorator().decorate(shardingRule.getEncryptRule(), properties, sqlRewriteContext);
+        shardingSQLRewriteContextDecorator.decorate(shardingRule, properties, sqlRewriteContext, routeContext);
+        new EncryptSQLRewriteContextDecorator().decorate(shardingRule.getEncryptRule(), properties, sqlRewriteContext, routeContext);
         sqlRewriteContext.generateSQLTokens();
         return new SQLRouteRewriteEngine().rewrite(sqlRewriteContext, routeContext.getRouteResult()).values();
     }
diff --git a/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/ShardingSQLRewriterParameterizedTest.java b/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/ShardingSQLRewriterParameterizedTest.java
index e612df3df11..25efb44f6e3 100644
--- a/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/ShardingSQLRewriterParameterizedTest.java
+++ b/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/ShardingSQLRewriterParameterizedTest.java
@@ -83,8 +83,7 @@ public final class ShardingSQLRewriterParameterizedTest extends AbstractSQLRewri
         SQLRewriteContext sqlRewriteContext = new SQLRewriteContext(
                 mock(SchemaMetaData.class), routeContext.getSqlStatementContext(), getTestParameters().getInputSQL(), getTestParameters().getInputParameters());
         ShardingSQLRewriteContextDecorator shardingSQLRewriteContextDecorator = new ShardingSQLRewriteContextDecorator();
-        shardingSQLRewriteContextDecorator.setRouteContext(routeContext);
-        shardingSQLRewriteContextDecorator.decorate(shardingRule, properties, sqlRewriteContext);
+        shardingSQLRewriteContextDecorator.decorate(shardingRule, properties, sqlRewriteContext, routeContext);
         sqlRewriteContext.generateSQLTokens();
         return new SQLRouteRewriteEngine().rewrite(sqlRewriteContext, routeContext.getRouteResult()).values();
     }
diff --git a/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingParsingHookTest.java b/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingParsingHookTest.java
index 5d67c0d023f..f50867c97d7 100644
--- a/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingParsingHookTest.java
+++ b/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingParsingHookTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.opentracing.hook;
 import io.opentracing.mock.MockSpan;
 import io.opentracing.tag.Tags;
 import org.apache.shardingsphere.opentracing.constant.ShardingTags;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.sql.parser.hook.ParsingHook;
 import org.apache.shardingsphere.sql.parser.hook.SPIParsingHook;
 import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
@@ -40,7 +40,7 @@ public final class OpenTracingParsingHookTest extends BaseOpenTracingHookTest {
     
     @BeforeClass
     public static void registerSPI() {
-        NewInstanceServiceLoader.register(ParsingHook.class);
+        ShardingSphereServiceLoader.register(ParsingHook.class);
     }
     
     @Test
diff --git a/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingRootInvokeHookTest.java b/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingRootInvokeHookTest.java
index fffdcad539e..aa2c33ef442 100644
--- a/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingRootInvokeHookTest.java
+++ b/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingRootInvokeHookTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.opentracing.hook;
 import org.apache.shardingsphere.underlying.executor.engine.ExecutorDataMap;
 import org.apache.shardingsphere.underlying.common.hook.RootInvokeHook;
 import org.apache.shardingsphere.underlying.common.hook.SPIRootInvokeHook;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -32,7 +32,7 @@ public final class OpenTracingRootInvokeHookTest extends BaseOpenTracingHookTest
     
     @BeforeClass
     public static void registerSPI() {
-        NewInstanceServiceLoader.register(RootInvokeHook.class);
+        ShardingSphereServiceLoader.register(RootInvokeHook.class);
     }
     
     @Test
diff --git a/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingSQLExecutionHookTest.java b/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingSQLExecutionHookTest.java
index bd47c19bd00..f064a7f6ab8 100644
--- a/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingSQLExecutionHookTest.java
+++ b/sharding-opentracing/src/test/java/org/apache/shardingsphere/opentracing/hook/OpenTracingSQLExecutionHookTest.java
@@ -24,7 +24,7 @@ import io.opentracing.tag.Tags;
 import org.apache.shardingsphere.opentracing.constant.ShardingTags;
 import org.apache.shardingsphere.underlying.executor.hook.SPISQLExecutionHook;
 import org.apache.shardingsphere.underlying.executor.hook.SQLExecutionHook;
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.spi.database.metadata.DataSourceMetaData;
 import org.apache.shardingsphere.underlying.executor.engine.ExecutorDataMap;
 import org.junit.After;
@@ -51,7 +51,7 @@ public final class OpenTracingSQLExecutionHookTest extends BaseOpenTracingHookTe
     
     @BeforeClass
     public static void registerSPI() {
-        NewInstanceServiceLoader.register(SQLExecutionHook.class);
+        ShardingSphereServiceLoader.register(SQLExecutionHook.class);
     }
     
     @Before
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/NewInstanceServiceLoaderTest.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoaderTest.java
similarity index 77%
rename from shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/NewInstanceServiceLoaderTest.java
rename to shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoaderTest.java
index 7522b710a95..c48dbd7649b 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/NewInstanceServiceLoaderTest.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/ShardingSphereServiceLoaderTest.java
@@ -26,19 +26,19 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
-public final class NewInstanceServiceLoaderTest {
+public final class ShardingSphereServiceLoaderTest {
     
     @Test
     public void assertNewServiceInstanceWhenIsNotExist() {
-        NewInstanceServiceLoader.register(Collection.class);
-        Collection collection = NewInstanceServiceLoader.newServiceInstances(Collection.class);
+        ShardingSphereServiceLoader.register(Collection.class);
+        Collection collection = ShardingSphereServiceLoader.newServiceInstances(Collection.class);
         assertTrue(collection.isEmpty());
     }
     
     @Test
     public void assertNewServiceInstanceWhenIsExist() {
-        NewInstanceServiceLoader.register(TypeBasedSPIFixture.class);
-        Collection collection = NewInstanceServiceLoader.newServiceInstances(TypeBasedSPIFixture.class);
+        ShardingSphereServiceLoader.register(TypeBasedSPIFixture.class);
+        Collection collection = ShardingSphereServiceLoader.newServiceInstances(TypeBasedSPIFixture.class);
         assertThat(collection.size(), is(1));
     }
 }
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/TypeBasedSPIFixture.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/TypeBasedSPIFixture.java
index a5159b2950b..fd891f42f8c 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/TypeBasedSPIFixture.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/TypeBasedSPIFixture.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.spi.fixture;
 
-import org.apache.shardingsphere.spi.TypeBasedSPI;
+import org.apache.shardingsphere.spi.type.TypeBasedSPI;
 
 public interface TypeBasedSPIFixture extends TypeBasedSPI {
 }
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/TypeBasedSPIFixtureServiceLoader.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/TypeBasedSPIFixtureServiceLoader.java
index 2251b4d1288..6be91a1e965 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/TypeBasedSPIFixtureServiceLoader.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/fixture/TypeBasedSPIFixtureServiceLoader.java
@@ -17,13 +17,13 @@
 
 package org.apache.shardingsphere.spi.fixture;
 
-import org.apache.shardingsphere.spi.NewInstanceServiceLoader;
-import org.apache.shardingsphere.spi.TypeBasedSPIServiceLoader;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.TypeBasedSPIServiceLoader;
 
 public final class TypeBasedSPIFixtureServiceLoader extends TypeBasedSPIServiceLoader<TypeBasedSPIFixture> {
     
     static {
-        NewInstanceServiceLoader.register(TypeBasedSPIFixture.class);
+        ShardingSphereServiceLoader.register(TypeBasedSPIFixture.class);
     }
     
     public TypeBasedSPIFixtureServiceLoader() {