|
|
@ -357,16 +357,14 @@ public class MySqlUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Class<?> clazz = conn.getClass(); |
|
|
|
Class<?> clazz = conn.getClass(); |
|
|
|
if (class_ConnectionImpl == null) { |
|
|
|
if (clazz.getName().equals("com.mysql.jdbc.ConnectionImpl")) { |
|
|
|
if (clazz.getName().equals("com.mysql.jdbc.ConnectionImpl")) { |
|
|
|
class_ConnectionImpl = clazz; |
|
|
|
class_ConnectionImpl = clazz; |
|
|
|
} else if (clazz.getName().equals("com.mysql.jdbc.Connection")) { // mysql 5.0.x
|
|
|
|
} else if (clazz.getName().equals("com.mysql.jdbc.Connection")) { // mysql 5.0.x
|
|
|
|
class_ConnectionImpl = clazz; |
|
|
|
class_ConnectionImpl = clazz; |
|
|
|
} else if (clazz.getName().equals("com.mysql.cj.jdbc.ConnectionImpl")) { // mysql 5.0.x
|
|
|
|
} else if (clazz.getName().equals("com.mysql.cj.jdbc.ConnectionImpl")) { // mysql 5.0.x
|
|
|
|
class_ConnectionImpl = clazz; |
|
|
|
class_ConnectionImpl = clazz; |
|
|
|
} else if (clazz.getSuperclass().getName().equals("com.mysql.jdbc.ConnectionImpl")) { |
|
|
|
} else if (clazz.getSuperclass().getName().equals("com.mysql.jdbc.ConnectionImpl")) { |
|
|
|
class_ConnectionImpl = clazz.getSuperclass(); |
|
|
|
class_ConnectionImpl = clazz.getSuperclass(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (class_ConnectionImpl == clazz || class_ConnectionImpl == clazz.getSuperclass()) { |
|
|
|
if (class_ConnectionImpl == clazz || class_ConnectionImpl == clazz.getSuperclass()) { |
|
|
@ -387,14 +385,16 @@ public class MySqlUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static long getLastPacketReceivedTimeMs(Connection conn) throws SQLException { |
|
|
|
public static long getLastPacketReceivedTimeMs(Connection conn) throws SQLException { |
|
|
|
if (class_connectionImpl == null && !class_connectionImpl_Error) { |
|
|
|
if (!class_connectionImpl_Error) { |
|
|
|
|
|
|
|
if (conn == null) { |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
class_connectionImpl = Utils.loadClass("com.mysql.jdbc.MySQLConnection"); |
|
|
|
//REPORT-66916 这里之前获取到的是lib下的mysql5实现,而不是自定义mysql8驱动的实现
|
|
|
|
if (class_connectionImpl == null) { |
|
|
|
String className = conn.getClass().getName(); |
|
|
|
class_connectionImpl = Utils.loadClass("com.mysql.cj.MysqlConnection"); |
|
|
|
class_connectionImpl = Utils.loadClass(className); |
|
|
|
if (class_connectionImpl != null) { |
|
|
|
if (className.equals("com.mysql.cj.MysqlConnection")) { |
|
|
|
mysqlJdbcVersion6 = true; |
|
|
|
mysqlJdbcVersion6 = true; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Throwable error) { |
|
|
|
} catch (Throwable error) { |
|
|
|
class_connectionImpl_Error = true; |
|
|
|
class_connectionImpl_Error = true; |
|
|
@ -406,9 +406,7 @@ public class MySqlUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(mysqlJdbcVersion6){ |
|
|
|
if(mysqlJdbcVersion6){ |
|
|
|
if (classJdbc == null) { |
|
|
|
classJdbc = Utils.loadClass("com.mysql.cj.jdbc.JdbcConnection"); |
|
|
|
classJdbc = Utils.loadClass("com.mysql.cj.jdbc.JdbcConnection"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (classJdbc == null) { |
|
|
|
if (classJdbc == null) { |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
@ -435,13 +433,13 @@ public class MySqlUtils { |
|
|
|
|
|
|
|
|
|
|
|
return System.currentTimeMillis() |
|
|
|
return System.currentTimeMillis() |
|
|
|
- ((Long) |
|
|
|
- ((Long) |
|
|
|
getIdleFor.invoke(connImpl)) |
|
|
|
getIdleFor.invoke(connImpl)) |
|
|
|
.longValue(); |
|
|
|
.longValue(); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
throw new SQLException("getIdleFor error", e); |
|
|
|
throw new SQLException("getIdleFor error", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (method_getIO == null && !method_getIO_error) { |
|
|
|
if (!method_getIO_error) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
method_getIO = class_connectionImpl.getMethod("getIO"); |
|
|
|
method_getIO = class_connectionImpl.getMethod("getIO"); |
|
|
|
} catch (Throwable error) { |
|
|
|
} catch (Throwable error) { |
|
|
@ -453,7 +451,7 @@ public class MySqlUtils { |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (class_MysqlIO == null && !class_MysqlIO_Error) { |
|
|
|
if (!class_MysqlIO_Error) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
class_MysqlIO = Utils.loadClass("com.mysql.jdbc.MysqlIO"); |
|
|
|
class_MysqlIO = Utils.loadClass("com.mysql.jdbc.MysqlIO"); |
|
|
|
} catch (Throwable error) { |
|
|
|
} catch (Throwable error) { |
|
|
@ -465,7 +463,7 @@ public class MySqlUtils { |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (method_getLastPacketReceivedTimeMs == null && !method_getLastPacketReceivedTimeMs_error) { |
|
|
|
if (!method_getLastPacketReceivedTimeMs_error) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Method method = class_MysqlIO.getDeclaredMethod("getLastPacketReceivedTimeMs"); |
|
|
|
Method method = class_MysqlIO.getDeclaredMethod("getLastPacketReceivedTimeMs"); |
|
|
|
method.setAccessible(true); |
|
|
|
method.setAccessible(true); |
|
|
|