You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "wangyjay (via GitHub)" <gi...@apache.org> on 2025/07/21 01:00:44 UTC

[PR] feature: XAUtils add support for DM Database [incubator-seata]

wangyjay opened a new pull request, #7551:
URL: https://github.com/apache/incubator-seata/pull/7551

   <!--
       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.
   -->
   <!-- Please make sure you have read and understood the contributing guidelines -->
   
   - [ ] I have registered the PR [changes](../changes).
   
   ### Ⅰ. Describe what this PR did
   XAUtils add support for DM Database
   
   ### Ⅱ. Does this pull request fix one issue?
   <!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
   
   
   ### Ⅲ. Why don't you add test cases (unit test/integration test)? 
   Test cases are included:
   
   XAUtilsTest.java
   
   ### Ⅳ. Describe how to verify it
   Run XAUtilsTest 
   
   ### Ⅴ. Special notes for reviews
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "wangyjay (via GitHub)" <gi...@apache.org>.
wangyjay commented on PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#issuecomment-3105496220

   > @wangyjay Is there an issue that describes the phenomenon before this?
   
   #7467


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "wangyjay (via GitHub)" <gi...@apache.org>.
wangyjay commented on code in PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#discussion_r2266152596


##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(mariaMockConnection, connectionParam);
+                })) {
+
+            XAConnection result = XAUtils.createXAConnection(mariaMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("MariaDB XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionKingbase() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(KINGBASE);
+        // 模拟Kingbase特定的连接类

Review Comment:
   done



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(mariaMockConnection, connectionParam);
+                })) {
+
+            XAConnection result = XAUtils.createXAConnection(mariaMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("MariaDB XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionKingbase() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(KINGBASE);
+        // 模拟Kingbase特定的连接类
+        Class<?> kingbaseConnectionClass = Class.forName("com.kingbase8.core.BaseConnection");
+        Connection kingbaseMockConnection = mock(kingbaseConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("com.kingbase8.xa.KBXAConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(kingbaseMockConnection, connectionParam);
+                })) {
+            XAConnection result = XAUtils.createXAConnection(kingbaseMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("Kingbase XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionDM() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(DM);
+        // 模拟达梦特定的连接类

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "wangyjay (via GitHub)" <gi...@apache.org>.
wangyjay commented on code in PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#discussion_r2250282175


##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/util/XAUtils.java:
##########
@@ -114,6 +116,9 @@ private static Constructor<XAConnection> getConstructorByDBType(Class xaConnecti
                 case JdbcConstants.KINGBASE:
                     Class<?> kingbaseConnectionClass = Class.forName("com.kingbase8.core.BaseConnection");
                     return xaConnectionClass.getConstructor(kingbaseConnectionClass);
+                case JdbcConstants.DM:
+                    // 达梦

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "wangyjay (via GitHub)" <gi...@apache.org>.
wangyjay commented on PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#issuecomment-3186307967

   `org.apache.seata.config.exception.ConfigNotFoundException: service.vgroupMapping.test-tx-group configuration item is required
   	at org.apache.seata.discovery.registry.FileRegistryServiceImpl.lookup(FileRegistryServiceImpl.java:76)
   	at org.apache.seata.core.rpc.netty.NettyClientChannelManager.getAvailServerList(NettyClientChannelManager.java:320)
   	at org.apache.seata.core.rpc.netty.NettyClientChannelManager.doReconnect(NettyClientChannelManager.java:194)`
   
   @funky-eyes  The test error messages now don't seem related to the changes I made. Why is that?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "slievrly (via GitHub)" <gi...@apache.org>.
slievrly commented on PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#issuecomment-3096955511

   @wangyjay Is there an issue that describes the phenomenon before this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "wangyjay (via GitHub)" <gi...@apache.org>.
wangyjay commented on code in PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#discussion_r2250282715


##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(mariaMockConnection, connectionParam);
+                })) {
+
+            XAConnection result = XAUtils.createXAConnection(mariaMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("MariaDB XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionKingbase() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(KINGBASE);
+        // 模拟Kingbase特定的连接类
+        Class<?> kingbaseConnectionClass = Class.forName("com.kingbase8.core.BaseConnection");
+        Connection kingbaseMockConnection = mock(kingbaseConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("com.kingbase8.xa.KBXAConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型

Review Comment:
   done



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(mariaMockConnection, connectionParam);
+                })) {
+
+            XAConnection result = XAUtils.createXAConnection(mariaMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("MariaDB XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionKingbase() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(KINGBASE);
+        // 模拟Kingbase特定的连接类
+        Class<?> kingbaseConnectionClass = Class.forName("com.kingbase8.core.BaseConnection");
+        Connection kingbaseMockConnection = mock(kingbaseConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("com.kingbase8.xa.KBXAConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(kingbaseMockConnection, connectionParam);
+                })) {
+            XAConnection result = XAUtils.createXAConnection(kingbaseMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("Kingbase XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionDM() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(DM);
+        // 模拟达梦特定的连接类
+        Class<?> dmConnectionClass = Class.forName("dm.jdbc.driver.DmdbConnection");
+        Connection dmMockConnection = mock(dmConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("dm.jdbc.driver.DmdbXAConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "wangyjay (via GitHub)" <gi...@apache.org>.
wangyjay commented on PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#issuecomment-3173957831

   > Please register your PR in those two files : https://github.com/apache/incubator-seata/blob/2.x/changes/zh-cn/2.x.md https://github.com/apache/incubator-seata/blob/2.x/changes/en-us/2.x.md
   
   done
   @funky-eyes 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "wangyjay (via GitHub)" <gi...@apache.org>.
wangyjay commented on code in PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#discussion_r2250282469


##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类

Review Comment:
   done



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "wangyjay (via GitHub)" <gi...@apache.org>.
wangyjay commented on code in PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#discussion_r2250283182


##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }

Review Comment:
   Extracted common parts and reduced duplicate code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#discussion_r2233628349


##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类

Review Comment:
   ditto



##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/util/XAUtils.java:
##########
@@ -114,6 +116,9 @@ private static Constructor<XAConnection> getConstructorByDBType(Class xaConnecti
                 case JdbcConstants.KINGBASE:
                     Class<?> kingbaseConnectionClass = Class.forName("com.kingbase8.core.BaseConnection");
                     return xaConnectionClass.getConstructor(kingbaseConnectionClass);
+                case JdbcConstants.DM:
+                    // 达梦

Review Comment:
   Please remove the Chinese comments.



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型

Review Comment:
   ditto



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(mariaMockConnection, connectionParam);
+                })) {
+
+            XAConnection result = XAUtils.createXAConnection(mariaMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("MariaDB XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionKingbase() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(KINGBASE);
+        // 模拟Kingbase特定的连接类
+        Class<?> kingbaseConnectionClass = Class.forName("com.kingbase8.core.BaseConnection");
+        Connection kingbaseMockConnection = mock(kingbaseConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("com.kingbase8.xa.KBXAConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型

Review Comment:
   ditto



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }

Review Comment:
   Since the `try` block is repeated across multiple tests, it would be better to use `@BeforeEach` and `@AfterEach` instead.



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(mariaMockConnection, connectionParam);
+                })) {
+
+            XAConnection result = XAUtils.createXAConnection(mariaMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("MariaDB XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionKingbase() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(KINGBASE);
+        // 模拟Kingbase特定的连接类

Review Comment:
   ditto



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(mariaMockConnection, connectionParam);
+                })) {
+
+            XAConnection result = XAUtils.createXAConnection(mariaMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("MariaDB XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionKingbase() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(KINGBASE);
+        // 模拟Kingbase特定的连接类
+        Class<?> kingbaseConnectionClass = Class.forName("com.kingbase8.core.BaseConnection");
+        Connection kingbaseMockConnection = mock(kingbaseConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("com.kingbase8.xa.KBXAConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(kingbaseMockConnection, connectionParam);
+                })) {
+            XAConnection result = XAUtils.createXAConnection(kingbaseMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("Kingbase XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionDM() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(DM);
+        // 模拟达梦特定的连接类

Review Comment:
   ditto



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/util/XAUtilsTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.seata.rm.datasource.util;
+
+import com.alibaba.druid.util.MySqlUtils;
+import com.alibaba.druid.util.PGUtils;
+import org.apache.seata.rm.BaseDataSourceResource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import javax.sql.XAConnection;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+
+import static org.apache.seata.sqlparser.util.JdbcConstants.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class XAUtilsTest {
+    private Connection mockConnection;
+    private Driver mockDriver;
+    private BaseDataSourceResource mockDataSourceResource;
+
+    @BeforeEach
+    public void setUp() {
+        mockConnection = mock(Connection.class);
+        mockDriver = mock(Driver.class);
+        mockDataSourceResource = mock(BaseDataSourceResource.class);
+        when(mockDataSourceResource.getDriver()).thenReturn(mockDriver);
+    }
+
+    @Test
+    public void testCreateXAConnectionMySQL() throws SQLException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MYSQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+
+        try (MockedStatic<MySqlUtils> mySqlUtilsMock = Mockito.mockStatic(MySqlUtils.class)) {
+            mySqlUtilsMock
+                    .when(() -> MySqlUtils.createXAConnection(any(), any()))
+                    .thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionPostgreSQL() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(POSTGRESQL);
+        XAConnection mockXAConnection = mock(XAConnection.class);
+        try (MockedStatic<PGUtils> pgUtilsMock = Mockito.mockStatic(PGUtils.class)) {
+            pgUtilsMock.when(() -> PGUtils.createXAConnection(any())).thenReturn(mockXAConnection);
+            XAConnection result = XAUtils.createXAConnection(mockConnection, mockDataSourceResource);
+            assertSame(mockXAConnection, result);
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionMariaDB() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(MARIADB);
+        // 模拟MariaDB特定的连接类
+        Class<?> mariaDbConnectionClass = Class.forName("org.mariadb.jdbc.MariaDbConnection");
+        Connection mariaMockConnection = mock(mariaDbConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("org.mariadb.jdbc.MariaXaConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(mariaMockConnection, connectionParam);
+                })) {
+
+            XAConnection result = XAUtils.createXAConnection(mariaMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("MariaDB XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionKingbase() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(KINGBASE);
+        // 模拟Kingbase特定的连接类
+        Class<?> kingbaseConnectionClass = Class.forName("com.kingbase8.core.BaseConnection");
+        Connection kingbaseMockConnection = mock(kingbaseConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("com.kingbase8.xa.KBXAConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型
+                    Connection connectionParam =
+                            (Connection) context.arguments().get(0);
+                    assertSame(kingbaseMockConnection, connectionParam);
+                })) {
+            XAConnection result = XAUtils.createXAConnection(kingbaseMockConnection, mockDataSourceResource);
+            assertNotNull(result);
+        } catch (ClassNotFoundException e) {
+            fail("Kingbase XAConnection class not found in test environment");
+        }
+    }
+
+    @Test
+    public void testCreateXAConnectionDM() throws SQLException, ClassNotFoundException {
+        when(mockDataSourceResource.getDbType()).thenReturn(DM);
+        // 模拟达梦特定的连接类
+        Class<?> dmConnectionClass = Class.forName("dm.jdbc.driver.DmdbConnection");
+        Connection dmMockConnection = mock(dmConnectionClass.asSubclass(Connection.class));
+        try (MockedConstruction<?> ignored = mockConstruction(
+                Class.forName("dm.jdbc.driver.DmdbXAConnection").asSubclass(XAConnection.class), (mock, context) -> {
+                    // 验证构造器参数类型

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] optimize: add support for DM Database in XAUtils class [incubator-seata]

Posted by "slievrly (via GitHub)" <gi...@apache.org>.
slievrly merged PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: XAUtils add support for DM Database [incubator-seata]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #7551:
URL: https://github.com/apache/incubator-seata/pull/7551#issuecomment-3097001351

   ## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/7551?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `83.33333%` with `1 line` in your changes missing coverage. Please review.
   > Project coverage is 60.50%. Comparing base [(`608785f`)](https://app.codecov.io/gh/apache/incubator-seata/commit/608785fa859b8901b5c7e3e8e558c89f96b508cf?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`9a811a1`)](https://app.codecov.io/gh/apache/incubator-seata/commit/9a811a155d19a9bfb98f8499e1615709de7c83bf?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/7551?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...a/org/apache/seata/rm/datasource/util/XAUtils.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7551?src=pr&el=tree&filepath=rm-datasource%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Fdatasource%2Futil%2FXAUtils.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cm0tZGF0YXNvdXJjZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZGF0YXNvdXJjZS91dGlsL1hBVXRpbHMuamF2YQ==) | 83.33% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7551?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##                2.x    #7551      +/-   ##
   ============================================
   - Coverage     60.50%   60.50%   -0.01%     
   - Complexity      656      658       +2     
   ============================================
     Files          1298     1298              
     Lines         49081    49087       +6     
     Branches       5771     5772       +1     
   ============================================
   + Hits          29697    29699       +2     
   - Misses        16751    16759       +8     
   + Partials       2633     2629       -4     
   ```
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/7551?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...a/org/apache/seata/rm/datasource/util/XAUtils.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7551?src=pr&el=tree&filepath=rm-datasource%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Fdatasource%2Futil%2FXAUtils.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cm0tZGF0YXNvdXJjZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZGF0YXNvdXJjZS91dGlsL1hBVXRpbHMuamF2YQ==) | `45.16% <83.33%> (+5.87%)` | :arrow_up: |
   
   ... and [6 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-seata/pull/7551/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/incubator-seata/pull/7551/graphs/tree.svg?width=650&height=150&src=pr&token=tbmHt2ZfxO&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/incubator-seata/pull/7551?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org