1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.jdbc.EmbedSQLWarning |
4 | |
5 | Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.jdbc; |
22 | |
23 | import org.apache.derby.iapi.services.i18n.MessageService; |
24 | import org.apache.derby.iapi.error.ExceptionSeverity; |
25 | |
26 | import org.apache.derby.iapi.error.StandardException; |
27 | |
28 | import java.sql.SQLWarning; |
29 | |
30 | /** |
31 | This class understands the message protocol and looks up |
32 | SQLExceptions based on keys, so that the Local JDBC driver's |
33 | messages can be localized. |
34 | |
35 | REMIND: May want to investigate putting some of this in the protocol |
36 | side, for the errors that any Cloudscape JDBC driver might return. |
37 | |
38 | The ASSERT mechanism is a wrapper of the basic services, |
39 | to ensure that failed asserts at this level will behave |
40 | well in a JDBC environment. |
41 | |
42 | @author ames |
43 | */ |
44 | public class EmbedSQLWarning extends SQLWarning { |
45 | |
46 | /* |
47 | ** instance fields |
48 | */ |
49 | |
50 | /* |
51 | ** Constructor |
52 | */ |
53 | |
54 | /** |
55 | * Because SQLWarning does not have settable fields, |
56 | * the caller of the constructor must do message lookup, |
57 | * and pass the appropriate values here for message and SQLState, |
58 | */ |
59 | protected EmbedSQLWarning(String message, String sqlstate) { |
60 | |
61 | super(message, sqlstate, ExceptionSeverity.WARNING_SEVERITY); |
62 | } |
63 | |
64 | /* |
65 | ** Methods of Throwable |
66 | */ |
67 | |
68 | |
69 | /* |
70 | ** Methods of Object |
71 | */ |
72 | |
73 | /** |
74 | Override Throwable's toString() to avoid the class name |
75 | appearing in the message. |
76 | */ |
77 | public String toString() { |
78 | return "SQL Warning: " + getMessage(); |
79 | } |
80 | |
81 | // class implementation |
82 | public static SQLWarning newEmbedSQLWarning(String messageId) { |
83 | return newEmbedSQLWarning(messageId, null); |
84 | } |
85 | |
86 | /** |
87 | This looks up the message and sqlstate values and generates |
88 | the appropriate exception off of them. |
89 | */ |
90 | public static SQLWarning newEmbedSQLWarning(String messageId, |
91 | Object arg) { |
92 | return new EmbedSQLWarning( |
93 | MessageService.getCompleteMessage(messageId, new Object[] {arg}), |
94 | StandardException.getSQLStateFromIdentifier(messageId)); |
95 | } |
96 | |
97 | /** Generate an SQL Warning from a Standard Exception |
98 | * @param se Exception to convert to a warning |
99 | * @return new SQLWarning with message and SQLState of the se |
100 | */ |
101 | public static SQLWarning generateCsSQLWarning(StandardException se) { |
102 | return new EmbedSQLWarning( |
103 | se.getMessage(), se.getSQLState()); |
104 | } |
105 | |
106 | } |
107 | |