uk.org.ury.backend.database
Class DatabaseDriver

java.lang.Object
  extended by uk.org.ury.backend.database.DatabaseDriver

public class DatabaseDriver
extends java.lang.Object

A database connection manager that connects to the URY databases using suitably privileged accounts, and handles the processing of SQL queries.

Author:
Matt Windsor, Nathan Lasseter

Constructor Summary
DatabaseDriver(ConfigReader config, UserClass type)
          Construct a new DatabaseDriver with the given user class.
 
Method Summary
 java.sql.ResultSet executeQuery(java.lang.String sql, int fetchSize)
          Execute an unprepared SQL statement with no arguments.
 java.sql.ResultSet executeQuery(java.lang.String sql, java.lang.Object[] params, int fetchSize)
          Perform a SQL statement with arguments.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseDriver

public DatabaseDriver(ConfigReader config,
                      UserClass type)
               throws MissingCredentialsException,
                      ConnectionFailureException
Construct a new DatabaseDriver with the given user class.

Parameters:
config - The config with login details.
type - The user class to log in to the database with.
Throws:
java.lang.IllegalArgumentException - if the user class is not supported (this should not happen).
MissingCredentialsException - if the user class login credentials could not be loaded.
ConnectionFailureException - if the database backend failed to connect to the database server.
Method Detail

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sql,
                                       int fetchSize)
                                throws java.sql.SQLException
Execute an unprepared SQL statement with no arguments.

Parameters:
sql - The SQL statement to execute.
fetchSize - The maximum number of query rows to return.
Returns:
the JDBC results set.
Throws:
java.sql.SQLException - if a SQL error occurs.

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sql,
                                       java.lang.Object[] params,
                                       int fetchSize)
                                throws java.sql.SQLException
Perform a SQL statement with arguments. This accepts an array of parameter objects, which must each either be String or Integer objects. The objects will be used sequentially to fill in '?' placeholders in the query text.

Parameters:
sql - The SQL statement to execute.
params - A list of parameter objects.
fetchSize - The maximum number of query rows to return.
Returns:
the set of results from the query.
Throws:
java.lang.IllegalArgumentException - if any of the parameters is unsupported by the database as a statement parameter.
java.sql.SQLException - if a SQL error occurs.