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 index 0f638c7e2b4cf..fdf7f15c0eddd 100644 --- 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 @@ -26,10 +26,6 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class EncryptDistSQLConstants { - public static final String COMMA = ","; - - public static final String SEMI = ";"; - public static final String CREATE_ENCRYPT = "CREATE ENCRYPT RULE"; public static final String ENCRYPT = " %s (" diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptRuleConfigurationToDistSQLConverter.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptRuleConfigurationToDistSQLConverter.java index b14d2aab2f603..6b925e814b6e0 100644 --- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptRuleConfigurationToDistSQLConverter.java +++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptRuleConfigurationToDistSQLConverter.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.encrypt.distsql.handler.provider; import com.google.common.base.Strings; +import org.apache.shardingsphere.distsql.handler.constant.DistSQLConstants; import org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.AlgorithmDistSQLConverter; import org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.RuleConfigurationToDistSQLConverter; import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration; @@ -47,10 +48,10 @@ public String convert(final EncryptRuleConfiguration ruleConfig) { EncryptTableRuleConfiguration tableRuleConfig = iterator.next(); result.append(String.format(EncryptDistSQLConstants.ENCRYPT, tableRuleConfig.getName(), getEncryptColumns(tableRuleConfig.getColumns(), ruleConfig.getEncryptors()))); if (iterator.hasNext()) { - result.append(EncryptDistSQLConstants.COMMA).append(System.lineSeparator()); + result.append(DistSQLConstants.COMMA).append(System.lineSeparator()); } } - result.append(EncryptDistSQLConstants.SEMI); + result.append(DistSQLConstants.SEMI); return result.toString(); } @@ -61,7 +62,7 @@ private String getEncryptColumns(final Collection readDataSourceNam while (iterator.hasNext()) { result.append(String.format(ReadwriteSplittingDistSQLConstants.READ_RESOURCE, iterator.next())); if (iterator.hasNext()) { - result.append(ReadwriteSplittingDistSQLConstants.COMMA); + result.append(DistSQLConstants.COMMA); } } return result.toString(); @@ -76,7 +77,7 @@ private String getLoadBalancerType(final AlgorithmConfiguration algorithmConfig) StringBuilder result = new StringBuilder(); String loadBalancerType = AlgorithmDistSQLConverter.getAlgorithmType(algorithmConfig); if (!Strings.isNullOrEmpty(loadBalancerType)) { - result.append(ReadwriteSplittingDistSQLConstants.COMMA).append(System.lineSeparator()).append(loadBalancerType); + result.append(DistSQLConstants.COMMA).append(System.lineSeparator()).append(loadBalancerType); } 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 index dec7d424cf18d..5fa04ea9f6a4e 100644 --- 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 @@ -26,10 +26,6 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ShadowDistSQLConstants { - public static final String COMMA = ","; - - public static final String SEMI = ";"; - public static final String CREATE_SHADOW = "CREATE SHADOW RULE"; public static final String SHADOW = " %s(" diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowRuleConfigurationToDistSQLConverter.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowRuleConfigurationToDistSQLConverter.java index f436647ebb48e..45975d5a6ddf1 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowRuleConfigurationToDistSQLConverter.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowRuleConfigurationToDistSQLConverter.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.shadow.distsql.handler.provider; +import org.apache.shardingsphere.distsql.handler.constant.DistSQLConstants; import org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.AlgorithmDistSQLConverter; import org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.RuleConfigurationToDistSQLConverter; import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; @@ -47,10 +48,10 @@ public String convert(final ShadowRuleConfiguration ruleConfig) { String shadowTables = getShadowTables(shadowRuleName, ruleConfig.getTables(), ruleConfig.getShadowAlgorithms()); result.append(String.format(ShadowDistSQLConstants.SHADOW, shadowRuleName, dataSourceConfig.getProductionDataSourceName(), dataSourceConfig.getShadowDataSourceName(), shadowTables)); if (iterator.hasNext()) { - result.append(ShadowDistSQLConstants.COMMA); + result.append(DistSQLConstants.COMMA); } } - result.append(ShadowDistSQLConstants.SEMI); + result.append(DistSQLConstants.SEMI); return result.toString(); } @@ -64,7 +65,7 @@ private String getShadowTables(final String shadowRuleName, final Map shadowAlgorithmNames while (iterator.hasNext()) { result.append(AlgorithmDistSQLConverter.getAlgorithmType(algorithmConfigs.get(iterator.next()))); if (iterator.hasNext()) { - result.append(ShadowDistSQLConstants.COMMA).append(' '); + result.append(DistSQLConstants.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 index d0a3f03ecca7b..14e581a6c3bae 100644 --- 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 @@ -34,10 +34,6 @@ public final class ShardingDistSQLConstants { public static final String NONE = ""; - public static final String COMMA = ","; - - public static final String SEMI = ";"; - public static final String CREATE_SHARDING_TABLE = "CREATE SHARDING TABLE RULE"; public static final String SHARDING_TABLE = " %s (" diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingRuleConfigurationToDistSQLConverter.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingRuleConfigurationToDistSQLConverter.java index b538e50793dee..e73acb9d7f593 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingRuleConfigurationToDistSQLConverter.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingRuleConfigurationToDistSQLConverter.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.sharding.distsql.handler.provider; import com.google.common.base.Strings; +import org.apache.shardingsphere.distsql.handler.constant.DistSQLConstants; import org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.AlgorithmDistSQLConverter; import org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.RuleConfigurationToDistSQLConverter; import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; @@ -65,9 +66,9 @@ private void appendShardingTableRules(final ShardingRuleConfiguration ruleConfig String autoTableRules = getAutoTableRules(ruleConfig); stringBuilder.append(ShardingDistSQLConstants.CREATE_SHARDING_TABLE).append(tableRules); if (!Strings.isNullOrEmpty(tableRules) && !Strings.isNullOrEmpty(autoTableRules)) { - stringBuilder.append(ShardingDistSQLConstants.COMMA); + stringBuilder.append(DistSQLConstants.COMMA); } - stringBuilder.append(autoTableRules).append(ShardingDistSQLConstants.SEMI); + stringBuilder.append(autoTableRules).append(DistSQLConstants.SEMI); } private void appendShardingBindingTableRules(final ShardingRuleConfiguration ruleConfig, final StringBuilder stringBuilder) { @@ -77,23 +78,23 @@ private void appendShardingBindingTableRules(final ShardingRuleConfiguration rul ShardingTableReferenceRuleConfiguration referenceRuleConfig = iterator.next(); stringBuilder.append(String.format(ShardingDistSQLConstants.BINDING_TABLES, referenceRuleConfig.getName(), referenceRuleConfig.getReference())); if (iterator.hasNext()) { - stringBuilder.append(ShardingDistSQLConstants.COMMA); + stringBuilder.append(DistSQLConstants.COMMA); } } - stringBuilder.append(ShardingDistSQLConstants.SEMI); + stringBuilder.append(DistSQLConstants.SEMI); } private void appendDefaultShardingStrategy(final ShardingRuleConfiguration ruleConfig, final StringBuilder result) { if (null != ruleConfig.getDefaultDatabaseShardingStrategy()) { appendStrategy(ruleConfig.getDefaultDatabaseShardingStrategy(), ShardingDistSQLConstants.DEFAULT_DATABASE_STRATEGY, result, ruleConfig.getShardingAlgorithms()); - result.append(ShardingDistSQLConstants.SEMI); + result.append(DistSQLConstants.SEMI); } if (null != ruleConfig.getDefaultTableShardingStrategy()) { if (null != ruleConfig.getDefaultDatabaseShardingStrategy()) { result.append(System.lineSeparator()).append(System.lineSeparator()); } appendStrategy(ruleConfig.getDefaultTableShardingStrategy(), ShardingDistSQLConstants.DEFAULT_TABLE_STRATEGY, result, ruleConfig.getShardingAlgorithms()); - result.append(ShardingDistSQLConstants.SEMI); + result.append(DistSQLConstants.SEMI); } } @@ -106,7 +107,7 @@ private String getTableRules(final ShardingRuleConfiguration ruleConfig) { result.append(String.format(ShardingDistSQLConstants.SHARDING_TABLE, tableRuleConfig.getLogicTable(), tableRuleConfig.getActualDataNodes(), appendTableStrategy(tableRuleConfig, ruleConfig))); if (iterator.hasNext()) { - result.append(ShardingDistSQLConstants.COMMA); + result.append(DistSQLConstants.COMMA); } } } @@ -122,7 +123,7 @@ private String getAutoTableRules(final ShardingRuleConfiguration ruleConfig) { result.append(String.format(ShardingDistSQLConstants.SHARDING_AUTO_TABLE, autoTableRuleConfig.getLogicTable(), autoTableRuleConfig.getActualDataSources(), appendAutoTableStrategy(autoTableRuleConfig, ruleConfig))); if (iterator.hasNext()) { - result.append(ShardingDistSQLConstants.COMMA); + result.append(DistSQLConstants.COMMA); } } } @@ -155,7 +156,7 @@ private void appendStrategy(final ShardingStrategyConfiguration strategyConfig, return; } if (Objects.equals(strategyType, ShardingDistSQLConstants.DATABASE_STRATEGY) || Objects.equals(strategyType, ShardingDistSQLConstants.TABLE_STRATEGY)) { - stringBuilder.append(ShardingDistSQLConstants.COMMA).append(System.lineSeparator()); + stringBuilder.append(DistSQLConstants.COMMA).append(System.lineSeparator()); } String type = strategyConfig.getType().toLowerCase(); String algorithmDefinition = AlgorithmDistSQLConverter.getAlgorithmType(shardingAlgorithms.get(strategyConfig.getShardingAlgorithmName())); @@ -184,14 +185,14 @@ private void appendKeyGenerateStrategy(final Map if (null == keyGenerateStrategyConfig) { return; } - stringBuilder.append(ShardingDistSQLConstants.COMMA).append(System.lineSeparator()); + stringBuilder.append(DistSQLConstants.COMMA).append(System.lineSeparator()); String algorithmDefinition = AlgorithmDistSQLConverter.getAlgorithmType(keyGenerators.get(keyGenerateStrategyConfig.getKeyGeneratorName())); stringBuilder.append(String.format(ShardingDistSQLConstants.KEY_GENERATOR_STRATEGY, keyGenerateStrategyConfig.getColumn(), algorithmDefinition)); } private void appendAuditStrategy(final Map auditors, final ShardingAuditStrategyConfiguration auditStrategy, final StringBuilder stringBuilder) { if (null != auditStrategy) { - stringBuilder.append(ShardingDistSQLConstants.COMMA).append(System.lineSeparator()); + stringBuilder.append(DistSQLConstants.COMMA).append(System.lineSeparator()); stringBuilder.append(String.format(ShardingDistSQLConstants.AUDIT_STRATEGY, getAlgorithmTypes(auditors, auditStrategy.getAuditorNames()), auditStrategy.isAllowHintDisable())); } } @@ -203,7 +204,7 @@ private String getAlgorithmTypes(final Map audit while (iterator.hasNext()) { result.append(AlgorithmDistSQLConverter.getAlgorithmType(auditors.get(iterator.next()))); if (iterator.hasNext()) { - result.append(ShardingDistSQLConstants.COMMA); + result.append(DistSQLConstants.COMMA); } } } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/constant/DistSQLConstants.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/constant/DistSQLConstants.java new file mode 100644 index 0000000000000..9116ff178af70 --- /dev/null +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/constant/DistSQLConstants.java @@ -0,0 +1,32 @@ +/* + * 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.distsql.handler.constant; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * DistSQL constants. + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class DistSQLConstants { + + public static final String COMMA = ","; + + public static final String SEMI = ";"; +}