KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > exceptions > driver > DriverIOException


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2006 Continuent, Inc.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Emmanuel Cecchet
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.common.exceptions.driver;
23
24 import java.io.PrintStream JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import java.sql.SQLException JavaDoc;
27
28 import org.continuent.sequoia.common.exceptions.driver.protocol.SerializableException;
29
30 /**
31  * This class customizes SQLException and is used for reporting internal IO
32  * exception catched by the driver.
33  */

34 public class DriverIOException extends SQLException JavaDoc
35 {
36   private static final long serialVersionUID = 5066115114622251828L;
37
38   /**
39    * @see SQLException#SQLException()
40    */

41   public DriverIOException()
42   {
43     super();
44   }
45
46   /**
47    * @see SQLException#SQLException(java.lang.String)
48    */

49   public DriverIOException(String JavaDoc reason)
50   {
51     super(reason);
52   }
53
54   /**
55    * @see SQLException#SQLException(java.lang.String, java.lang.String)
56    */

57   public DriverIOException(String JavaDoc reason, String JavaDoc sQLState)
58   {
59     super(reason, sQLState);
60   }
61
62   /**
63    * @see SQLException#SQLException(java.lang.String, java.lang.String, int)
64    */

65   public DriverIOException(String JavaDoc reason, String JavaDoc sQLState, int vendorCode)
66   {
67     super(reason, sQLState, vendorCode);
68   }
69
70   /**
71    * Creates a new <code>DriverIOException</code> around a
72    * SerializableException received from controller, itself converted from an
73    * SQLException in most cases. So we set SQLState and vendorCode.
74    *
75    * @param message message
76    * @param cause exception from controller to wrap
77    */

78   public DriverIOException(String JavaDoc message, SerializableException cause)
79   {
80     super(message, cause.getSQLState(), cause.getErrorCode());
81     initCause(cause);
82   }
83
84   /**
85    * Missing message constructor: let's borrow message from cause.
86    *
87    * @param cause exception to wrap
88    */

89   public DriverIOException(SerializableException cause)
90   {
91     this("Message of cause: " + cause.getLocalizedMessage(), cause);
92   }
93
94   /**
95    * Missing message constructor: let's borrow message from cause.
96    *
97    * @param cause exception to wrap
98    */

99   public DriverIOException(Exception JavaDoc cause)
100   {
101     /**
102      * @see #DriverIOException(String, SerializableException)
103      * @see #DriverIOException(String, Exception)
104      */

105     this("Message of cause: " + cause.getLocalizedMessage(), cause);
106   }
107
108   /**
109    * Creates a new <code>DriverIOException</code> around an exception of a
110    * type not specifically handled elsewhere. Typically used for exceptions
111    * internal to the driver.
112    *
113    * @param message message
114    * @param cause generic exception to wrap
115    */

116   public DriverIOException(String JavaDoc message, Exception JavaDoc cause)
117   {
118     super(message);
119     initCause(cause);
120   }
121
122   /**
123    * @see #DriverIOException(String, SQLException)
124    * @deprecated
125    */

126   public DriverIOException(SQLException JavaDoc cause)
127   {
128     this("", cause);
129   }
130
131   /**
132    * An SQLException should not be wrapped inside a DriverSQLException: this is
133    * a symptom of mixing different layers.
134    *
135    * @param message message
136    * @param cause cause
137    * @deprecated
138    * @throws IllegalArgumentException always
139    */

140   public DriverIOException(String JavaDoc message, SQLException JavaDoc cause)
141       throws IllegalArgumentException JavaDoc
142   {
143     // ok let's be tolerant for the moment
144
super(message);
145     initCause(cause);
146
147     // TODO: ... but this is the future:
148
// A (Driver-)SQLException should be created here and nowhere below
149

150     // IllegalArgumentException iae = new IllegalArgumentException(
151
// "Bug: cause of a DriverSQLException should not itself be an SQLException
152
// "
153
// + message);
154
// iae.initCause(cause);
155
// throw iae;
156
}
157
158   /**
159    * Overrides super method so we print the serializable stack trace of next
160    * exceptions in the chain (if they use our serializable stack trace)
161    *
162    * @see java.lang.Throwable#printStackTrace(java.io.PrintStream)
163    */

164   public void printStackTrace(PrintStream JavaDoc s)
165   {
166     /*
167      * super does unfortunately not call printStackTrace() recursively on the
168      * chain: instead it breaks object encapsulation by calling instead printing
169      * methods and private fields on nexts. And since our chain uses its own
170      * private stack trace implementation (because of JDK 1.4 woes) this does
171      * print nothing in the end.
172      */

173     super.printStackTrace(s);
174
175     // So we have to call printStackStrace() ourselves.
176
Throwable JavaDoc cause = getCause();
177     if (null != cause && cause instanceof SerializableException)
178     {
179       s.println("SerializableStackTrace of each cause:");
180       ((SerializableException) cause).printStackTrace(s);
181     }
182   }
183
184   /**
185    * Overrides super method so we print the serializable stack trace of next
186    * exceptions in the chain (if they use our serializable stack trace)
187    *
188    * @see java.lang.Throwable#printStackTrace()
189    */

190   public void printStackTrace()
191   {
192     /**
193      * This comes back to
194      *
195      * @see DriverSQLException#printStackTrace(PrintStream)
196      */

197     super.printStackTrace();
198
199   }
200
201   /**
202    * Overrides super method so we print the serializable stack trace of next
203    * exceptions in the chain (if they use our serializable stack trace)
204    *
205    * @see java.lang.Throwable#printStackTrace(java.io.PrintWriter)
206    */

207   public void printStackTrace(PrintWriter JavaDoc s)
208   {
209     /** @see #printStackTrace(PrintStream) */
210     super.printStackTrace(s);
211
212     Throwable JavaDoc cause = getCause();
213     if (null != cause && cause instanceof SerializableException)
214     {
215       s.println("SerializableStackTrace of each cause:");
216       ((SerializableException) cause).printStackTrace(s);
217     }
218   }
219
220 }
221
Popular Tags