KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > common > jdbc > exception > RuntimeSQLException


1 /*
2  * Copyright 2004 Clinton Begin
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.ibatis.common.jdbc.exception;
17
18 import com.ibatis.common.exception.NestedRuntimeException;
19
20 import java.sql.SQLException JavaDoc;
21
22 /**
23  * Unchecked exception to allow passing an Exception with the original SQLException
24  */

25 public class RuntimeSQLException extends NestedRuntimeException {
26
27   /**
28    * Default constructor
29    */

30   public RuntimeSQLException() {
31   }
32
33   /**
34    * Constructor to pass along a message
35    * @see com.ibatis.common.exception.NestedRuntimeException
36    * @param msg - the message
37    */

38   public RuntimeSQLException(String JavaDoc msg) {
39     super(msg);
40   }
41
42   /**
43    * Constructor to pass along another exception
44    * @see com.ibatis.common.exception.NestedRuntimeException
45    * @param sqlException - the exception
46    */

47   public RuntimeSQLException(SQLException JavaDoc sqlException) {
48     super(sqlException);
49   }
50
51   /**
52    * Constructor to pass along a message and an exception
53    * @see com.ibatis.common.exception.NestedRuntimeException
54    * @param msg - the message
55    * @param sqlException - the exception
56    */

57   public RuntimeSQLException(String JavaDoc msg, SQLException JavaDoc sqlException) {
58     super(msg, sqlException);
59   }
60
61   /**
62    * Getter for the SQL State
63    * @return - the state
64    */

65   public String JavaDoc getSQLState() {
66     Throwable JavaDoc cause = getCause();
67     if (cause instanceof SQLException JavaDoc) {
68       return ((SQLException JavaDoc) cause).getSQLState();
69     } else {
70       return null;
71     }
72
73   }
74
75   /**
76    * Getter for the error code
77    * @return - the error code
78    */

79   public int getErrorCode() {
80     Throwable JavaDoc cause = getCause();
81     if (cause instanceof SQLException JavaDoc) {
82       return ((SQLException JavaDoc) cause).getErrorCode();
83     } else {
84       return -1;
85     }
86   }
87
88   /**
89    * Get the next exception in the chain
90    * @return - the next exception
91    */

92   public SQLException JavaDoc getNextException() {
93     Throwable JavaDoc cause = getCause();
94     if (cause instanceof SQLException JavaDoc) {
95       return ((SQLException JavaDoc) cause).getNextException();
96     } else {
97       return null;
98     }
99   }
100
101   /**
102    * Set the next exception in the chain
103    * @param ex - the next exception
104    */

105   public synchronized void setNextException(SQLException JavaDoc ex) {
106     Throwable JavaDoc cause = getCause();
107     if (cause instanceof SQLException JavaDoc) {
108       ((SQLException JavaDoc) cause).setNextException(ex);
109     }
110   }
111
112 }
113
Popular Tags