01: /*
02: * HA-JDBC: High-Availability JDBC
03: * Copyright (c) 2004-2007 Paul Ferraro
04: *
05: * This library is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU Lesser General Public License as published by the
07: * Free Software Foundation; either version 2.1 of the License, or (at your
08: * option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13: * for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public License
16: * along with this library; if not, write to the Free Software Foundation,
17: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * Contact: ferraro@users.sourceforge.net
20: */
21: package net.sf.hajdbc.util;
22:
23: import java.sql.SQLException;
24:
25: /**
26: * @author Paul Ferraro
27: *
28: */
29: public final class SQLExceptionFactory {
30: /**
31: * Helper method for missing SQLException(String, Throwable) constructor in Java < 1.6
32: * @param message the description of the exception
33: * @param cause the exception to wrap
34: * @return an SQLException wrapping the given cause
35: */
36: public static SQLException createSQLException(String message,
37: Throwable cause) {
38: SQLException exception = new SQLException(message);
39:
40: exception.initCause(cause);
41:
42: return exception;
43: }
44:
45: /**
46: * Helper method for missing SQLException(Throwable) constructor in Java < 1.6
47: * @param cause the exception to wrap
48: * @return an SQLException wrapping the given cause
49: */
50: public static SQLException createSQLException(Throwable cause) {
51: if (cause instanceof SQLException) {
52: return (SQLException) cause;
53: }
54:
55: SQLException exception = new SQLException();
56:
57: exception.initCause(cause);
58:
59: return exception;
60: }
61: }
|