| java.lang.Object org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
SQLErrorCodeSQLExceptionTranslator | public class SQLErrorCodeSQLExceptionTranslator implements SQLExceptionTranslator(Code) | | Implementation of SQLExceptionTranslator that analyzes vendor-specific error codes.
More precise than an implementation based on SQL state, but vendor-specific.
This class applies the following matching rules:
- Try custom translation implemented by any subclass. Note that this class is
concrete and is typically used itself, in which case this rule doesn't apply.
- Apply error code matching. Error codes are obtained from the SQLErrorCodesFactory
by default. This factory loads a "sql-error-codes.xml" file from the class path,
defining error code mappings for database names from database metadata.
- Fallback to a fallback translator. SQLStateSQLExceptionTranslator 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
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).
author: Rod Johnson author: Thomas Risberg author: Juergen Hoeller See Also: SQLErrorCodesFactory See Also: SQLStateSQLExceptionTranslator |
Field Summary | |
final protected Log | logger |
Method Summary | |
protected String | buildMessage(String task, String sql, SQLException sqlEx) Build a message String for the given SQLException.
Called when creating an instance of a generic DataAccessException class.
Parameters: task - readable text describing the task being attempted Parameters: sql - SQL query or update that caused the problem. | protected DataAccessException | createCustomException(String task, String sql, SQLException sqlEx, Class exceptionClass) Create a custom DataAccessException, based on a given exception
class from a CustomSQLErrorCodesTranslation definition.
Parameters: task - readable text describing the task being attempted Parameters: sql - SQL query or update that caused the problem. | protected DataAccessException | customTranslate(String task, String sql, SQLException sqlEx) Subclasses can override this method to attempt a custom mapping from SQLException
to DataAccessException.
Parameters: task - readable text describing the task being attempted Parameters: sql - SQL query or update that caused the problem. | public SQLExceptionTranslator | getFallbackTranslator() Return the fallback exception translator. | public SQLErrorCodes | getSqlErrorCodes() Return the error codes used by this translator. | public void | setDataSource(DataSource dataSource) Set the DataSource for this translator. | public void | setDatabaseProductName(String dbName) Set the database product name for this translator. | public void | setFallbackTranslator(SQLExceptionTranslator fallback) Override the default SQL state fallback translator. | public void | setSqlErrorCodes(SQLErrorCodes sec) Set custom error codes to be used for translation. | public DataAccessException | translate(String task, String sql, SQLException sqlEx) |
logger | final protected Log logger(Code) | | Logger available to subclasses
|
SQLErrorCodeSQLExceptionTranslator | public SQLErrorCodeSQLExceptionTranslator()(Code) | | Constructor for use as a JavaBean.
The SqlErrorCodes or DataSource property must be set.
|
SQLErrorCodeSQLExceptionTranslator | public SQLErrorCodeSQLExceptionTranslator(DataSource dataSource)(Code) | | 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.
Parameters: dataSource - DataSource to use to find metadata and establishwhich error codes are usable See Also: SQLErrorCodesFactory |
SQLErrorCodeSQLExceptionTranslator | public SQLErrorCodeSQLExceptionTranslator(String dbName)(Code) | | 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.
Parameters: dbName - the database product name that identifies the error codes entry See Also: SQLErrorCodesFactory See Also: java.sql.DatabaseMetaData.getDatabaseProductName |
SQLErrorCodeSQLExceptionTranslator | public SQLErrorCodeSQLExceptionTranslator(SQLErrorCodes sec)(Code) | | Create a SQLErrorCode translator given these error codes.
Does not require a database metadata lookup to be performed using a connection.
Parameters: sec - error codes |
buildMessage | protected String buildMessage(String task, String sql, SQLException sqlEx)(Code) | | Build a message String for the given SQLException.
Called when creating an instance of a generic DataAccessException class.
Parameters: task - readable text describing the task being attempted Parameters: sql - SQL query or update that caused the problem. May be null . Parameters: sqlEx - the offending SQLException the message String to use |
createCustomException | protected DataAccessException createCustomException(String task, String sql, SQLException sqlEx, Class exceptionClass)(Code) | | Create a custom DataAccessException, based on a given exception
class from a CustomSQLErrorCodesTranslation definition.
Parameters: task - readable text describing the task being attempted Parameters: sql - SQL query or update that caused the problem. May be null . Parameters: sqlEx - the offending SQLException Parameters: exceptionClass - the exception class to use, as defined in theCustomSQLErrorCodesTranslation definition null if the custom exception could not be created, otherwisethe resulting DataAccessException. This exception should include thesqlEx parameter as a nested root cause. See Also: CustomSQLErrorCodesTranslation.setExceptionClass |
customTranslate | protected DataAccessException customTranslate(String task, String sql, SQLException sqlEx)(Code) | | Subclasses can override this method to attempt a custom mapping from SQLException
to DataAccessException.
Parameters: task - readable text describing the task being attempted Parameters: sql - SQL query or update that caused the problem. May be null . Parameters: sqlEx - the offending SQLException null if no custom translation was possible, otherwise a DataAccessExceptionresulting from custom translation. This exception should include the sqlEx parameteras a nested root cause. This implementation always returns null, meaning thatthe translator always falls back to the default error codes. |
setSqlErrorCodes | public void setSqlErrorCodes(SQLErrorCodes sec)(Code) | | Set custom error codes to be used for translation.
Parameters: sec - custom error codes to use |
|
|