taojintianxia commented on a change in pull request #16179:
URL: https://github.com/apache/shardingsphere/pull/16179#discussion_r829735987



##########
File path: 
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/connection/dialect/MySQLXAConnectionWrapper.java
##########
@@ -31,28 +31,44 @@
  */
 public final class MySQLXAConnectionWrapper implements XAConnectionWrapper {
     
-    private static final String MYSQL_XA_DATASOURCE_5 = 
"com.mysql.jdbc.jdbc2.optional.MysqlXADataSource";
+    private static final Class<Connection> JDBC_CONNECTION_CLASS = 
getJDBCConnectionClass();
     
-    private static final String MYSQL_XA_DATASOURCE_8 = 
"com.mysql.cj.jdbc.MysqlXADataSource";
+    private static final Method XA_CONNECTION_CREATOR_METHOD = 
getXAConnectionCreatorMethod();
     
+    @SuppressWarnings("unchecked")
     @SneakyThrows(ReflectiveOperationException.class)
-    @Override
-    public XAConnection wrap(final XADataSource xaDataSource, final Connection 
connection) {
-        Connection physicalConnection = 
unwrapPhysicalConnection(xaDataSource.getClass().getName(), connection);
-        Method method = 
xaDataSource.getClass().getDeclaredMethod("wrapConnection", Connection.class);
-        method.setAccessible(true);
-        return (XAConnection) method.invoke(xaDataSource, physicalConnection);
+    private static Class<Connection> getJDBCConnectionClass() {
+        try {
+            return (Class<Connection>) 
Class.forName("com.mysql.jdbc.Connection");
+        } catch (final ClassNotFoundException ignored) {
+            return (Class<Connection>) 
Class.forName("com.mysql.cj.jdbc.JdbcConnection");

Review comment:
       why not make this a constant




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to