You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/07/19 05:10:53 UTC

(shardingsphere) branch master updated: For code formant (#39182)

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 5f8d1c00c6a For code formant (#39182)
5f8d1c00c6a is described below

commit 5f8d1c00c6a3e7015d295493a2134da937ad2f54
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Jul 19 13:10:47 2026 +0800

    For code formant (#39182)
---
 .../shardingsphere/encrypt/enums/EncryptColumnItemType.java    |  4 +++-
 .../merge/dal/show/EncryptShowCreateTableMergedResultTest.java |  4 ++--
 .../distsql/handler/update/CreateEncryptRuleExecutor.java      |  8 ++++----
 .../distsql/handler/update/AlterEncryptRuleExecutorTest.java   |  2 +-
 .../distsql/handler/converter/MaskRuleStatementConverter.java  |  3 ++-
 ...adwriteSplittingDataSourceRuleConfigurationCheckerTest.java |  6 +++---
 .../context/statement/type/dml/SelectStatementContextTest.java |  2 +-
 .../org/apache/shardingsphere/infra/hint/SQLHintUtils.java     |  7 ++++---
 .../infra/rule/builder/database/DatabaseRulesBuilder.java      |  4 +++-
 .../executor/rql/resource/ShowLogicalTablesExecutor.java       | 10 ++++++----
 .../impl/driver/jdbc/metadata/JDBCQueryResultMetaDataTest.java |  8 +++++++-
 11 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/enums/EncryptColumnItemType.java b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/enums/EncryptColumnItemType.java
index b2e8388d026..8ab9a40ae0f 100644
--- a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/enums/EncryptColumnItemType.java
+++ b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/enums/EncryptColumnItemType.java
@@ -22,5 +22,7 @@ package org.apache.shardingsphere.encrypt.enums;
  */
 public enum EncryptColumnItemType {
     
-    CIPHER, ASSISTED_QUERY, LIKE_QUERY
+    CIPHER,
+    ASSISTED_QUERY,
+    LIKE_QUERY
 }
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResultTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResultTest.java
index 6d54e13e82e..dfe60b412bb 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResultTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResultTest.java
@@ -134,8 +134,8 @@ class EncryptShowCreateTableMergedResultTest {
         columnRuleConfig.setLikeQuery(new EncryptColumnItemRuleConfiguration("user_id_like", "foo_like_encryptor"));
         EncryptShowCreateTableMergedResult actual = createMergedResult(mergedResult, "foo_tbl", mockEncryptRule(Collections.singleton(columnRuleConfig)));
         assertTrue(actual.next());
-        String expectedSQL = "CREATE TABLE `foo_tbl` (`id` INT NOT NULL, `user_id` VARCHAR(100) NOT NULL, `order_id` VARCHAR(30) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
-        assertThat(actual.getValue(2, String.class), is(expectedSQL));
+        assertThat(actual.getValue(2, String.class),
+                is("CREATE TABLE `foo_tbl` (`id` INT NOT NULL, `user_id` VARCHAR(100) NOT NULL, `order_id` VARCHAR(30) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"));
     }
     
     @Test
diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutor.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutor.java
index 89c2a527bad..eaecd379ea7 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutor.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutor.java
@@ -123,13 +123,13 @@ public final class CreateEncryptRuleExecutor implements DatabaseRuleCreateExecut
         encryptors.stream().filter(Objects::nonNull).forEach(each -> TypedSPILoader.checkService(EncryptAlgorithm.class, each.getName(), each.getProps()));
     }
     
-    private void addToEncryptors(final EncryptColumnSegment column, final Collection<AlgorithmSegment> result) {
-        result.add(column.getCipher().getEncryptor());
+    private void addToEncryptors(final EncryptColumnSegment column, final Collection<AlgorithmSegment> algorithmSegments) {
+        algorithmSegments.add(column.getCipher().getEncryptor());
         if (null != column.getAssistedQuery()) {
-            result.add(column.getAssistedQuery().getEncryptor());
+            algorithmSegments.add(column.getAssistedQuery().getEncryptor());
         }
         if (null != column.getLikeQuery()) {
-            result.add(column.getLikeQuery().getEncryptor());
+            algorithmSegments.add(column.getLikeQuery().getEncryptor());
         }
     }
     
diff --git a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
index c4a6face2eb..97d5332c07c 100644
--- a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
+++ b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
@@ -112,12 +112,12 @@ class AlterEncryptRuleExecutorTest {
     }
     
     private ContextManager mockContextManager(final EncryptRule rule) {
-        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
         DatabaseType databaseType = mock(DatabaseType.class);
         ResourceMetaData resourceMetaData = mock(ResourceMetaData.class);
         ShardingSphereDatabase database =
                 new ShardingSphereDatabase("foo_db", databaseType, resourceMetaData, new RuleMetaData(Collections.singleton(rule)), Collections.emptyList(),
                         new ConfigurationProperties(new Properties()));
+        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
         when(result.getDatabase("foo_db")).thenReturn(database);
         return result;
     }
diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleStatementConverter.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleStatementConverter.java
index c89ea2e3e38..d10a10d49c3 100644
--- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleStatementConverter.java
+++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleStatementConverter.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.mask.distsql.segment.MaskRuleSegment;
 
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -46,7 +47,7 @@ public final class MaskRuleStatementConverter {
      */
     public static MaskRuleConfiguration convert(final Collection<MaskRuleSegment> ruleSegments) {
         Collection<MaskTableRuleConfiguration> tables = new LinkedList<>();
-        Map<String, AlgorithmConfiguration> algorithms = new HashMap<>();
+        Map<String, AlgorithmConfiguration> algorithms = new LinkedHashMap<>();
         for (MaskRuleSegment each : ruleSegments) {
             tables.add(createMaskTableRuleConfiguration(each));
             algorithms.putAll(createMaskAlgorithmConfigurations(each));
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingDataSourceRuleConfigurationCheckerTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingDataSourceRuleConfigurationCheckerTest.java
index 6a230395874..9725fead8e7 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingDataSourceRuleConfigurationCheckerTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingDataSourceRuleConfigurationCheckerTest.java
@@ -25,9 +25,9 @@ import org.apache.shardingsphere.readwritesplitting.exception.actual.DuplicateRe
 import org.apache.shardingsphere.readwritesplitting.exception.actual.MissingRequiredReadwriteSplittingActualDataSourceException;
 import org.apache.shardingsphere.readwritesplitting.exception.actual.ReadwriteSplittingActualDataSourceNotFoundException;
 import org.apache.shardingsphere.readwritesplitting.exception.logic.MissingRequiredReadwriteSplittingDataSourceRuleNameException;
+import org.apache.shardingsphere.test.infra.fixture.jdbc.MockedDataSource;
 import org.junit.jupiter.api.Test;
 
-import javax.sql.DataSource;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
@@ -72,14 +72,14 @@ class ReadwriteSplittingDataSourceRuleConfigurationCheckerTest {
     void assertCheckWithDuplicatedWriteDataSourceName() {
         ReadwriteSplittingDataSourceGroupRuleConfiguration config = new ReadwriteSplittingDataSourceGroupRuleConfiguration("foo_group", "write_ds", Arrays.asList("read_ds0", "read_ds1"), "foo_algo");
         assertThrows(DuplicateReadwriteSplittingActualDataSourceException.class, () -> new ReadwriteSplittingDataSourceRuleConfigurationChecker("foo_db",
-                config, Collections.singletonMap("write_ds", mock(DataSource.class))).check(new HashSet<>(Collections.singleton("write_ds")), Collections.emptyList(), Collections.emptyList()));
+                config, Collections.singletonMap("write_ds", new MockedDataSource())).check(new HashSet<>(Collections.singleton("write_ds")), Collections.emptyList(), Collections.emptyList()));
     }
     
     @Test
     void assertCheckSuccess() {
         ReadwriteSplittingDataSourceGroupRuleConfiguration config = new ReadwriteSplittingDataSourceGroupRuleConfiguration("foo_group", "write_ds", Arrays.asList("read_ds0", "read_ds1"), "foo_algo");
         assertDoesNotThrow(() -> new ReadwriteSplittingDataSourceRuleConfigurationChecker("foo_db", config,
-                Collections.singletonMap("write_ds", mock(DataSource.class))).check(new HashSet<>(), new HashSet<>(), Arrays.asList(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS), mockRule())));
+                Collections.singletonMap("write_ds", new MockedDataSource())).check(new HashSet<>(), new HashSet<>(), Arrays.asList(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS), mockRule())));
     }
     
     private static ShardingSphereRule mockRule() {
diff --git a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContextTest.java b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContextTest.java
index abce5baa330..4850231ab08 100644
--- a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContextTest.java
+++ b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContextTest.java
@@ -360,7 +360,7 @@ class SelectStatementContextTest {
     }
     
     private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
-        return new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
+        return new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), new ConfigurationProperties(new Properties()));
     }
     
     private OrderByItemSegment createOrderByItemSegment(final String type) {
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintUtils.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintUtils.java
index 9f46c93b973..2f5b0a91d91 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintUtils.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintUtils.java
@@ -25,7 +25,7 @@ import lombok.NoArgsConstructor;
 import java.math.BigInteger;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -95,7 +95,8 @@ public final class SQLHintUtils {
     }
     
     private static int getHintKeyValueBeginIndex(final String sql) {
-        int tokenBeginIndex = sql.contains(SQLHintTokenType.SQL_START_HINT_TOKEN.getKey()) ? sql.indexOf(SQLHintTokenType.SQL_START_HINT_TOKEN.getKey())
+        int tokenBeginIndex = sql.contains(SQLHintTokenType.SQL_START_HINT_TOKEN.getKey())
+                ? sql.indexOf(SQLHintTokenType.SQL_START_HINT_TOKEN.getKey())
                 : sql.indexOf(SQLHintTokenType.SQL_START_HINT_TOKEN.getAlias());
         return sql.indexOf(":", tokenBeginIndex) + 1;
     }
@@ -139,7 +140,7 @@ public final class SQLHintUtils {
     }
     
     private static Collection<String> getSplitterSQLHintValue(final String property) {
-        return property.isEmpty() ? Collections.emptySet() : new HashSet<>(Splitter.on(SQL_HINT_VALUE_COLLECTION_SPLIT).omitEmptyStrings().trimResults().splitToList(property));
+        return property.isEmpty() ? Collections.emptySet() : new LinkedHashSet<>(Splitter.on(SQL_HINT_VALUE_COLLECTION_SPLIT).omitEmptyStrings().trimResults().splitToList(property));
     }
     
     /**
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilder.java
index ec5fa96aff3..40abab78286 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilder.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilder.java
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurati
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
 import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.scope.DatabaseRule;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 
@@ -69,7 +70,8 @@ public final class DatabaseRulesBuilder {
             if (null != configChecker) {
                 configChecker.check(databaseName, entry.getKey(), resourceMetaData.getDataSourceMap(), result);
             }
-            result.add(entry.getValue().build(entry.getKey(), databaseName, protocolType, resourceMetaData, result, computeNodeInstanceContext));
+            DatabaseRule rule = entry.getValue().build(entry.getKey(), databaseName, protocolType, resourceMetaData, result, computeNodeInstanceContext);
+            result.add(rule);
         }
         return result;
     }
diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTablesExecutor.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTablesExecutor.java
index 59ffa689c52..3f9e7be36a6 100644
--- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTablesExecutor.java
+++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rql/resource/ShowLogicalTablesExecutor.java
@@ -61,12 +61,14 @@ public final class ShowLogicalTablesExecutor implements DistSQLQueryExecutor<Sho
         if (null == database.getSchema(schemaName)) {
             return Collections.emptyList();
         }
-        return getTables(schemaName, sqlStatement).stream().map(each -> getRow(schemaName, each, sqlStatement)).collect(Collectors.toList());
+        return getTables(schemaName, sqlStatement).stream().map(each -> getRow(schemaName, each, sqlStatement, dialectDatabaseMetaData)).collect(Collectors.toList());
     }
     
-    private LocalDataQueryResultRow getRow(final IdentifierValue schemaName, final ShardingSphereTable table, final ShowLogicalTablesStatement sqlStatement) {
-        if (new DatabaseTypeRegistry(database.getProtocolType()).getDialectDatabaseMetaData().getSchemaOption().isSchemaAvailable()) {
-            return sqlStatement.isContainsFull() ? new LocalDataQueryResultRow(table.getName(), table.getType(), schemaName.getValue())
+    private LocalDataQueryResultRow getRow(final IdentifierValue schemaName, final ShardingSphereTable table, final ShowLogicalTablesStatement sqlStatement,
+                                           final DialectDatabaseMetaData dialectDatabaseMetaData) {
+        if (dialectDatabaseMetaData.getSchemaOption().isSchemaAvailable()) {
+            return sqlStatement.isContainsFull()
+                    ? new LocalDataQueryResultRow(table.getName(), table.getType(), schemaName.getValue())
                     : new LocalDataQueryResultRow(table.getName(), schemaName.getValue());
         }
         return sqlStatement.isContainsFull() ? new LocalDataQueryResultRow(table.getName(), table.getType()) : new LocalDataQueryResultRow(table.getName());
diff --git a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/metadata/JDBCQueryResultMetaDataTest.java b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/metadata/JDBCQueryResultMetaDataTest.java
index ed018e57898..13a6846e424 100644
--- a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/metadata/JDBCQueryResultMetaDataTest.java
+++ b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/metadata/JDBCQueryResultMetaDataTest.java
@@ -19,6 +19,10 @@ package org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.d
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
 
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
@@ -32,6 +36,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
 class JDBCQueryResultMetaDataTest {
     
     private ResultSetMetaData resultSetMetaData;
@@ -61,7 +67,7 @@ class JDBCQueryResultMetaDataTest {
     }
     
     @Test
-    void assertGetResultSetMetaData() throws SQLException {
+    void assertGetResultSetMetaData() {
         assertThat(queryResultMetaData.getResultSetMetaData(), is(resultSetMetaData));
     }