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

jianglongtao 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 19c5fd20685 add convert rule configuration provider for Single table. 
(#30544)
19c5fd20685 is described below

commit 19c5fd20685bf7d9c3f95c541243941176912199
Author: Zonglei Dong <[email protected]>
AuthorDate: Thu Mar 21 12:41:09 2024 +0800

    add convert rule configuration provider for Single table. (#30544)
---
 .../handler/constant/SingleDistSQLConstants.java   | 36 ++++++++++++++
 .../SingleConvertRuleConfigurationProvider.java    | 58 ++++++++++++++++++++++
 ...ry.ral.convert.ConvertRuleConfigurationProvider | 18 +++++++
 3 files changed, 112 insertions(+)

diff --git 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/constant/SingleDistSQLConstants.java
 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/constant/SingleDistSQLConstants.java
new file mode 100644
index 00000000000..00b7dcc296a
--- /dev/null
+++ 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/constant/SingleDistSQLConstants.java
@@ -0,0 +1,36 @@
+/*
+ * 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.single.distsql.handler.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Single DistSQL constants.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SingleDistSQLConstants {
+    
+    public static final String COMMA = ", ";
+    
+    public static final String SEMI = ";";
+    
+    public static final String LOAD_SINGLE_TABLE = "LOAD SINGLE TABLE ";
+    
+    public static final String DATASOURCE_AND_TABLE = "%s.%s";
+}
diff --git 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/provider/SingleConvertRuleConfigurationProvider.java
 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/provider/SingleConvertRuleConfigurationProvider.java
new file mode 100644
index 00000000000..2dbdd228324
--- /dev/null
+++ 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/provider/SingleConvertRuleConfigurationProvider.java
@@ -0,0 +1,58 @@
+/*
+ * 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.single.distsql.handler.provider;
+
+import 
org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
+import 
org.apache.shardingsphere.single.distsql.handler.constant.SingleDistSQLConstants;
+
+import java.util.Iterator;
+
+/**
+ * Single convert rule configuration provider.
+ */
+public final class SingleConvertRuleConfigurationProvider implements 
ConvertRuleConfigurationProvider {
+    
+    @Override
+    public String convert(final RuleConfiguration ruleConfig) {
+        return getSingleDistSQL((SingleRuleConfiguration) ruleConfig);
+    }
+    
+    private String getSingleDistSQL(final SingleRuleConfiguration ruleConfig) {
+        if (ruleConfig.getTables().isEmpty()) {
+            return "";
+        }
+        StringBuilder result = new 
StringBuilder(SingleDistSQLConstants.LOAD_SINGLE_TABLE);
+        Iterator<String> iterator = ruleConfig.getTables().iterator();
+        while (iterator.hasNext()) {
+            String tableName = iterator.next();
+            
result.append(String.format(SingleDistSQLConstants.DATASOURCE_AND_TABLE, 
ruleConfig.getDefaultDataSource(), tableName));
+            if (iterator.hasNext()) {
+                result.append(SingleDistSQLConstants.COMMA);
+            }
+        }
+        
result.append(SingleDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+        return result.toString();
+    }
+    
+    @Override
+    public Class<? extends RuleConfiguration> getType() {
+        return SingleRuleConfiguration.class;
+    }
+}
diff --git 
a/kernel/single/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider
 
b/kernel/single/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider
new file mode 100644
index 00000000000..05e84059a59
--- /dev/null
+++ 
b/kernel/single/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.single.distsql.handler.provider.SingleConvertRuleConfigurationProvider

Reply via email to