package com.fufan.mtsaas.exception;

import org.apache.commons.lang3.StringUtils;

import java.sql.SQLIntegrityConstraintViolationException;
import java.util.Objects;

public class ExceptionHandle {

    public static boolean isDoubleKey(Exception e){
        if(Objects.nonNull(e) && Objects.nonNull(e.getCause()) && e.getCause() instanceof SQLIntegrityConstraintViolationException){
            SQLIntegrityConstraintViolationException f = (SQLIntegrityConstraintViolationException)e.getCause();
            if(StringUtils.isNotEmpty(f.getSQLState()) && f.getSQLState().equals("23000")){
                return true;
            }

        }
        return false;
    }
}
