SQLExceptionTranslator 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:
SQLStateSQLExceptionTranslator is the
default fallback translator, analyzing the exception's SQL state only. Since Java 6
which introduces its own SQLException subclass hierarchy, we use
SQLExceptionSubclassTranslator by default, which in turns falls back
to Spring's own SQL state translation when not encountering specific subclasses.
The configuration file named "sql-error-codes.xml" is by default read from this 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.
This translator is commonly used by default if a user-provided `sql-error-codes.xml`
file has been found in the root of the classpath, as a signal to use this strategy.
Otherwise, SQLExceptionSubclassTranslator serves as the default translator
as of 6.0.
SQLErrorCodesFactory, SQLStateSQLExceptionTranslator
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private SingletonSupplier | |
| private static final boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public | SQLErrorCodeSQLExceptionTranslator(DataSource
the DataSource to use to find meta-data and establish
which error codes are usable dataSource)Create an SQL error code translator for the given DataSource. |
| public | SQLErrorCodeSQLExceptionTranslator(String
the database product name that identifies the error codes entry dbName)Create an SQL error code translator for the given database product name. |
| public | SQLErrorCodeSQLExceptionTranslator(SQLErrorCodes
error codes sec)Create an SQLErrorCode translator given these error codes. |
| Modifier and Type | Method and Description |
|---|---|
| protected DataAccessException | Returns: null if the custom exception could not be created, otherwise
the resulting DataAccessException. This exception should include the
sqlEx parameter as a nested root cause.readable text describing the task being attempted task, String the SQL query or update that caused the problem (may be sql, SQLException null)the offending SQLException sqlEx, Class<?> the exception class to use, as defined in the
exceptionClass)CustomSQLErrorCodesTranslation definitionCreate a custom |
| protected DataAccessException | Returns: null if no custom translation applies, otherwise a DataAccessException
resulting from custom translation. This exception should include the sqlEx parameter
as a nested root cause. This implementation always returns null, meaning that the
translator always falls back to the default error codes.readable text describing the task being attempted task, String the SQL query or update that caused the problem (may be sql, SQLException null)the offending SQLException sqlEx)
Deprecated
since 6.1. as of 6.1, in favor of
setCustomTranslator
Subclasses can override this method to attempt a custom mapping from
|
| protected DataAccessException | doTranslate(String
readable text describing the task being attempted task, String the SQL query or update that caused the problem (if known) sql, SQLException the offending ex)SQLExceptionImplements abstract org. Template method for actually translating the given exception. |
| public SQLErrorCodes | |
| pack-priv static boolean | hasUserProvidedErrorCodesFile()
Check whether there is a user-provided `sql-error-codes.xml` file in the root of the classpath. |
| private void | |
| public void | setDatabaseProductName(String
the database product name that identifies the error codes entry dbName)Set the database product name for this translator. |
| public void | setDataSource(DataSource
the DataSource to use to find meta-data and establish
which error codes are usable dataSource)Set the DataSource for this translator. |
| public void | setSqlErrorCodes(SQLErrorCodes
custom error codes to use sec)Set custom error codes to be used for translation. |
| MESSAGE_ONLY_CONSTRUCTOR | back to summary |
|---|---|
| private static final int MESSAGE_ONLY_CONSTRUCTOR | |
| MESSAGE_SQL_SQLEX_CONSTRUCTOR | back to summary |
|---|---|
| private static final int MESSAGE_SQL_SQLEX_CONSTRUCTOR | |
| MESSAGE_SQL_THROWABLE_CONSTRUCTOR | back to summary |
|---|---|
| private static final int MESSAGE_SQL_THROWABLE_CONSTRUCTOR | |
| MESSAGE_SQLEX_CONSTRUCTOR | back to summary |
|---|---|
| private static final int MESSAGE_SQLEX_CONSTRUCTOR | |
| MESSAGE_THROWABLE_CONSTRUCTOR | back to summary |
|---|---|
| private static final int MESSAGE_THROWABLE_CONSTRUCTOR | |
| sqlErrorCodes | back to summary |
|---|---|
| private SingletonSupplier<SQLErrorCodes> sqlErrorCodes
| |
| userProvidedErrorCodesFilePresent | back to summary |
|---|---|
| private static final boolean userProvidedErrorCodesFilePresent | |
| SQLErrorCodeSQLExceptionTranslator | back to summary |
|---|---|
| public SQLErrorCodeSQLExceptionTranslator() Constructor for use as a JavaBean. The SqlErrorCodes or DataSource property must be set. | |
| SQLErrorCodeSQLExceptionTranslator | back to summary |
|---|---|
| public SQLErrorCodeSQLExceptionTranslator(DataSource dataSource) Create an SQL error code translator for the given DataSource. Invoking this constructor will cause a Connection to be obtained from the DataSource to get the meta-data.
| |
| SQLErrorCodeSQLExceptionTranslator | back to summary |
|---|---|
| public SQLErrorCodeSQLExceptionTranslator(String dbName) Create an SQL error code translator for the given database product name. Invoking this constructor will avoid obtaining a Connection from the DataSource to get the meta-data.
| |
| SQLErrorCodeSQLExceptionTranslator | back to summary |
|---|---|
| public SQLErrorCodeSQLExceptionTranslator(SQLErrorCodes sec) Create an SQLErrorCode translator given these error codes. Does not require a database meta-data lookup to be performed using a connection.
| |
| createCustomException | back to summary |
|---|---|
| protected DataAccessException createCustomException(String task, String sql, SQLException sqlEx, Class<?> exceptionClass) Create a custom
| |
| customTranslate | back to summary |
|---|---|
| protected DataAccessException customTranslate(String task, String sql, SQLException sqlEx)
Subclasses can override this method to attempt a custom mapping from
| |
| doTranslate | back to summary |
|---|---|
| protected DataAccessException doTranslate(String task, String sql, SQLException ex) Implements abstract org. Doc from org. Template method for actually translating the given exception. The passed-in arguments will have been pre-checked. Furthermore, this method
is allowed to return
| |
| getSqlErrorCodes | back to summary |
|---|---|
| public SQLErrorCodes getSqlErrorCodes() Return the error codes used by this translator. Usually determined via a DataSource.
| |
| hasUserProvidedErrorCodesFile | back to summary |
|---|---|
| pack-priv static boolean hasUserProvidedErrorCodesFile() Check whether there is a user-provided `sql-error-codes.xml` file in the root of the classpath. | |
| logTranslation | back to summary |
|---|---|
| private void logTranslation(String task, String sql, SQLException sqlEx, boolean custom) | |
| setDatabaseProductName | back to summary |
|---|---|
| public void setDatabaseProductName(String dbName) Set the database product name for this translator. Setting this property will avoid obtaining a Connection from the DataSource to get the meta-data.
| |
| setDataSource | back to summary |
|---|---|
| public void setDataSource(DataSource dataSource) Set the DataSource for this translator. Setting this property will cause a Connection to be obtained from the DataSource to get the meta-data.
| |
| setSqlErrorCodes | back to summary |
|---|---|
| public void setSqlErrorCodes(SQLErrorCodes sec) Set custom error codes to be used for translation.
| |