OpMath

com.opmath.test.db
Class ContactConnection

java.lang.Object
  |
  +--com.opmath.test.db.ContactConnection

public class ContactConnection
extends Object

Provides mediation between the com.opmath.util.db JDBC interface and the contact book servlet.

Demonstrates the use of DMLDoc (as contained within Open Math Utilities v010) with Tomcat 4.0 / Servlet 2.3 and a local JDBC connection.

Copyright: (c) 2002 The Open Math Company Limited

The Terms of Distribution of this software are stipulated in the javadoc Overview for this project.

Since:
J2SE 1.3.0, Java Servlet 2.3
Version:
ExpDMLDoc v1.0
Author:
Bruno Beloff bruno.beloff@opmath.com
See Also:
com.opmath.util.db

Constructor Summary
ContactConnection(String className, String path, String user, String pass)
          Constructs a new ContactConnection instance, which mediates between the contact servlet and the database adapter.
 
Method Summary
 void close()
          Closes the database.
 void create(String given, String family, String email, String phone)
          Creates a new contact book entry.
 void createTable()
          Creates a new contact book table in the database.
 void delete(int id)
          Delets an existing contact book entry with the given unique ID.
 ResultSet query(String given, String family)
          Selects contact book records whose given name or family name fields are similar to those in the given parameters.
 ResultSet read(int id)
          Finds one contact book entry with the given unique ID.
 ResultSet readAll()
          Finds all contact book records.
 void update(int id, String given, String family, String email, String phone)
          Updates an existing contact book entry.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContactConnection

public ContactConnection(String className,
                         String path,
                         String user,
                         String pass)
                  throws ClassNotFoundException,
                         SQLException

Constructs a new ContactConnection instance, which mediates between the contact servlet and the database adapter. A database connection is opened.

Parameters:
className - a String naming the class of the database adapter for DBObject.
path - a String giving the absolute path to the directory used by the embedded database driver.
user - a String for the database username.
pass - a String for the database password.
Throws:
ClassNotFoundException - if the class className cannot be accessed.
SQLException - if a database connection cannot be established.
Since:
J2SE 1.3
Method Detail

createTable

public void createTable()
                 throws SQLException

Creates a new contact book table in the database. The fields are contactId (the primary key) givenName, familyName, emailAddress, and phoneNumber

Throws:
SQLException - if the table could not be created.
Since:
J2SE 1.3

close

public void close()
           throws SQLException

Closes the database. (In the case of a remote database, the client connection is closed. In the case of an embedded database, the driver is 'shut down'.) Once the database is closed, this class only allows it to be reopened by creating a new instance.

Throws:
SQLException - if the database could not be closed.
Since:
J2SE 1.3

readAll

public ResultSet readAll()
                  throws SQLException

Finds all contact book records. The returned result set is sorted by family name, then given name.

Returns:
A ResultSet carrying the retrieved data.
Throws:
SQLException - if the find operation failed.
Since:
J2SE 1.3

read

public ResultSet read(int id)
               throws SQLException

Finds one contact book entry with the given unique ID.

Parameters:
id - an int supplying the unique ID.
Returns:
A ResultSet carrying the retrieved data.
Throws:
SQLException - if the find operation failed.
Since:
J2SE 1.3

query

public ResultSet query(String given,
                       String family)
                throws SQLException

Selects contact book records whose given name or family name fields are similar to those in the given parameters. If oneor other parameter is the empty string, it is treated as a wildcard. The returned result set is sorted by family name, then given name.

Parameters:
given - a String specifying the given name field.
family - a String specifying the family name field.
Returns:
A ResultSet carrying the retrieved data.
Throws:
SQLException - if the query could not be completed.
Since:
J2SE 1.3

create

public void create(String given,
                   String family,
                   String email,
                   String phone)
            throws SQLException

Creates a new contact book entry. The new entry will have givenName, familyName, emailAddress, and phoneNumber fields as specified by the given paramters.

The primary key value of the new contact book entry is calculated by selecting the highest existing primary key value, and adding 1. (The primary keyis set to 1 if this is the first record in the contact book.)

Parameters:
given - a String specifying the givenName field.
family - a String specifying the familyName field.
email - a String specifying the emailAddress field.
phone - a String specifying the phoneNumber field.
Throws:
SQLException - if the add operation could not be completed.
Since:
J2SE 1.3

update

public void update(int id,
                   String given,
                   String family,
                   String email,
                   String phone)
            throws SQLException

Updates an existing contact book entry. All fields of the contact book record are updated, with the exception of the primary key.

Parameters:
given - a String specifying the new givenName value.
family - a String specifying the new familyName value.
email - a String specifying the new emailAddress value.
phone - a String specifying the new phoneNumber value.
Throws:
SQLException - if the update operation could not be completed.
Since:
J2SE 1.3

delete

public void delete(int id)
            throws SQLException

Delets an existing contact book entry with the given unique ID.

Parameters:
id - an int supplying the unique ID.
Throws:
SQLException - if the delete operation could not be completed.
Since:
J2SE 1.3

OpMath

Submit a bug or feature to Open Math
Copyright © 2002 Open Math Company Limited, Brighton, UK