Package org.springframework.jdbc.support
Class SQLErrorCodesFactory
java.lang.Object
org.springframework.jdbc.support.SQLErrorCodesFactory
Factory for creating
SQLErrorCodes based on the
"databaseProductName" taken from the 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).
- Author:
- Thomas Risberg, Rod Johnson, Juergen Hoeller
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetErrorCodes(String databaseName) Return theSQLErrorCodesinstance for the given database.getErrorCodes(DataSource dataSource) ReturnSQLErrorCodesfor the givenDataSource, evaluating "databaseProductName" from theDatabaseMetaData, or an empty error codes instance if noSQLErrorCodeswere found.static SQLErrorCodesFactoryReturn the singleton instance.protected ResourceloadResource(String path) Load the given resource from the class path.registerDatabase(DataSource dataSource, String databaseName) Associate the specified database name with the givenDataSource.resolveErrorCodes(DataSource dataSource) ReturnSQLErrorCodesfor the givenDataSource, evaluating "databaseProductName" from theDatabaseMetaData, ornullif case of a JDBC meta-data access problem.unregisterDatabase(DataSource dataSource) Clear the cache for the specifiedDataSource, if registered.
-
Field Details
-
SQL_ERROR_CODE_OVERRIDE_PATH
The name of custom SQL error codes file, loading from the root of the class path (for example, from the "/WEB-INF/classes" directory).- See Also:
-
SQL_ERROR_CODE_DEFAULT_PATH
The name of default SQL error code files, loading from the class path.- See Also:
-
-
Constructor Details
-
SQLErrorCodesFactory
protected SQLErrorCodesFactory()Create a new instance of theSQLErrorCodesFactoryclass.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.
- See Also:
-
-
Method Details
-
getInstance
Return the singleton instance. -
loadResource
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 eitherSQL_ERROR_CODE_DEFAULT_PATHorSQL_ERROR_CODE_OVERRIDE_PATH.- Returns:
- the resource, or
nullif the resource wasn't found - See Also:
-
getErrorCodes
Return theSQLErrorCodesinstance for the given database.No need for a database meta-data lookup.
- Parameters:
databaseName- the database name (must not benull)- Returns:
- the
SQLErrorCodesinstance for the given database (nevernull; potentially empty) - Throws:
IllegalArgumentException- if the supplied database name isnull
-
getErrorCodes
ReturnSQLErrorCodesfor the givenDataSource, evaluating "databaseProductName" from theDatabaseMetaData, or an empty error codes instance if noSQLErrorCodeswere found.- Parameters:
dataSource- theDataSourceidentifying the database- Returns:
- the corresponding
SQLErrorCodesobject (nevernull; potentially empty) - See Also:
-
resolveErrorCodes
ReturnSQLErrorCodesfor the givenDataSource, evaluating "databaseProductName" from theDatabaseMetaData, ornullif case of a JDBC meta-data access problem.- Parameters:
dataSource- theDataSourceidentifying the database- Returns:
- the corresponding
SQLErrorCodesobject, ornullin case of a JDBC meta-data access problem - Since:
- 5.2.9
- See Also:
-
registerDatabase
Associate the specified database name with the givenDataSource.- Parameters:
dataSource- theDataSourceidentifying the databasedatabaseName- the corresponding database name as stated in the error codes definition file (must not benull)- Returns:
- the corresponding
SQLErrorCodesobject (nevernull) - See Also:
-
unregisterDatabase
Clear the cache for the specifiedDataSource, if registered.- Parameters:
dataSource- theDataSourceidentifying the database- Returns:
- the corresponding
SQLErrorCodesobject that got removed, ornullif not registered - Since:
- 4.3.5
- See Also:
-