UniVista.database
Class DatabaseHelper

java.lang.Object
  |
  +--UniVista.database.DatabaseHelper

public class DatabaseHelper
extends java.lang.Object

Contains database helper functions for UniVista. The goal of putting all database functions inside this class is to isolate other UniVista code from JDBC calls.


Field Summary
static boolean isDebug
          determines whether we're in debug mode or not
protected static boolean issueConnectingSql
          determines whether the internally stored SQL string needs to be issued after each connection is created
static boolean oneConnectionOnly
          determines if we use one or many connections...requires testConnection() to be called
 
Constructor Summary
DatabaseHelper()
           
 
Method Summary
static java.lang.String countRun(java.lang.String toCount, Run theRun)
           
static void createCode(Code newCode)
          Adds a new code to the database.
static void createRunTable(Study theStudy)
          Create a new Run table in the database.
static void doStuff()
          Verify if the URL contained in the DatabaseHelper object is a valid URL
protected  void finalize()
          our finalize method will attempt to close the connection if we're in one connection only mode
static java.lang.String getDatabaseURL()
          Accessors for the internal database, username, and password members
static java.lang.String getPassword()
           
static java.lang.String getUsername()
           
static void initializeDrivers(java.lang.String driverName)
          Initializes the JDBC drivers
static void insertOneStudy(Study toInsert)
          Inserts a single study into the database.
static void insertRun(Run toInsert)
          Inserts a new Run entry.
static void insertStudy(java.lang.String tableName, Study toInsert)
          Inserts a new study entry into the passed table.
static void insertVariableType(Variable toAdd)
          Adds a new variable type to the UniVista database
 void issueConnectingSQL(boolean newVal)
          sets the flag to indicate to the DatabaseHelper to issue the connecting SQL statement or not
static void issueSQL(java.lang.String toSend)
          issue a single SQL statement over the connected database.
static boolean isURLValid()
           
static void main(java.lang.String[] args)
           
static CodeHash readAllCodes()
          Reads in all of the code objects from the codes table of the database.
static VariableHash readAllVariableTypes()
          Goes through the vartypes table and loads the variable types
static Run readRun(Study theStudy, java.lang.String runName)
           
static java.util.Vector readRuns(Study theStudy)
          Reads all of the runs for a passed code
static java.util.Vector readRuns(Study theStudy, java.lang.String theSQL, boolean useDesc)
           
static StudyHash readStudies(Code theCode)
          Reads all of the studies for a passed code
 void setConnectingSQL(java.lang.String newSql)
          used to set the sql string that is to be issued by the DatabaseHelper after each connection to the database is created
static void setDatabaseURL(java.lang.String newVal)
           
static void setPassword(java.lang.String newVal)
           
static void setUsername(java.lang.String newVal)
           
static void testConnection()
          Tests to see if a connection can be made to the database with the information contained in the private variables.
static void updateCode(Code toUpdate)
          Updates the code object in the database.
static void updateCodeStudies(Code toUpdate)
          Updates the studies for a particular code.
static void updateOneStudy(Study toUpdate)
          Updates a single study in the database.
static void updateRun(Run toUpdate)
          Updates a Run entry.
static void updateStudy(java.lang.String tableName, Study toUpdate)
          Updates a study entry in the passed table.
static void updateVariableType(Variable toUpdate)
          Updates the entry of a variable type in the database
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isDebug

public static final boolean isDebug
determines whether we're in debug mode or not

oneConnectionOnly

public static final boolean oneConnectionOnly
determines if we use one or many connections...requires testConnection() to be called

issueConnectingSql

protected static boolean issueConnectingSql
determines whether the internally stored SQL string needs to be issued after each connection is created
Constructor Detail

DatabaseHelper

public DatabaseHelper()
Method Detail

countRun

public static java.lang.String countRun(java.lang.String toCount,
                                        Run theRun)

createCode

public static void createCode(Code newCode)
                       throws java.sql.SQLException,
                              DatabaseException
Adds a new code to the database. This function adds it to the overall index, creates the necessary tables, and insertes the initial data
Parameters:
newCode - the Code object to add to the database
Throws:
java.sql.SQLException -  
DatabaseException - thrown if a non-sql error occurs

createRunTable

public static void createRunTable(Study theStudy)
                           throws java.sql.SQLException,
                                  DatabaseException
Create a new Run table in the database. The Runs will be associated by their common Study, so there will be one Run table per Study.

finalize

protected void finalize()
our finalize method will attempt to close the connection if we're in one connection only mode
Overrides:
finalize in class java.lang.Object

getDatabaseURL

public static java.lang.String getDatabaseURL()
Accessors for the internal database, username, and password members

getPassword

public static java.lang.String getPassword()

getUsername

public static java.lang.String getUsername()

initializeDrivers

public static void initializeDrivers(java.lang.String driverName)
                              throws java.lang.ClassNotFoundException,
                                     DatabaseException
Initializes the JDBC drivers
Parameters:
driverName - A String that contains the full driver class name
Throws:
java.lang.ClassNotFoundException - thrown if the driver is not installed on the machine
DatabaseException - thrown if something goes wrong with installing the driver on the machine

insertOneStudy

public static void insertOneStudy(Study toInsert)
                           throws java.sql.SQLException,
                                  DatabaseException
Inserts a single study into the database.
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

insertRun

public static void insertRun(Run toInsert)
                      throws java.sql.SQLException,
                             DatabaseException
Inserts a new Run entry.
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

insertStudy

public static void insertStudy(java.lang.String tableName,
                               Study toInsert)
                        throws java.sql.SQLException,
                               DatabaseException
Inserts a new study entry into the passed table.
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

insertVariableType

public static void insertVariableType(Variable toAdd)
                               throws java.sql.SQLException,
                                      DatabaseException
Adds a new variable type to the UniVista database
Parameters:
toAdd - The Variable object to insert into the database
Throws:
java.sql.SQLException -  
DatabaseException - thrown if the database does not correspond to the UniVista format, i.e. tables missing

issueConnectingSQL

public void issueConnectingSQL(boolean newVal)
sets the flag to indicate to the DatabaseHelper to issue the connecting SQL statement or not

issueSQL

public static void issueSQL(java.lang.String toSend)
                     throws java.sql.SQLException,
                            DatabaseException
issue a single SQL statement over the connected database. For use only in dire circumstances. Note that is does not issue any connecting SQL statement if it is set.
Throws:
java.sql.SQLException -  
DatabaseException - thrown if something goes wrong with connecting to the specified database

doStuff

public static void doStuff()
                    throws java.sql.SQLException,
                           DatabaseException
Verify if the URL contained in the DatabaseHelper object is a valid URL
Throws:
java.sql.SQLException -  
DatabaseException - thrown if something goes wrong with attempting to load a driver

isURLValid

public static boolean isURLValid()
                          throws java.sql.SQLException,
                                 DatabaseException

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException

readAllCodes

public static CodeHash readAllCodes()
                             throws java.sql.SQLException,
                                    DatabaseException
Reads in all of the code objects from the codes table of the database.
Returns:
a CodeHash containing all of the elements of the codes table
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

readAllVariableTypes

public static VariableHash readAllVariableTypes()
                                         throws java.sql.SQLException,
                                                DatabaseException
Goes through the vartypes table and loads the variable types
Returns:
variables in a VariableHash object
Throws:
java.sql.SQLException -  
DatabaseException - Thrown if there is a problem with the database for a UniVista format

readRuns

public static java.util.Vector readRuns(Study theStudy)
                                 throws java.sql.SQLException,
                                        DatabaseException
Reads all of the runs for a passed code
Returns:
a RunHash containing all of the screen objects
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

readRuns

public static java.util.Vector readRuns(Study theStudy,
                                        java.lang.String theSQL,
                                        boolean useDesc)
                                 throws java.sql.SQLException,
                                        DatabaseException

readRun

public static Run readRun(Study theStudy,
                          java.lang.String runName)
                   throws java.sql.SQLException,
                          DatabaseException

readStudies

public static StudyHash readStudies(Code theCode)
                             throws java.sql.SQLException,
                                    DatabaseException
Reads all of the studies for a passed code
Returns:
a StudyHash containing all of the screen objects
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

setConnectingSQL

public void setConnectingSQL(java.lang.String newSql)
used to set the sql string that is to be issued by the DatabaseHelper after each connection to the database is created

setDatabaseURL

public static void setDatabaseURL(java.lang.String newVal)

setPassword

public static void setPassword(java.lang.String newVal)

setUsername

public static void setUsername(java.lang.String newVal)

testConnection

public static void testConnection()
                           throws java.sql.SQLException,
                                  DatabaseException
Tests to see if a connection can be made to the database with the information contained in the private variables.
Throws:
java.sql.SQLException -  
DatabaseException - thrown if the connection is not able to be established.

updateCode

public static void updateCode(Code toUpdate)
                       throws DatabaseException,
                              java.sql.SQLException
Updates the code object in the database. Does not update internal names, however.
Parameters:
toUpdate - code object to be placed in the database again
Throws:
java.sql.SQLException -  
DatabaseException - thrown for errors not caused by the database driver

updateCodeStudies

public static void updateCodeStudies(Code toUpdate)
                              throws java.sql.SQLException,
                                     DatabaseException
Updates the studies for a particular code.
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

updateOneStudy

public static void updateOneStudy(Study toUpdate)
                           throws java.sql.SQLException,
                                  DatabaseException
Updates a single study in the database.
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

updateRun

public static void updateRun(Run toUpdate)
                      throws java.sql.SQLException,
                             DatabaseException
Updates a Run entry.
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

updateStudy

public static void updateStudy(java.lang.String tableName,
                               Study toUpdate)
                        throws java.sql.SQLException,
                               DatabaseException
Updates a study entry in the passed table.
Throws:
java.sql.SQLException -  
DatabaseException - thrown for non-JDBC errors

updateVariableType

public static void updateVariableType(Variable toUpdate)
                               throws java.sql.SQLException,
                                      DatabaseException
Updates the entry of a variable type in the database
Throws:
java.sql.SQLException -  
DatabaseException - thrown on problems with the database or other ancillary routines