KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > hajdbc > SQLException


1 /*
2  * HA-JDBC: High-Availability JDBC
3  * Copyright (c) 2004-2006 Paul Ferraro
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2.1 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: ferraro@users.sourceforge.net
20  */

21 package net.sf.hajdbc;
22
23 /**
24  * Wrapper for java.sql.SQLException that handles nested exceptions.
25  *
26  * @author Paul Ferraro
27  * @version $Revision: 1043 $
28  * @since 1.0
29  */

30 public class SQLException extends java.sql.SQLException JavaDoc
31 {
32     private static final long serialVersionUID = 4122254034733510710L;
33
34     /**
35      * Constructs a new SQLException.
36      * @param message the description of this exception
37      */

38     public SQLException(String JavaDoc message)
39     {
40         super(message);
41     }
42     
43     /**
44      * Constructs a new SQLException.
45      * @param message the description of this exception
46      * @param cause the cause of this exception
47      */

48     public SQLException(String JavaDoc message, Throwable JavaDoc cause)
49     {
50         super(message);
51
52         this.initCause(cause);
53     }
54     
55     /**
56      * Constructs a new SQLException.
57      * @param cause the cause of this exception
58      */

59     public SQLException(Throwable JavaDoc cause)
60     {
61         super(cause.toString());
62         
63         this.initCause(cause);
64     }
65
66     /**
67      * @see java.sql.SQLException#getErrorCode()
68      */

69     @Override JavaDoc
70     public int getErrorCode()
71     {
72         Throwable JavaDoc cause = this.getCause();
73
74         if ((cause != null) && java.sql.SQLException JavaDoc.class.isInstance(cause))
75         {
76             return java.sql.SQLException JavaDoc.class.cast(cause).getErrorCode();
77         }
78         
79         return super.getErrorCode();
80     }
81
82     /**
83      * @see java.sql.SQLException#getNextException()
84      */

85     @Override JavaDoc
86     public java.sql.SQLException JavaDoc getNextException()
87     {
88         Throwable JavaDoc cause = this.getCause();
89         
90         if ((cause != null) && java.sql.SQLException JavaDoc.class.isInstance(cause))
91         {
92             return java.sql.SQLException JavaDoc.class.cast(cause).getNextException();
93         }
94         
95         return super.getNextException();
96     }
97
98     /**
99      * @see java.sql.SQLException#getSQLState()
100      */

101     @Override JavaDoc
102     public String JavaDoc getSQLState()
103     {
104         Throwable JavaDoc cause = this.getCause();
105         
106         if ((cause != null) && java.sql.SQLException JavaDoc.class.isInstance(cause))
107         {
108             return java.sql.SQLException JavaDoc.class.cast(cause).getSQLState();
109         }
110         
111         return super.getSQLState();
112     }
113 }
114
Popular Tags