java.lang.Object | ||
↳ | org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator | |
↳ | org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator |
Implementation of 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. On Java 6
which introduces its own SQLException
subclass hierarchy, we will
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.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor for use as a JavaBean.
| |||||||||||
Create a SQL error code translator for the given DataSource.
| |||||||||||
Create a SQL error code translator for the given database product name.
| |||||||||||
Create a SQLErrorCode translator given these error codes.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return the error codes used by this translator.
| |||||||||||
Set the DataSource for this translator.
| |||||||||||
Set the database product name for this translator.
| |||||||||||
Set custom error codes to be used for translation.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a custom DataAccessException, based on a given exception
class from a CustomSQLErrorCodesTranslation definition.
| |||||||||||
Subclasses can override this method to attempt a custom mapping from SQLException
to DataAccessException.
| |||||||||||
Template method for actually translating the given exception.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.jdbc.support.SQLExceptionTranslator
|
Constructor for use as a JavaBean. The SqlErrorCodes or DataSource property must be set.
Create a SQL error code translator for the given DataSource. Invoking this constructor will cause a Connection to be obtained from the DataSource to get the metadata.
dataSource | DataSource to use to find metadata and establish which error codes are usable |
---|
Create a SQL error code translator for the given database product name. Invoking this constructor will avoid obtaining a Connection from the DataSource to get the metadata.
dbName | the database product name that identifies the error codes entry |
---|
Create a SQLErrorCode translator given these error codes. Does not require a database metadata lookup to be performed using a connection.
sec | error codes |
---|
Return the error codes used by this translator. Usually determined via a DataSource.
Set the DataSource for this translator.
Setting this property will cause a Connection to be obtained from the DataSource to get the metadata.
dataSource | DataSource to use to find metadata and establish which error codes are usable |
---|
Set the database product name for this translator.
Setting this property will avoid obtaining a Connection from the DataSource to get the metadata.
dbName | the database product name that identifies the error codes entry |
---|
Set custom error codes to be used for translation.
sec | custom error codes to use |
---|
Create a custom DataAccessException, based on a given exception class from a CustomSQLErrorCodesTranslation definition.
task | readable text describing the task being attempted |
---|---|
sql | SQL query or update that caused the problem. May be null . |
sqlEx | the offending SQLException |
exceptionClass | the exception class to use, as defined in the CustomSQLErrorCodesTranslation definition |
Subclasses can override this method to attempt a custom mapping from SQLException to DataAccessException.
task | readable text describing the task being attempted |
---|---|
sql | SQL query or update that caused the problem. May be null . |
sqlEx | the offending SQLException |
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 attempted |
---|---|
sql | SQL query or update that caused the problem (may be null ) |
ex | the offending SQLException |
SQLException
;
or null
if no exception match found