public class SqlErrorCodeR2dbcExceptionTranslator extends AbstractFallbackR2dbcExceptionTranslator
R2dbcExceptionTranslator that analyzes vendor-specific error codes. More precise than an
implementation based on SQL state, but heavily vendor-specific.
This class applies the following matching rules:
SqlStateR2dbcExceptionTranslator is the default fallback translator,
analyzing the exception's SQL state only.
The configuration file named "sql-error-codes.xml" is by default read from the
org.springframework.jdbc.support package. It can be overridden through a file of the same name in the root of
the class path (e.g. in the "/WEB-INF/classes" directory), as long as the Spring JDBC package is loaded from the same
ClassLoader.
SQLErrorCodesFactory,
SqlStateR2dbcExceptionTranslatorlogger| Constructor and Description |
|---|
SqlErrorCodeR2dbcExceptionTranslator()
Creates a new
SqlErrorCodeR2dbcExceptionTranslator. |
SqlErrorCodeR2dbcExceptionTranslator(ConnectionFactory connectionFactory)
Create a SQL error code translator for the given DataSource.
|
SqlErrorCodeR2dbcExceptionTranslator(SQLErrorCodes sec)
Create a SQLErrorCode translator given these error codes.
|
SqlErrorCodeR2dbcExceptionTranslator(String dbName)
Create a SQL error code translator for the given database product name.
|
| Modifier and Type | Method and Description |
|---|---|
protected DataAccessException |
customTranslate(String task,
String sql,
R2dbcException ex)
Subclasses can override this method to attempt a custom mapping from
R2dbcException to
DataAccessException. |
protected DataAccessException |
doTranslate(String task,
String sql,
R2dbcException ex)
Template method for actually translating the given exception.
|
SQLErrorCodes |
getSqlErrorCodes()
Return the error codes used by this translator.
|
void |
setConnectionFactory(ConnectionFactory connectionFactory)
Set the DataSource for this translator.
|
void |
setDatabaseProductName(String dbName)
Set the database product name for this translator.
|
void |
setSqlErrorCodes(SQLErrorCodes sec)
Set custom error codes to be used for translation.
|
buildMessage, getFallbackTranslator, setFallbackTranslator, translatepublic SqlErrorCodeR2dbcExceptionTranslator()
SqlErrorCodeR2dbcExceptionTranslator. The SQLErrorCodes or
ConnectionFactory property must be set.public SqlErrorCodeR2dbcExceptionTranslator(ConnectionFactory connectionFactory)
connectionFactory - ConnectionFactory to use to find meta-data and establish which error codes are
usable.SQLErrorCodesFactorypublic SqlErrorCodeR2dbcExceptionTranslator(String dbName)
dbName - the database product name that identifies the error codes entrySQLErrorCodesFactory,
DatabaseMetaData.getDatabaseProductName()public SqlErrorCodeR2dbcExceptionTranslator(@Nullable SQLErrorCodes sec)
sec - error codespublic void setConnectionFactory(ConnectionFactory connectionFactory)
Setting this property will cause a Connection to be obtained from the DataSource to get the meta-data.
connectionFactory - ConnectionFactory to use to find meta-data and establish which error codes are
usable.SQLErrorCodesFactory.getErrorCodes(String),
ConnectionFactoryMetadata.getName()public void setDatabaseProductName(String dbName)
Setting this property will avoid obtaining a Connection from the DataSource to get the meta-data.
dbName - the database product name that identifies the error codes entry.SQLErrorCodesFactory.getErrorCodes(String),
ConnectionFactoryMetadata.getName()public void setSqlErrorCodes(@Nullable SQLErrorCodes sec)
sec - custom error codes to use.@Nullable public SQLErrorCodes getSqlErrorCodes()
@Nullable protected DataAccessException doTranslate(String task, @Nullable String sql, R2dbcException ex)
AbstractFallbackR2dbcExceptionTranslatorThe 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.
doTranslate in class AbstractFallbackR2dbcExceptionTranslatortask - readable text describing the task being attempted.sql - SQL query or update that caused the problem (if known).ex - the offending R2dbcException.R2dbcException; or null if no exception match
found.@Nullable protected DataAccessException customTranslate(String task, @Nullable String sql, R2dbcException ex)
R2dbcException to
DataAccessException.task - readable text describing the task being attemptedsql - SQL query or update that caused the problem. May be null.ex - the offending R2dbcException.DataAccessException resulting from custom
translation. This exception should include the R2dbcException parameter as a nested root cause.
This implementation always returns null, meaning that the translator always falls back to the default error
codes.Copyright © 2018–2020 Pivotal Software, Inc.. All rights reserved.