@FunctionalInterface
public interface SQLExceptionTranslator
SQLExceptions
and Spring's data access strategy-agnostic DataAccessException
hierarchy.
Implementations can be generic (for example, using
SQLState
codes for JDBC) or wholly
proprietary (for example, using Oracle error codes) for greater precision.
DataAccessException
Modifier and Type | Method and Description |
---|---|
DataAccessException |
translate(java.lang.String task,
java.lang.String sql,
java.sql.SQLException ex)
Translate the given
SQLException into a generic DataAccessException . |
@Nullable DataAccessException translate(java.lang.String task, @Nullable java.lang.String sql, java.sql.SQLException ex)
SQLException
into a generic DataAccessException
.
The returned DataAccessException is supposed to contain the original
SQLException
as root cause. However, client code may not generally
rely on this due to DataAccessExceptions possibly being caused by other resource
APIs as well. That said, a getRootCause() instanceof SQLException
check (and subsequent cast) is considered reliable when expecting JDBC-based
access to have happened.
task
- readable text describing the task being attemptedsql
- SQL query or update that caused the problem (if known)ex
- the offending SQLException
SQLException
,
or null
if no translation could be applied
(in a custom translator; the default translators always throw an
UncategorizedSQLException
in such a case)NestedRuntimeException.getRootCause()