KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > SqlWarning


1 /*
2
3    Derby - Class org.apache.derby.client.am.SqlWarning
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.client.am;
23
24 import java.sql.SQLWarning JavaDoc;
25 import org.apache.derby.iapi.services.info.JVMInfo;
26
27 /**
28  * This represents a warning versus a full exception. As with
29  * SqlException, this is an internal representation of java.sql.SQLWarning.
30  *
31  * Public JDBC methods need to convert an internal SqlWarning to a SQLWarning
32  * using <code>getSQLWarning()</code>
33  */

34 public class SqlWarning extends SqlException implements Diagnosable {
35
36     protected SqlWarning nextWarning_;
37     
38     public SqlWarning(LogWriter logwriter,
39         ClientMessageId msgid, Object JavaDoc[] args, Throwable JavaDoc cause)
40     {
41         super(logwriter, msgid, args, cause);
42     }
43     
44     public SqlWarning(LogWriter logwriter, ClientMessageId msgid, Object JavaDoc[] args)
45     {
46         this(logwriter, msgid, args, null);
47     }
48     
49     public SqlWarning (LogWriter logwriter, ClientMessageId msgid)
50     {
51         super(logwriter, msgid);
52     }
53     
54     public SqlWarning(LogWriter logwriter, ClientMessageId msgid, Object JavaDoc arg1)
55     {
56         super(logwriter, msgid, arg1);
57     }
58     
59     public SqlWarning(LogWriter logwriter,
60         ClientMessageId msgid, Object JavaDoc arg1, Object JavaDoc arg2)
61     {
62         super(logwriter, msgid, arg1, arg2);
63     }
64     
65     public SqlWarning(LogWriter logwriter,
66         ClientMessageId msgid, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3)
67     {
68         super(logwriter, msgid, arg1, arg2, arg3);
69     }
70     
71     public SqlWarning(LogWriter logWriter, Sqlca sqlca)
72     {
73         super(logWriter, sqlca);
74     }
75     
76     public void setNextWarning(SqlWarning warning)
77     {
78         // Add this warning to the end of the chain
79
SqlWarning theEnd = this;
80         while (theEnd.nextWarning_ != null) {
81             theEnd = theEnd.nextWarning_;
82         }
83         theEnd.nextWarning_ = warning;
84     }
85     
86     public SqlWarning getNextWarning()
87     {
88         return nextWarning_;
89     }
90     
91     /**
92      * Get the java.sql.SQLWarning for this SqlWarning
93      */

94     public SQLWarning JavaDoc getSQLWarning()
95     {
96         SQLWarning JavaDoc sqlw = new SQLWarning JavaDoc(getMessage(), getSQLState(),
97             getErrorCode());
98
99         // If we're in a runtime that supports chained exceptions, set the cause
100
// of the SQLWarning to be this SqlWarning.
101
if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
102         {
103             sqlw.initCause(this);
104         }
105
106         // Set up the nextException chain
107
if ( nextWarning_ != null )
108         {
109             // The exception chain gets constructed automatically through
110
// the beautiful power of recursion
111
//
112
// We have to use the right method to convert the next exception
113
// depending upon its type. Luckily with all the other subclasses
114
// of SQLException we don't have to make our own matching
115
// subclasses because
116
sqlw.setNextException(
117                 nextException_ instanceof SqlWarning ?
118                     ((SqlWarning)nextException_).getSQLWarning() :
119                     nextException_.getSQLException());
120         }
121         
122         return sqlw;
123         
124     }
125 }
126
127
Popular Tags