1 /***
2 * SQLExceptionHandlerSybase.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 Sybase. It takes advantage of the
33 * vendor codes to determine the type of the exceptions.
34 *
35 * @author $Author: dbregeon $
36 * @version $Revision: 1.1 $
37 */
38 public class SQLExceptionHandlerSybase extends DefaultSQLExceptionHandler
39 implements SQLExceptionHandler {
40 /***
41 * As specified in the Sybase documentation.
42 */
43 public static final String SYBASE_CONNECTION_LOST_SQLSTATE = "JZ006";
44
45 /***
46 * As specified in the Sybase documentation.
47 */
48 public static final String SYBASE_IO_ERROR_SQLSTATE = "JW0I0";
49
50 /***
51 * As specified in the Sybase documentation.
52 */
53 public static final String SYBASE_CONNECTION_ALREADY_CLOSED_SQLSTATE = "JZ0C0";
54
55 /***
56 * The unique instance of this SQLExceptionHandler.
57 */
58 private static final SQLExceptionHandlerSybase instance = new SQLExceptionHandlerSybase();
59
60 /***
61 * Gives access to the unique instance of the class.
62 *
63 * @return the unique instance of the class.
64 */
65 public static SQLExceptionHandlerSybase getInstance() {
66 return instance;
67 }
68
69 /***
70 * This method can be used to test an SQLException.
71 *
72 * @param e
73 * an SQLException to test.
74 * @return true if the exception is a loss of connection, false otherwise.
75 */
76 public boolean isLossOfConnection(SQLException e) {
77 String state = e.getSQLState();
78 return (((state != null) && ((state
79 .equals(SYBASE_CONNECTION_LOST_SQLSTATE))
80 || (state.equals(SYBASE_IO_ERROR_SQLSTATE)) || (state
81 .equals(SYBASE_CONNECTION_ALREADY_CLOSED_SQLSTATE)))) || (super
82 .isLossOfConnection(e)));
83 }
84 }