SQLWarning.java revision 32c2297a959b72abdb18743f0519e1d8b7c7ea88
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package java.sql;
19
20import java.io.Serializable;
21
22/**
23 * An exception class that holds information about Database access warnings.
24 */
25public class SQLWarning extends SQLException implements Serializable {
26
27    private static final long serialVersionUID = 3917336774604784856L;
28
29    /**
30     * Creates an {@code SQLWarning} object. The reason string is set to {@code
31     * null}, the {@code SQLState} string is set to {@code null} and the error
32     * code is set to 0.
33     */
34    public SQLWarning() {
35    }
36
37    /**
38     * Creates an {@code SQLWarning} object. The reason string is set to the
39     * given reason string, the {@code SQLState} string is set to {@code null}
40     * and the error code is set to 0.
41     *
42     * @param theReason
43     *            the reason why this warning is issued.
44     */
45    public SQLWarning(String theReason) {
46        super(theReason);
47    }
48
49    /**
50     * Creates an {@code SQLWarning} object. The reason string is set to the
51     * given reason string, the {@code SQLState} string is set to the given
52     * {@code SQLState} string and the error code is set to 0.
53     *
54     * @param theReason
55     *            the reason why this warning is issued.
56     * @param theSQLState
57     *            the string to use as the {@code SQLState} string.
58     */
59    public SQLWarning(String theReason, String theSQLState) {
60        super(theReason, theSQLState);
61    }
62
63    /**
64     * Creates an {@code SQLWarning} object. The reason string is set to the
65     * given reason string, the {@code SQLState} string is set to the given
66     * {@code SQLState} string and the error code is set to the given error code
67     * value.
68     *
69     * @param theReason
70     *            the reason why this warning is issued.
71     * @param theSQLState
72     *            the X/Open standard specifc error code.
73     * @param theErrorCode
74     *            a vendor specific error code.
75     */
76    public SQLWarning(String theReason, String theSQLState, int theErrorCode) {
77        super(theReason, theSQLState, theErrorCode);
78    }
79
80    /**
81     * Creates an SQLWarning object. The Reason string is set to null, the
82     * SQLState string is set to null and the Error Code is set to 0, cause is
83     * set to cause.
84     *
85     * @since 1.6
86     */
87    public SQLWarning(Throwable cause) {
88        super(cause);
89    }
90
91    /**
92     * Creates an SQLWarning object. The Reason string is set to reason, the
93     * SQLState string is set to null and the Error Code is set to 0, cause is
94     * set to the given cause
95     *
96     * @since 1.6
97     */
98    public SQLWarning(String reason, Throwable cause) {
99        super(reason, cause);
100    }
101
102    /**
103     * Creates an SQLWarning object. The Reason string is set to reason, the
104     * SQLState string is set to given SQLState and the Error Code is set to 0,
105     * cause is set to the given cause
106     *
107     * @since 1.6
108     */
109    public SQLWarning(String reason, String SQLState, Throwable cause) {
110        super(reason, SQLState, cause);
111    }
112
113    /**
114     * Creates an SQLWarning object. The Reason string is set to reason, the
115     * SQLState string is set to given SQLState and the Error Code is set to
116     * vendorCode, cause is set to the given cause
117     *
118     * @since 1.6
119     */
120    public SQLWarning(String reason, String SQLState, int vendorCode,
121            Throwable cause) {
122        super(reason, SQLState, vendorCode, cause);
123    }
124
125    /**
126     * Gets the next {@code SQLWarning} chained to this {@code SQLWarning} object.
127     *
128     * @return the {@code SQLWarning} chained to this {@code SQLWarning}.
129     *         {@code null} if no {@code SQLWarning} is chained to this {@code
130     *         SQLWarning}.
131     */
132    public SQLWarning getNextWarning() {
133        SQLException next = super.getNextException();
134        if (next == null) {
135            return null;
136        }
137        if (next instanceof SQLWarning) {
138            return (SQLWarning) next;
139        }
140        throw new Error("SQLWarning chain holds value that is not a SQLWarning");
141    }
142
143    /**
144     * Chains a supplied {@code SQLWarning} to this {@code SQLWarning}.
145     *
146     * @param w
147     *            the {@code SQLWarning} linked to this {@code SQLWarning}.
148     */
149    public void setNextWarning(SQLWarning w) {
150        super.setNextException(w);
151    }
152}
153