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

zhonghongsheng 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 ad78338caa7 Extract DatabaseTypeUtils.getTypeAndBranchTypes (#37843)
ad78338caa7 is described below

commit ad78338caa7691fb36fd4f5cc03f2ea1224e661f
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Mon Jan 26 11:07:58 2026 +0800

    Extract DatabaseTypeUtils.getTypeAndBranchTypes (#37843)
---
 .../CRC32MatchTableDataConsistencyChecker.java     | 10 +----
 .../data/pipeline/core/util/DatabaseTypeUtils.java | 50 ++++++++++++++++++++++
 test/it/pipeline/pom.xml                           |  6 +++
 .../pipeline/core/util/DatabaseTypeUtilsTest.java  | 40 +++++++++++++++++
 4 files changed, 98 insertions(+), 8 deletions(-)

diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/CRC32MatchTableDataConsistencyChecker.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/CRC32MatchTableDataConsistencyChecker.java
index 7e2c209fdf7..7df72f430c7 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/CRC32MatchTableDataConsistencyChecker.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/CRC32MatchTableDataConsistencyChecker.java
@@ -20,13 +20,11 @@ package 
org.apache.shardingsphere.data.pipeline.core.consistencycheck.table;
 import 
org.apache.shardingsphere.data.pipeline.core.consistencycheck.result.TableInventoryCheckCalculatedResult;
 import 
org.apache.shardingsphere.data.pipeline.core.consistencycheck.table.calculator.CRC32TableInventoryCheckCalculator;
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.inventory.query.calculator.TableInventoryCalculator;
+import org.apache.shardingsphere.data.pipeline.core.util.DatabaseTypeUtils;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import 
org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.infra.spi.annotation.SPIDescription;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 
 import java.util.Collection;
-import java.util.LinkedList;
 
 /**
  * CRC32 match table data consistency checker.
@@ -41,11 +39,7 @@ public final class CRC32MatchTableDataConsistencyChecker 
implements TableDataCon
     
     @Override
     public Collection<DatabaseType> getSupportedDatabaseTypes() {
-        Collection<DatabaseType> result = new LinkedList<>();
-        DatabaseType supportedDatabaseType = 
TypedSPILoader.getService(DatabaseType.class, "MySQL");
-        result.add(supportedDatabaseType);
-        result.addAll(new 
DatabaseTypeRegistry(supportedDatabaseType).getAllBranchDatabaseTypes());
-        return result;
+        return DatabaseTypeUtils.getTypeAndBranchTypes("MySQL");
     }
     
     @Override
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/DatabaseTypeUtils.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/DatabaseTypeUtils.java
new file mode 100644
index 00000000000..620424d6633
--- /dev/null
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/DatabaseTypeUtils.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.data.pipeline.core.util;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import 
org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * Database type utility.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+@Slf4j
+public final class DatabaseTypeUtils {
+    
+    /**
+     * Get type and branch types.
+     *
+     * @param databaseType database type
+     * @return type and branch types
+     */
+    public static Collection<DatabaseType> getTypeAndBranchTypes(final String 
databaseType) {
+        Collection<DatabaseType> result = new LinkedList<>();
+        DatabaseType supportedDatabaseType = 
TypedSPILoader.getService(DatabaseType.class, databaseType);
+        result.add(supportedDatabaseType);
+        result.addAll(new 
DatabaseTypeRegistry(supportedDatabaseType).getAllBranchDatabaseTypes());
+        return result;
+    }
+}
diff --git a/test/it/pipeline/pom.xml b/test/it/pipeline/pom.xml
index ce909eb7f38..0812c840de5 100644
--- a/test/it/pipeline/pom.xml
+++ b/test/it/pipeline/pom.xml
@@ -115,6 +115,12 @@
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-database-connector-mariadb</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
         
         <dependency>
             <groupId>com.h2database</groupId>
diff --git 
a/test/it/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/DatabaseTypeUtilsTest.java
 
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/DatabaseTypeUtilsTest.java
new file mode 100644
index 00000000000..ab4de2cc197
--- /dev/null
+++ 
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/DatabaseTypeUtilsTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.data.pipeline.core.util;
+
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class DatabaseTypeUtilsTest {
+    
+    @Test
+    void assertGetTypeAndBranchTypes() {
+        Collection<DatabaseType> actual = 
DatabaseTypeUtils.getTypeAndBranchTypes("MySQL");
+        assertNotNull(actual);
+        assertFalse(actual.isEmpty());
+        
assertTrue(actual.contains(TypedSPILoader.getService(DatabaseType.class, 
"MySQL")));
+        
assertTrue(actual.contains(TypedSPILoader.getService(DatabaseType.class, 
"MariaDB")));
+    }
+}

Reply via email to