Package org.springframework.jdbc.support
Class SQLErrorCodesFactory
- java.lang.Object
- org.springframework.jdbc.support.SQLErrorCodesFactory
public class SQLErrorCodesFactory extends Object
Factory for creatingSQLErrorCodes
based on the "databaseProductName" taken from theDatabaseMetaData
.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:
DatabaseMetaData.getDatabaseProductName()
Field Summary
Fields Modifier and Type Field Description static String
SQL_ERROR_CODE_DEFAULT_PATH
The name of default SQL error code files, loading from the class path.static String
SQL_ERROR_CODE_OVERRIDE_PATH
The name of custom SQL error codes file, loading from the root of the class path (e.g.
Constructor Summary
Constructors Modifier Constructor Description protected
SQLErrorCodesFactory()
Create a new instance of theSQLErrorCodesFactory
class.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SQLErrorCodes
getErrorCodes(String databaseName)
Return theSQLErrorCodes
instance for the given database.SQLErrorCodes
getErrorCodes(DataSource dataSource)
ReturnSQLErrorCodes
for the givenDataSource
, evaluating "databaseProductName" from theDatabaseMetaData
, or an empty error codes instance if noSQLErrorCodes
were found.static SQLErrorCodesFactory
getInstance()
Return the singleton instance.protected Resource
loadResource(String path)
Load the given resource from the class path.SQLErrorCodes
registerDatabase(DataSource dataSource, String databaseName)
Associate the specified database name with the givenDataSource
.SQLErrorCodes
unregisterDatabase(DataSource dataSource)
Clear the cache for the specifiedDataSource
, if registered.
Field Detail
SQL_ERROR_CODE_OVERRIDE_PATH
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).- See Also:
- Constant Field Values
SQL_ERROR_CODE_DEFAULT_PATH
public static final String SQL_ERROR_CODE_DEFAULT_PATH
The name of default SQL error code files, loading from the class path.- See Also:
- Constant Field Values
Constructor Detail
SQLErrorCodesFactory
protected SQLErrorCodesFactory()
Create a new instance of theSQLErrorCodesFactory
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.
- See Also:
loadResource(String)
Method Detail
getInstance
public static SQLErrorCodesFactory getInstance()
Return the singleton instance.
loadResource
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 eitherSQL_ERROR_CODE_DEFAULT_PATH
orSQL_ERROR_CODE_OVERRIDE_PATH
.- Returns:
- the resource, or
null
if the resource wasn't found - See Also:
getInstance()
getErrorCodes
public SQLErrorCodes getErrorCodes(String databaseName)
Return theSQLErrorCodes
instance for the given database.No need for a database meta-data lookup.
- Parameters:
databaseName
- the database name (must not benull
)- Returns:
- the
SQLErrorCodes
instance for the given database - Throws:
IllegalArgumentException
- if the supplied database name isnull
getErrorCodes
public SQLErrorCodes getErrorCodes(DataSource dataSource)
ReturnSQLErrorCodes
for the givenDataSource
, evaluating "databaseProductName" from theDatabaseMetaData
, or an empty error codes instance if noSQLErrorCodes
were found.- Parameters:
dataSource
- theDataSource
identifying the database- Returns:
- the corresponding
SQLErrorCodes
object - See Also:
DatabaseMetaData.getDatabaseProductName()
registerDatabase
public SQLErrorCodes registerDatabase(DataSource dataSource, String databaseName)
Associate the specified database name with the givenDataSource
.- Parameters:
dataSource
- theDataSource
identifying the databasedatabaseName
- the corresponding database name as stated in the error codes definition file (must not benull
)- Returns:
- the corresponding
SQLErrorCodes
object (nevernull
) - See Also:
unregisterDatabase(DataSource)
unregisterDatabase
public SQLErrorCodes unregisterDatabase(DataSource dataSource)
Clear the cache for the specifiedDataSource
, if registered.- Parameters:
dataSource
- theDataSource
identifying the database- Returns:
- the corresponding
SQLErrorCodes
object that got removed, ornull
if not registered - Since:
- 4.3.5
- See Also:
registerDatabase(DataSource, String)