|
| 1 | +/* |
| 2 | + * Copyright 1999-2011 Alibaba Group Holding Ltd. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.alibaba.druid.pool.vendor; |
| 17 | + |
| 18 | +import java.sql.SQLException; |
| 19 | +import java.util.Properties; |
| 20 | + |
| 21 | +import com.alibaba.druid.pool.ExceptionSorter; |
| 22 | + |
| 23 | +public class DB2ExceptionSorter implements ExceptionSorter { |
| 24 | + |
| 25 | + @Override |
| 26 | + public boolean isExceptionFatal(SQLException e) { |
| 27 | + String sqlState = e.getSQLState(); |
| 28 | + if (sqlState != null && sqlState.startsWith("08")) { // Connection Exception |
| 29 | + return true; |
| 30 | + } |
| 31 | + |
| 32 | + int errorCode = e.getErrorCode(); |
| 33 | + switch (errorCode) { |
| 34 | + case -512: // STATEMENT REFERENCE TO REMOTE OBJECT IS INVALID |
| 35 | + case -514: // THE CURSOR IS NOT IN A PREPARED STATE |
| 36 | + case -516: // THE DESCRIBE STATEMENT DOES NOT SPECIFY A PREPARED STATEMENT |
| 37 | + case -518: // THE EXECUTE STATEMENT DOES NOT IDENTIFY A VALID PREPARED STATEMENT |
| 38 | + case -525: // THE SQL STATEMENT CANNOT BE EXECUTED BECAUSE IT WAS IN ERROR AT BIND TIME FOR SECTION = sectno |
| 39 | + // PACKAGE = pkgname CONSISTENCY TOKEN = contoken |
| 40 | + case -909: // THE OBJECT HAS BEEN DELETED OR ALTERED |
| 41 | + case -918: // THE SQL STATEMENT CANNOT BE EXECUTED BECAUSE A CONNECTION HAS BEEN LOST |
| 42 | + case -924: // DB2 CONNECTION INTERNAL ERROR, function-code,return-code,reason-code |
| 43 | + return true; |
| 44 | + default: |
| 45 | + break; |
| 46 | + } |
| 47 | + return false; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public void configFromProperties(Properties properties) { |
| 52 | + |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments