util.sql
Class SQLProcessor

java.lang.Object
  |
  +--util.sql.SQLProcessor

public class SQLProcessor
extends java.lang.Object

Main class for performing all SQL operations, querying, updating, transactions etc... The main goal of this class is to take away the redundancy and overhead that occurs with each SQL query/update. The only variability in each SQL operation is:

All other functionality, including getting a connection, entering values into a prepared statement, exception handling etc... should factored out. That's just what this class does.

Since:
12/3/2001
Version:
1.0
Author:
Ryan Daigle

Method Summary
 void closeConn(java.sql.Connection conn)
          Close the connection, can handle null connections.
 java.lang.Object[] executeQuery(java.lang.String sql, java.lang.Object[] pStmntValues, ResultProcessor processor)
          Start the execution of SQL query.
 void executeUpdate(java.lang.String sql, java.lang.Object[] pStmntValues, UpdateProcessor processor)
          Execute an update and setup and destroy the connection associate with it.
static SQLProcessor getInstance()
          Get an instance of a SQLProcessor.
protected  java.lang.Object[] handleQuery(java.lang.String sql, java.lang.Object[] pStmntValues, ResultProcessor processor, java.sql.Connection conn)
          Method that handles the bulk of the query processing.
protected  void handleUpdate(java.lang.String sql, java.lang.Object[] pStmntValues, UpdateProcessor processor, java.sql.Connection conn)
          Method that handles the bulk of the update processing.
 SQLTransaction startTransaction()
          Start a transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static SQLProcessor getInstance()
Get an instance of a SQLProcessor. At this point it could be a singleton, or pooled etc... But you don't care, so always use this method to get an instance.
Returns:
a SQLProcessor

executeQuery

public java.lang.Object[] executeQuery(java.lang.String sql,
                                       java.lang.Object[] pStmntValues,
                                       ResultProcessor processor)
Start the execution of SQL query.
Parameters:
sql - the sql query string to execute
pStmntValues - the values to enter into the prepared statement. If there are no values, use null
processor - the result processor that will handle the result set produced by this query. This is what will ultimately decide what return value is handed back.
Returns:
the objects formed by the given result processor

handleQuery

protected java.lang.Object[] handleQuery(java.lang.String sql,
                                         java.lang.Object[] pStmntValues,
                                         ResultProcessor processor,
                                         java.sql.Connection conn)
Method that handles the bulk of the query processing. This method assumes that the given sql string is a valid sql statement. This string will be formed into a prepared statement hand handled appropriately. Calling members should always use the executeQuery method when complete statement and connection handling is desired!

Note: This method does not close the connection. This is left up to the calling method as it is what supplied the connection. If all handling of the connections is desired, use the executeQuery method! (However, in the case of any exceptions, the connection will closed)

Parameters:
sql - the sql query string to execute
pStmntValues - the values to enter into the prepared statement. If there are no values, use null
processor - the result processor that will handle the result set produced by this query. This is what will ultimately decide what return value is handed back.
conn - the connection to use when getting a prepared statement
Returns:
the objects formed by the given result processor
Throws:
DatabaseQueryException -  

executeUpdate

public void executeUpdate(java.lang.String sql,
                          java.lang.Object[] pStmntValues,
                          UpdateProcessor processor)
Execute an update and setup and destroy the connection associate with it.
Parameters:
sql - the sql query string to execute
pStmntValues - the values to enter into the prepared statement. If there are no values, use null
processor - the result processor that will handle the result set produced by this query. This is what will ultimately decide what return value is handed back.
appId - the app id of the application that's calling this method. Used to get an app specific connection.

handleUpdate

protected void handleUpdate(java.lang.String sql,
                            java.lang.Object[] pStmntValues,
                            UpdateProcessor processor,
                            java.sql.Connection conn)
Method that handles the bulk of the update processing. This method assumes that the given sql string is a valid sql statement. This string will be formed into a prepared statement hand handled appropriately.

Note: This method does not close the connection by default. This is left up to the calling method as it is what supplied the connection. It will only be closed in the case of an exception.

Parameters:
sql - the sql update string to execute
pStmntValues - the values to enter into the prepared statement. If there are no values, use null
processor -  
conn -  

closeConn

public void closeConn(java.sql.Connection conn)
Close the connection, can handle null connections.
Parameters:
conn - the connection to close

startTransaction

public SQLTransaction startTransaction()
Start a transaction.
Parameters:
appId - the app id to use when determining the connection's permissions
Returns:
the transaction object to use when performing queries and updates that are a part of this transaction.