Package org.springframework.jdbc.support
Class AbstractFallbackSQLExceptionTranslator
- java.lang.Object
- org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator
- All Implemented Interfaces:
SQLExceptionTranslator
- Direct Known Subclasses:
SQLErrorCodeSQLExceptionTranslator,SQLExceptionSubclassTranslator,SQLStateSQLExceptionTranslator
public abstract class AbstractFallbackSQLExceptionTranslator extends Object implements SQLExceptionTranslator
Base class forSQLExceptionTranslatorimplementations that allow for fallback to some otherSQLExceptionTranslator.- Since:
- 2.5.6
- Author:
- Juergen Hoeller
Constructor Summary
Constructors Constructor Description AbstractFallbackSQLExceptionTranslator()
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StringbuildMessage(String task, String sql, SQLException ex)Build a messageStringfor the givenSQLException.protected abstract DataAccessExceptiondoTranslate(String task, String sql, SQLException ex)Template method for actually translating the given exception.SQLExceptionTranslatorgetFallbackTranslator()Return the fallback exception translator, if any.voidsetFallbackTranslator(SQLExceptionTranslator fallback)Override the default SQL state fallback translator (typically aSQLStateSQLExceptionTranslator).DataAccessExceptiontranslate(String task, String sql, SQLException ex)Pre-checks the arguments, callsdoTranslate(java.lang.String, java.lang.String, java.sql.SQLException), and invokes thefallback translatorif necessary.
Constructor Detail
AbstractFallbackSQLExceptionTranslator
public AbstractFallbackSQLExceptionTranslator()
Method Detail
setFallbackTranslator
public void setFallbackTranslator(@Nullable SQLExceptionTranslator fallback)
Override the default SQL state fallback translator (typically aSQLStateSQLExceptionTranslator).
getFallbackTranslator
@Nullable public SQLExceptionTranslator getFallbackTranslator()
Return the fallback exception translator, if any.
translate
@NonNull public DataAccessException translate(String task, @Nullable String sql, SQLException ex)
Pre-checks the arguments, callsdoTranslate(java.lang.String, java.lang.String, java.sql.SQLException), and invokes thefallback translatorif necessary.- Specified by:
translatein interfaceSQLExceptionTranslator- Parameters:
task- readable text describing the task being attemptedsql- the SQL query or update that caused the problem (if known)ex- the offendingSQLException- Returns:
- the DataAccessException wrapping the
SQLException, ornullif no translation could be applied (in a custom translator; the default translators always throw anUncategorizedSQLExceptionin such a case) - See Also:
NestedRuntimeException.getRootCause()
doTranslate
@Nullable protected abstract DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex)
Template method for actually translating the given exception.The passed-in arguments will have been pre-checked. Furthermore, this method is allowed to return
nullto indicate that no exception match has been found and that fallback translation should kick in.- Parameters:
task- readable text describing the task being attemptedsql- the SQL query or update that caused the problem (if known)ex- the offendingSQLException- Returns:
- the DataAccessException, wrapping the
SQLException; ornullif no exception match found
buildMessage
protected String buildMessage(String task, @Nullable String sql, SQLException ex)
Build a messageStringfor the givenSQLException.To be called by translator subclasses when creating an instance of a generic
DataAccessExceptionclass.- Parameters:
task- readable text describing the task being attemptedsql- the SQL statement that caused the problemex- the offendingSQLException- Returns:
- the message
Stringto use