All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.icodegarden.nutrient.lang.exception.DuplicateKeyException Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
package io.github.icodegarden.nutrient.lang.exception;

import java.sql.SQLIntegrityConstraintViolationException;

import io.github.icodegarden.nutrient.lang.util.ExceptionUtils;

/**
 * 
 * @author Fangfang.Xu
 *
 */
public class DuplicateKeyException extends RuntimeException {
	private static final long serialVersionUID = 1L;

	public DuplicateKeyException(String message, Throwable cause) {
		super(message, cause);
	}

	public DuplicateKeyException(String message) {
		super(message);
	}

	public static void throwIfCompatible(Exception e) throws DuplicateKeyException {
		SQLIntegrityConstraintViolationException cause = ExceptionUtils.causeOf(e,
				SQLIntegrityConstraintViolationException.class);
		if (cause != null && cause.getMessage().contains("Duplicate")) {
			throw new DuplicateKeyException("Duplicate key", e);
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy