public class

SQLErrorCodesFactory

extends Object
java.lang.Object
   ↳ org.springframework.jdbc.support.SQLErrorCodesFactory

Class Overview

Factory for creating SQLErrorCodes based on the "databaseProductName" taken from the java.sql.DatabaseMetaData.

Returns SQLErrorCodes populated with vendor codes defined in a configuration file named "sql-error-codes.xml". Reads the default file in this package if not overridden by a file in the root of the class path (for example in the "/WEB-INF/classes" directory).

Summary

Constants
String SQL_ERROR_CODE_DEFAULT_PATH The name of default SQL error code files, loading from the class path.
String SQL_ERROR_CODE_OVERRIDE_PATH The name of custom SQL error codes file, loading from the root of the class path (e.g.
Protected Constructors
SQLErrorCodesFactory()
Create a new instance of the SQLErrorCodesFactory class.
Public Methods
SQLErrorCodes getErrorCodes(String dbName)
Return the SQLErrorCodes instance for the given database.
SQLErrorCodes getErrorCodes(DataSource dataSource)
Return SQLErrorCodes for the given DataSource, evaluating "databaseProductName" from the DatabaseMetaData, or an empty error codes instance if no SQLErrorCodes were found.
static SQLErrorCodesFactory getInstance()
Return the singleton instance.
SQLErrorCodes registerDatabase(DataSource dataSource, String dbName)
Associate the specified database name with the given DataSource.
Protected Methods
Resource loadResource(String path)
Load the given resource from the class path.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String SQL_ERROR_CODE_DEFAULT_PATH

The name of default SQL error code files, loading from the class path.

Constant Value: "org/springframework/jdbc/support/sql-error-codes.xml"

public static final String SQL_ERROR_CODE_OVERRIDE_PATH

The name of custom SQL error codes file, loading from the root of the class path (e.g. from the "/WEB-INF/classes" directory).

Constant Value: "sql-error-codes.xml"

Protected Constructors

protected SQLErrorCodesFactory ()

Create a new instance of the SQLErrorCodesFactory class.

Not public to enforce Singleton design pattern. Would be private except to allow testing via overriding the loadResource(String) method.

Do not subclass in application code.

Public Methods

public SQLErrorCodes getErrorCodes (String dbName)

Return the SQLErrorCodes instance for the given database.

No need for a database metadata lookup.

Parameters
dbName the database name (must not be null)
Returns
  • the SQLErrorCodes instance for the given database
Throws
IllegalArgumentException if the supplied database name is null

public SQLErrorCodes getErrorCodes (DataSource dataSource)

Return SQLErrorCodes for the given DataSource, evaluating "databaseProductName" from the DatabaseMetaData, or an empty error codes instance if no SQLErrorCodes were found.

Parameters
dataSource the DataSource identifying the database
Returns
  • the corresponding SQLErrorCodes object

public static SQLErrorCodesFactory getInstance ()

Return the singleton instance.

public SQLErrorCodes registerDatabase (DataSource dataSource, String dbName)

Associate the specified database name with the given DataSource.

Parameters
dataSource the DataSource identifying the database
dbName the corresponding database name as stated in the error codes definition file (must not be null)
Returns
  • the corresponding SQLErrorCodes object

Protected Methods

protected Resource loadResource (String path)

Load the given resource from the class path.

Not to be overridden by application developers, who should obtain instances of this class from the static getInstance() method.

Protected for testability.

Parameters
path resource path; either a custom path or one of either SQL_ERROR_CODE_DEFAULT_PATH or SQL_ERROR_CODE_OVERRIDE_PATH.
Returns
  • the resource, or null if the resource wasn't found
See Also