abbreviationdb
Class AbbreviationDB

java.lang.Object
  extended by abbreviationdb.AbbreviationDB

public class AbbreviationDB
extends java.lang.Object

Manage connection and accesses to the abbreviations database.

This class manages the connection to the abbreviations database and multiplexes database queries using a single connection.


Field Summary
private static java.lang.String abbreviationDB
          The connection string to be used to connect to the database.
private static java.lang.String abbreviationQuery
          The SQL statement to be used to look up abbreviations.
private  java.sql.Connection dbConn
          The database connection.
private  java.sql.PreparedStatement dbQuery
          The prepared query.
private static java.lang.String jdbcDriverClassName
          The class name of the JDBC driver to be used.
 
Constructor Summary
AbbreviationDB()
          Constructor: Create a new instance of a database connection.
 
Method Summary
 void close()
          Close the database connections.
 java.lang.String translate(java.lang.String code)
          Lookup an abbreviation in a database, returning the translation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jdbcDriverClassName

private static final java.lang.String jdbcDriverClassName
The class name of the JDBC driver to be used.

See Also:
Constant Field Values

abbreviationDB

private static final java.lang.String abbreviationDB
The connection string to be used to connect to the database.

See Also:
Constant Field Values

abbreviationQuery

private static final java.lang.String abbreviationQuery
The SQL statement to be used to look up abbreviations.

See Also:
Constant Field Values

dbConn

private final java.sql.Connection dbConn
The database connection.


dbQuery

private final java.sql.PreparedStatement dbQuery
The prepared query.

Constructor Detail

AbbreviationDB

public AbbreviationDB()
               throws java.sql.SQLException,
                      java.lang.ClassNotFoundException
Constructor: Create a new instance of a database connection.

Throws:
java.sql.SQLException - if database connection cannot be initialized
java.lang.ClassNotFoundException - if database driver cannot be loaded
Method Detail

close

public void close()
Close the database connections.


translate

public java.lang.String translate(java.lang.String code)
                           throws java.util.NoSuchElementException,
                                  java.sql.SQLException
Lookup an abbreviation in a database, returning the translation.

This method is synchronized so that accesses from different sessions using a single compiled query will not interfere with each other.

Parameters:
code - the abbreviation to be translated
Returns:
the translation for the abbreviation
Throws:
java.util.NoSuchElementException - if the abbreviation is not in the database
java.sql.SQLException - if the database query fails