View Javadoc

1   /***
2    * DeadLockException.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.BatchUpdateException;
30  import java.sql.SQLException;
31  
32  /***
33   * This class enables to precise the nature of an SQLException. When a deadlock
34   * is detected, this class enables to report it and eventually handle it (for
35   * instance by repeating the query a number of times).
36   * 
37   * @author $Author: dbregeon $
38   * @version $Revision: 1.1 $
39   */
40  public class DeadLockException extends SQLException {
41      /***
42       * Specifies if the statement that threw this exception was a
43       * BatchStatement.
44       */
45      private boolean wasBatchStatement = false;
46  
47      /***
48       * Creates a new DeadLockException.
49       * 
50       * @param reason
51       *            a description of the exception.
52       * @param sqlState
53       *            an XOPEN or SQL 99 code identifying the exception
54       * @param vendorCode
55       *            a database vendor-specific exception code
56       */
57      public DeadLockException(String reason, String sqlState, int vendorCode) {
58          super(reason, sqlState, vendorCode);
59      }
60  
61      /***
62       * Adds a BatchUpdateException object to the end of the chain. The flag
63       * wasBatchStatement is also set to true.
64       * 
65       * @param exc
66       *            the new exception that will be added to the end of the
67       *            SQLException chain.
68       */
69      public void setNextException(BatchUpdateException exc) {
70          this.wasBatchStatement = true;
71          super.setNextException(exc);
72      }
73  
74      /***
75       * Adds a SQLException object to the end of the chain. The flag
76       * wasBatchStatement is also set to false.
77       * 
78       * @param exc
79       *            the new exception that will be added to the end of the
80       *            SQLException chain.
81       */
82      public void setNextException(SQLException exc) {
83          this.wasBatchStatement = false;
84          super.setNextException(exc);
85      }
86  
87      /***
88       * Gives access to the wasBatchStatement flag.
89       * 
90       * @return true if the statement that threw this exception was a Batch
91       *         Statement, false otherwise.
92       */
93      public boolean getWasBatchStatement() {
94          return this.wasBatchStatement;
95      }
96  }