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 03:22:39 UTC

[shardingsphere] branch master updated: Add SQLRewriteContextDecoratorFactory (#17217)

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

zhonghongsheng 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 2b8c627c11f Add SQLRewriteContextDecoratorFactory (#17217)
2b8c627c11f is described below

commit 2b8c627c11fec02099dfbd90dd79b148bea0b9a7
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 30 11:22:34 2022 +0800

    Add SQLRewriteContextDecoratorFactory (#17217)
---
 .../infra/rewrite/SQLRewriteEntry.java             |  9 +---
 .../context/SQLRewriteContextDecoratorFactory.java | 49 ++++++++++++++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java
index fec576d6ea7..3c280a985a3 100644
--- a/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java
@@ -22,13 +22,12 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext;
 import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator;
+import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecoratorFactory;
 import org.apache.shardingsphere.infra.rewrite.engine.GenericSQLRewriteEngine;
 import org.apache.shardingsphere.infra.rewrite.engine.RouteSQLRewriteEngine;
 import org.apache.shardingsphere.infra.rewrite.engine.result.SQLRewriteResult;
 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.util.Collection;
 import java.util.List;
@@ -40,10 +39,6 @@ import java.util.Map.Entry;
  */
 public final class SQLRewriteEntry {
     
-    static {
-        ShardingSphereServiceLoader.register(SQLRewriteContextDecorator.class);
-    }
-    
     private final String databaseName;
     
     private final Map<String, ShardingSphereSchema> schemas;
@@ -57,7 +52,7 @@ public final class SQLRewriteEntry {
         this.databaseName = databaseName;
         this.schemas = schemas;
         this.props = props;
-        decorators = OrderedSPIRegistry.getRegisteredServices(SQLRewriteContextDecorator.class, rules);
+        decorators = SQLRewriteContextDecoratorFactory.newInstance(rules);
     }
     
     /**
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextDecoratorFactory.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextDecoratorFactory.java
new file mode 100644
index 00000000000..69b3be675cf
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextDecoratorFactory.java
@@ -0,0 +1,49 @@
+/*
+ * 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.rewrite.context;
+
+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;
+
+/**
+ * SQL rewrite context decorator factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SQLRewriteContextDecoratorFactory {
+    
+    static {
+        ShardingSphereServiceLoader.register(SQLRewriteContextDecorator.class);
+    }
+    
+    /**
+     * Create new instance of SQL rewrite context decorator.
+     * 
+     * @param rules rules
+     * @return new instance of SQL rewrite context decorator
+     */
+    @SuppressWarnings("rawtypes")
+    public static Map<ShardingSphereRule, SQLRewriteContextDecorator> newInstance(final Collection<ShardingSphereRule> rules) {
+        return OrderedSPIRegistry.getRegisteredServices(SQLRewriteContextDecorator.class, rules);
+    }
+}