From 78d90fa2b0b78777647b1528658df3b88b81c4c8 Mon Sep 17 00:00:00 2001 From: "liangjie.li" Date: Fri, 28 Jun 2013 18:18:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9mysql=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pool/vendor/MySqlExceptionSorter.java | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/alibaba/druid/pool/vendor/MySqlExceptionSorter.java b/src/main/java/com/alibaba/druid/pool/vendor/MySqlExceptionSorter.java index 37a98bdfcc..d09dcae74b 100644 --- a/src/main/java/com/alibaba/druid/pool/vendor/MySqlExceptionSorter.java +++ b/src/main/java/com/alibaba/druid/pool/vendor/MySqlExceptionSorter.java @@ -24,12 +24,32 @@ public class MySqlExceptionSorter implements ExceptionSorter { @Override public boolean isExceptionFatal(SQLException e) { + int loopCount = 20; + + Throwable cause = e; + while (cause != null) { + if (cause instanceof SQLException) { + SQLException sqlException = (SQLException) cause; + + if (isExceptionFatal0(sqlException)) { + return true; + } + } + cause = cause.getCause(); + if (--loopCount < 0) { + break; + } + } + return false; + } + + private boolean isExceptionFatal0(SQLException e) { String sqlState = e.getSQLState(); - if (sqlState != null && sqlState.startsWith("08")) { // per Mark Matthews at MySQL + final int errorCode = Math.abs(e.getErrorCode()); + + if (sqlState != null && sqlState.startsWith("08")) { return true; } - - final int errorCode = e.getErrorCode(); switch (errorCode) { // Communications Errors case 1040: // ER_CON_COUNT_ERROR @@ -39,35 +59,32 @@ public class MySqlExceptionSorter implements ExceptionSorter { case 1081: // ER_IPSOCK_ERROR case 1129: // ER_HOST_IS_BLOCKED case 1130: // ER_HOST_NOT_PRIVILEGED - // Authentication Errors case 1045: // ER_ACCESS_DENIED_ERROR - // Resource errors case 1004: // ER_CANT_CREATE_FILE case 1005: // ER_CANT_CREATE_TABLE case 1015: // ER_CANT_LOCK case 1021: // ER_DISK_FULL case 1041: // ER_OUT_OF_RESOURCES - // Out-of-memory errors case 1037: // ER_OUTOFMEMORY case 1038: // ER_OUT_OF_SORTMEMORY return true; - - default: - break; - } - - if (errorCode >= -10000 && errorCode <= -9000) { - return true; } + if (StringUtils.isNotBlank(e.getMessage())) { + final String errorText = e.getMessage().toUpperCase(); + + if (errorCode == 0 + && (errorText.indexOf("COMMUNICATIONS LINK FAILURE") > -1 || errorText + .indexOf("COULD NOT CREATE CONNECTION") > -1) + || errorText.indexOf("NO DATASOURCE") > -1 + || errorText.indexOf("NO ALIVE DATASOURCE") > -1) { + return true; + } + } return false; } - - public void configFromProperties(Properties properties) { - - } }