You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/04/30 05:33:10 UTC

[shardingsphere] branch master updated: Add ExecutionPrepareDecoratorFactory (#17225)

This is an automated email from the ASF dual-hosted git repository.

panjuan 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 81b48bde734 Add ExecutionPrepareDecoratorFactory (#17225)
81b48bde734 is described below

commit 81b48bde734570b17b52f3f4d922fc6eb034db65
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 30 13:33:04 2022 +0800

    Add ExecutionPrepareDecoratorFactory (#17225)
---
 .../prepare/AbstractExecutionPrepareEngine.java    |  8 +---
 .../prepare/ExecutionPrepareDecoratorFactory.java  | 43 ++++++++++++++++++++++
 2 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java
index a0c2bffb615..85979fbc090 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java
@@ -25,8 +25,6 @@ import org.apache.shardingsphere.infra.executor.sql.context.SQLUnit;
 import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
 
 import java.sql.SQLException;
 import java.util.Collection;
@@ -43,10 +41,6 @@ import java.util.Map.Entry;
  */
 public abstract class AbstractExecutionPrepareEngine<T> implements ExecutionPrepareEngine<T> {
     
-    static {
-        ShardingSphereServiceLoader.register(ExecutionPrepareDecorator.class);
-    }
-    
     private final int maxConnectionsSizePerQuery;
     
     @SuppressWarnings("rawtypes")
@@ -54,7 +48,7 @@ public abstract class AbstractExecutionPrepareEngine<T> implements ExecutionPrep
     
     protected AbstractExecutionPrepareEngine(final int maxConnectionsSizePerQuery, final Collection<ShardingSphereRule> rules) {
         this.maxConnectionsSizePerQuery = maxConnectionsSizePerQuery;
-        decorators = OrderedSPIRegistry.getRegisteredServices(ExecutionPrepareDecorator.class, rules);
+        decorators = ExecutionPrepareDecoratorFactory.newInstance(rules);
     }
     
     @Override
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/ExecutionPrepareDecoratorFactory.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/ExecutionPrepareDecoratorFactory.java
new file mode 100644
index 00000000000..8aeb4365497
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/ExecutionPrepareDecoratorFactory.java
@@ -0,0 +1,43 @@
+/*
+ * 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.executor.sql.prepare;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.ordered.OrderedSPIRegistry;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Execution prepare decorator factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ExecutionPrepareDecoratorFactory {
+    
+    static {
+        ShardingSphereServiceLoader.register(ExecutionPrepareDecorator.class);
+    }
+    
+    @SuppressWarnings("rawtypes")
+    public static Map<ShardingSphereRule, ExecutionPrepareDecorator> newInstance(final Collection<ShardingSphereRule> rules) {
+        return OrderedSPIRegistry.getRegisteredServices(ExecutionPrepareDecorator.class, rules);
+    }
+}