1 /***
2 * SQLExceptionHandlerDB2.java
3 *
4 * This file is part of the creme library.
5 * The creme library intends to ease the development effort of large
6 * applications by providing easy to use support classes.
7 *
8 * Copyright (C) 2002 Denis Bregeon
9 *
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 * contact information: dbregeon@sourceforge.net
26 */
27 package org.jcreme.sql;
28
29 import java.sql.SQLException;
30
31 /***
32 * This SQLExceptionHandler is specific to DB2. It takes advantage of the vendor
33 * codes to determine the type of the exceptions.
34 *
35 * @author $Author: dbregeon $
36 * @version $Revision: 1.1 $
37 */
38 public class SQLExceptionHandlerDB2 extends DefaultSQLExceptionHandler
39 implements SQLExceptionHandler {
40 /***
41 * As specified in the DB2 documentation.
42 */
43 public static final int DB2_COMMUNICATION_ERROR = -30081;
44
45 /***
46 * As specified in the DB2 documentation.
47 */
48 public static final int DB2_DISABLED_FUNCTION = -906;
49
50 /***
51 * As specified in the DB2 documentation.
52 */
53 public static final int DB2_DISABLED_STATE = -981;
54
55 /***
56 * As specified in the DB2 documentation.
57 */
58 public static final int DB2_DEADLOCK_OR_TIMEOUT = -913;
59
60 /***
61 * As specified in the DB2 documentation.
62 */
63 public static final String DB2_DEADLOCK_WITHOUT_ROLLBACK = "57033";
64
65 /***
66 * The unique instance of this SQLExceptionHandler.
67 */
68 private static final SQLExceptionHandlerDB2 instance = new SQLExceptionHandlerDB2();
69
70 /***
71 * Gives access to the unique instance of the class.
72 *
73 * @return the unique instance of the class.
74 */
75 public static SQLExceptionHandlerDB2 getInstance() {
76 return instance;
77 }
78
79 /***
80 * This method can be used to test an SQLException.
81 *
82 * @param e
83 * an SQLException to test.
84 * @return true if the exception is a loss of connection, false otherwise.
85 */
86 public boolean isLossOfConnection(SQLException e) {
87 int code = e.getErrorCode();
88 return (((code == DB2_COMMUNICATION_ERROR)
89 || (code == DB2_DISABLED_FUNCTION) || (code == DB2_DISABLED_STATE)) || (super
90 .isLossOfConnection(e)));
91 }
92
93 /***
94 * This method can be used to test an SQLException.
95 *
96 * @param e
97 * an SQLException to test.
98 * @return true if the exception is a simple deadlock, false otherwise.
99 */
100 public boolean isPlainDeadLock(SQLException e) {
101 String state = e.getSQLState();
102 int code = e.getErrorCode();
103 return ((code == DB2_DEADLOCK_OR_TIMEOUT)
104 || ((state != null) && (state.equals("57033"))) || (super
105 .isPlainDeadLock(e)));
106 }
107 }