Skip to content

Commit

Permalink
Merge pull request alibaba#742 from wenshao/master
Browse files Browse the repository at this point in the history
improved mysql exception sorter
  • Loading branch information
wenshao committed Dec 7, 2014
2 parents 67c4044 + e0e851a commit 09f1c1b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ public class MySqlExceptionSorter implements ExceptionSorter {

@Override
public boolean isExceptionFatal(SQLException e) {
String sqlState = e.getSQLState();
final String sqlState = e.getSQLState();
final int errorCode = e.getErrorCode();

if (sqlState != null && sqlState.startsWith("08")) {
return true;
}

switch (errorCode) {
// Communications Errors
case 1040: // ER_CON_COUNT_ERROR
Expand All @@ -55,9 +56,15 @@ public boolean isExceptionFatal(SQLException e) {
break;
}

// for oceanbase
if (errorCode >= -10000 && errorCode <= -9000) {
return true;
}

String className = e.getClass().getName();
if ("com.mysql.jdbc.CommunicationsException".equals(className)) {
return true;
}

String message = e.getMessage();
if (message != null && message.length() > 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/alibaba/druid/TestOracle.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ protected void setUp() throws Exception {
// password = "ccbuauto";
// SQL = "SELECT * FROM WP_ORDERS WHERE ID = ?";

jdbcUrl = "jdbc:oracle:thin:@10.20.149.81:1521:ointest3";
user = "alibaba";
password = "deYcR7facWSJtCuDpm2r";
jdbcUrl = "jdbc:oracle:thin:@a.b.c.d:1521:xx";
user = "a";
password = "b";
SQL = "SELECT * FROM AV_INFO WHERE ID = ?";

driverClass = "oracle.jdbc.driver.OracleDriver";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public void test_false_1() throws Exception {
MySqlExceptionSorter sorter = new MySqlExceptionSorter();
Assert.assertFalse(sorter.isExceptionFatal(new SQLException("", "", -8000)));
}

public void test_true_3() throws Exception {
MySqlExceptionSorter sorter = new MySqlExceptionSorter();
Assert.assertTrue(sorter.isExceptionFatal(new com.mysql.jdbc.CommunicationsException(null, 0, 0, null)));
}
}

0 comments on commit 09f1c1b

Please sign in to comment.