edu.jhu.tmaj.database
Class DatabaseUtil

java.lang.Object
  extended by edu.jhu.tmaj.database.DatabaseUtil

public final class DatabaseUtil
extends java.lang.Object

Contains various functions used to modify the database (UPDATE, INSERT, and DELETE statements) and to query the database (very simple SELECT statements). For general use of SELECT statements, use the AbstractDatabaseQuery class.


Constructor Summary
DatabaseUtil()
           
DatabaseUtil(DatabaseLink databaseLink)
          Constructs this object.
 
Method Summary
 void deleteSingleRecord(DeleteSQL sql)
           
 int doDelete(DeleteSQL sql)
          Handles a single update SQL statement, and returns the number of rows updated
 int doInsert(InsertSQL insertSQL)
          Inserts a row into the database given a SQL statement and returns the ID assigned.
 void doModifies(java.util.List<? extends ModifySQL> modifingSQLList)
           
 void doModifies(java.util.List<? extends ModifySQL> modifingSQLList, java.lang.String description)
          Executes a List of Modifying SQL statements.
 int doUpdate(UpdateSQL updateSQL)
          Handles a single update SQL statement, and returns the number of rows updated
static DatabaseUtil getInstance()
           
 java.util.List<java.lang.Integer> getIntegerList(java.lang.String sql, java.lang.String columnName)
          Returns a List of Integers generated by a SQL statement.
 java.lang.Integer getSQLInteger(java.lang.String sql, java.lang.String columnName)
          Queries the database for the Integer of the first row in the specified column, given a SQL query.
 java.lang.String getSQLString(java.lang.String sql, java.lang.String columnName)
           
 java.util.List<java.lang.String> getStringList(java.lang.String sql, java.lang.String columnName)
          Returns a List of Strings generated by a SQL statement.
 void updateSingleRecord(UpdateSQL sql)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseUtil

public DatabaseUtil(DatabaseLink databaseLink)
Constructs this object.

Parameters:
connectionManager - the connection manager that will give us our connection to the database
sqlMaker - the sql maker that will convert SQL objects to text sql

DatabaseUtil

public DatabaseUtil()
Method Detail

getInstance

public static DatabaseUtil getInstance()

doInsert

public int doInsert(InsertSQL insertSQL)
             throws java.sql.SQLException
Inserts a row into the database given a SQL statement and returns the ID assigned.

Throws:
java.sql.SQLException

doUpdate

public int doUpdate(UpdateSQL updateSQL)
             throws java.sql.SQLException
Handles a single update SQL statement, and returns the number of rows updated

Throws:
java.sql.SQLException

doDelete

public int doDelete(DeleteSQL sql)
             throws java.sql.SQLException
Handles a single update SQL statement, and returns the number of rows updated

Throws:
java.sql.SQLException

doModifies

public void doModifies(java.util.List<? extends ModifySQL> modifingSQLList,
                       java.lang.String description)
                throws java.sql.SQLException
Executes a List of Modifying SQL statements. Modifies can be either UPDATES or INSERTS. For an UPDATE, the user does not care how many rows were returned, and for an INSERT the user does not care the value of the auto-incremented key is.

Parameters:
modifingSQLList - a List of UpdateSQL,InsertSQL, and DeleteSQL objects
progressMonitor - an optional TextProgressMonitor
doNotLogSQL - true if you do not want this sql logged. You might want to set this to true if there is just an incredible amount of sql that would slow this operation down, or the sql contained sensitive information.
Throws:
java.sql.SQLException

doModifies

public void doModifies(java.util.List<? extends ModifySQL> modifingSQLList)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

updateSingleRecord

public void updateSingleRecord(UpdateSQL sql)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

deleteSingleRecord

public void deleteSingleRecord(DeleteSQL sql)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

getSQLInteger

public java.lang.Integer getSQLInteger(java.lang.String sql,
                                       java.lang.String columnName)
                                throws java.sql.SQLException
Queries the database for the Integer of the first row in the specified column, given a SQL query.

Parameters:
sql - a SQL SELECT statement returning one row. For example, "SELECT COUNT(*) AS My_Count"
columnName - the column name to be retrieved, who type is numeric. For example "My_Count"
Returns:
the integer found in the column name specified of the first row, or null if there are no rows.
Throws:
java.lang.RuntimeException - if more than 1 row is returned
java.sql.SQLException

getSQLString

public java.lang.String getSQLString(java.lang.String sql,
                                     java.lang.String columnName)
                              throws java.sql.SQLException
Throws:
java.sql.SQLException

getIntegerList

public java.util.List<java.lang.Integer> getIntegerList(java.lang.String sql,
                                                        java.lang.String columnName)
                                                 throws java.sql.SQLException
Returns a List of Integers generated by a SQL statement.

Parameters:
sql - the sql, example: SELECT EmployeeID FROM Employees
columnName - the name of the column to get. Example: "EmployeeID"
Throws:
java.sql.SQLException

getStringList

public java.util.List<java.lang.String> getStringList(java.lang.String sql,
                                                      java.lang.String columnName)
                                               throws java.sql.SQLException
Returns a List of Strings generated by a SQL statement.

Parameters:
sql - the sql, example: SELECT EmployeeName FROM Employees
columnName - the name of the column to get. Example: "EmployeeName"
Throws:
java.sql.SQLException