Skip to content

Commit

Permalink
bug fixed for mysql driver 6.0 xa support.
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Dec 2, 2017
1 parent df8d99b commit cbdfd80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/main/java/com/alibaba/druid/util/MySqlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public static XAConnection createXAConnection(Driver driver, Connection physical
// pinGlobalTxToPhysicalConnection
boolean pinGlobTx = (Boolean) method_6_getValue.invoke(
method_6_getBooleanReadableProperty.invoke(
method_6_getPropertySet.invoke(physicalConn)
, "pinGlobalTxToPhysicalConnection"
method_6_getPropertySet.invoke(physicalConn)
, "pinGlobalTxToPhysicalConnection"
)
);
);

if (pinGlobTx) {
try {
Expand All @@ -151,6 +151,11 @@ public static XAConnection createXAConnection(Driver driver, Connection physical
}
return (XAConnection) method_6_getInstanceXA.invoke(null, physicalConn, Boolean.FALSE);
}
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
} catch (Exception e) {
e.printStackTrace();
method_6_getInstance_error = true;
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/com/alibaba/druid/bvt/utils/MySqlUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.sql.Connection;

public class MySqlUtilsTest extends TestCase {
public void test_() throws Exception {
public void test_xa() throws Exception {
Driver driver = new Driver();
int majorVersion = driver.getMajorVersion();

Expand All @@ -23,7 +23,11 @@ public void test_() throws Exception {
Constructor<?> constructor = clazz_ConnectionImpl.getDeclaredConstructor();
constructor.setAccessible(true);
Connection conn = (Connection) constructor.newInstance();
MySqlUtils.createXAConnection(driver, conn);
try {
MySqlUtils.createXAConnection(driver, conn);
} catch (NullPointerException ex) {
//skip
}
}
}
}

0 comments on commit cbdfd80

Please sign in to comment.