|
|
|
@ -60,6 +60,11 @@ import org.springframework.util.function.SupplierUtils; |
|
|
|
* of the class path (e.g. in the "/WEB-INF/classes" directory), as long as the |
|
|
|
* of the class path (e.g. in the "/WEB-INF/classes" directory), as long as the |
|
|
|
* Spring JDBC package is loaded from the same ClassLoader. |
|
|
|
* Spring JDBC package is loaded from the same ClassLoader. |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* <p>This translator is commonly used by default if a user-provided `sql-error-codes.xml` |
|
|
|
|
|
|
|
* file has been found in the root of the classpath, as a signal to use this strategy. |
|
|
|
|
|
|
|
* Otherwise, {@link SQLExceptionSubclassTranslator} serves as the default translator |
|
|
|
|
|
|
|
* as of 6.0. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Thomas Risberg |
|
|
|
* @author Thomas Risberg |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
@ -75,11 +80,10 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep |
|
|
|
private static final int MESSAGE_SQL_THROWABLE_CONSTRUCTOR = 4; |
|
|
|
private static final int MESSAGE_SQL_THROWABLE_CONSTRUCTOR = 4; |
|
|
|
private static final int MESSAGE_SQL_SQLEX_CONSTRUCTOR = 5; |
|
|
|
private static final int MESSAGE_SQL_SQLEX_CONSTRUCTOR = 5; |
|
|
|
|
|
|
|
|
|
|
|
private static final boolean USER_PROVIDED_ERROR_CODES_FILE_PRESENT = |
|
|
|
private static final boolean userProvidedErrorCodesFilePresent = |
|
|
|
new ClassPathResource(SQLErrorCodesFactory.SQL_ERROR_CODE_OVERRIDE_PATH, SQLErrorCodesFactory.class.getClassLoader()).exists(); |
|
|
|
new ClassPathResource(SQLErrorCodesFactory.SQL_ERROR_CODE_OVERRIDE_PATH, |
|
|
|
|
|
|
|
SQLErrorCodesFactory.class.getClassLoader()).exists(); |
|
|
|
|
|
|
|
|
|
|
|
/** Error codes used by this translator. */ |
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private SingletonSupplier<SQLErrorCodes> sqlErrorCodes; |
|
|
|
private SingletonSupplier<SQLErrorCodes> sqlErrorCodes; |
|
|
|
|
|
|
|
|
|
|
|
@ -198,9 +202,9 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep |
|
|
|
if (sqlErrorCodes != null) { |
|
|
|
if (sqlErrorCodes != null) { |
|
|
|
SQLExceptionTranslator customTranslator = sqlErrorCodes.getCustomSqlExceptionTranslator(); |
|
|
|
SQLExceptionTranslator customTranslator = sqlErrorCodes.getCustomSqlExceptionTranslator(); |
|
|
|
if (customTranslator != null) { |
|
|
|
if (customTranslator != null) { |
|
|
|
DataAccessException customDex = customTranslator.translate(task, sql, sqlEx); |
|
|
|
dae = customTranslator.translate(task, sql, sqlEx); |
|
|
|
if (customDex != null) { |
|
|
|
if (dae != null) { |
|
|
|
return customDex; |
|
|
|
return dae; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -228,11 +232,10 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep |
|
|
|
for (CustomSQLErrorCodesTranslation customTranslation : customTranslations) { |
|
|
|
for (CustomSQLErrorCodesTranslation customTranslation : customTranslations) { |
|
|
|
if (Arrays.binarySearch(customTranslation.getErrorCodes(), errorCode) >= 0 && |
|
|
|
if (Arrays.binarySearch(customTranslation.getErrorCodes(), errorCode) >= 0 && |
|
|
|
customTranslation.getExceptionClass() != null) { |
|
|
|
customTranslation.getExceptionClass() != null) { |
|
|
|
DataAccessException customException = createCustomException( |
|
|
|
dae = createCustomException(task, sql, sqlEx, customTranslation.getExceptionClass()); |
|
|
|
task, sql, sqlEx, customTranslation.getExceptionClass()); |
|
|
|
if (dae != null) { |
|
|
|
if (customException != null) { |
|
|
|
|
|
|
|
logTranslation(task, sql, sqlEx, true); |
|
|
|
logTranslation(task, sql, sqlEx, true); |
|
|
|
return customException; |
|
|
|
return dae; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -306,7 +309,9 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep |
|
|
|
* resulting from custom translation. This exception should include the {@code sqlEx} parameter |
|
|
|
* resulting from custom translation. This exception should include the {@code sqlEx} parameter |
|
|
|
* as a nested root cause. This implementation always returns {@code null}, meaning that the |
|
|
|
* as a nested root cause. This implementation always returns {@code null}, meaning that the |
|
|
|
* translator always falls back to the default error codes. |
|
|
|
* translator always falls back to the default error codes. |
|
|
|
|
|
|
|
* @deprecated as of 6.1, in favor of {@link #setCustomTranslator} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated(since = "6.1") |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
protected DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlEx) { |
|
|
|
protected DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlEx) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
@ -426,7 +431,7 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep |
|
|
|
* in the root of the classpath. |
|
|
|
* in the root of the classpath. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static boolean hasUserProvidedErrorCodesFile() { |
|
|
|
static boolean hasUserProvidedErrorCodesFile() { |
|
|
|
return USER_PROVIDED_ERROR_CODES_FILE_PRESENT; |
|
|
|
return userProvidedErrorCodesFilePresent; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|