Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/alibaba/druid
Browse files Browse the repository at this point in the history
  • Loading branch information
高阳 committed Jul 17, 2013
2 parents 27ee6dd + 34d07a9 commit 6ec43a8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/com/alibaba/druid/pool/DruidDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.alibaba.druid.filter.FilterChainImpl;
import com.alibaba.druid.mock.MockDriver;
import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
import com.alibaba.druid.pool.vendor.DB2ExceptionSorter;
import com.alibaba.druid.pool.vendor.InformixExceptionSorter;
import com.alibaba.druid.pool.vendor.MSSQLValidConnectionChecker;
import com.alibaba.druid.pool.vendor.MockExceptionSorter;
Expand Down Expand Up @@ -853,9 +854,9 @@ private void initValidConnectionChecker() {

private void initExceptionSorter() {
String realDriverClassName = driver.getClass().getName();
if (realDriverClassName.equals("com.mysql.jdbc.Driver")) {
if (realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER)) {
this.exceptionSorter = new MySqlExceptionSorter();
} else if (realDriverClassName.equals("oracle.jdbc.driver.OracleDriver")) {
} else if (realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER)) {
this.exceptionSorter = new OracleExceptionSorter();
} else if (realDriverClassName.equals("com.informix.jdbc.IfxDriver")) {
this.exceptionSorter = new InformixExceptionSorter();
Expand All @@ -865,6 +866,8 @@ private void initExceptionSorter() {

} else if (realDriverClassName.equals("com.alibaba.druid.mock.MockDriver")) {
this.exceptionSorter = new MockExceptionSorter();
} else if (realDriverClassName.contains("DB2")) {
this.exceptionSorter = new DB2ExceptionSorter();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.pool.vendor;

import java.sql.SQLException;
import java.util.Properties;

import com.alibaba.druid.pool.ExceptionSorter;

public class DB2ExceptionSorter implements ExceptionSorter {

@Override
public boolean isExceptionFatal(SQLException e) {
String sqlState = e.getSQLState();
if (sqlState != null && sqlState.startsWith("08")) { // Connection Exception
return true;
}

int errorCode = e.getErrorCode();
switch (errorCode) {
case -512: // STATEMENT REFERENCE TO REMOTE OBJECT IS INVALID
case -514: // THE CURSOR IS NOT IN A PREPARED STATE
case -516: // THE DESCRIBE STATEMENT DOES NOT SPECIFY A PREPARED STATEMENT
case -518: // THE EXECUTE STATEMENT DOES NOT IDENTIFY A VALID PREPARED STATEMENT
case -525: // THE SQL STATEMENT CANNOT BE EXECUTED BECAUSE IT WAS IN ERROR AT BIND TIME FOR SECTION = sectno
// PACKAGE = pkgname CONSISTENCY TOKEN = contoken
case -909: // THE OBJECT HAS BEEN DELETED OR ALTERED
case -918: // THE SQL STATEMENT CANNOT BE EXECUTED BECAUSE A CONNECTION HAS BEEN LOST
case -924: // DB2 CONNECTION INTERNAL ERROR, function-code,return-code,reason-code
return true;
default:
break;
}
return false;
}

@Override
public void configFromProperties(Properties properties) {

}

}

0 comments on commit 6ec43a8

Please sign in to comment.