added a DuplicatKeyException catagory for SQLException translation (SPR-5125)
This commit is contained in:
@@ -32,6 +32,7 @@ import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.dao.DeadlockLoserDataAccessException;
|
||||
import org.springframework.dao.PermissionDeniedDataAccessException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
import org.springframework.jdbc.InvalidResultSetAccessException;
|
||||
|
||||
@@ -224,6 +225,10 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
|
||||
logTranslation(task, sql, sqlEx, false);
|
||||
return new InvalidResultSetAccessException(task, sql, sqlEx);
|
||||
}
|
||||
else if (Arrays.binarySearch(this.sqlErrorCodes.getDuplicateKeyCodes(), errorCode) >= 0) {
|
||||
logTranslation(task, sql, sqlEx, false);
|
||||
return new DuplicateKeyException(buildMessage(task, sql, sqlEx), sqlEx);
|
||||
}
|
||||
else if (Arrays.binarySearch(this.sqlErrorCodes.getDataIntegrityViolationCodes(), errorCode) >= 0) {
|
||||
logTranslation(task, sql, sqlEx, false);
|
||||
return new DataIntegrityViolationException(buildMessage(task, sql, sqlEx), sqlEx);
|
||||
|
||||
@@ -41,6 +41,8 @@ public class SQLErrorCodes {
|
||||
|
||||
private String[] invalidResultSetAccessCodes = new String[0];
|
||||
|
||||
private String[] duplicateKeyCodes = new String[0];
|
||||
|
||||
private String[] dataIntegrityViolationCodes = new String[0];
|
||||
|
||||
private String[] permissionDeniedCodes = new String[0];
|
||||
@@ -112,6 +114,14 @@ public class SQLErrorCodes {
|
||||
return this.invalidResultSetAccessCodes;
|
||||
}
|
||||
|
||||
public String[] getDuplicateKeyCodes() {
|
||||
return duplicateKeyCodes;
|
||||
}
|
||||
|
||||
public void setDuplicateKeyCodes(String[] duplicateKeyCodes) {
|
||||
this.duplicateKeyCodes = duplicateKeyCodes;
|
||||
}
|
||||
|
||||
public void setDataIntegrityViolationCodes(String[] dataIntegrityViolationCodes) {
|
||||
this.dataIntegrityViolationCodes = StringUtils.sortStringArray(dataIntegrityViolationCodes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user