类 SQLErrorCodesFactory
- java.lang.Object
- org.springframework.jdbc.support.SQLErrorCodesFactory
public class SQLErrorCodesFactory extends Object
Factory for creatingSQLErrorCodesbased on the "databaseProductName" taken from theDatabaseMetaData.Returns
SQLErrorCodespopulated 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).- 作者:
- Thomas Risberg, Rod Johnson, Juergen Hoeller
- 另请参阅:
DatabaseMetaData.getDatabaseProductName()
字段概要
字段 修饰符和类型 字段 说明 static StringSQL_ERROR_CODE_DEFAULT_PATHThe name of default SQL error code files, loading from the class path.static StringSQL_ERROR_CODE_OVERRIDE_PATHThe name of custom SQL error codes file, loading from the root of the class path (e.g. from the "/WEB-INF/classes" directory).
构造器概要
构造器 限定符 构造器 说明 protectedSQLErrorCodesFactory()Create a new instance of theSQLErrorCodesFactoryclass.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 SQLErrorCodesgetErrorCodes(String databaseName)Return theSQLErrorCodesinstance for the given database.SQLErrorCodesgetErrorCodes(DataSource dataSource)ReturnSQLErrorCodesfor the givenDataSource, evaluating "databaseProductName" from theDatabaseMetaData, or an empty error codes instance if noSQLErrorCodeswere found.static SQLErrorCodesFactorygetInstance()Return the singleton instance.protected ResourceloadResource(String path)Load the given resource from the class path.SQLErrorCodesregisterDatabase(DataSource dataSource, String databaseName)Associate the specified database name with the givenDataSource.SQLErrorCodesresolveErrorCodes(DataSource dataSource)ReturnSQLErrorCodesfor the givenDataSource, evaluating "databaseProductName" from theDatabaseMetaData, ornullif case of a JDBC meta-data access problem.SQLErrorCodesunregisterDatabase(DataSource dataSource)Clear the cache for the specifiedDataSource, if registered.
字段详细资料
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).- 另请参阅:
- 常量字段值
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.- 另请参阅:
- 常量字段值
构造器详细资料
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.
- 另请参阅:
loadResource(String)
方法详细资料
getInstance
public static SQLErrorCodesFactory getInstance()
Return the singleton instance.
loadResource
@Nullable 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.
- 参数:
path- resource path; either a custom path or one of eitherSQL_ERROR_CODE_DEFAULT_PATHorSQL_ERROR_CODE_OVERRIDE_PATH.- 返回:
- the resource, or
nullif the resource wasn't found - 另请参阅:
getInstance()
getErrorCodes
public SQLErrorCodes getErrorCodes(String databaseName)
Return theSQLErrorCodesinstance for the given database.No need for a database meta-data lookup.
- 参数:
databaseName- the database name (must not benull)- 返回:
- the
SQLErrorCodesinstance for the given database (nevernull; potentially empty) - 抛出:
IllegalArgumentException- if the supplied database name isnull
getErrorCodes
public SQLErrorCodes getErrorCodes(DataSource dataSource)
ReturnSQLErrorCodesfor the givenDataSource, evaluating "databaseProductName" from theDatabaseMetaData, or an empty error codes instance if noSQLErrorCodeswere found.- 参数:
dataSource- theDataSourceidentifying the database- 返回:
- the corresponding
SQLErrorCodesobject (nevernull; potentially empty) - 另请参阅:
DatabaseMetaData.getDatabaseProductName()
resolveErrorCodes
@Nullable public SQLErrorCodes resolveErrorCodes(DataSource dataSource)
ReturnSQLErrorCodesfor the givenDataSource, evaluating "databaseProductName" from theDatabaseMetaData, ornullif case of a JDBC meta-data access problem.- 参数:
dataSource- theDataSourceidentifying the database- 返回:
- the corresponding
SQLErrorCodesobject, ornullin case of a JDBC meta-data access problem - 从以下版本开始:
- 5.2.9
- 另请参阅:
DatabaseMetaData.getDatabaseProductName()
registerDatabase
public SQLErrorCodes registerDatabase(DataSource dataSource, String databaseName)
Associate the specified database name with the givenDataSource.- 参数:
dataSource- theDataSourceidentifying the databasedatabaseName- the corresponding database name as stated in the error codes definition file (must not benull)- 返回:
- the corresponding
SQLErrorCodesobject (nevernull) - 另请参阅:
unregisterDatabase(DataSource)
unregisterDatabase
@Nullable public SQLErrorCodes unregisterDatabase(DataSource dataSource)
Clear the cache for the specifiedDataSource, if registered.- 参数:
dataSource- theDataSourceidentifying the database- 返回:
- the corresponding
SQLErrorCodesobject that got removed, ornullif not registered - 从以下版本开始:
- 4.3.5
- 另请参阅:
registerDatabase(DataSource, String)