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 04:55:15 UTC

[shardingsphere] branch master updated: Add SQLExecutionHookFactory (#17223)

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 7196f022b88 Add SQLExecutionHookFactory (#17223)
7196f022b88 is described below

commit 7196f022b885bab3d59392be07ff06f216106575
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 30 12:55:10 2022 +0800

    Add SQLExecutionHookFactory (#17223)
---
 .../executor/sql/hook/SPISQLExecutionHook.java     |  7 +---
 .../executor/sql/hook/SQLExecutionHookFactory.java | 44 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/hook/SPISQLExecutionHook.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/hook/SPISQLExecutionHook.java
index d04aa00ff0b..572cd5b64e7 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/hook/SPISQLExecutionHook.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/hook/SPISQLExecutionHook.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.infra.executor.sql.hook;
 
 import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 
 import java.util.Collection;
 import java.util.List;
@@ -29,11 +28,7 @@ import java.util.Map;
  */
 public final class SPISQLExecutionHook implements SQLExecutionHook {
     
-    private final Collection<SQLExecutionHook> sqlExecutionHooks = ShardingSphereServiceLoader.getServiceInstances(SQLExecutionHook.class);
-    
-    static {
-        ShardingSphereServiceLoader.register(SQLExecutionHook.class);
-    }
+    private final Collection<SQLExecutionHook> sqlExecutionHooks = SQLExecutionHookFactory.newInstances();
     
     @Override
     public void start(final String dataSourceName, final String sql, final List<Object> parameters,
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/hook/SQLExecutionHookFactory.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/hook/SQLExecutionHookFactory.java
new file mode 100644
index 00000000000..585fdc36dbc
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/hook/SQLExecutionHookFactory.java
@@ -0,0 +1,44 @@
+/*
+ * 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.hook;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+
+import java.util.Collection;
+
+/**
+ * SQL Execution hook factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SQLExecutionHookFactory {
+    
+    static {
+        ShardingSphereServiceLoader.register(SQLExecutionHook.class);
+    }
+    
+    /**
+     * Create new instances of SQL Execution hook.
+     *
+     * @return new instances of SQL Execution hook
+     */
+    public static Collection<SQLExecutionHook> newInstances() {
+        return ShardingSphereServiceLoader.getServiceInstances(SQLExecutionHook.class);
+    }
+}