added the option of providing a database specific custom SQLExceptionTranslator to provide customized translation for any SQLException before the error codes translation happens (SPR-4899)
This commit is contained in:
parent
943e359c4a
commit
49549d66ae
|
|
@ -188,6 +188,17 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
|
||||||
return dex;
|
return dex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next, try the custom SQLException translator, if available.
|
||||||
|
if (this.sqlErrorCodes != null) {
|
||||||
|
SQLExceptionTranslator customTranslator = this.sqlErrorCodes.getCustomSqlExceptionTranslator();
|
||||||
|
if (customTranslator != null) {
|
||||||
|
DataAccessException customDex = customTranslator.translate(task, sql, sqlEx);
|
||||||
|
if (customDex != null) {
|
||||||
|
return customDex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check SQLErrorCodes with corresponding error code, if available.
|
// Check SQLErrorCodes with corresponding error code, if available.
|
||||||
if (this.sqlErrorCodes != null) {
|
if (this.sqlErrorCodes != null) {
|
||||||
String errorCode = null;
|
String errorCode = null;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
package org.springframework.jdbc.support;
|
package org.springframework.jdbc.support;
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JavaBean for holding JDBC error codes for a particular database.
|
* JavaBean for holding JDBC error codes for a particular database.
|
||||||
|
|
@ -37,6 +39,8 @@ public class SQLErrorCodes {
|
||||||
|
|
||||||
private boolean useSqlStateForTranslation = false;
|
private boolean useSqlStateForTranslation = false;
|
||||||
|
|
||||||
|
private SQLExceptionTranslator customSqlExceptionTranslator = null;
|
||||||
|
|
||||||
private String[] badSqlGrammarCodes = new String[0];
|
private String[] badSqlGrammarCodes = new String[0];
|
||||||
|
|
||||||
private String[] invalidResultSetAccessCodes = new String[0];
|
private String[] invalidResultSetAccessCodes = new String[0];
|
||||||
|
|
@ -97,6 +101,26 @@ public class SQLErrorCodes {
|
||||||
return this.useSqlStateForTranslation;
|
return this.useSqlStateForTranslation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SQLExceptionTranslator getCustomSqlExceptionTranslator() {
|
||||||
|
return customSqlExceptionTranslator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomSqlExceptionTranslatorClass(Class customSqlExceptionTranslatorClass) {
|
||||||
|
if (customSqlExceptionTranslatorClass != null) {
|
||||||
|
try {
|
||||||
|
this.customSqlExceptionTranslator =
|
||||||
|
(SQLExceptionTranslator) customSqlExceptionTranslatorClass.newInstance();
|
||||||
|
}
|
||||||
|
catch (InstantiationException e) {
|
||||||
|
throw new InvalidDataAccessResourceUsageException(
|
||||||
|
"Unable to instantiate " + customSqlExceptionTranslatorClass.getName(), e);
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException e) {
|
||||||
|
throw new InvalidDataAccessResourceUsageException(
|
||||||
|
"Unable to instantiate " + customSqlExceptionTranslatorClass.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setBadSqlGrammarCodes(String[] badSqlGrammarCodes) {
|
public void setBadSqlGrammarCodes(String[] badSqlGrammarCodes) {
|
||||||
this.badSqlGrammarCodes = StringUtils.sortStringArray(badSqlGrammarCodes);
|
this.badSqlGrammarCodes = StringUtils.sortStringArray(badSqlGrammarCodes);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue