uk.org.ogsadai.activity.sql.statement
Class ParameterisedSQLStatement

java.lang.Object
  |
  +--uk.org.ogsadai.activity.sql.statement.ParameterisedSQLStatement
All Implemented Interfaces:
SQLStatement
Direct Known Subclasses:
CallableSQLStatement

public class ParameterisedSQLStatement
extends java.lang.Object
implements SQLStatement

Executes parameterised SQL statements.

Author:
The OGSA-DAI Project Team.

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement
private static DAILogger LOG
          Logger object for logging in this class
private  java.sql.Connection mConnection
          JDBC connection handler
private  java.lang.String mExpression
          Parameterised SQL expression
private  boolean mFinishedProcessing
          Has expression completed (default false)
private  ParameterList mParameters
          SQL expression parameters
protected  java.sql.PreparedStatement mStatement
          JDBC prepared statement handler
private  java.util.List mTempFileInputStreams
          Input streams that need to be closed when the query is executed
private  java.util.List mTempFiles
          Temporary files that need to be deleted when the query is executed
 
Constructor Summary
ParameterisedSQLStatement()
          Constructor
ParameterisedSQLStatement(java.sql.Connection conx, ParameterList parameters, java.lang.String expression)
          Constructor.
 
Method Summary
 void close()
          Closes this SQL statement.
protected  void closeTempFilesAndInputStreams()
          Cleans up any temporany files that were passed as parameters.
 java.sql.ResultSet executeQuery()
          Executes this SQL statement
 int executeUpdate()
          Executes this SQL statement as an update
 java.sql.Connection getConnection()
          Returns the JDBC connection handler.
 java.lang.String getExpression()
          Get the SQL expression
 ParameterList getParameters()
          Gets the parameters
 void initialise()
          Initialise the SQL statement.
protected  void prepareParameters()
          Adds parameters to the JDBC prepared statement handler.
private  void prepareParametersPrivate()
          Adds parameters to the JDBC prepared statement handler.
 void setConnection(java.sql.Connection connection)
          Set the connection for this SQL statement
 void setExpression(java.lang.String expression)
          Set the expression for this SQL statement
 void setParameters(ParameterList parameters)
          Set the parameters for this SQL statement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement

See Also:
Constant Field Values

LOG

private static DAILogger LOG
Logger object for logging in this class


mConnection

private java.sql.Connection mConnection
JDBC connection handler


mParameters

private ParameterList mParameters
SQL expression parameters


mExpression

private java.lang.String mExpression
Parameterised SQL expression


mStatement

protected java.sql.PreparedStatement mStatement
JDBC prepared statement handler


mFinishedProcessing

private boolean mFinishedProcessing
Has expression completed (default false)


mTempFiles

private java.util.List mTempFiles
Temporary files that need to be deleted when the query is executed


mTempFileInputStreams

private java.util.List mTempFileInputStreams
Input streams that need to be closed when the query is executed

Constructor Detail

ParameterisedSQLStatement

public ParameterisedSQLStatement()
Constructor


ParameterisedSQLStatement

public ParameterisedSQLStatement(java.sql.Connection conx,
                                 ParameterList parameters,
                                 java.lang.String expression)
                          throws java.sql.SQLException
Constructor.

Parameters:
conx - JDBC connection
parameters - A list of parameters
expression - SQL expression
Throws:
java.sql.SQLException - If the statement could not be prepared
Method Detail

initialise

public void initialise()
                throws java.sql.SQLException
Description copied from interface: SQLStatement
Initialise the SQL statement.

Specified by:
initialise in interface SQLStatement
Throws:
java.sql.SQLException - If any problem occurs in the driver.

setConnection

public void setConnection(java.sql.Connection connection)
Description copied from interface: SQLStatement
Set the connection for this SQL statement

Specified by:
setConnection in interface SQLStatement
Parameters:
connection - JDBC connection

getConnection

public java.sql.Connection getConnection()
Returns the JDBC connection handler.

Returns:
the connection handler

setExpression

public void setExpression(java.lang.String expression)
Description copied from interface: SQLStatement
Set the expression for this SQL statement

Specified by:
setExpression in interface SQLStatement
Parameters:
expression - SQL expression

getExpression

public java.lang.String getExpression()
Get the SQL expression

Returns:
the expression

setParameters

public void setParameters(ParameterList parameters)
Description copied from interface: SQLStatement
Set the parameters for this SQL statement

Specified by:
setParameters in interface SQLStatement
Parameters:
parameters - List of parameters

getParameters

public ParameterList getParameters()
Gets the parameters

Returns:
parameters

close

public void close()
           throws java.sql.SQLException
Description copied from interface: SQLStatement
Closes this SQL statement.

Specified by:
close in interface SQLStatement
Throws:
java.sql.SQLException - If any problem occurs in the driver.

executeQuery

public java.sql.ResultSet executeQuery()
                                throws java.sql.SQLException,
                                       MissingParametersException,
                                       ParameterAccessException
Description copied from interface: SQLStatement
Executes this SQL statement

Specified by:
executeQuery in interface SQLStatement
Returns:
a ResultSet or null if there are no more parameters to process.
Throws:
MissingParametersException - If some of the parameters provided all their values yet others did not.
ParameterAccessException - If there is a problem when accessing a parameter value.
java.sql.SQLException - If any problem occurs in the driver.

executeUpdate

public int executeUpdate()
                  throws java.sql.SQLException,
                         MissingParametersException,
                         ParameterAccessException
Description copied from interface: SQLStatement
Executes this SQL statement as an update

Specified by:
executeUpdate in interface SQLStatement
Returns:
an update count or -1 if there are no more parameters to process
Throws:
ParameterAccessException - If there is a problem when accessing a parameter value.
MissingParametersException - If some of the parameters provided all their values yet others did not.
java.sql.SQLException - If any problem occurs in the driver.

prepareParameters

protected void prepareParameters()
                          throws java.sql.SQLException,
                                 MissingParametersException,
                                 ParameterAccessException
Adds parameters to the JDBC prepared statement handler.

Throws:
java.sql.SQLException - If any problem occurs in the driver.
MissingParametersException - If some of the parameters provided all their values yet others did not.
ParameterAccessException - If there is a problem when accessing a parameter value.

prepareParametersPrivate

private void prepareParametersPrivate()
                               throws java.sql.SQLException,
                                      MissingParametersException,
                                      ParameterAccessException
Adds parameters to the JDBC prepared statement handler. If an error is thrown then it is the responsibility of the caller to clean up any open input streams and delete any temporary files.

Throws:
java.sql.SQLException - If any problem occurs in the driver.
MissingParametersException - If some of the parameters provided all their values yet others did not.
ParameterAccessException - If there is a problem when accessing a parameter value.

closeTempFilesAndInputStreams

protected void closeTempFilesAndInputStreams()
Cleans up any temporany files that were passed as parameters. The input streams associated with the files are closed and the files are deleted.