strongduanmu commented on code in PR #22857:
URL: https://github.com/apache/shardingsphere/pull/22857#discussion_r1058049420


##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/DefaultShardingConditionEngine.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.sharding.route.engine.condition.engine.impl;
+
+import java.util.List;
+
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
+import 
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
+import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition;
+import 
org.apache.shardingsphere.sharding.route.engine.condition.engine.ShardingConditionEngine;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+
+/**
+ * Default implementation of the sharding condition engine.
+ */
+public class DefaultShardingConditionEngine implements 
ShardingConditionEngine<SQLStatementContext<?>> {

Review Comment:
   Please add final for DefaultShardingConditionEngine.



##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactory.java:
##########
@@ -54,6 +57,8 @@ public static ShardingConditionEngine<?> 
createShardingConditionEngine(final Que
      * @return created instance
      */
     public static ShardingConditionEngine<?> 
createShardingConditionEngine(final SQLStatementContext<?> sqlStatementContext, 
final ShardingSphereDatabase database, final ShardingRule rule) {
-        return sqlStatementContext instanceof InsertStatementContext ? new 
InsertClauseShardingConditionEngine(rule, database) : new 
WhereClauseShardingConditionEngine(rule, database);
+        ShardingConditionEngine conditionEngine = 
RequiredSPIRegistry.getRegisteredService(ShardingConditionEngine.class);
+        conditionEngine.init(rule, database);
+        return conditionEngine;

Review Comment:
   Please rename conditionEngine to result.



##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngine.java:
##########
@@ -21,11 +21,22 @@
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 
 import java.util.List;
+import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPI;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
 
 /**
  * Sharding condition engine.
  */
-public interface ShardingConditionEngine<T extends SQLStatementContext<?>> {
+public interface ShardingConditionEngine<T extends SQLStatementContext<?>> 
extends RequiredSPI {
+    
+    /**
+     * Initialize the sharding condition engine.
+     *
+     * @param rule sharding rule
+     * @param database sharding database
+     */
+    void init(ShardingRule rule, ShardingSphereDatabase database);

Review Comment:
   Why add init method?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to