001: /*
002:
003: Derby - Class org.apache.derby.client.am.SqlWarning
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.client.am;
023:
024: import java.sql.SQLWarning;
025: import org.apache.derby.iapi.services.info.JVMInfo;
026:
027: /**
028: * This represents a warning versus a full exception. As with
029: * SqlException, this is an internal representation of java.sql.SQLWarning.
030: *
031: * Public JDBC methods need to convert an internal SqlWarning to a SQLWarning
032: * using <code>getSQLWarning()</code>
033: */
034: public class SqlWarning extends SqlException implements Diagnosable {
035:
036: protected SqlWarning nextWarning_;
037:
038: public SqlWarning(LogWriter logwriter, ClientMessageId msgid,
039: Object[] args, Throwable cause) {
040: super (logwriter, msgid, args, cause);
041: }
042:
043: public SqlWarning(LogWriter logwriter, ClientMessageId msgid,
044: Object[] args) {
045: this (logwriter, msgid, args, null);
046: }
047:
048: public SqlWarning(LogWriter logwriter, ClientMessageId msgid) {
049: super (logwriter, msgid);
050: }
051:
052: public SqlWarning(LogWriter logwriter, ClientMessageId msgid,
053: Object arg1) {
054: super (logwriter, msgid, arg1);
055: }
056:
057: public SqlWarning(LogWriter logwriter, ClientMessageId msgid,
058: Object arg1, Object arg2) {
059: super (logwriter, msgid, arg1, arg2);
060: }
061:
062: public SqlWarning(LogWriter logwriter, ClientMessageId msgid,
063: Object arg1, Object arg2, Object arg3) {
064: super (logwriter, msgid, arg1, arg2, arg3);
065: }
066:
067: public SqlWarning(LogWriter logWriter, Sqlca sqlca) {
068: super (logWriter, sqlca);
069: }
070:
071: public void setNextWarning(SqlWarning warning) {
072: // Add this warning to the end of the chain
073: SqlWarning theEnd = this ;
074: while (theEnd.nextWarning_ != null) {
075: theEnd = theEnd.nextWarning_;
076: }
077: theEnd.nextWarning_ = warning;
078: }
079:
080: public SqlWarning getNextWarning() {
081: return nextWarning_;
082: }
083:
084: /**
085: * Get the java.sql.SQLWarning for this SqlWarning
086: */
087: public SQLWarning getSQLWarning() {
088: SQLWarning sqlw = new SQLWarning(getMessage(), getSQLState(),
089: getErrorCode());
090:
091: // If we're in a runtime that supports chained exceptions, set the cause
092: // of the SQLWarning to be this SqlWarning.
093: if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14) {
094: sqlw.initCause(this );
095: }
096:
097: // Set up the nextException chain
098: if (nextWarning_ != null) {
099: // The exception chain gets constructed automatically through
100: // the beautiful power of recursion
101: //
102: // We have to use the right method to convert the next exception
103: // depending upon its type. Luckily with all the other subclasses
104: // of SQLException we don't have to make our own matching
105: // subclasses because
106: sqlw
107: .setNextException(nextException_ instanceof SqlWarning ? ((SqlWarning) nextException_)
108: .getSQLWarning()
109: : nextException_.getSQLException());
110: }
111:
112: return sqlw;
113:
114: }
115: }
|