001package gu.sql2java.exception;
002
003import java.sql.SQLException;
004
005/**
006 * @author sql2java
007 */
008public class DaoException extends SQLException
009{
010    private static final long serialVersionUID = 5165438223391151142L;
011
012    /**
013     * contructor
014     */
015    public DaoException()
016    {
017        super();
018    }
019
020    /**
021     * contructor
022     */
023    public DaoException(String message)
024    {
025        super(message);
026    }
027
028    /**
029     * contructor
030     */
031    public DaoException(Throwable cause)
032    {
033        super(cause);
034    }
035
036    /**
037     * contructor
038     */
039    public DaoException(String message, Throwable cause)
040    {
041        super(message, cause);
042    }
043    /**
044     * recursively strip exception to get real SQLException instance thrown by JDBC driver
045     * @param e 
046     * @return SQLException OR {@code null} if not SQLException
047     */
048    public static final SQLException stripSQLException(Throwable e){
049        if(e != null){
050                        if(e instanceof SQLException && !DaoException.class.getPackage().equals(e.getClass().getPackage())){                    
051                                return (SQLException) e;
052                        }
053                        return stripSQLException(e.getCause());
054        }
055        return null;
056    }
057}