J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package java.sql; |
| 27 | |
| 28 | /** |
| 29 | * <P>An exception that provides information on database access |
| 30 | * warnings. Warnings are silently chained to the object whose method |
| 31 | * caused it to be reported. |
| 32 | * <P> |
| 33 | * Warnings may be retrieved from <code>Connection</code>, <code>Statement</code>, |
| 34 | * and <code>ResultSet</code> objects. Trying to retrieve a warning on a |
| 35 | * connection after it has been closed will cause an exception to be thrown. |
| 36 | * Similarly, trying to retrieve a warning on a statement after it has been |
| 37 | * closed or on a result set after it has been closed will cause |
| 38 | * an exception to be thrown. Note that closing a statement also |
| 39 | * closes a result set that it might have produced. |
| 40 | * |
| 41 | * @see Connection#getWarnings |
| 42 | * @see Statement#getWarnings |
| 43 | * @see ResultSet#getWarnings |
| 44 | */ |
| 45 | public class SQLWarning extends SQLException { |
| 46 | |
| 47 | /** |
| 48 | * Constructs a <code>SQLWarning</code> object |
| 49 | * with a given <code>reason</code>, <code>SQLState</code> and |
| 50 | * <code>vendorCode</code>. |
| 51 | * |
| 52 | * The <code>cause</code> is not initialized, and may subsequently be |
| 53 | * initialized by a call to the |
| 54 | * {@link Throwable#initCause(java.lang.Throwable)} method. |
| 55 | * <p> |
| 56 | * @param reason a description of the warning |
| 57 | * @param SQLState an XOPEN or SQL:2003 code identifying the warning |
| 58 | * @param vendorCode a database vendor-specific warning code |
| 59 | */ |
| 60 | public SQLWarning(String reason, String SQLState, int vendorCode) { |
| 61 | super(reason, SQLState, vendorCode); |
| 62 | DriverManager.println("SQLWarning: reason(" + reason + |
| 63 | ") SQLState(" + SQLState + |
| 64 | ") vendor code(" + vendorCode + ")"); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * Constructs a <code>SQLWarning</code> object |
| 70 | * with a given <code>reason</code> and <code>SQLState</code>. |
| 71 | * |
| 72 | * The <code>cause</code> is not initialized, and may subsequently be |
| 73 | * initialized by a call to the |
| 74 | * {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code |
| 75 | * is initialized to 0. |
| 76 | * <p> |
| 77 | * @param reason a description of the warning |
| 78 | * @param SQLState an XOPEN or SQL:2003 code identifying the warning |
| 79 | */ |
| 80 | public SQLWarning(String reason, String SQLState) { |
| 81 | super(reason, SQLState); |
| 82 | DriverManager.println("SQLWarning: reason(" + reason + |
| 83 | ") SQLState(" + SQLState + ")"); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Constructs a <code>SQLWarning</code> object |
| 88 | * with a given <code>reason</code>. The <code>SQLState</code> |
| 89 | * is initialized to <code>null</code> and the vender code is initialized |
| 90 | * to 0. |
| 91 | * |
| 92 | * The <code>cause</code> is not initialized, and may subsequently be |
| 93 | * initialized by a call to the |
| 94 | * {@link Throwable#initCause(java.lang.Throwable)} method. |
| 95 | * <p> |
| 96 | * @param reason a description of the warning |
| 97 | */ |
| 98 | public SQLWarning(String reason) { |
| 99 | super(reason); |
| 100 | DriverManager.println("SQLWarning: reason(" + reason + ")"); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Constructs a <code>SQLWarning</code> object. |
| 105 | * The <code>reason</code>, <code>SQLState</code> are initialized |
| 106 | * to <code>null</code> and the vendor code is initialized to 0. |
| 107 | * |
| 108 | * The <code>cause</code> is not initialized, and may subsequently be |
| 109 | * initialized by a call to the |
| 110 | * {@link Throwable#initCause(java.lang.Throwable)} method. |
| 111 | * <p> |
| 112 | */ |
| 113 | public SQLWarning() { |
| 114 | super(); |
| 115 | DriverManager.println("SQLWarning: "); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Constructs a <code>SQLWarning</code> object |
| 120 | * with a given <code>cause</code>. |
| 121 | * The <code>SQLState</code> is initialized |
| 122 | * to <code>null</code> and the vendor code is initialized to 0. |
| 123 | * The <code>reason</code> is initialized to <code>null</code> if |
| 124 | * <code>cause==null</code> or to <code>cause.toString()</code> if |
| 125 | * <code>cause!=null</code>. |
| 126 | * <p> |
| 127 | * @param cause the underlying reason for this <code>SQLWarning</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating |
| 128 | * the cause is non-existent or unknown. |
| 129 | */ |
| 130 | public SQLWarning(Throwable cause) { |
| 131 | super(cause); |
| 132 | DriverManager.println("SQLWarning"); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Constructs a <code>SQLWarning</code> object |
| 137 | * with a given |
| 138 | * <code>reason</code> and <code>cause</code>. |
| 139 | * The <code>SQLState</code> is initialized to <code>null</code> |
| 140 | * and the vendor code is initialized to 0. |
| 141 | * <p> |
| 142 | * @param reason a description of the warning |
| 143 | * @param cause the underlying reason for this <code>SQLWarning</code> |
| 144 | * (which is saved for later retrieval by the <code>getCause()</code> method); |
| 145 | * may be null indicating the cause is non-existent or unknown. |
| 146 | */ |
| 147 | public SQLWarning(String reason, Throwable cause) { |
| 148 | super(reason,cause); |
| 149 | DriverManager.println("SQLWarning : reason("+ reason + ")"); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Constructs a <code>SQLWarning</code> object |
| 154 | * with a given |
| 155 | * <code>reason</code>, <code>SQLState</code> and <code>cause</code>. |
| 156 | * The vendor code is initialized to 0. |
| 157 | * <p> |
| 158 | * @param reason a description of the warning |
| 159 | * @param SQLState an XOPEN or SQL:2003 code identifying the warning |
| 160 | * @param cause the underlying reason for this <code>SQLWarning</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating |
| 161 | * the cause is non-existent or unknown. |
| 162 | */ |
| 163 | public SQLWarning(String reason, String SQLState, Throwable cause) { |
| 164 | super(reason,SQLState,cause); |
| 165 | DriverManager.println("SQLWarning: reason(" + reason + |
| 166 | ") SQLState(" + SQLState + ")"); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Constructs a<code>SQLWarning</code> object |
| 171 | * with a given |
| 172 | * <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code> |
| 173 | * and <code>cause</code>. |
| 174 | * <p> |
| 175 | * @param reason a description of the warning |
| 176 | * @param SQLState an XOPEN or SQL:2003 code identifying the warning |
| 177 | * @param vendorCode a database vendor-specific warning code |
| 178 | * @param cause the underlying reason for this <code>SQLWarning</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating |
| 179 | * the cause is non-existent or unknown. |
| 180 | */ |
| 181 | public SQLWarning(String reason, String SQLState, int vendorCode, Throwable cause) { |
| 182 | super(reason,SQLState,vendorCode,cause); |
| 183 | DriverManager.println("SQLWarning: reason(" + reason + |
| 184 | ") SQLState(" + SQLState + |
| 185 | ") vendor code(" + vendorCode + ")"); |
| 186 | |
| 187 | } |
| 188 | /** |
| 189 | * Retrieves the warning chained to this <code>SQLWarning</code> object by |
| 190 | * <code>setNextWarning</code>. |
| 191 | * |
| 192 | * @return the next <code>SQLException</code> in the chain; <code>null</code> if none |
| 193 | * @see #setNextWarning |
| 194 | */ |
| 195 | public SQLWarning getNextWarning() { |
| 196 | try { |
| 197 | return ((SQLWarning)getNextException()); |
| 198 | } catch (ClassCastException ex) { |
| 199 | // The chained value isn't a SQLWarning. |
| 200 | // This is a programming error by whoever added it to |
| 201 | // the SQLWarning chain. We throw a Java "Error". |
| 202 | throw new Error("SQLWarning chain holds value that is not a SQLWarning"); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Adds a <code>SQLWarning</code> object to the end of the chain. |
| 208 | * |
| 209 | * @param w the new end of the <code>SQLException</code> chain |
| 210 | * @see #getNextWarning |
| 211 | */ |
| 212 | public void setNextWarning(SQLWarning w) { |
| 213 | setNextException(w); |
| 214 | } |
| 215 | |
| 216 | private static final long serialVersionUID = 3917336774604784856L; |
| 217 | } |