|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--uk.org.ogsadai.dataresource.JDBCDataResourceAccessor
A data resource accessor that provides access to JDBC data resources.
The configuration file is named dataResourceConfig.xml
and is assumed to reside in the configuration files directory for the data service resource that owns this data resource accessor.
Field Summary | |
private static java.lang.String |
COPYRIGHT_NOTICE |
private static DAILogger |
LOG |
private static java.lang.String |
MAIN_CONFIG_FILE_NAME |
private java.lang.String |
mConnectionURI |
private java.lang.String |
mDriverClassName |
private Property[] |
mProperties |
private java.lang.String |
mResourceName |
private RoleMapper |
mRoleMapper |
Constructor Summary | |
JDBCDataResourceAccessor() |
Method Summary | |
private java.lang.String |
getAndLoadDriverClassName(org.w3c.dom.Document configDoc) Returns the name of the JDBC driver class and loads the class. |
private org.w3c.dom.Document |
getConfigAsDOM(java.lang.String name, java.io.File dir) Reads the data resource accessor configuration file and converts it to DOM. |
protected java.sql.Connection |
getConnection(java.lang.String connectionURI, java.lang.String user, java.lang.String password) Obtains a connection from the database. |
private java.lang.String |
getConnectionURI(org.w3c.dom.Document configDoc) Returns the URI of the database. |
java.sql.Connection |
getJDBCConnection(java.lang.String userCredentials) Returns a JDBC connection. |
java.lang.String |
getJDBCDriverClassName() Returns the name of the JDBC driver class. |
private Property[] |
getMetaData(java.lang.String name, org.w3c.dom.Document configDoc) Extract meta data from the data resource accessor configuration and convert to properties. |
private Property |
getProductInfo(org.w3c.dom.Document configDoc) Extract product meta data from the data resource accessor configuration and convert to property. |
Property[] |
getProperties() Gets the resource properties associated with the data resource accessor. |
private Property[] |
getProperties(Property productInfo, Property[] metaData) Gets data resource accessor properties - formed from aggregation of all meta data properties. |
private RoleMapper |
getRoleMapper(org.w3c.dom.Document configDoc) Extracts the role mapper implementation class, creates an instance of it and initialises it with a role map file. |
void |
readConfig(java.lang.String name, java.io.File directory) |
void |
releaseJDBCConnection(java.sql.Connection connection) Releases a previously obtained JDBC connection. |
void |
restoreFromConfig(java.io.File directory) Configures the data resource accessor by reading any relevant configuration files in the given directory. |
void |
setResourceName(java.lang.String resourceName) Sets the name of the resource. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final java.lang.String COPYRIGHT_NOTICE
private static DAILogger LOG
private static final java.lang.String MAIN_CONFIG_FILE_NAME
private java.lang.String mResourceName
private Property[] mProperties
private RoleMapper mRoleMapper
private java.lang.String mDriverClassName
private java.lang.String mConnectionURI
Constructor Detail |
public JDBCDataResourceAccessor()
Method Detail |
public void setResourceName(java.lang.String resourceName)
DataResourceAccessor
setResourceName
in interface DataResourceAccessor
resourceName
- Name of the data service resource which will use this data resource accessor to mediate access to a data resource.public void restoreFromConfig(java.io.File directory) throws DataResourceAccessorConfigException, DataResourceAccessorMetaDataException, DataResourceAccessorSetupException, java.lang.IllegalArgumentException
PersistInFiles
If a data service resource is being constructed by reading from a configuration file this method will be called once immediately after the setName
method is called. The data resource accessor should read its configuration from the files in the given directory of the data service resource which uses it.
Data resource accessors are free to add, amend or delete files in the given directory at any time throughout their lifetime. The exception to this rule is the dataResourceClassConfig.xml
file which must be left unaltered since this specifies the data resource accessor class name.
restoreFromConfig
in interface PersistInFiles
directory
- Directory containing the data service resource configuration files. This includes the data resource accessor configuration files.java.lang.IllegalArgumentException
- if the directory
argument is null
or is not a directory.DataResourceAccessorSetupException
- if an error occurs when setting up the data resource accessor after having read the configuration files.DataResourceAccessorConfigException
- if an error occurs reading the configuration files.DataResourceAccessorMetaDataException
- if an error occurs when constructing data resource accessor meta data properties.public void readConfig(java.lang.String name, java.io.File directory) throws DataResourceAccessorConfigException, DataResourceAccessorMetaDataException, DataResourceAccessorSetupException, java.lang.IllegalArgumentException
DataResourceAccessorConfigException
DataResourceAccessorMetaDataException
DataResourceAccessorSetupException
java.lang.IllegalArgumentException
private org.w3c.dom.Document getConfigAsDOM(java.lang.String name, java.io.File dir) throws DataResourceAccessorConfigException
name
- Data service resource name.dir
- Data service resource configuration files directory.DataResourceAccessorConfigException
- if there is an error in reading the configuration file.private Property getProductInfo(org.w3c.dom.Document configDoc)
configDoc
- Data resource accessor configuration document.null
if none.private Property[] getMetaData(java.lang.String name, org.w3c.dom.Document configDoc) throws DataResourceAccessorMetaDataException
name
- Data service resource name.configDoc
- Data resource accessor configuration document.DataResourceAccessorMetaDataException
- if an error occurs when constructing data resource accessor meta data properties.private Property[] getProperties(Property productInfo, Property[] metaData)
productInfo
- Product meta data property.metaData
- Other meta data properties.private RoleMapper getRoleMapper(org.w3c.dom.Document configDoc) throws RoleMapperCreationException, RoleMapConfigurationException
The information is held within the roleMap
element of a data resource accessor configuration file.
configDoc
- Data resource accessor configuration document.RoleMapperCreationException
- if the role mapper cannot be created.RoleMapConfigurationException
- if the role mapper cannot be configured with a role map file.private java.lang.String getAndLoadDriverClassName(org.w3c.dom.Document configDoc) throws DAIClassNotFoundException
configDoc
- Data resource accessor configuration document.DAIClassNotFoundException
- if the driver class cannot be loaded.private java.lang.String getConnectionURI(org.w3c.dom.Document configDoc)
configDoc
- Data resource accessor configuration document.public Property[] getProperties()
DataResourceAccessor
This method should be called once after the readConfig
method has been called but before any other methods are called.
getProperties
in interface DataResourceAccessor
public java.lang.String getJDBCDriverClassName()
JDBCConnectionProvider
getJDBCDriverClassName
in interface JDBCConnectionProvider
public java.sql.Connection getJDBCConnection(java.lang.String userCredentials) throws DataResourceAuthorizationException, JDBCConnectionUseException, AuthorizationExecutionException
JDBCConnectionProvider
The specified user credential may be used to authorize access to the data resource.
getJDBCConnection
in interface JDBCConnectionProvider
userCredentials
- Credentials specifing a user.AuthorizationExecutionException
- if there is a problem encountered during the authorization.JDBCConnectionUseException
- if there is a problem in using the data resource.DataResourceAuthorizationException
- if the user is not authorized to access the connection.public void releaseJDBCConnection(java.sql.Connection connection) throws JDBCConnectionUseException
JDBCConnectionProvider
Once a connection is finished with it should be passed back to this method. This allows connection pooling to be performed under the surface.
releaseJDBCConnection
in interface JDBCConnectionProvider
connection
- JDBC connection to release. If the connection is null
or already released then nothing is done.JDBCConnectionUseException
- if there is a problem in using the data resource.protected java.sql.Connection getConnection(java.lang.String connectionURI, java.lang.String user, java.lang.String password) throws JDBCConnectionUseException
connectionURI
- URI of the database connection.user
- User name used to access databasepassword
- Password used to access database.null
if there is no such connection.JDBCConnectionUseException
- if the connection cannot be accessed.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |