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/04/30 04:52:01 UTC

[shardingsphere] branch master updated: Add RawExecutorCallbackFactory (#17222)

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 202fdf97960 Add RawExecutorCallbackFactory (#17222)
202fdf97960 is described below

commit 202fdf97960e3ce5ae5f0d4b803acaf3bde5cb26
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 30 12:51:57 2022 +0800

    Add RawExecutorCallbackFactory (#17222)
    
    * Add RawExecutorCallbackFactory
    
    * Add RawExecutorCallbackFactory
---
 .../raw/callback/RawExecutorCallbackFactory.java   | 45 ++++++++++++++++++++++
 .../raw/callback/RawSQLExecutorCallback.java       |  7 +---
 2 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawExecutorCallbackFactory.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawExecutorCallbackFactory.java
new file mode 100644
index 00000000000..515c895c39e
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawExecutorCallbackFactory.java
@@ -0,0 +1,45 @@
+/*
+ * 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.execute.engine.raw.callback;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+
+import java.util.Collection;
+
+/**
+ * Raw executor callback factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class RawExecutorCallbackFactory {
+    
+    static {
+        ShardingSphereServiceLoader.register(RawExecutorCallback.class);
+    }
+    
+    /**
+     * Create new instances of raw executor callback.
+     * 
+     * @return new instances of raw executor callback
+     */
+    @SuppressWarnings("rawtypes")
+    public static Collection<RawExecutorCallback> newInstances() {
+        return ShardingSphereServiceLoader.getServiceInstances(RawExecutorCallback.class);
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawSQLExecutorCallback.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawSQLExecutorCallback.java
index 5b2b5226b10..1582557de89 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawSQLExecutorCallback.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawSQLExecutorCallback.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.RawSQLExe
 import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
 import org.apache.shardingsphere.infra.executor.sql.process.ExecuteProcessEngine;
 import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessConstants;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 
 import java.sql.SQLException;
 import java.util.Collection;
@@ -34,15 +33,11 @@ import java.util.Map;
  */
 public final class RawSQLExecutorCallback implements ExecutorCallback<RawSQLExecutionUnit, ExecuteResult> {
     
-    static {
-        ShardingSphereServiceLoader.register(RawExecutorCallback.class);
-    }
-    
     @SuppressWarnings("rawtypes")
     private final Collection<RawExecutorCallback> callbacks;
     
     public RawSQLExecutorCallback() {
-        callbacks = ShardingSphereServiceLoader.getServiceInstances(RawExecutorCallback.class);
+        callbacks = RawExecutorCallbackFactory.newInstances();
         Preconditions.checkState(!callbacks.isEmpty(), "No raw executor callback implementation found.");
     }