类 AbstractFallbackSQLExceptionTranslator
- java.lang.Object
- org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator
- 所有已实现的接口:
SQLExceptionTranslator
- 直接已知子类:
SQLErrorCodeSQLExceptionTranslator
,SQLExceptionSubclassTranslator
,SQLStateSQLExceptionTranslator
public abstract class AbstractFallbackSQLExceptionTranslator extends Object implements SQLExceptionTranslator
Base class forSQLExceptionTranslator
implementations that allow for fallback to some otherSQLExceptionTranslator
.- 从以下版本开始:
- 2.5.6
- 作者:
- Juergen Hoeller
构造器概要
构造器 构造器 说明 AbstractFallbackSQLExceptionTranslator()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected String
buildMessage(String task, String sql, SQLException ex)
Build a messageString
for the givenSQLException
.protected abstract DataAccessException
doTranslate(String task, String 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 aSQLStateSQLExceptionTranslator
).DataAccessException
translate(String task, String sql, SQLException ex)
Pre-checks the arguments, callsdoTranslate(java.lang.String, java.lang.String, java.sql.SQLException)
, and invokes thefallback translator
if necessary.
构造器详细资料
AbstractFallbackSQLExceptionTranslator
public AbstractFallbackSQLExceptionTranslator()
方法详细资料
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 translator
if necessary.- 指定者:
translate
在接口中SQLExceptionTranslator
- 参数:
task
- readable text describing the task being attemptedsql
- the SQL query or update that caused the problem (if known)ex
- the offendingSQLException
- 返回:
- the DataAccessException wrapping the
SQLException
, ornull
if no translation could be applied (in a custom translator; the default translators always throw anUncategorizedSQLException
in such a case) - 另请参阅:
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
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
- the SQL query or update that caused the problem (if known)ex
- the offendingSQLException
- 返回:
- the DataAccessException, wrapping the
SQLException
; ornull
if no exception match found
buildMessage
protected String buildMessage(String task, @Nullable String sql, SQLException ex)
Build a messageString
for the givenSQLException
.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 offendingSQLException
- 返回:
- the message
String
to use