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 for 
SQLExceptionTranslator implementations that allow for a
fallback to some other SQLExceptionTranslator, as well as for custom
overrides.- Since:
- 2.5.6
- Author:
- Juergen Hoeller
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.LogLogger available to subclasses.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected StringbuildMessage(String task, @Nullable String sql, SQLException ex) Build a messageStringfor the givenSQLException.protected abstract @Nullable DataAccessExceptiondoTranslate(String task, @Nullable String sql, SQLException ex) Template method for actually translating the given exception.Return a custom exception translator, if any.Return the fallback exception translator, if any.voidsetCustomTranslator(@Nullable SQLExceptionTranslator customTranslator) Set a custom exception translator to override any match that this translator would find.voidSet the fallback translator to use when this translator cannot find a specific match itself.translate(String task, @Nullable String sql, SQLException ex) Pre-checks the arguments, callsdoTranslate(String, String, SQLException), and invokes thefallback translatorif necessary.
- 
Field Details- 
loggerprotected final org.apache.commons.logging.Log loggerLogger available to subclasses.
 
- 
- 
Constructor Details- 
AbstractFallbackSQLExceptionTranslatorpublic AbstractFallbackSQLExceptionTranslator()
 
- 
- 
Method Details- 
setFallbackTranslatorSet the fallback translator to use when this translator cannot find a specific match itself.
- 
getFallbackTranslatorReturn the fallback exception translator, if any.- See Also:
 
- 
setCustomTranslatorSet a custom exception translator to override any match that this translator would find. Note that such a customSQLExceptionTranslatordelegate is meant to returnnullif it does not have an override itself.- Since:
- 6.1
 
- 
getCustomTranslatorReturn a custom exception translator, if any.- Since:
- 6.1
- See Also:
 
- 
translatePre-checks the arguments, callsdoTranslate(String, String, SQLException), and invokes thefallback translatorif necessary.- Specified by:
- translatein interface- SQLExceptionTranslator
- Parameters:
- task- readable text describing the task being attempted
- sql- the SQL query or update that caused the problem (if known)
- ex- the offending- SQLException
- Returns:
- the DataAccessException wrapping the SQLException, ornullif no specific translation could be applied
- See Also:
 
- 
doTranslateprotected abstract @Nullable 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 attempted
- sql- the SQL query or update that caused the problem (if known)
- ex- the offending- SQLException
- Returns:
- the DataAccessException, wrapping the SQLException; ornullif no exception match found
 
- 
buildMessageBuild 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 attempted
- sql- the SQL statement that caused the problem
- ex- the offending- SQLException
- Returns:
- the message Stringto use
 
 
-