This is an automated email from the ASF dual-hosted git repository.
terrymanu 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 0163d9d7930 Migrate Mask table name uniqueness to Bean Validation
(#40055)
0163d9d7930 is described below
commit 0163d9d7930feb1f0d982c767c0d731f84c6a34d
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Oct 5 00:26:37 2026 +0800
Migrate Mask table name uniqueness to Bean Validation (#40055)
---
.../mask/config/MaskRuleConfiguration.java | 2 +
.../mask/config/MaskRuleConfigurationTest.java | 26 ++++++++++
.../mask/checker/MaskRuleConfigurationChecker.java | 47 ------------------
...g.rule.checker.DatabaseRuleConfigurationChecker | 19 -------
.../checker/MaskRuleConfigurationCheckerTest.java | 58 ----------------------
.../reachability-metadata.json | 4 ++
6 files changed, 32 insertions(+), 124 deletions(-)
diff --git
a/features/mask/api/src/main/java/org/apache/shardingsphere/mask/config/MaskRuleConfiguration.java
b/features/mask/api/src/main/java/org/apache/shardingsphere/mask/config/MaskRuleConfiguration.java
index 6685ff93404..e58e4cff502 100644
---
a/features/mask/api/src/main/java/org/apache/shardingsphere/mask/config/MaskRuleConfiguration.java
+++
b/features/mask/api/src/main/java/org/apache/shardingsphere/mask/config/MaskRuleConfiguration.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.infra.config.rule.function.EnhancedRuleConfigur
import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.validator.constraint.reference.ConfigurationReferenceExists;
import
org.apache.shardingsphere.infra.config.rule.validator.constraint.spi.SPITypeExists;
+import
org.apache.shardingsphere.infra.config.rule.validator.constraint.unique.UniqueTableNames;
import
org.apache.shardingsphere.infra.config.rule.validator.group.RuleConfigurationTypeValidationGroup;
import org.apache.shardingsphere.mask.config.rule.MaskTableRuleConfiguration;
@@ -45,6 +46,7 @@ public final class MaskRuleConfiguration implements
DatabaseRuleConfiguration, E
@NotNull
@Valid
+ @UniqueTableNames(groups = RuleConfigurationTypeValidationGroup.class)
private final Collection<@NotNull MaskTableRuleConfiguration> tables;
@NotNull
diff --git
a/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java
b/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java
index cf1e999367d..9b83e3c8e5a 100644
---
a/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java
+++
b/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java
@@ -27,6 +27,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
+import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -66,6 +67,8 @@ class MaskRuleConfigurationTest {
Arguments.of("Empty configuration", new
MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap())),
Arguments.of("Table without columns", new
MaskRuleConfiguration(
Collections.singleton(new
MaskTableRuleConfiguration("foo_tbl", Collections.emptyList())),
Collections.emptyMap())),
+ Arguments.of("Table names remain case sensitive", new
MaskRuleConfiguration(Arrays.asList(
+ new MaskTableRuleConfiguration("foo_tbl",
Collections.emptyList()), new MaskTableRuleConfiguration("FOO_TBL",
Collections.emptyList())), Collections.emptyMap())),
Arguments.of("Complete configuration", new
MaskRuleConfiguration(Collections.singleton(tableConfig),
Collections.singletonMap("foo_mask", new
AlgorithmConfiguration("FIXTURE", new Properties())))));
}
@@ -83,6 +86,29 @@ class MaskRuleConfigurationTest {
assertThat(actual.getMessage(), containsString("Property `tables`
references unconfigured maskAlgorithms `bar_mask`."));
}
+ @Test
+ void assertDuplicateTableNamesViolation() {
+ MaskRuleConfiguration ruleConfig = new
MaskRuleConfiguration(Arrays.asList(new MaskTableRuleConfiguration("foo_tbl",
Collections.emptyList()),
+ new MaskTableRuleConfiguration("bar_tbl",
Collections.emptyList()), new MaskTableRuleConfiguration("foo_tbl",
Collections.emptyList()),
+ new MaskTableRuleConfiguration("bar_tbl",
Collections.emptyList()), new MaskTableRuleConfiguration("foo_tbl",
Collections.emptyList())), Collections.emptyMap());
+ InvalidRuleConfigurationException actual =
assertThrows(InvalidRuleConfigurationException.class, () ->
RuleConfigurationValidator.validate(ruleConfig));
+ assertThat(actual.getMessage(), is("Invalid 'MaskRuleConfiguration'
rule, error message is: Property `tables` must not contain duplicate table
names `foo_tbl, bar_tbl`."));
+ SQLException actualSQLException = actual.toSQLException();
+ assertThat(actualSQLException.getMessage(), is(actual.getMessage()));
+ assertThat(actualSQLException.getSQLState(), is("44000"));
+ assertThat(actualSQLException.getErrorCode(), is(10200));
+ }
+
+ @Test
+ void assertDuplicateTableNamesAndUnconfiguredMaskAlgorithmViolations() {
+ MaskRuleConfiguration ruleConfig = new
MaskRuleConfiguration(Arrays.asList(
+ new MaskTableRuleConfiguration("foo_tbl",
Collections.singleton(new MaskColumnRuleConfiguration("foo_col", "bar_mask"))),
+ new MaskTableRuleConfiguration("foo_tbl",
Collections.emptyList())), Collections.emptyMap());
+ InvalidRuleConfigurationException actual =
assertThrows(InvalidRuleConfigurationException.class, () ->
RuleConfigurationValidator.validate(ruleConfig));
+ assertThat(actual.getMessage(), is("Invalid 'MaskRuleConfiguration'
rule, error message is: Property `tables` must not contain duplicate table
names `foo_tbl`.; "
+ + "Property `tables` references unconfigured maskAlgorithms
`bar_mask`."));
+ }
+
private static Stream<Arguments> invalidRuleConfigurationArguments() {
AlgorithmConfiguration algorithmConfig = new
AlgorithmConfiguration("FIXTURE", new Properties());
return Stream.of(
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
deleted file mode 100644
index 44930f13ad9..00000000000
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.checker;
-
-import
org.apache.shardingsphere.infra.config.rule.checker.DatabaseRuleConfigurationChecker;
-import org.apache.shardingsphere.mask.config.MaskRuleConfiguration;
-import org.apache.shardingsphere.mask.config.rule.MaskTableRuleConfiguration;
-import org.apache.shardingsphere.mask.constant.MaskOrder;
-
-import java.util.Collection;
-import java.util.stream.Collectors;
-
-/**
- * Mask rule configuration checker.
- */
-public final class MaskRuleConfigurationChecker implements
DatabaseRuleConfigurationChecker<MaskRuleConfiguration> {
-
- @Override
- public Collection<String> getTableNames(final MaskRuleConfiguration
ruleConfig) {
- return
ruleConfig.getTables().stream().map(MaskTableRuleConfiguration::getName).collect(Collectors.toList());
- }
-
- @Override
- public int getOrder() {
- return MaskOrder.ORDER;
- }
-
- @Override
- public Class<MaskRuleConfiguration> getTypeClass() {
- return MaskRuleConfiguration.class;
- }
-}
diff --git
a/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.checker.DatabaseRuleConfigurationChecker
b/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.checker.DatabaseRuleConfigurationChecker
deleted file mode 100644
index c59d97271b1..00000000000
---
a/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.checker.DatabaseRuleConfigurationChecker
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.mask.checker.MaskRuleConfigurationChecker
-
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationCheckerTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationCheckerTest.java
deleted file mode 100644
index 00ae6600335..00000000000
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationCheckerTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.checker;
-
-import
org.apache.shardingsphere.infra.config.rule.checker.DatabaseRuleConfigurationChecker;
-import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
-import org.apache.shardingsphere.mask.config.MaskRuleConfiguration;
-import org.apache.shardingsphere.mask.config.rule.MaskTableRuleConfiguration;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class MaskRuleConfigurationCheckerTest {
-
- @SuppressWarnings("rawtypes")
- private DatabaseRuleConfigurationChecker checker;
-
- @BeforeEach
- void setUp() {
- checker =
OrderedSPILoader.getServicesByClass(DatabaseRuleConfigurationChecker.class,
Collections.singleton(MaskRuleConfiguration.class)).get(MaskRuleConfiguration.class);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- void assertGetTableNames() {
- MaskRuleConfiguration ruleConfig = mockValidConfiguration();
- assertTrue(checker.getTableNames(ruleConfig).contains("t_mask"));
- }
-
- private MaskRuleConfiguration mockValidConfiguration() {
- MaskRuleConfiguration result = mock(MaskRuleConfiguration.class);
- MaskTableRuleConfiguration tableRuleConfig =
mock(MaskTableRuleConfiguration.class);
- when(tableRuleConfig.getName()).thenReturn("t_mask");
-
when(result.getTables()).thenReturn(Collections.singleton(tableRuleConfig));
- return result;
- }
-
-}
diff --git
a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/infra-reachability-metadata/reachability-metadata.json
b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/infra-reachability-metadata/reachability-metadata.json
index cbc131c4a6e..6e44e9493e8 100644
---
a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/infra-reachability-metadata/reachability-metadata.json
+++
b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/infra-reachability-metadata/reachability-metadata.json
@@ -578,6 +578,10 @@
{
"name": "getColumns",
"parameterTypes": []
+ },
+ {
+ "name": "getName",
+ "parameterTypes": []
}
]
},