You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/07/24 14:36:07 UTC
[shardingsphere] branch master updated: Split DistSQL Constants to feature (#27374)
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 24867f7bb33 Split DistSQL Constants to feature (#27374)
24867f7bb33 is described below
commit 24867f7bb33a94b6f7274c408372d421ab61a498
Author: yx9o <ya...@163.com>
AuthorDate: Mon Jul 24 22:35:59 2023 +0800
Split DistSQL Constants to feature (#27374)
---
.../handler/constant/EncryptDistSQLConstants.java | 62 +++++++++
.../EncryptConvertRuleConfigurationProvider.java | 36 ++---
.../handler/constant/MaskDistSQLConstants.java | 50 +++++++
.../MaskConvertRuleConfigurationProvider.java | 20 +--
.../ReadwriteSplittingDistSQLConstants.java | 52 ++++++++
...eSplittingConvertRuleConfigurationProvider.java | 24 ++--
.../handler/constant/ShadowDistSQLConstants.java | 52 ++++++++
.../ShadowConvertRuleConfigurationProvider.java | 24 ++--
.../handler/constant/ShardingDistSQLConstants.java | 98 ++++++++++++++
.../ShardingConvertRuleConfigurationProvider.java | 76 +++++------
.../ral/constant/DistSQLScriptConstants.java | 148 ---------------------
11 files changed, 404 insertions(+), 238 deletions(-)
diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/constant/EncryptDistSQLConstants.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/constant/EncryptDistSQLConstants.java
new file mode 100644
index 00000000000..d914d27d1c4
--- /dev/null
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/constant/EncryptDistSQLConstants.java
@@ -0,0 +1,62 @@
+/*
+ * 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.encrypt.distsql.handler.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Encrypt DistSQL constants.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class EncryptDistSQLConstants {
+
+ public static final String COMMA = ",";
+
+ public static final String SEMI = ";";
+
+ public static final String PROPERTY = "'%s'='%s'";
+
+ public static final String CREATE_ENCRYPT = "CREATE ENCRYPT RULE";
+
+ public static final String ENCRYPT = " %s ("
+ + System.lineSeparator()
+ + "COLUMNS("
+ + System.lineSeparator()
+ + "%s"
+ + System.lineSeparator()
+ + "))";
+
+ public static final String ENCRYPT_COLUMN = "(NAME=%s, %s, %s)";
+
+ public static final String CIPHER = "CIPHER=%s";
+
+ public static final String ASSISTED_QUERY_COLUMN = "ASSISTED_QUERY_COLUMN=%s";
+
+ public static final String LIKE_QUERY_COLUMN = "LIKE_QUERY_COLUMN=%s";
+
+ public static final String ENCRYPT_ALGORITHM = "ENCRYPT_ALGORITHM(%s)";
+
+ public static final String ASSISTED_QUERY_ALGORITHM = "ASSISTED_QUERY_ALGORITHM(%s)";
+
+ public static final String LIKE_QUERY_ALGORITHM = "LIKE_QUERY_ALGORITHM(%s)";
+
+ public static final String ALGORITHM_TYPE = "TYPE(NAME='%s', PROPERTIES(%s))";
+
+ public static final String ALGORITHM_TYPE_WITHOUT_PROPS = "TYPE(NAME='%s')";
+}
diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptConvertRuleConfigurationProvider.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptConvertRuleConfigurationProvider.java
index 19f6ec44d91..ca3a30194f2 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptConvertRuleConfigurationProvider.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptConvertRuleConfigurationProvider.java
@@ -18,12 +18,12 @@
package org.apache.shardingsphere.encrypt.distsql.handler.provider;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.distsql.handler.ral.constant.DistSQLScriptConstants;
import org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
+import org.apache.shardingsphere.encrypt.distsql.handler.constant.EncryptDistSQLConstants;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
@@ -47,16 +47,16 @@ public final class EncryptConvertRuleConfigurationProvider implements ConvertRul
if (ruleConfig.getTables().isEmpty()) {
return "";
}
- StringBuilder result = new StringBuilder(DistSQLScriptConstants.CREATE_ENCRYPT);
+ StringBuilder result = new StringBuilder(EncryptDistSQLConstants.CREATE_ENCRYPT);
Iterator<EncryptTableRuleConfiguration> iterator = ruleConfig.getTables().iterator();
while (iterator.hasNext()) {
EncryptTableRuleConfiguration tableRuleConfig = iterator.next();
- result.append(String.format(DistSQLScriptConstants.ENCRYPT, tableRuleConfig.getName(), getEncryptColumns(tableRuleConfig.getColumns(), ruleConfig.getEncryptors())));
+ result.append(String.format(EncryptDistSQLConstants.ENCRYPT, tableRuleConfig.getName(), getEncryptColumns(tableRuleConfig.getColumns(), ruleConfig.getEncryptors())));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
+ result.append(EncryptDistSQLConstants.COMMA).append(System.lineSeparator());
}
}
- result.append(DistSQLScriptConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+ result.append(EncryptDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
return result.toString();
}
@@ -65,9 +65,9 @@ public final class EncryptConvertRuleConfigurationProvider implements ConvertRul
Iterator<EncryptColumnRuleConfiguration> iterator = ruleConfigs.iterator();
while (iterator.hasNext()) {
EncryptColumnRuleConfiguration columnRuleConfig = iterator.next();
- result.append(String.format(DistSQLScriptConstants.ENCRYPT_COLUMN, columnRuleConfig.getName(), getColumns(columnRuleConfig), getEncryptAlgorithms(columnRuleConfig, encryptors)));
+ result.append(String.format(EncryptDistSQLConstants.ENCRYPT_COLUMN, columnRuleConfig.getName(), getColumns(columnRuleConfig), getEncryptAlgorithms(columnRuleConfig, encryptors)));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
+ result.append(EncryptDistSQLConstants.COMMA).append(System.lineSeparator());
}
}
return result.toString();
@@ -77,13 +77,13 @@ public final class EncryptConvertRuleConfigurationProvider implements ConvertRul
StringBuilder result = new StringBuilder();
String cipherColumnName = ruleConfig.getCipher().getName();
if (!Strings.isNullOrEmpty(cipherColumnName)) {
- result.append(String.format(DistSQLScriptConstants.CIPHER, cipherColumnName));
+ result.append(String.format(EncryptDistSQLConstants.CIPHER, cipherColumnName));
}
if (ruleConfig.getAssistedQuery().isPresent()) {
- result.append(DistSQLScriptConstants.COMMA).append(' ').append(String.format(DistSQLScriptConstants.ASSISTED_QUERY_COLUMN, ruleConfig.getAssistedQuery().get().getName()));
+ result.append(EncryptDistSQLConstants.COMMA).append(' ').append(String.format(EncryptDistSQLConstants.ASSISTED_QUERY_COLUMN, ruleConfig.getAssistedQuery().get().getName()));
}
if (ruleConfig.getLikeQuery().isPresent()) {
- result.append(DistSQLScriptConstants.COMMA).append(' ').append(String.format(DistSQLScriptConstants.LIKE_QUERY_COLUMN, ruleConfig.getLikeQuery().get().getName()));
+ result.append(EncryptDistSQLConstants.COMMA).append(' ').append(String.format(EncryptDistSQLConstants.LIKE_QUERY_COLUMN, ruleConfig.getLikeQuery().get().getName()));
}
return result.toString();
}
@@ -94,14 +94,14 @@ public final class EncryptConvertRuleConfigurationProvider implements ConvertRul
String assistedQueryEncryptorName = ruleConfig.getAssistedQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse("");
String likeQueryEncryptorName = ruleConfig.getLikeQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse("");
if (!Strings.isNullOrEmpty(cipherEncryptorName)) {
- result.append(String.format(DistSQLScriptConstants.ENCRYPT_ALGORITHM, getAlgorithmType(encryptors.get(cipherEncryptorName))));
+ result.append(String.format(EncryptDistSQLConstants.ENCRYPT_ALGORITHM, getAlgorithmType(encryptors.get(cipherEncryptorName))));
}
if (!Strings.isNullOrEmpty(assistedQueryEncryptorName)) {
- result.append(DistSQLScriptConstants.COMMA).append(' ')
- .append(String.format(DistSQLScriptConstants.ASSISTED_QUERY_ALGORITHM, getAlgorithmType(encryptors.get(assistedQueryEncryptorName))));
+ result.append(EncryptDistSQLConstants.COMMA).append(' ')
+ .append(String.format(EncryptDistSQLConstants.ASSISTED_QUERY_ALGORITHM, getAlgorithmType(encryptors.get(assistedQueryEncryptorName))));
}
if (!Strings.isNullOrEmpty(likeQueryEncryptorName)) {
- result.append(DistSQLScriptConstants.COMMA).append(' ').append(String.format(DistSQLScriptConstants.LIKE_QUERY_ALGORITHM, getAlgorithmType(encryptors.get(likeQueryEncryptorName))));
+ result.append(EncryptDistSQLConstants.COMMA).append(' ').append(String.format(EncryptDistSQLConstants.LIKE_QUERY_ALGORITHM, getAlgorithmType(encryptors.get(likeQueryEncryptorName))));
}
return result.toString();
}
@@ -113,9 +113,9 @@ public final class EncryptConvertRuleConfigurationProvider implements ConvertRul
}
String type = algorithmConfig.getType().toLowerCase();
if (algorithmConfig.getProps().isEmpty()) {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
+ result.append(String.format(EncryptDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
} else {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
+ result.append(String.format(EncryptDistSQLConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
}
return result.toString();
}
@@ -130,9 +130,9 @@ public final class EncryptConvertRuleConfigurationProvider implements ConvertRul
if (null == value) {
continue;
}
- result.append(String.format(DistSQLScriptConstants.PROPERTY, key, value));
+ result.append(String.format(EncryptDistSQLConstants.PROPERTY, key, value));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(' ');
+ result.append(EncryptDistSQLConstants.COMMA).append(' ');
}
}
return result.toString();
diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/constant/MaskDistSQLConstants.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/constant/MaskDistSQLConstants.java
new file mode 100644
index 00000000000..76ed63164e0
--- /dev/null
+++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/constant/MaskDistSQLConstants.java
@@ -0,0 +1,50 @@
+/*
+ * 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.mask.distsql.handler.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Mask DistSQL constants.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class MaskDistSQLConstants {
+
+ public static final String COMMA = ",";
+
+ public static final String SEMI = ";";
+
+ public static final String PROPERTY = "'%s'='%s'";
+
+ public static final String ALGORITHM_TYPE = "TYPE(NAME='%s', PROPERTIES(%s))";
+
+ public static final String ALGORITHM_TYPE_WITHOUT_PROPS = "TYPE(NAME='%s')";
+
+ public static final String CREATE_MASK = "CREATE MASK RULE";
+
+ public static final String MASK = " %s ("
+ + System.lineSeparator()
+ + "COLUMNS("
+ + System.lineSeparator()
+ + "%s"
+ + System.lineSeparator()
+ + "),";
+
+ public static final String MASK_COLUMN = "(NAME=%s, %s)";
+}
diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskConvertRuleConfigurationProvider.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskConvertRuleConfigurationProvider.java
index aa075a55cb2..2263303d8a1 100644
--- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskConvertRuleConfigurationProvider.java
+++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskConvertRuleConfigurationProvider.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.mask.distsql.handler.provider;
-import org.apache.shardingsphere.distsql.handler.ral.constant.DistSQLScriptConstants;
import org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration;
import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
+import org.apache.shardingsphere.mask.distsql.handler.constant.MaskDistSQLConstants;
import java.util.Collection;
import java.util.Iterator;
@@ -45,16 +45,16 @@ public final class MaskConvertRuleConfigurationProvider implements ConvertRuleCo
if (ruleConfig.getTables().isEmpty()) {
return "";
}
- StringBuilder result = new StringBuilder(DistSQLScriptConstants.CREATE_MASK);
+ StringBuilder result = new StringBuilder(MaskDistSQLConstants.CREATE_MASK);
Iterator<MaskTableRuleConfiguration> iterator = ruleConfig.getTables().iterator();
while (iterator.hasNext()) {
MaskTableRuleConfiguration tableRuleConfig = iterator.next();
- result.append(String.format(DistSQLScriptConstants.MASK, tableRuleConfig.getName(), getMaskColumns(tableRuleConfig.getColumns(), ruleConfig.getMaskAlgorithms())));
+ result.append(String.format(MaskDistSQLConstants.MASK, tableRuleConfig.getName(), getMaskColumns(tableRuleConfig.getColumns(), ruleConfig.getMaskAlgorithms())));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
+ result.append(MaskDistSQLConstants.COMMA).append(System.lineSeparator());
}
}
- result.append(DistSQLScriptConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+ result.append(MaskDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
return result.toString();
}
@@ -63,7 +63,7 @@ public final class MaskConvertRuleConfigurationProvider implements ConvertRuleCo
Iterator<MaskColumnRuleConfiguration> iterator = columnRuleConfig.iterator();
if (iterator.hasNext()) {
MaskColumnRuleConfiguration column = iterator.next();
- result.append(String.format(DistSQLScriptConstants.MASK_COLUMN, column.getLogicColumn(), getMaskAlgorithms(column, maskAlgorithms)));
+ result.append(String.format(MaskDistSQLConstants.MASK_COLUMN, column.getLogicColumn(), getMaskAlgorithms(column, maskAlgorithms)));
}
return result.toString();
}
@@ -79,9 +79,9 @@ public final class MaskConvertRuleConfigurationProvider implements ConvertRuleCo
}
String type = algorithmConfig.getType().toLowerCase();
if (algorithmConfig.getProps().isEmpty()) {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
+ result.append(String.format(MaskDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
} else {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
+ result.append(String.format(MaskDistSQLConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
}
return result.toString();
}
@@ -96,9 +96,9 @@ public final class MaskConvertRuleConfigurationProvider implements ConvertRuleCo
if (null == value) {
continue;
}
- result.append(String.format(DistSQLScriptConstants.PROPERTY, key, value));
+ result.append(String.format(MaskDistSQLConstants.PROPERTY, key, value));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(' ');
+ result.append(MaskDistSQLConstants.COMMA).append(' ');
}
}
return result.toString();
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/constant/ReadwriteSplittingDistSQLConstants.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/constant/ReadwriteSplittingDistSQLConstants.java
new file mode 100644
index 00000000000..a1c73613b14
--- /dev/null
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/constant/ReadwriteSplittingDistSQLConstants.java
@@ -0,0 +1,52 @@
+/*
+ * 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.readwritesplitting.distsql.handler.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Readwrite-splitting DistSQL constants.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ReadwriteSplittingDistSQLConstants {
+
+ public static final String COMMA = ",";
+
+ public static final String SEMI = ";";
+
+ public static final String PROPERTY = "'%s'='%s'";
+
+ public static final String CREATE_READWRITE_SPLITTING_RULE = "CREATE READWRITE_SPLITTING RULE";
+
+ public static final String READWRITE_SPLITTING_FOR_STATIC = " %s ("
+ + System.lineSeparator()
+ + "WRITE_STORAGE_UNIT=%s,"
+ + System.lineSeparator()
+ + "READ_STORAGE_UNITS(%s),"
+ + System.lineSeparator()
+ + "TRANSACTIONAL_READ_QUERY_STRATEGY='%s'%s"
+ + System.lineSeparator()
+ + ")";
+
+ public static final String READ_RESOURCE = "%s";
+
+ public static final String ALGORITHM_TYPE = "TYPE(NAME='%s', PROPERTIES(%s))";
+
+ public static final String ALGORITHM_TYPE_WITHOUT_PROPS = "TYPE(NAME='%s')";
+}
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingConvertRuleConfigurationProvider.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingConvertRuleConfigurationProvider.java
index fb7badf6453..d80e1631e5a 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingConvertRuleConfigurationProvider.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingConvertRuleConfigurationProvider.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.provider;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.distsql.handler.ral.constant.DistSQLScriptConstants;
import org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
+import org.apache.shardingsphere.readwritesplitting.distsql.handler.constant.ReadwriteSplittingDistSQLConstants;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import java.util.Collection;
@@ -45,15 +45,15 @@ public final class ReadwriteSplittingConvertRuleConfigurationProvider implements
if (ruleConfig.getDataSources().isEmpty()) {
return "";
}
- StringBuilder result = new StringBuilder(DistSQLScriptConstants.CREATE_READWRITE_SPLITTING_RULE);
+ StringBuilder result = new StringBuilder(ReadwriteSplittingDistSQLConstants.CREATE_READWRITE_SPLITTING_RULE);
Iterator<ReadwriteSplittingDataSourceRuleConfiguration> iterator = ruleConfig.getDataSources().iterator();
while (iterator.hasNext()) {
appendStaticReadWriteSplittingRule(ruleConfig.getLoadBalancers(), iterator.next(), result);
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA);
+ result.append(ReadwriteSplittingDistSQLConstants.COMMA);
}
}
- result.append(DistSQLScriptConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+ result.append(ReadwriteSplittingDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
return result.toString();
}
@@ -62,7 +62,7 @@ public final class ReadwriteSplittingConvertRuleConfigurationProvider implements
String readDataSourceNames = getReadDataSourceNames(dataSourceRuleConfig.getReadDataSourceNames());
String transactionalReadQueryStrategy = dataSourceRuleConfig.getTransactionalReadQueryStrategy().name();
String loadBalancerType = getLoadBalancerType(loadBalancers.get(dataSourceRuleConfig.getLoadBalancerName()));
- stringBuilder.append(String.format(DistSQLScriptConstants.READWRITE_SPLITTING_FOR_STATIC,
+ stringBuilder.append(String.format(ReadwriteSplittingDistSQLConstants.READWRITE_SPLITTING_FOR_STATIC,
dataSourceRuleConfig.getName(), dataSourceRuleConfig.getWriteDataSourceName(), readDataSourceNames, transactionalReadQueryStrategy, loadBalancerType));
}
@@ -70,9 +70,9 @@ public final class ReadwriteSplittingConvertRuleConfigurationProvider implements
StringBuilder result = new StringBuilder();
Iterator<String> iterator = readDataSourceNames.iterator();
while (iterator.hasNext()) {
- result.append(String.format(DistSQLScriptConstants.READ_RESOURCE, iterator.next()));
+ result.append(String.format(ReadwriteSplittingDistSQLConstants.READ_RESOURCE, iterator.next()));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA);
+ result.append(ReadwriteSplittingDistSQLConstants.COMMA);
}
}
return result.toString();
@@ -82,7 +82,7 @@ public final class ReadwriteSplittingConvertRuleConfigurationProvider implements
StringBuilder result = new StringBuilder();
String loadBalancerType = getAlgorithmType(algorithmConfig);
if (!Strings.isNullOrEmpty(loadBalancerType)) {
- result.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator()).append(loadBalancerType);
+ result.append(ReadwriteSplittingDistSQLConstants.COMMA).append(System.lineSeparator()).append(loadBalancerType);
}
return result.toString();
}
@@ -94,9 +94,9 @@ public final class ReadwriteSplittingConvertRuleConfigurationProvider implements
}
String type = algorithmConfig.getType().toLowerCase();
if (algorithmConfig.getProps().isEmpty()) {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
+ result.append(String.format(ReadwriteSplittingDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
} else {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
+ result.append(String.format(ReadwriteSplittingDistSQLConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
}
return result.toString();
}
@@ -111,9 +111,9 @@ public final class ReadwriteSplittingConvertRuleConfigurationProvider implements
if (null == value) {
continue;
}
- result.append(String.format(DistSQLScriptConstants.PROPERTY, key, value));
+ result.append(String.format(ReadwriteSplittingDistSQLConstants.PROPERTY, key, value));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(' ');
+ result.append(ReadwriteSplittingDistSQLConstants.COMMA).append(' ');
}
}
return result.toString();
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/constant/ShadowDistSQLConstants.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/constant/ShadowDistSQLConstants.java
new file mode 100644
index 00000000000..1dfcc993789
--- /dev/null
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/constant/ShadowDistSQLConstants.java
@@ -0,0 +1,52 @@
+/*
+ * 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.shadow.distsql.handler.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Shadow DistSQL constants.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShadowDistSQLConstants {
+
+ public static final String COMMA = ",";
+
+ public static final String SEMI = ";";
+
+ public static final String PROPERTY = "'%s'='%s'";
+
+ public static final String ALGORITHM_TYPE = "TYPE(NAME='%s', PROPERTIES(%s))";
+
+ public static final String ALGORITHM_TYPE_WITHOUT_PROPS = "TYPE(NAME='%s')";
+
+ public static final String CREATE_SHADOW = "CREATE SHADOW RULE";
+
+ public static final String SHADOW = " %s("
+ + System.lineSeparator()
+ + "SOURCE=%s,"
+ + System.lineSeparator()
+ + "SHADOW=%s,"
+ + System.lineSeparator()
+ + "%s"
+ + System.lineSeparator()
+ + ")";
+
+ public static final String SHADOW_TABLE = "%s(%s)";
+}
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowConvertRuleConfigurationProvider.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowConvertRuleConfigurationProvider.java
index 2af4cd0c61a..207e34654e8 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowConvertRuleConfigurationProvider.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowConvertRuleConfigurationProvider.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.shadow.distsql.handler.provider;
-import org.apache.shardingsphere.distsql.handler.ral.constant.DistSQLScriptConstants;
import org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.distsql.handler.constant.ShadowDistSQLConstants;
import java.util.Collection;
import java.util.Iterator;
@@ -45,18 +45,18 @@ public final class ShadowConvertRuleConfigurationProvider implements ConvertRule
if (ruleConfig.getDataSources().isEmpty()) {
return "";
}
- StringBuilder result = new StringBuilder(DistSQLScriptConstants.CREATE_SHADOW);
+ StringBuilder result = new StringBuilder(ShadowDistSQLConstants.CREATE_SHADOW);
Iterator<ShadowDataSourceConfiguration> iterator = ruleConfig.getDataSources().iterator();
while (iterator.hasNext()) {
ShadowDataSourceConfiguration dataSourceConfig = iterator.next();
String shadowRuleName = dataSourceConfig.getName();
String shadowTables = getShadowTables(shadowRuleName, ruleConfig.getTables(), ruleConfig.getShadowAlgorithms());
- result.append(String.format(DistSQLScriptConstants.SHADOW, shadowRuleName, dataSourceConfig.getProductionDataSourceName(), dataSourceConfig.getShadowDataSourceName(), shadowTables));
+ result.append(String.format(ShadowDistSQLConstants.SHADOW, shadowRuleName, dataSourceConfig.getProductionDataSourceName(), dataSourceConfig.getShadowDataSourceName(), shadowTables));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA);
+ result.append(ShadowDistSQLConstants.COMMA);
}
}
- result.append(DistSQLScriptConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+ result.append(ShadowDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
return result.toString();
}
@@ -67,10 +67,10 @@ public final class ShadowConvertRuleConfigurationProvider implements ConvertRule
Map.Entry<String, ShadowTableConfiguration> shadowTableConfig = iterator.next();
if (shadowTableConfig.getValue().getDataSourceNames().contains(shadowRuleName)) {
String shadowTableTypes = getShadowTableTypes(shadowTableConfig.getValue().getShadowAlgorithmNames(), algorithmConfigs);
- result.append(String.format(DistSQLScriptConstants.SHADOW_TABLE, shadowTableConfig.getKey(), shadowTableTypes));
+ result.append(String.format(ShadowDistSQLConstants.SHADOW_TABLE, shadowTableConfig.getKey(), shadowTableTypes));
}
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
+ result.append(ShadowDistSQLConstants.COMMA).append(System.lineSeparator());
}
}
return result.toString();
@@ -82,7 +82,7 @@ public final class ShadowConvertRuleConfigurationProvider implements ConvertRule
while (iterator.hasNext()) {
result.append(getAlgorithmType(algorithmConfigs.get(iterator.next())));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(' ');
+ result.append(ShadowDistSQLConstants.COMMA).append(' ');
}
}
return result.toString();
@@ -95,9 +95,9 @@ public final class ShadowConvertRuleConfigurationProvider implements ConvertRule
}
String type = algorithmConfig.getType().toLowerCase();
if (algorithmConfig.getProps().isEmpty()) {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
+ result.append(String.format(ShadowDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
} else {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
+ result.append(String.format(ShadowDistSQLConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
}
return result.toString();
}
@@ -112,9 +112,9 @@ public final class ShadowConvertRuleConfigurationProvider implements ConvertRule
if (null == value) {
continue;
}
- result.append(String.format(DistSQLScriptConstants.PROPERTY, key, value));
+ result.append(String.format(ShadowDistSQLConstants.PROPERTY, key, value));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(' ');
+ result.append(ShadowDistSQLConstants.COMMA).append(' ');
}
}
return result.toString();
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/constant/ShardingDistSQLConstants.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/constant/ShardingDistSQLConstants.java
new file mode 100644
index 00000000000..ed106445407
--- /dev/null
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/constant/ShardingDistSQLConstants.java
@@ -0,0 +1,98 @@
+/*
+ * 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.distsql.handler.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Sharding DistSQL constants.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShardingDistSQLConstants {
+
+ public static final String STANDARD = "standard";
+
+ public static final String COMPLEX = "complex";
+
+ public static final String HINT = "hint";
+
+ public static final String NONE = "";
+
+ public static final String COMMA = ",";
+
+ public static final String SEMI = ";";
+
+ public static final String PROPERTY = "'%s'='%s'";
+
+ public static final String CREATE_SHARDING_TABLE = "CREATE SHARDING TABLE RULE";
+
+ public static final String SHARDING_TABLE = " %s ("
+ + System.lineSeparator()
+ + "DATANODES('%s')%s"
+ + System.lineSeparator()
+ + ")";
+
+ public static final String SHARDING_AUTO_TABLE = " %s ("
+ + System.lineSeparator()
+ + "STORAGE_UNITS(%s),"
+ + System.lineSeparator()
+ + "%s"
+ + System.lineSeparator()
+ + ")";
+
+ public static final String AUTO_TABLE_STRATEGY = "SHARDING_COLUMN=%s,"
+ + System.lineSeparator()
+ + "%s";
+
+ public static final String DATABASE_STRATEGY = "DATABASE_STRATEGY";
+
+ public static final String TABLE_STRATEGY = "TABLE_STRATEGY";
+
+ public static final String STRATEGY_STANDARD = "TYPE='%s', SHARDING_COLUMN=%s, SHARDING_ALGORITHM(%s)";
+
+ public static final String STRATEGY_COMPLEX = "TYPE='%s', SHARDING_COLUMNS=%s, SHARDING_ALGORITHM(%s)";
+
+ public static final String STRATEGY_HINT = "TYPE='%s', SHARDING_ALGORITHM(%s)";
+
+ public static final String STRATEGY_NONE = "TYPE='%s'";
+
+ public static final String SHARDING_STRATEGY_STANDARD = "%s(" + STRATEGY_STANDARD + ")";
+
+ public static final String SHARDING_STRATEGY_COMPLEX = "%s(" + STRATEGY_COMPLEX + ")";
+
+ public static final String SHARDING_STRATEGY_HINT = "%s(" + STRATEGY_HINT + ")";
+
+ public static final String SHARDING_STRATEGY_NONE = "%s(" + STRATEGY_NONE + ")";
+
+ public static final String KEY_GENERATOR_STRATEGY = "KEY_GENERATE_STRATEGY(COLUMN=%s, %s)";
+
+ public static final String AUDIT_STRATEGY = "AUDIT_STRATEGY(%s, ALLOW_HINT_DISABLE=%s)";
+
+ public static final String SHARDING_BINDING_TABLE_RULES = "CREATE SHARDING TABLE REFERENCE RULE";
+
+ public static final String BINDING_TABLES = " %s (%s)";
+
+ public static final String DEFAULT_DATABASE_STRATEGY = "CREATE DEFAULT SHARDING DATABASE STRATEGY";
+
+ public static final String DEFAULT_TABLE_STRATEGY = "CREATE DEFAULT SHARDING TABLE STRATEGY";
+
+ public static final String ALGORITHM_TYPE = "TYPE(NAME='%s', PROPERTIES(%s))";
+
+ public static final String ALGORITHM_TYPE_WITHOUT_PROPS = "TYPE(NAME='%s')";
+}
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingConvertRuleConfigurationProvider.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingConvertRuleConfigurationProvider.java
index 44d30930242..84f3c2936ce 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingConvertRuleConfigurationProvider.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingConvertRuleConfigurationProvider.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.distsql.handler.provider;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.distsql.handler.ral.constant.DistSQLScriptConstants;
import org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
@@ -31,6 +30,7 @@ import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerate
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ComplexShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import org.apache.shardingsphere.sharding.distsql.handler.constant.ShardingDistSQLConstants;
import java.util.Collection;
import java.util.Iterator;
@@ -60,27 +60,27 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
}
String tableRules = getTableRules(ruleConfig);
String autoTableRules = getAutoTableRules(ruleConfig);
- stringBuilder.append(DistSQLScriptConstants.CREATE_SHARDING_TABLE).append(tableRules);
+ stringBuilder.append(ShardingDistSQLConstants.CREATE_SHARDING_TABLE).append(tableRules);
if (!Strings.isNullOrEmpty(tableRules) && !Strings.isNullOrEmpty(autoTableRules)) {
- stringBuilder.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
+ stringBuilder.append(ShardingDistSQLConstants.COMMA).append(System.lineSeparator());
}
- stringBuilder.append(autoTableRules).append(DistSQLScriptConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+ stringBuilder.append(autoTableRules).append(ShardingDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
}
private void appendShardingBindingTableRules(final ShardingRuleConfiguration ruleConfig, final StringBuilder stringBuilder) {
if (ruleConfig.getBindingTableGroups().isEmpty()) {
return;
}
- stringBuilder.append(DistSQLScriptConstants.SHARDING_BINDING_TABLE_RULES);
+ stringBuilder.append(ShardingDistSQLConstants.SHARDING_BINDING_TABLE_RULES);
Iterator<ShardingTableReferenceRuleConfiguration> iterator = ruleConfig.getBindingTableGroups().iterator();
while (iterator.hasNext()) {
ShardingTableReferenceRuleConfiguration referenceRuleConfig = iterator.next();
- stringBuilder.append(String.format(DistSQLScriptConstants.BINDING_TABLES, referenceRuleConfig.getName(), referenceRuleConfig.getReference()));
+ stringBuilder.append(String.format(ShardingDistSQLConstants.BINDING_TABLES, referenceRuleConfig.getName(), referenceRuleConfig.getReference()));
if (iterator.hasNext()) {
- stringBuilder.append(DistSQLScriptConstants.COMMA);
+ stringBuilder.append(ShardingDistSQLConstants.COMMA);
}
}
- stringBuilder.append(DistSQLScriptConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+ stringBuilder.append(ShardingDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
}
private void appendDefaultShardingStrategy(final ShardingRuleConfiguration ruleConfig, final StringBuilder result) {
@@ -88,12 +88,12 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
return;
}
if (null != ruleConfig.getDefaultDatabaseShardingStrategy()) {
- appendStrategy(ruleConfig.getDefaultDatabaseShardingStrategy(), DistSQLScriptConstants.DEFAULT_DATABASE_STRATEGY, result, ruleConfig.getShardingAlgorithms());
- result.append(DistSQLScriptConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+ appendStrategy(ruleConfig.getDefaultDatabaseShardingStrategy(), ShardingDistSQLConstants.DEFAULT_DATABASE_STRATEGY, result, ruleConfig.getShardingAlgorithms());
+ result.append(ShardingDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
}
if (null != ruleConfig.getDefaultTableShardingStrategy()) {
- appendStrategy(ruleConfig.getDefaultTableShardingStrategy(), DistSQLScriptConstants.DEFAULT_TABLE_STRATEGY, result, ruleConfig.getShardingAlgorithms());
- result.append(DistSQLScriptConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+ appendStrategy(ruleConfig.getDefaultTableShardingStrategy(), ShardingDistSQLConstants.DEFAULT_TABLE_STRATEGY, result, ruleConfig.getShardingAlgorithms());
+ result.append(ShardingDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
}
}
@@ -103,10 +103,10 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
Iterator<ShardingTableRuleConfiguration> iterator = ruleConfig.getTables().iterator();
while (iterator.hasNext()) {
ShardingTableRuleConfiguration tableRuleConfig = iterator.next();
- result.append(String.format(DistSQLScriptConstants.SHARDING_TABLE, tableRuleConfig.getLogicTable(), tableRuleConfig.getActualDataNodes(),
+ result.append(String.format(ShardingDistSQLConstants.SHARDING_TABLE, tableRuleConfig.getLogicTable(), tableRuleConfig.getActualDataNodes(),
appendTableStrategy(tableRuleConfig, ruleConfig)));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA);
+ result.append(ShardingDistSQLConstants.COMMA);
}
}
}
@@ -119,10 +119,10 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
Iterator<ShardingAutoTableRuleConfiguration> iterator = ruleConfig.getAutoTables().iterator();
while (iterator.hasNext()) {
ShardingAutoTableRuleConfiguration autoTableRuleConfig = iterator.next();
- result.append(String.format(DistSQLScriptConstants.SHARDING_AUTO_TABLE, autoTableRuleConfig.getLogicTable(), autoTableRuleConfig.getActualDataSources(),
+ result.append(String.format(ShardingDistSQLConstants.SHARDING_AUTO_TABLE, autoTableRuleConfig.getLogicTable(), autoTableRuleConfig.getActualDataSources(),
appendAutoTableStrategy(autoTableRuleConfig, ruleConfig)));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA);
+ result.append(ShardingDistSQLConstants.COMMA);
}
}
}
@@ -131,8 +131,8 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
private String appendTableStrategy(final ShardingTableRuleConfiguration tableRuleConfig, final ShardingRuleConfiguration ruleConfig) {
StringBuilder result = new StringBuilder();
- appendStrategy(tableRuleConfig.getDatabaseShardingStrategy(), DistSQLScriptConstants.DATABASE_STRATEGY, result, ruleConfig.getShardingAlgorithms());
- appendStrategy(tableRuleConfig.getTableShardingStrategy(), DistSQLScriptConstants.TABLE_STRATEGY, result, ruleConfig.getShardingAlgorithms());
+ appendStrategy(tableRuleConfig.getDatabaseShardingStrategy(), ShardingDistSQLConstants.DATABASE_STRATEGY, result, ruleConfig.getShardingAlgorithms());
+ appendStrategy(tableRuleConfig.getTableShardingStrategy(), ShardingDistSQLConstants.TABLE_STRATEGY, result, ruleConfig.getShardingAlgorithms());
appendKeyGenerateStrategy(ruleConfig.getKeyGenerators(), tableRuleConfig.getKeyGenerateStrategy(), result);
appendAuditStrategy(ruleConfig.getAuditors(), null != tableRuleConfig.getAuditStrategy() ? tableRuleConfig.getAuditStrategy() : ruleConfig.getDefaultAuditStrategy(), result);
return result.toString();
@@ -142,7 +142,7 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
StringBuilder result = new StringBuilder();
StandardShardingStrategyConfiguration strategyConfig = (StandardShardingStrategyConfiguration) autoTableRuleConfig.getShardingStrategy();
String shardingColumn = Strings.isNullOrEmpty(strategyConfig.getShardingColumn()) ? ruleConfig.getDefaultShardingColumn() : strategyConfig.getShardingColumn();
- result.append(String.format(DistSQLScriptConstants.AUTO_TABLE_STRATEGY, shardingColumn, getAlgorithmType(ruleConfig.getShardingAlgorithms().get(strategyConfig.getShardingAlgorithmName()))));
+ result.append(String.format(ShardingDistSQLConstants.AUTO_TABLE_STRATEGY, shardingColumn, getAlgorithmType(ruleConfig.getShardingAlgorithms().get(strategyConfig.getShardingAlgorithmName()))));
appendKeyGenerateStrategy(ruleConfig.getKeyGenerators(), autoTableRuleConfig.getKeyGenerateStrategy(), result);
appendAuditStrategy(ruleConfig.getAuditors(), null != autoTableRuleConfig.getAuditStrategy() ? autoTableRuleConfig.getAuditStrategy() : ruleConfig.getDefaultAuditStrategy(), result);
return result.toString();
@@ -153,25 +153,25 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
if (null == strategyConfig) {
return;
}
- if (Objects.equals(strategyType, DistSQLScriptConstants.DATABASE_STRATEGY) || Objects.equals(strategyType, DistSQLScriptConstants.TABLE_STRATEGY)) {
- stringBuilder.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
+ if (Objects.equals(strategyType, ShardingDistSQLConstants.DATABASE_STRATEGY) || Objects.equals(strategyType, ShardingDistSQLConstants.TABLE_STRATEGY)) {
+ stringBuilder.append(ShardingDistSQLConstants.COMMA).append(System.lineSeparator());
}
String type = strategyConfig.getType().toLowerCase();
String algorithmDefinition = getAlgorithmType(shardingAlgorithms.get(strategyConfig.getShardingAlgorithmName()));
switch (type) {
- case DistSQLScriptConstants.STANDARD:
+ case ShardingDistSQLConstants.STANDARD:
StandardShardingStrategyConfiguration standardShardingStrategyConfig = (StandardShardingStrategyConfiguration) strategyConfig;
- stringBuilder.append(String.format(DistSQLScriptConstants.SHARDING_STRATEGY_STANDARD, strategyType, type, standardShardingStrategyConfig.getShardingColumn(), algorithmDefinition));
+ stringBuilder.append(String.format(ShardingDistSQLConstants.SHARDING_STRATEGY_STANDARD, strategyType, type, standardShardingStrategyConfig.getShardingColumn(), algorithmDefinition));
break;
- case DistSQLScriptConstants.COMPLEX:
+ case ShardingDistSQLConstants.COMPLEX:
ComplexShardingStrategyConfiguration complexShardingStrategyConfig = (ComplexShardingStrategyConfiguration) strategyConfig;
- stringBuilder.append(String.format(DistSQLScriptConstants.SHARDING_STRATEGY_COMPLEX, strategyType, type, complexShardingStrategyConfig.getShardingColumns(), algorithmDefinition));
+ stringBuilder.append(String.format(ShardingDistSQLConstants.SHARDING_STRATEGY_COMPLEX, strategyType, type, complexShardingStrategyConfig.getShardingColumns(), algorithmDefinition));
break;
- case DistSQLScriptConstants.HINT:
- stringBuilder.append(String.format(DistSQLScriptConstants.SHARDING_STRATEGY_HINT, strategyType, type, algorithmDefinition));
+ case ShardingDistSQLConstants.HINT:
+ stringBuilder.append(String.format(ShardingDistSQLConstants.SHARDING_STRATEGY_HINT, strategyType, type, algorithmDefinition));
break;
- case DistSQLScriptConstants.NONE:
- stringBuilder.append(String.format(DistSQLScriptConstants.SHARDING_STRATEGY_NONE, strategyType, "none"));
+ case ShardingDistSQLConstants.NONE:
+ stringBuilder.append(String.format(ShardingDistSQLConstants.SHARDING_STRATEGY_NONE, strategyType, "none"));
break;
default:
break;
@@ -183,15 +183,15 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
if (null == keyGenerateStrategyConfig) {
return;
}
- stringBuilder.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
+ stringBuilder.append(ShardingDistSQLConstants.COMMA).append(System.lineSeparator());
String algorithmDefinition = getAlgorithmType(keyGenerators.get(keyGenerateStrategyConfig.getKeyGeneratorName()));
- stringBuilder.append(String.format(DistSQLScriptConstants.KEY_GENERATOR_STRATEGY, keyGenerateStrategyConfig.getColumn(), algorithmDefinition));
+ stringBuilder.append(String.format(ShardingDistSQLConstants.KEY_GENERATOR_STRATEGY, keyGenerateStrategyConfig.getColumn(), algorithmDefinition));
}
private void appendAuditStrategy(final Map<String, AlgorithmConfiguration> auditors, final ShardingAuditStrategyConfiguration auditStrategy, final StringBuilder stringBuilder) {
if (null != auditStrategy) {
- stringBuilder.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
- stringBuilder.append(String.format(DistSQLScriptConstants.AUDIT_STRATEGY, getAlgorithmTypes(auditors, auditStrategy.getAuditorNames()), auditStrategy.isAllowHintDisable()));
+ stringBuilder.append(ShardingDistSQLConstants.COMMA).append(System.lineSeparator());
+ stringBuilder.append(String.format(ShardingDistSQLConstants.AUDIT_STRATEGY, getAlgorithmTypes(auditors, auditStrategy.getAuditorNames()), auditStrategy.isAllowHintDisable()));
}
}
@@ -202,9 +202,9 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
}
String type = algorithmConfig.getType().toLowerCase();
if (algorithmConfig.getProps().isEmpty()) {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
+ result.append(String.format(ShardingDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS, type));
} else {
- result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
+ result.append(String.format(ShardingDistSQLConstants.ALGORITHM_TYPE, type, getAlgorithmProperties(algorithmConfig.getProps())));
}
return result.toString();
}
@@ -216,7 +216,7 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
while (iterator.hasNext()) {
result.append(getAlgorithmType(auditors.get(iterator.next())));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA);
+ result.append(ShardingDistSQLConstants.COMMA);
}
}
}
@@ -233,9 +233,9 @@ public final class ShardingConvertRuleConfigurationProvider implements ConvertRu
if (null == value) {
continue;
}
- result.append(String.format(DistSQLScriptConstants.PROPERTY, key, value));
+ result.append(String.format(ShardingDistSQLConstants.PROPERTY, key, value));
if (iterator.hasNext()) {
- result.append(DistSQLScriptConstants.COMMA).append(' ');
+ result.append(ShardingDistSQLConstants.COMMA).append(' ');
}
}
return result.toString();
diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/constant/DistSQLScriptConstants.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/constant/DistSQLScriptConstants.java
index 9d5b895f0da..711acccf4c4 100644
--- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/constant/DistSQLScriptConstants.java
+++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/constant/DistSQLScriptConstants.java
@@ -26,14 +26,6 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DistSQLScriptConstants {
- public static final String STANDARD = "standard";
-
- public static final String COMPLEX = "complex";
-
- public static final String HINT = "hint";
-
- public static final String NONE = "";
-
public static final String COMMA = ",";
public static final String SEMI = ";";
@@ -72,144 +64,4 @@ public final class DistSQLScriptConstants {
+ ")";
public static final String PROPERTY = "'%s'='%s'";
-
- public static final String CREATE_SHARDING_TABLE = "CREATE SHARDING TABLE RULE";
-
- public static final String SHARDING_TABLE = " %s ("
- + System.lineSeparator()
- + "DATANODES('%s')%s"
- + System.lineSeparator()
- + ")";
-
- public static final String SHARDING_AUTO_TABLE = " %s ("
- + System.lineSeparator()
- + "STORAGE_UNITS(%s),"
- + System.lineSeparator()
- + "%s"
- + System.lineSeparator()
- + ")";
-
- public static final String AUTO_TABLE_STRATEGY = "SHARDING_COLUMN=%s,"
- + System.lineSeparator()
- + "%s";
-
- public static final String DATABASE_STRATEGY = "DATABASE_STRATEGY";
-
- public static final String TABLE_STRATEGY = "TABLE_STRATEGY";
-
- public static final String STRATEGY_STANDARD = "TYPE='%s', SHARDING_COLUMN=%s, SHARDING_ALGORITHM(%s)";
-
- public static final String STRATEGY_COMPLEX = "TYPE='%s', SHARDING_COLUMNS=%s, SHARDING_ALGORITHM(%s)";
-
- public static final String STRATEGY_HINT = "TYPE='%s', SHARDING_ALGORITHM(%s)";
-
- public static final String STRATEGY_NONE = "TYPE='%s'";
-
- public static final String SHARDING_STRATEGY_STANDARD = "%s(" + STRATEGY_STANDARD + ")";
-
- public static final String SHARDING_STRATEGY_COMPLEX = "%s(" + STRATEGY_COMPLEX + ")";
-
- public static final String SHARDING_STRATEGY_HINT = "%s(" + STRATEGY_HINT + ")";
-
- public static final String SHARDING_STRATEGY_NONE = "%s(" + STRATEGY_NONE + ")";
-
- public static final String KEY_GENERATOR_STRATEGY = "KEY_GENERATE_STRATEGY(COLUMN=%s, %s)";
-
- public static final String AUDIT_STRATEGY = "AUDIT_STRATEGY(%s, ALLOW_HINT_DISABLE=%s)";
-
- public static final String SHARDING_BINDING_TABLE_RULES = "CREATE SHARDING TABLE REFERENCE RULE";
-
- public static final String BINDING_TABLES = " %s (%s)";
-
- public static final String BROADCAST_TABLE_RULE = "CREATE BROADCAST TABLE RULE %s";
-
- public static final String DEFAULT_DATABASE_STRATEGY = "CREATE DEFAULT SHARDING DATABASE STRATEGY";
-
- public static final String DEFAULT_TABLE_STRATEGY = "CREATE DEFAULT SHARDING TABLE STRATEGY";
-
- public static final String CREATE_READWRITE_SPLITTING_RULE = "CREATE READWRITE_SPLITTING RULE";
-
- public static final String READWRITE_SPLITTING_FOR_STATIC = " %s ("
- + System.lineSeparator()
- + "WRITE_STORAGE_UNIT=%s,"
- + System.lineSeparator()
- + "READ_STORAGE_UNITS(%s),"
- + System.lineSeparator()
- + "TRANSACTIONAL_READ_QUERY_STRATEGY='%s'%s"
- + System.lineSeparator()
- + ")";
-
- public static final String READWRITE_SPLITTING_FOR_DYNAMIC = " %s ("
- + System.lineSeparator()
- + "AUTO_AWARE_RESOURCE=%s"
- + System.lineSeparator()
- + ")";
-
- public static final String READ_RESOURCE = "%s";
-
- public static final String CREATE_DB_DISCOVERY = "CREATE DB_DISCOVERY RULE";
-
- public static final String DB_DISCOVERY = " %s ("
- + System.lineSeparator()
- + "STORAGE_UNITS(%s),"
- + System.lineSeparator()
- + "%s,"
- + System.lineSeparator()
- + "HEARTBEAT(PROPERTIES(%s))"
- + System.lineSeparator()
- + ")";
-
- public static final String CREATE_ENCRYPT = "CREATE ENCRYPT RULE";
-
- public static final String ENCRYPT = " %s ("
- + System.lineSeparator()
- + "COLUMNS("
- + System.lineSeparator()
- + "%s"
- + System.lineSeparator()
- + "))";
-
- public static final String ENCRYPT_COLUMN = "(NAME=%s, %s, %s)";
-
- public static final String CIPHER = "CIPHER=%s";
-
- public static final String ASSISTED_QUERY_COLUMN = "ASSISTED_QUERY_COLUMN=%s";
-
- public static final String LIKE_QUERY_COLUMN = "LIKE_QUERY_COLUMN=%s";
-
- public static final String ENCRYPT_ALGORITHM = "ENCRYPT_ALGORITHM(%s)";
-
- public static final String ASSISTED_QUERY_ALGORITHM = "ASSISTED_QUERY_ALGORITHM(%s)";
-
- public static final String LIKE_QUERY_ALGORITHM = "LIKE_QUERY_ALGORITHM(%s)";
-
- public static final String ALGORITHM_TYPE = "TYPE(NAME='%s', PROPERTIES(%s))";
-
- public static final String ALGORITHM_TYPE_WITHOUT_PROPS = "TYPE(NAME='%s')";
-
- public static final String CREATE_SHADOW = "CREATE SHADOW RULE";
-
- public static final String SHADOW = " %s("
- + System.lineSeparator()
- + "SOURCE=%s,"
- + System.lineSeparator()
- + "SHADOW=%s,"
- + System.lineSeparator()
- + "%s"
- + System.lineSeparator()
- + ")";
-
- public static final String SHADOW_TABLE = "%s(%s)";
-
- public static final String CREATE_MASK = "CREATE MASK RULE";
-
- public static final String MASK = " %s ("
- + System.lineSeparator()
- + "COLUMNS("
- + System.lineSeparator()
- + "%s"
- + System.lineSeparator()
- + "),";
-
- public static final String MASK_COLUMN = "(NAME=%s, %s)";
}