public class SQLErrorCodesFactory extends Object
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).
DatabaseMetaData.getDatabaseProductName()
Modifier and Type | Field and 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.
|
Modifier | Constructor and Description |
---|---|
protected |
SQLErrorCodesFactory()
Create a new instance of the
SQLErrorCodesFactory class. |
Modifier and Type | Method and Description |
---|---|
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. |
SQLErrorCodes |
getErrorCodes(String databaseName)
Return the
SQLErrorCodes instance for the given database. |
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 given
DataSource . |
SQLErrorCodes |
resolveErrorCodes(DataSource dataSource)
Return
SQLErrorCodes for the given DataSource ,
evaluating "databaseProductName" from the
DatabaseMetaData , or null if case
of a JDBC meta-data access problem. |
SQLErrorCodes |
unregisterDatabase(DataSource dataSource)
Clear the cache for the specified
DataSource , if registered. |
public static final String SQL_ERROR_CODE_OVERRIDE_PATH
public static final String SQL_ERROR_CODE_DEFAULT_PATH
protected SQLErrorCodesFactory()
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.
loadResource(String)
public static SQLErrorCodesFactory getInstance()
@Nullable protected Resource loadResource(String 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 either
SQL_ERROR_CODE_DEFAULT_PATH
or
SQL_ERROR_CODE_OVERRIDE_PATH
.null
if the resource wasn't foundgetInstance()
public SQLErrorCodes getErrorCodes(String databaseName)
SQLErrorCodes
instance for the given database.
No need for a database meta-data lookup.
databaseName
- the database name (must not be null
)SQLErrorCodes
instance for the given database
(never null
; potentially empty)IllegalArgumentException
- if the supplied database name is null
public SQLErrorCodes getErrorCodes(DataSource dataSource)
SQLErrorCodes
for the given DataSource
,
evaluating "databaseProductName" from the
DatabaseMetaData
, or an empty error codes
instance if no SQLErrorCodes
were found.dataSource
- the DataSource
identifying the databaseSQLErrorCodes
object
(never null
; potentially empty)DatabaseMetaData.getDatabaseProductName()
@Nullable public SQLErrorCodes resolveErrorCodes(DataSource dataSource)
SQLErrorCodes
for the given DataSource
,
evaluating "databaseProductName" from the
DatabaseMetaData
, or null
if case
of a JDBC meta-data access problem.dataSource
- the DataSource
identifying the databaseSQLErrorCodes
object,
or null
in case of a JDBC meta-data access problemDatabaseMetaData.getDatabaseProductName()
public SQLErrorCodes registerDatabase(DataSource dataSource, String databaseName)
DataSource
.dataSource
- the DataSource
identifying the databasedatabaseName
- the corresponding database name as stated in the error codes
definition file (must not be null
)SQLErrorCodes
object (never null
)unregisterDatabase(DataSource)
@Nullable public SQLErrorCodes unregisterDatabase(DataSource dataSource)
DataSource
, if registered.dataSource
- the DataSource
identifying the databaseSQLErrorCodes
object that got removed,
or null
if not registeredregisterDatabase(DataSource, String)