|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.jdbc.support.SQLErrorCodesFactory
public class 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).
DatabaseMetaData.getDatabaseProductName()
Field Summary | |
---|---|
private java.util.Map<javax.sql.DataSource,SQLErrorCodes> |
dataSourceCache
Map to cache the SQLErrorCodes instance per DataSource. |
private java.util.Map<java.lang.String,SQLErrorCodes> |
errorCodesMap
Map to hold error codes for all databases defined in the config file. |
private static SQLErrorCodesFactory |
instance
Keep track of a single instance so we can return it to classes that request it. |
private static Log |
logger
|
static java.lang.String |
SQL_ERROR_CODE_DEFAULT_PATH
The name of default SQL error code files, loading from the class path. |
static java.lang.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 | |
---|---|
protected |
SQLErrorCodesFactory()
Create a new instance of the SQLErrorCodesFactory class. |
Method Summary | |
---|---|
SQLErrorCodes |
getErrorCodes(javax.sql.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(java.lang.String dbName)
Return the SQLErrorCodes instance for the given database. |
static SQLErrorCodesFactory |
getInstance()
Return the singleton instance. |
protected Resource |
loadResource(java.lang.String path)
Load the given resource from the class path. |
SQLErrorCodes |
registerDatabase(javax.sql.DataSource dataSource,
java.lang.String dbName)
Associate the specified database name with the given DataSource . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String SQL_ERROR_CODE_OVERRIDE_PATH
public static final java.lang.String SQL_ERROR_CODE_DEFAULT_PATH
private static final Log logger
private static final SQLErrorCodesFactory instance
private final java.util.Map<java.lang.String,SQLErrorCodes> errorCodesMap
private final java.util.Map<javax.sql.DataSource,SQLErrorCodes> dataSourceCache
Constructor Detail |
---|
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)
Method Detail |
---|
public static SQLErrorCodesFactory getInstance()
protected Resource loadResource(java.lang.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(java.lang.String dbName)
SQLErrorCodes
instance for the given database.
No need for a database metadata lookup.
dbName
- the database name (must not be null
)
SQLErrorCodes
instance for the given database
java.lang.IllegalArgumentException
- if the supplied database name is null
public SQLErrorCodes getErrorCodes(javax.sql.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 database
SQLErrorCodes
objectDatabaseMetaData.getDatabaseProductName()
public SQLErrorCodes registerDatabase(javax.sql.DataSource dataSource, java.lang.String dbName)
DataSource
.
dataSource
- the DataSource
identifying the databasedbName
- the corresponding database name as stated in the error codes
definition file (must not be null
)
SQLErrorCodes
object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |