/*
 * Copyright 2009-2010 Yuichiro Moriguchi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.morilib.lisp.relation;

import java.sql.SQLException;

import net.morilib.lisp.Datum;
import net.morilib.lisp.LispException;
import net.morilib.lisp.LispMessage;
import net.morilib.lisp.sql.LispSQLException;
import net.morilib.relation.RelationException;

/**
 *
 *
 * @author MORIGUCHI, Yuichiro 2011/02/06
 */
public class LispRelationException extends RelationException {

	//
	private static final long serialVersionUID = 3186245000178787583L;

	/**
	 * @param message
	 * @param cause
	 */
	public LispRelationException(String message, Throwable cause) {
		super(message, cause);
	}

	/**
	 * @param cause
	 */
	public LispRelationException(Throwable cause) {
		super(cause);
	}

	/**
	 * 
	 * @return
	 */
	public LispException getLispException(LispMessage mesg) {
		if(getCause() instanceof SQLException) {
			throw LispSQLException.getError(
					mesg, (SQLException)getCause());
		} else {
			throw mesg.getError(getMessage());
		}
	}

	/**
	 * 
	 * @return
	 */
	public LispException getLispException(LispMessage mesg, Datum d) {
		if(getCause() instanceof SQLException) {
			throw LispSQLException.getError(
					mesg, (SQLException)getCause());
		} else {
			throw mesg.getError(getMessage(), d);
		}
	}

	/**
	 * 
	 * @return
	 */
	public LispException getLispException(LispMessage mesg, String s) {
		if(getCause() instanceof SQLException) {
			throw LispSQLException.getError(
					mesg, (SQLException)getCause());
		} else {
			throw mesg.getError(getMessage(), s);
		}
	}

}
