--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.jdbc.EmbedSQLWarning\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.jdbc;\r
+\r
+import org.apache.derby.iapi.services.i18n.MessageService;\r
+import org.apache.derby.iapi.error.ExceptionSeverity;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import java.sql.SQLWarning;\r
+\r
+/**\r
+ This class understands the message protocol and looks up\r
+ SQLExceptions based on keys, so that the Local JDBC driver's\r
+ messages can be localized.\r
+\r
+ REMIND: May want to investigate putting some of this in the protocol\r
+ side, for the errors that any Derby JDBC driver might return.\r
+\r
+ The ASSERT mechanism is a wrapper of the basic services,\r
+ to ensure that failed asserts at this level will behave\r
+ well in a JDBC environment.\r
+\r
+*/\r
+public class EmbedSQLWarning extends SQLWarning {\r
+\r
+ /*\r
+ ** instance fields\r
+ */\r
+\r
+ /*\r
+ ** Constructor\r
+ */\r
+\r
+ /**\r
+ * Because SQLWarning does not have settable fields,\r
+ * the caller of the constructor must do message lookup,\r
+ * and pass the appropriate values here for message and SQLState,\r
+ */\r
+ protected EmbedSQLWarning(String message, String sqlstate) {\r
+\r
+ super(message, sqlstate, ExceptionSeverity.WARNING_SEVERITY);\r
+ }\r
+\r
+ /*\r
+ ** Methods of Throwable\r
+ */\r
+\r
+\r
+ /*\r
+ ** Methods of Object\r
+ */\r
+\r
+ /**\r
+ Override Throwable's toString() to avoid the class name\r
+ appearing in the message. \r
+ */\r
+ public String toString() {\r
+ return "SQL Warning: " + getMessage();\r
+ }\r
+\r
+ // class implementation\r
+ public static SQLWarning newEmbedSQLWarning(String messageId) {\r
+ return newEmbedSQLWarning(messageId, null);\r
+ }\r
+\r
+ /**\r
+ This looks up the message and sqlstate values and generates\r
+ the appropriate exception off of them.\r
+ */\r
+ public static SQLWarning newEmbedSQLWarning(String messageId,\r
+ Object arg) {\r
+ return new EmbedSQLWarning(\r
+ MessageService.getCompleteMessage(messageId, new Object[] {arg}),\r
+ StandardException.getSQLStateFromIdentifier(messageId));\r
+ }\r
+\r
+ /** Generate an SQL Warning from a Standard Exception\r
+ * @param se Exception to convert to a warning\r
+ * @return new SQLWarning with message and SQLState of the se\r
+ */\r
+ public static SQLWarning generateCsSQLWarning(StandardException se) {\r
+ return new EmbedSQLWarning(\r
+ se.getMessage(), se.getSQLState());\r
+ }\r
+\r
+}\r
+\r