001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.jdbc;
032:
033: import java.sql.SQLException;
034:
035: import org.hsqldb.HsqlException;
036: import org.hsqldb.Result;
037: import org.hsqldb.Trace;
038:
039: import java.sql.SQLWarning;
040:
041: /**
042: * Provides driver constants and a gateway from internal HsqlExceptions to
043: * external SQLExceptions.
044: *
045: * @author fredt@users
046: * @version 1.7.2
047: * @since 1.7.2
048: */
049: public class Util {
050:
051: static final void throwError(HsqlException e) throws SQLException {
052: throw new SQLException(e.getMessage(), e.getSQLState(), e
053: .getErrorCode());
054: }
055:
056: static final void throwError(Result r) throws SQLException {
057: throw new SQLException(r.getMainString(), r.getSubString(), r
058: .getStatementID());
059: }
060:
061: public static final SQLException sqlException(HsqlException e) {
062: return new SQLException(e.getMessage(), e.getSQLState(), e
063: .getErrorCode());
064: }
065:
066: public static final SQLWarning sqlWarning(HsqlException e) {
067: return new SQLWarning(e.getMessage(), e.getSQLState(), e
068: .getErrorCode());
069: }
070:
071: static final SQLException sqlException(int id) {
072: return sqlException(Trace.error(id));
073: }
074:
075: static final SQLException sqlException(int id, String message) {
076: return sqlException(Trace.error(id, message));
077: }
078:
079: static final SQLException sqlException(int id, int subId,
080: Object[] add) {
081: return sqlException(Trace.error(id, subId, add));
082: }
083:
084: static final SQLException notSupported() {
085: return sqlException(Trace.error(Trace.FUNCTION_NOT_SUPPORTED));
086: }
087:
088: public static SQLException nullArgument() {
089: return sqlException(Trace.INVALID_JDBC_ARGUMENT);
090: }
091:
092: static SQLException nullArgument(String name) {
093: return sqlException(Trace.INVALID_JDBC_ARGUMENT, name
094: + ": null");
095: }
096:
097: public static SQLException invalidArgument() {
098: return sqlException(Trace.INVALID_JDBC_ARGUMENT);
099: }
100:
101: public static SQLException invalidArgument(String name) {
102: return sqlException(Trace.INVALID_JDBC_ARGUMENT, name);
103: }
104:
105: public static SQLException outOfRangeArgument() {
106: return sqlException(Trace.INVALID_JDBC_ARGUMENT);
107: }
108:
109: public static SQLException outOfRangeArgument(String name) {
110: return sqlException(Trace.INVALID_JDBC_ARGUMENT, name);
111: }
112:
113: public static SQLException connectionClosedException() {
114: return sqlException(Trace.CONNECTION_IS_CLOSED);
115: }
116: }
|