001: /*
002: * DataSourceException.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.jdbc;
023:
024: import java.sql.SQLException;
025:
026: /* ----------------------------------------------------------
027: * CVS NOTE: Changes to the CVS repository prior to the
028: * release of version 3.0.0beta1 has meant a
029: * resetting of CVS revision numbers.
030: * ----------------------------------------------------------
031: */
032:
033: /**
034: * Generic exception thrown by data source related methods/classes.
035: *
036: * @author Takis Diakoumis
037: * @version $Revision: 1.5 $
038: * @date $Date: 2006/08/24 09:35:55 $
039: */
040: public class DataSourceException extends Exception {
041:
042: /** closed connection indictaor value */
043: private boolean connectionClosed;
044:
045: /** underlying dump cause */
046: private Throwable cause;
047:
048: public DataSourceException() {
049: super ();
050: }
051:
052: public DataSourceException(String message) {
053: super (message);
054: }
055:
056: public DataSourceException(String message, boolean connectionClosed) {
057: super (message);
058: this .connectionClosed = connectionClosed;
059: }
060:
061: public DataSourceException(Throwable cause) {
062: super (cause);
063: this .cause = cause;
064: }
065:
066: public DataSourceException(String message, Throwable cause) {
067: super (message, cause);
068: }
069:
070: public Throwable getCause() {
071: return cause;
072: }
073:
074: public boolean wasConnectionClosed() {
075: return connectionClosed;
076: }
077:
078: public String getExtendedMessage() {
079: if (cause == null) {
080: return getMessage() == null ? "" : getMessage();
081: }
082:
083: StringBuffer sb = new StringBuffer();
084: String message = cause.getMessage();
085: if (message != null) {
086: sb.append(message);
087: } else {
088: sb.append(cause);
089: }
090:
091: if (cause instanceof SQLException) {
092: SQLException sqlCause = (SQLException) cause;
093: sb.append("\nError Code: " + sqlCause.getErrorCode());
094:
095: String state = sqlCause.getSQLState();
096: if (state != null) {
097: sb.append("\nSQL State Code: " + state);
098: }
099: sb.append("\n");
100: }
101: return sb.toString();
102: }
103:
104: }
|