mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql driver 6.0 support.
This commit is contained in:
+36
-8
@@ -2,9 +2,9 @@ package com.alibaba.druid.bvt.pool.vendor;
|
||||
|
||||
import com.alibaba.druid.PoolTestCase;
|
||||
import com.alibaba.druid.pool.vendor.MySqlExceptionSorter;
|
||||
import com.mysql.jdbc.CommunicationsException;
|
||||
import junit.framework.TestCase;
|
||||
import com.alibaba.druid.util.MySqlUtils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
@@ -14,12 +14,40 @@ public class MySqlExceptionSorterTest_1 extends PoolTestCase {
|
||||
public void test_0() throws Exception {
|
||||
MySqlExceptionSorter sorter = new MySqlExceptionSorter();
|
||||
|
||||
SQLException rootException = new SQLException(
|
||||
new SQLException("Could not retrieve transation read-only status server",
|
||||
new CommunicationsException(null, 0, 0, null)
|
||||
)
|
||||
);
|
||||
Class clazz = MySqlUtils.getCommunicationsExceptionClass();
|
||||
|
||||
assertTrue(sorter.isExceptionFatal(rootException));
|
||||
if ("com.mysql.jdbc.CommunicationsException".equals(clazz.getName())) {
|
||||
Constructor constructor = null;
|
||||
for (Constructor item : clazz.getConstructors()) {
|
||||
if (item.getParameterTypes().length == 4) {
|
||||
constructor = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SQLException rootException = new SQLException(
|
||||
new SQLException("Could not retrieve transation read-only status server",
|
||||
(Exception) constructor.newInstance(null, 0, 0, null)
|
||||
)
|
||||
);
|
||||
|
||||
assertTrue(sorter.isExceptionFatal(rootException));
|
||||
} else {
|
||||
Constructor constructor = null;
|
||||
for (Constructor item : clazz.getConstructors()) {
|
||||
if (item.getParameterTypes().length == 2) {
|
||||
constructor = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SQLException rootException = new SQLException(
|
||||
new SQLException("Could not retrieve transation read-only status server",
|
||||
(Exception) constructor.newInstance(null, null)
|
||||
)
|
||||
);
|
||||
|
||||
assertTrue(sorter.isExceptionFatal(rootException));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -2,9 +2,10 @@ package com.alibaba.druid.bvt.pool.vendor;
|
||||
|
||||
import com.alibaba.druid.PoolTestCase;
|
||||
import com.alibaba.druid.pool.vendor.MySqlExceptionSorter;
|
||||
import com.mysql.jdbc.CommunicationsException;
|
||||
import com.alibaba.druid.util.MySqlUtils;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
@@ -76,7 +76,13 @@ public class DruidDriverTest extends TestCase {
|
||||
}
|
||||
|
||||
public void test_getRawDriverClassName() throws Exception {
|
||||
Assert.assertEquals("com.mysql.jdbc.Driver", JdbcUtils.getDriverClassName("jdbc:mysql:"));
|
||||
String className = JdbcUtils.getDriverClassName("jdbc:mysql:");
|
||||
if (className.equals("com.mysql.jdbc.Driver")) {
|
||||
assertEquals("com.mysql.jdbc.Driver", JdbcUtils.getDriverClassName("jdbc:mysql:"));
|
||||
} else {
|
||||
assertEquals("com.mysql.cj.jdbc.Driver", JdbcUtils.getDriverClassName("jdbc:mysql:"));
|
||||
}
|
||||
|
||||
Assert.assertEquals("oracle.jdbc.OracleDriver", JdbcUtils.getDriverClassName("jdbc:oracle:"));
|
||||
Assert.assertEquals("com.microsoft.jdbc.sqlserver.SQLServerDriver",
|
||||
JdbcUtils.getDriverClassName("jdbc:microsoft:"));
|
||||
|
||||
@@ -19,7 +19,11 @@ public class MySqlUtilsTest extends TestCase {
|
||||
Connection conn = (Connection) constructor.newInstance();
|
||||
MySqlUtils.createXAConnection(driver, conn);
|
||||
} else if (majorVersion == 6) {
|
||||
|
||||
Class<?> clazz_ConnectionImpl = Class.forName("com.mysql.cj.jdbc.ConnectionImpl");
|
||||
Constructor<?> constructor = clazz_ConnectionImpl.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
Connection conn = (Connection) constructor.newInstance();
|
||||
MySqlUtils.createXAConnection(driver, conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user