public abstract class AbstractFallbackSQLExceptionTranslator extends java.lang.Object implements SQLExceptionTranslator
SQLExceptionTranslator
implementations that allow for
fallback to some other SQLExceptionTranslator
.Modifier and Type | Field and Description |
---|---|
protected Log |
logger
Logger available to subclasses
|
Constructor and Description |
---|
AbstractFallbackSQLExceptionTranslator() |
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
buildMessage(java.lang.String task,
java.lang.String sql,
java.sql.SQLException ex)
Build a message
String for the given SQLException . |
protected abstract DataAccessException |
doTranslate(java.lang.String task,
java.lang.String sql,
java.sql.SQLException ex)
Template method for actually translating the given exception.
|
SQLExceptionTranslator |
getFallbackTranslator()
Return the fallback exception translator, if any.
|
void |
setFallbackTranslator(SQLExceptionTranslator fallback)
Override the default SQL state fallback translator
(typically a
SQLStateSQLExceptionTranslator ). |
DataAccessException |
translate(java.lang.String task,
java.lang.String sql,
java.sql.SQLException ex)
Pre-checks the arguments, calls
doTranslate(java.lang.String, java.lang.String, java.sql.SQLException) , and invokes the
fallback translator if necessary. |
protected final Log logger
public AbstractFallbackSQLExceptionTranslator()
public void setFallbackTranslator(@Nullable SQLExceptionTranslator fallback)
SQLStateSQLExceptionTranslator
).@Nullable public SQLExceptionTranslator getFallbackTranslator()
@NonNull public DataAccessException translate(java.lang.String task, @Nullable java.lang.String sql, java.sql.SQLException ex)
doTranslate(java.lang.String, java.lang.String, java.sql.SQLException)
, and invokes the
fallback translator
if necessary.translate
in interface SQLExceptionTranslator
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()
@Nullable protected abstract DataAccessException doTranslate(java.lang.String task, @Nullable java.lang.String sql, java.sql.SQLException ex)
The passed-in arguments will have been pre-checked. Furthermore, this method
is allowed to return null
to indicate that no exception match has
been found and that fallback translation should kick in.
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 exception match foundprotected java.lang.String buildMessage(java.lang.String task, @Nullable java.lang.String sql, java.sql.SQLException ex)
String
for the given SQLException
.
To be called by translator subclasses when creating an instance of a generic
DataAccessException
class.
task
- readable text describing the task being attemptedsql
- the SQL statement that caused the problemex
- the offending SQLException
String
to use