KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > jdbc > EmbedSQLWarning


1 /*
2
3    Derby - Class org.apache.derby.impl.jdbc.EmbedSQLWarning
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.impl.jdbc;
23
24 import org.apache.derby.iapi.services.i18n.MessageService;
25 import org.apache.derby.iapi.error.ExceptionSeverity;
26
27 import org.apache.derby.iapi.error.StandardException;
28
29 import java.sql.SQLWarning JavaDoc;
30
31 /**
32     This class understands the message protocol and looks up
33     SQLExceptions based on keys, so that the Local JDBC driver's
34     messages can be localized.
35
36     REMIND: May want to investigate putting some of this in the protocol
37     side, for the errors that any Cloudscape JDBC driver might return.
38
39     The ASSERT mechanism is a wrapper of the basic services,
40     to ensure that failed asserts at this level will behave
41     well in a JDBC environment.
42
43     @author ames
44 */

45 public class EmbedSQLWarning extends SQLWarning JavaDoc {
46
47     /*
48     ** instance fields
49     */

50
51     /*
52     ** Constructor
53     */

54
55     /**
56      * Because SQLWarning does not have settable fields,
57      * the caller of the constructor must do message lookup,
58      * and pass the appropriate values here for message and SQLState,
59      */

60     protected EmbedSQLWarning(String JavaDoc message, String JavaDoc sqlstate) {
61
62         super(message, sqlstate, ExceptionSeverity.WARNING_SEVERITY);
63     }
64
65     /*
66     ** Methods of Throwable
67     */

68
69
70     /*
71     ** Methods of Object
72     */

73
74     /**
75         Override Throwable's toString() to avoid the class name
76         appearing in the message.
77     */

78     public String JavaDoc toString() {
79         return "SQL Warning: " + getMessage();
80     }
81
82     // class implementation
83
public static SQLWarning JavaDoc newEmbedSQLWarning(String JavaDoc messageId) {
84         return newEmbedSQLWarning(messageId, null);
85     }
86
87     /**
88         This looks up the message and sqlstate values and generates
89         the appropriate exception off of them.
90      */

91     public static SQLWarning JavaDoc newEmbedSQLWarning(String JavaDoc messageId,
92             Object JavaDoc arg) {
93         return new EmbedSQLWarning(
94             MessageService.getCompleteMessage(messageId, new Object JavaDoc[] {arg}),
95             StandardException.getSQLStateFromIdentifier(messageId));
96     }
97
98     /** Generate an SQL Warning from a Standard Exception
99      * @param se Exception to convert to a warning
100      * @return new SQLWarning with message and SQLState of the se
101      */

102     public static SQLWarning JavaDoc generateCsSQLWarning(StandardException se) {
103         return new EmbedSQLWarning(
104                        se.getMessage(), se.getSQLState());
105     }
106
107 }
108
109
Popular Tags