/* ================================================================== * Created [2009-4-27 下午11:32:55] by Jon.King * ================================================================== * TSS * ================================================================== * mailTo:jinpujun@hotmail.com * Copyright (c) Jon.King, 2009-2012 * ================================================================== */ package com.jinhe.tss.core.exception.convert.impl; import org.hibernate.exception.ConstraintViolationException; import org.springframework.dao.DataIntegrityViolationException; import com.jinhe.tss.core.exception.BusinessException; import com.jinhe.tss.core.exception.convert.IExceptionConvertor; public class SameNodeNameExceptionConvertor implements IExceptionConvertor { public Exception execute(Exception be) { if(null != be && (be instanceof ConstraintViolationException || be instanceof DataIntegrityViolationException)){ if (be.getCause().getMessage().indexOf("MULTI_NAME") != -1) { return new BusinessException("操作失败!名称已存在请更换名称!", be); } } if(null != be && (be instanceof ConstraintViolationException || be instanceof DataIntegrityViolationException)){ if (be.getCause().getMessage().indexOf("MULTI_CODE") != -1) { return new BusinessException("操作失败!code已存在!", be); } } if(null != be && (be instanceof ConstraintViolationException || be instanceof DataIntegrityViolationException)){ if (be.getCause().getMessage().indexOf("MULTI_ID") != -1) { return new BusinessException("操作失败!ID已存在!", be); } } return be; } }