org.jafer.databeans
Class JDBC

java.lang.Object
  extended by org.jafer.interfaces.Databean
      extended by org.jafer.databeans.JDBC
All Implemented Interfaces:
java.io.Serializable, Present, Search, Z3950Connection
Direct Known Subclasses:
MySQLDatabean, TDSDatabean

public abstract class JDBC
extends Databean
implements Z3950Connection, Present, Search

Superclass with behaviour common to subclasses. Specific subclasses configured to make use of specific JDBC drivers should be instantiated.
No caching available, apart from the ResultSet object (which may have a Forward Only cursor).

XML configuration files:
config.xml
Database name, username, password for JDBC driver to use.
Toggle to return results with initial search (piggyback) on/off.
List of XML templates for creating records of different formats, with locations of the files.
Mappings of Z39.50 Use attributes to SQL database tables and columns. (Also prefix/append values to add wildcards to SQL query for each.)
Mappings for translation of Relation attribute values to SQL operators.
OAITemplate.xml
Template record conforming to OAI schema. Data from database is inserted in place of nodes, from the column specified.
MODSTemplate.xml
Template record conforming to MODS schema. Data from database is inserted in place of nodes, from the column specified.

(Column names used in building the SQL query are taken from the XML record template in use, and are expected to be of the form tableName.columnName.)

query.xsl
The incoming query is translated from an XML format to SQL via this stylesheet.

See Also:
Serialized Form

Field Summary
private static org.apache.xpath.CachedXPathAPI cachedXPath
           
static java.lang.String CONFIG_FILE
           
private  org.w3c.dom.Document configDocument
           
protected  java.sql.Connection connection
           
private  java.lang.String currentDatabase
           
protected  javax.sql.DataSource dataSource
           
protected  java.lang.String foreignKey
           
private  java.lang.String hostName
           
static java.util.logging.Logger logger
           
protected  int nResults
           
private  java.util.Hashtable paramMap
           
protected  java.lang.String password
           
private  int port
           
protected  java.lang.String primaryKey
           
protected  java.lang.String primaryTable
           
protected  org.w3c.dom.Node query
           
static java.lang.String QUERY_XSLT
           
private  java.lang.String queryString
           
private  java.net.URL queryXSLT
           
private  int recordCursor
           
private  org.w3c.dom.Document recordDocument
           
private  java.lang.String recordSchema
           
private  java.util.Hashtable recordSchemas
           
private  org.w3c.dom.Document recordTemplate
           
protected  java.sql.ResultSet resultSet
           
private  JaferException searchException
          Stores a reference to exception that occured in the last search or null if no errors occured
protected  java.lang.String username
           
 
Constructor Summary
JDBC()
          Loads configuration info from config files.
 
Method Summary
protected  boolean alignCursor()
           
protected abstract  void configureDataSource()
           
private  Field createRecord()
           
private  java.lang.String getAttributeValue(org.w3c.dom.Node node, java.lang.String attName)
           
protected  java.sql.Connection getConnection()
          Gets a conection from the DataSource in use.
 java.lang.String getCurrentDatabase()
          Get database of current record
 Field getCurrentRecord()
          Creates record from data in database, following the layout of the chosen record template.
 java.lang.String[] getDatabases()
          Returns an array containing the name of the single database that can be searched.
 java.lang.String getElementSpec()
          Get current element specification setting
 java.lang.String getHost()
          Get current Z39.50 host
 int getNumberOfResults()
          Get number of results for last query
 int getNumberOfResults(java.lang.String databaseName)
          Get number of results from the named database for last query
 int getPort()
          Get Z39.50 datasource IP Port
 java.lang.Object getQuery()
          Get the last submitted query
protected  java.lang.String getQueryString()
           
 int getRecordCursor()
          Get the current record position cursor
 java.lang.String getRecordSchema()
          Get currently set record schema
 java.lang.String getResultSetName()
           
protected  JaferException getSearchException()
          This method returns the JaferException from the last search.
 JaferException getSearchException(java.lang.String database)
          If a search fails this method will return the JaferException for the specified database
 JaferException[] getSearchException(java.lang.String[] databases)
          If a search fails this method will return the JaferException for the specified databases
 java.lang.String getSearchProfile()
           
protected  java.sql.Statement getStatement()
          Gets a new Statement, which can be modified in subclasses.
protected  java.lang.String getXMLConfigValue(java.lang.String XPath)
           
private  void initialise()
          Loads XML config file, sets available schemas (and default schema).
Loads query transform stylesheet.
Loads database name, user name and password for JDBC conection from XML config file.
 boolean isCheckRecordFormat()
          Get record schema checking setting
 boolean isParseQuery()
           
private  void loadRecordSchemas()
           
protected  java.util.Vector processInsert(java.lang.String columnName)
           
private  org.apache.xpath.NodeSet processJaferData(org.w3c.dom.Node jaferNode)
           
private  org.apache.xpath.NodeSet processJaferElement(org.w3c.dom.Node jaferNode, org.apache.xpath.NodeSet childSet)
           
private  org.apache.xpath.NodeSet processNode(org.w3c.dom.Node node)
           
private  org.w3c.dom.Node processTemplate(org.w3c.dom.Node template)
           
 void saveQuery(java.lang.String filePath)
           
protected  void search()
          Executes search on database using current query.
private  org.w3c.dom.Node selectNode(org.w3c.dom.Node sourceNode, java.lang.String XPath)
           
private  org.w3c.dom.NodeList selectNodeList(org.w3c.dom.Node sourceNode, java.lang.String XPath)
           
 void setCheckRecordFormat(boolean checkRecordFormat)
          Throw exception is record schema not preferred schema
private  void setDatabaseConfiguration()
           
 void setDatabases(java.lang.String database)
          Method doesn't do anything.
 void setDatabases(java.lang.String[] databases)
          Method doesn't do anything.
 void setElementSpec(java.lang.String elementSpec)
          Set element specification for record retrieval
 void setHost(java.lang.String hostName)
          Z39.50 Host address
 void setParseQuery(boolean parseQuery)
           
 void setPort(int port)
          Set Z39.50 datasource IP port
protected  void setQueryString(java.lang.String selectPhrase)
          Transforms XML query to SQL string via stylesheet.
 void setRecordCursor(int nRecord)
          Set the current record cursor
 void setRecordSchema(java.lang.String schema)
          Sets record format to be produced, using name of XML Schema for record format.
If a suitable template is not available, uses default record format set in config.xml, or last schema set successfully.
private  void setRecordTemplate(java.lang.String schema)
           
 void setResultSetName(java.lang.String resultSetName)
           
protected  void setSearchException(JaferException exc)
          This method sets the last exception that occurred during a search
 void setSearchProfile(java.lang.String searchProfile)
           
 int submitQuery(org.w3c.dom.Node query)
           
 int submitQuery(java.lang.Object query)
          Send query (can be in XML form)
 int submitQuery(z3950.v3.RPNQuery query)
           
 
Methods inherited from class org.jafer.interfaces.Databean
getCacheSupport, getPresentSupport, getScanSupport, getSearchSupport
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static java.util.logging.Logger logger

queryXSLT

private java.net.URL queryXSLT

configDocument

private org.w3c.dom.Document configDocument

recordTemplate

private org.w3c.dom.Document recordTemplate

recordDocument

private org.w3c.dom.Document recordDocument

paramMap

private java.util.Hashtable paramMap

recordSchemas

private java.util.Hashtable recordSchemas

query

protected org.w3c.dom.Node query

dataSource

protected javax.sql.DataSource dataSource

connection

protected java.sql.Connection connection

resultSet

protected java.sql.ResultSet resultSet

hostName

private java.lang.String hostName

currentDatabase

private java.lang.String currentDatabase

recordSchema

private java.lang.String recordSchema

queryString

private java.lang.String queryString

username

protected java.lang.String username

password

protected java.lang.String password

primaryTable

protected java.lang.String primaryTable

primaryKey

protected java.lang.String primaryKey

foreignKey

protected java.lang.String foreignKey

port

private int port

recordCursor

private int recordCursor

nResults

protected int nResults

cachedXPath

private static org.apache.xpath.CachedXPathAPI cachedXPath

CONFIG_FILE

public static final java.lang.String CONFIG_FILE
See Also:
Constant Field Values

QUERY_XSLT

public static final java.lang.String QUERY_XSLT
See Also:
Constant Field Values

searchException

private JaferException searchException
Stores a reference to exception that occured in the last search or null if no errors occured

Constructor Detail

JDBC

public JDBC()
Loads configuration info from config files.

See Also:
initialise()
Method Detail

setHost

public void setHost(java.lang.String hostName)
Description copied from interface: Z3950Connection
Z39.50 Host address

Specified by:
setHost in interface Z3950Connection
Parameters:
hostName - Host ip address

getHost

public java.lang.String getHost()
Description copied from interface: Z3950Connection
Get current Z39.50 host

Specified by:
getHost in interface Z3950Connection
Returns:
Host ip address

setPort

public void setPort(int port)
Description copied from interface: Z3950Connection
Set Z39.50 datasource IP port

Specified by:
setPort in interface Z3950Connection

getPort

public int getPort()
Description copied from interface: Z3950Connection
Get Z39.50 datasource IP Port

Specified by:
getPort in interface Z3950Connection
Returns:
IP port

setRecordCursor

public void setRecordCursor(int nRecord)
                     throws JaferException
Description copied from interface: Present
Set the current record cursor

Specified by:
setRecordCursor in interface Present
Parameters:
nRecord - Record position (starting at 1)
Throws:
JaferException

getRecordCursor

public int getRecordCursor()
Description copied from interface: Present
Get the current record position cursor

Specified by:
getRecordCursor in interface Present
Returns:
get record position

setCheckRecordFormat

public void setCheckRecordFormat(boolean checkRecordFormat)
Description copied from interface: Present
Throw exception is record schema not preferred schema

Specified by:
setCheckRecordFormat in interface Present
Parameters:
checkRecordFormat - setting of record schema checking

isCheckRecordFormat

public boolean isCheckRecordFormat()
Description copied from interface: Present
Get record schema checking setting

Specified by:
isCheckRecordFormat in interface Present
Returns:
record checking setting

setElementSpec

public void setElementSpec(java.lang.String elementSpec)
Description copied from interface: Present
Set element specification for record retrieval

Specified by:
setElementSpec in interface Present
Parameters:
elementSpec - element specification

getElementSpec

public java.lang.String getElementSpec()
Description copied from interface: Present
Get current element specification setting

Specified by:
getElementSpec in interface Present
Returns:
element specification

setRecordSchema

public void setRecordSchema(java.lang.String schema)
Sets record format to be produced, using name of XML Schema for record format.
If a suitable template is not available, uses default record format set in config.xml, or last schema set successfully.

Specified by:
setRecordSchema in interface Present
Parameters:
schema - record schema

getRecordSchema

public java.lang.String getRecordSchema()
Description copied from interface: Present
Get currently set record schema

Specified by:
getRecordSchema in interface Present
Returns:
record schema

getCurrentRecord

public Field getCurrentRecord()
                       throws JaferException
Creates record from data in database, following the layout of the chosen record template.

Specified by:
getCurrentRecord in interface Present
Returns:
record
Throws:
JaferException

getCurrentDatabase

public java.lang.String getCurrentDatabase()
Description copied from interface: Present
Get database of current record

Specified by:
getCurrentDatabase in interface Present
Returns:
database

setSearchProfile

public void setSearchProfile(java.lang.String searchProfile)

getSearchProfile

public java.lang.String getSearchProfile()

setResultSetName

public void setResultSetName(java.lang.String resultSetName)
Specified by:
setResultSetName in interface Search

getResultSetName

public java.lang.String getResultSetName()
Specified by:
getResultSetName in interface Search

setDatabases

public void setDatabases(java.lang.String database)
Method doesn't do anything. (Single database name is loaded from XML configuration file: config.xml)

Specified by:
setDatabases in interface Search
Parameters:
database - (not used)

setDatabases

public void setDatabases(java.lang.String[] databases)
Method doesn't do anything. (Single database name is loaded from XML configuration file: config.xml)

Specified by:
setDatabases in interface Search
Parameters:
databases - (not used)

getDatabases

public java.lang.String[] getDatabases()
Returns an array containing the name of the single database that can be searched. Database name is loaded from XML configuration file: config.xml)

Specified by:
getDatabases in interface Search
Returns:
databases

setParseQuery

public void setParseQuery(boolean parseQuery)
Specified by:
setParseQuery in interface Search

isParseQuery

public boolean isParseQuery()
Specified by:
isParseQuery in interface Search

submitQuery

public int submitQuery(java.lang.Object query)
                throws JaferException
Description copied from interface: Search
Send query (can be in XML form)

Specified by:
submitQuery in interface Search
Returns:
number of records found
Throws:
JaferException

submitQuery

public int submitQuery(z3950.v3.RPNQuery query)
                throws JaferException
Throws:
JaferException

submitQuery

public int submitQuery(org.w3c.dom.Node query)
                throws JaferException
Throws:
JaferException

saveQuery

public void saveQuery(java.lang.String filePath)
               throws JaferException
Specified by:
saveQuery in interface Search
Throws:
JaferException

getNumberOfResults

public int getNumberOfResults()
Description copied from interface: Search
Get number of results for last query

Specified by:
getNumberOfResults in interface Search
Returns:
number of results

getNumberOfResults

public int getNumberOfResults(java.lang.String databaseName)
Description copied from interface: Search
Get number of results from the named database for last query

Specified by:
getNumberOfResults in interface Search
Returns:
number of results

getQuery

public java.lang.Object getQuery()
Description copied from interface: Search
Get the last submitted query

Specified by:
getQuery in interface Search
Returns:
query

search

protected void search()
               throws java.sql.SQLException,
                      JaferException
Executes search on database using current query.

Throws:
java.sql.SQLException
JaferException

getConnection

protected java.sql.Connection getConnection()
                                     throws java.sql.SQLException
Gets a conection from the DataSource in use.

Throws:
java.sql.SQLException

getStatement

protected java.sql.Statement getStatement()
                                   throws java.sql.SQLException
Gets a new Statement, which can be modified in subclasses.

Throws:
java.sql.SQLException

setQueryString

protected void setQueryString(java.lang.String selectPhrase)
                       throws JaferException
Transforms XML query to SQL string via stylesheet.

Throws:
JaferException

getQueryString

protected java.lang.String getQueryString()

createRecord

private Field createRecord()
                    throws java.sql.SQLException,
                           JaferException
Throws:
java.sql.SQLException
JaferException

processTemplate

private org.w3c.dom.Node processTemplate(org.w3c.dom.Node template)
                                  throws java.sql.SQLException,
                                         JaferException
Throws:
java.sql.SQLException
JaferException

processNode

private org.apache.xpath.NodeSet processNode(org.w3c.dom.Node node)
                                      throws java.sql.SQLException,
                                             JaferException
Throws:
java.sql.SQLException
JaferException

processJaferElement

private org.apache.xpath.NodeSet processJaferElement(org.w3c.dom.Node jaferNode,
                                                     org.apache.xpath.NodeSet childSet)
                                              throws JaferException,
                                                     java.sql.SQLException
Throws:
JaferException
java.sql.SQLException

processJaferData

private org.apache.xpath.NodeSet processJaferData(org.w3c.dom.Node jaferNode)
                                           throws JaferException,
                                                  java.sql.SQLException
Throws:
JaferException
java.sql.SQLException

processInsert

protected java.util.Vector processInsert(java.lang.String columnName)
                                  throws java.sql.SQLException,
                                         JaferException
Throws:
java.sql.SQLException
JaferException

alignCursor

protected boolean alignCursor()
                       throws java.sql.SQLException,
                              JaferException
Throws:
java.sql.SQLException
JaferException

initialise

private void initialise()
                 throws JaferException
Loads XML config file, sets available schemas (and default schema).
Loads query transform stylesheet.
Loads database name, user name and password for JDBC conection from XML config file.

Throws:
JaferException

setDatabaseConfiguration

private void setDatabaseConfiguration()
                               throws JaferException
Throws:
JaferException

configureDataSource

protected abstract void configureDataSource()
                                     throws JaferException
Throws:
JaferException

loadRecordSchemas

private void loadRecordSchemas()
                        throws JaferException
Throws:
JaferException

setRecordTemplate

private void setRecordTemplate(java.lang.String schema)

getXMLConfigValue

protected java.lang.String getXMLConfigValue(java.lang.String XPath)
                                      throws JaferException
Throws:
JaferException

selectNode

private org.w3c.dom.Node selectNode(org.w3c.dom.Node sourceNode,
                                    java.lang.String XPath)
                             throws JaferException
Throws:
JaferException

selectNodeList

private org.w3c.dom.NodeList selectNodeList(org.w3c.dom.Node sourceNode,
                                            java.lang.String XPath)
                                     throws JaferException
Throws:
JaferException

getAttributeValue

private java.lang.String getAttributeValue(org.w3c.dom.Node node,
                                           java.lang.String attName)

getSearchException

public JaferException getSearchException(java.lang.String database)
                                  throws JaferException
Description copied from interface: Search
If a search fails this method will return the JaferException for the specified database

Specified by:
getSearchException in interface Search
Parameters:
database - The name of the database to check
Returns:
null if no errors were found
Throws:
JaferException

getSearchException

public JaferException[] getSearchException(java.lang.String[] databases)
                                    throws JaferException
Description copied from interface: Search
If a search fails this method will return the JaferException for the specified databases

Specified by:
getSearchException in interface Search
Parameters:
databases - The databases to search
Returns:
An empty array if no errors were found
Throws:
JaferException

getSearchException

protected JaferException getSearchException()
This method returns the JaferException from the last search.

Returns:
JaferException instance or null if no errors were found

setSearchException

protected void setSearchException(JaferException exc)
This method sets the last exception that occurred during a search

Parameters:
exc - The exception that occurred