记录下来的日志,我想看ClientPreparedStatement的第 953 行到底发生了什么,结果在下载的源文件里死活找不到对应的入口:

    1. Caused by: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
    2. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:123)
    3. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
    4. at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    5. at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
    6. at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092)
    7. at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)
    8. at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347)
    9. at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)
    10. at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
    11. at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
    12. at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
    13. ... 186 common frames omitted

    我查找ClientPreparedStatement的第 953 行:

    1. protected <M extends Message> ResultSetInternalMethods executeInternal(int maxRowsToRetrieve, M sendPacket, boolean createStreamingResultSet,
    2. boolean queryIsSelectOnly, ColumnDefinition metadata, boolean isBatch) throws SQLException {
    3. synchronized (checkClosed().getConnectionMutex()) {
    4. try {
    5. JdbcConnection locallyScopedConnection = this.connection;
    6. ((PreparedQuery<?>) this.query).getQueryBindings()
    7. .setNumberOfExecutions(((PreparedQuery<?>) this.query).getQueryBindings().getNumberOfExecutions() + 1);
    8. ResultSetInternalMethods rs;
    9. CancelQueryTask timeoutTask = null;
    10. try {
    11. timeoutTask = startQueryTimer(this, getTimeoutInMillis());
    12. if (!isBatch) {
    13. statementBegins();
    14. }
    15. rs = ((NativeSession) locallyScopedConnection.getSession()).execSQL(this, null, maxRowsToRetrieve, (NativePacketPayload) sendPacket,
    16. createStreamingResultSet, getResultSetFactory(), metadata, isBatch);
    17. if (timeoutTask != null) {
    18. stopQueryTimer(timeoutTask, true, true);
    19. timeoutTask = null;
    20. }
    21. } finally {
    22. if (!isBatch) {
    23. this.query.getStatementExecuting().set(false);
    24. }
    25. stopQueryTimer(timeoutTask, false, false);
    26. }
    27. return rs;
    28. } catch (NullPointerException npe) {
    29. checkClosed(); // we can't synchronize ourselves against async connection-close due to deadlock issues, so this is the next best thing for
    30. // this particular corner case.
    31. throw npe;
    32. }
    33. }
    34. } // 这一行在文件中是第953行

    人傻了,通过字节码发现确实是存在的对应的一段操作方法的,那我就纳闷了,后来突然想起来代码增强这一件事,去 Github 上还真找到了,这一部分就是用来增强一些方法的异常捕获能力。当build源码时会触发增强,详情看 build.xml