View Javadoc

1   /***
2    * SQLExceptionHandlerOracle.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 Oracle. 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 SQLExceptionHandlerOracle extends DefaultSQLExceptionHandler
39          implements SQLExceptionHandler {
40      /***
41       * As specified in the Oracle documentation.
42       */
43      public static final int ORACLE_NOT_AVAILABLE = 1034;
44  
45      /***
46       * As specified in the Oracle documentation.
47       */
48      public static final int ORACLE_IMMEDIATE_SHUTDOWN_IN_PROGRESS = 1089;
49  
50      /***
51       * As specified in the Oracle documentation.
52       */
53      public static final int ORACLE_CONNECTION_RESET_BY_PEER_CODE = 17002;
54  
55      /***
56       * As specified in the Oracle documentation.
57       */
58      public static final int ORACLE_CONNECTION_LOST_ERROR_CODE = 17008;
59  
60      /***
61       * As specified in the Oracle documentation.
62       */
63      public static final int ORACLE_DEADLOCK = 60;
64  
65      /***
66       * The unique instance of this SQLExceptionHandler.
67       */
68      private static final SQLExceptionHandlerOracle instance = new SQLExceptionHandlerOracle();
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 SQLExceptionHandlerOracle 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 == ORACLE_CONNECTION_LOST_ERROR_CODE)
89                  || (code == ORACLE_NOT_AVAILABLE)
90                  || (code == ORACLE_IMMEDIATE_SHUTDOWN_IN_PROGRESS)
91                  || (code == ORACLE_CONNECTION_RESET_BY_PEER_CODE) || (super
92                  .isLossOfConnection(e)));
93      }
94  
95      /***
96       * This method can be used to test an SQLException.
97       * 
98       * @param e
99       *            an SQLException to test.
100      * @return true if the exception is a deadlock and the transaction was
101      *         rolled back, false otherwise.
102      */
103     public boolean isRolledBackDeadLock(SQLException e) {
104         int code = e.getErrorCode();
105         return ((code == ORACLE_DEADLOCK) || (super.isRolledBackDeadLock(e)));
106     }
107 }