org.jafer.databeans
Class JDBC

java.lang.Object
  |
  +--org.jafer.interfaces.Databean
        |
        +--org.jafer.databeans.JDBC
All Implemented Interfaces:
Present, Search, java.io.Serializable, 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.
Number of results to return.
List of templates for creating records of different formats, with locations of the files.
Mappings of Use attributes to database tables and columns. (Also prefix/append values to add 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 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
           
private  java.util.Hashtable columnNames
           
static java.lang.String CONFIG_FILE
           
private  org.w3c.dom.Document configDocument
           
protected  java.sql.Connection connection
           
private  java.lang.String currentDatabase
           
private  javax.sql.DataSource dataSource
           
private  java.lang.String defaultRecordSchema
           
protected  int fetchSize
           
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  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  java.util.Hashtable tableNames
           
protected  java.lang.String username
           
 
Constructor Summary
JDBC()
          Loads configuration info from config files.
 
Method Summary
private  void configure(java.lang.String schema)
          Sets current record template according to schema supplied.
protected abstract  void configureDataSource()
           
private  org.w3c.dom.Element createParamNodeSet(java.util.Hashtable table, java.lang.String elementName)
           
private  Field createRecord()
           
private  java.lang.String getAttributeValue(org.w3c.dom.Node node, java.lang.String attName)
           
protected abstract  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 record template layout.
 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
 int getFetchSize()
           
 java.lang.String getHost()
          Get current Z39.50 host
private  org.w3c.dom.Node getNewTemplate()
           
 int getNumberOfResults()
          Get number of results for last query
 int getPort()
          Get Z39.50 datasource IP Port
 org.w3c.dom.Node 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()
           
 java.lang.String getSearchProfile()
           
protected  java.sql.Statement getStatement()
          Gets a new Statement, which can be modified in subclasses.
private  void getTemplateColumns(org.w3c.dom.Node node)
           
protected  java.lang.String getXMLConfigValue(java.lang.String name)
           
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()
           
protected  java.lang.String processInsert(java.lang.String columnName)
           
private  void processNode(org.w3c.dom.Node node)
           
 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)
           
 void setCheckRecordFormat(boolean checkRecordFormat)
          Throw exception is record schema not preferred schema
private  void setColumnName(java.lang.String name)
           
 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 setFetchSize(int fetchSize)
           
 void setFetchSize(java.lang.String fetchSize)
           
 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(boolean includeResults)
          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 produce, using schema name.
If a template is not available, uses default record format set in config.xml, or last schema set successfully.
private  void setRecordSchemas()
           
private  void setRecordTemplate(java.lang.String schema)
           
 void setResultSetName(java.lang.String resultSetName)
           
 void setSearchProfile(java.lang.String searchProfile)
           
private  void setTableName(java.lang.String name)
           
private  void setTransformParams()
           
 int submitQuery(org.w3c.dom.Node query)
          Send query in XML form
 
Methods inherited from class org.jafer.interfaces.Databean
 
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

columnNames

private java.util.Hashtable columnNames

tableNames

private java.util.Hashtable tableNames

paramMap

private java.util.Hashtable paramMap

recordSchemas

private java.util.Hashtable recordSchemas

query

protected org.w3c.dom.Node query

dataSource

private 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

defaultRecordSchema

private java.lang.String defaultRecordSchema

recordSchema

private java.lang.String recordSchema

queryString

private java.lang.String queryString

username

protected java.lang.String username

password

protected java.lang.String password

port

private int port

recordCursor

private int recordCursor

nResults

protected int nResults

fetchSize

protected int fetchSize

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
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)
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 produce, using schema name.
If a 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 record template layout.

Specified by:
getCurrentRecord in interface Present
Returns:
record
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)
Specified by:
setSearchProfile in interface Search

getSearchProfile

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

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(org.w3c.dom.Node query)
                throws JaferException
Description copied from interface: Search
Send query in XML form

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

saveQuery

public void saveQuery(java.lang.String filePath)
               throws JaferException
Specified by:
saveQuery in interface Search
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

getQuery

public org.w3c.dom.Node getQuery()
Description copied from interface: Search
Get the last submitted query

Specified by:
getQuery in interface Search
Returns:
query

setFetchSize

public void setFetchSize(int fetchSize)

setFetchSize

public void setFetchSize(java.lang.String fetchSize)

getFetchSize

public int getFetchSize()

search

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

java.sql.SQLException
JaferException

getConnection

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

java.sql.SQLException

getStatement

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

java.sql.SQLException

setQueryString

protected void setQueryString(boolean includeResults)
                       throws JaferException
Transforms XML query to SQL string via stylesheet.

JaferException

getQueryString

protected java.lang.String getQueryString()

createRecord

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

getNewTemplate

private org.w3c.dom.Node getNewTemplate()

processNode

private void processNode(org.w3c.dom.Node node)
                  throws java.sql.SQLException,
                         JaferException
java.sql.SQLException
JaferException

processInsert

protected java.lang.String processInsert(java.lang.String columnName)
                                  throws java.sql.SQLException,
                                         JaferException
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.

JaferException

configure

private void configure(java.lang.String schema)
Sets current record template according to schema supplied. Extracts table and column names to use in SQL from record template. Includes table and column names in parameters supplied to query transform.


configureDataSource

protected abstract void configureDataSource()
                                     throws JaferException
JaferException

setRecordSchemas

private void setRecordSchemas()
                       throws JaferException
JaferException

setRecordTemplate

private void setRecordTemplate(java.lang.String schema)

getTemplateColumns

private void getTemplateColumns(org.w3c.dom.Node node)

setTransformParams

private void setTransformParams()

getXMLConfigValue

protected java.lang.String getXMLConfigValue(java.lang.String name)
                                      throws JaferException
JaferException

setColumnName

private void setColumnName(java.lang.String name)

setTableName

private void setTableName(java.lang.String name)

createParamNodeSet

private org.w3c.dom.Element createParamNodeSet(java.util.Hashtable table,
                                               java.lang.String elementName)

selectNode

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

getAttributeValue

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