uk.org.ogsadai.activity.sql
Class SQLQueryStatementActivity

java.lang.Object
  |
  +--uk.org.ogsadai.engine.Activity
        |
        +--uk.org.ogsadai.activity.sql.SQLActivity
              |
              +--uk.org.ogsadai.activity.sql.SQLQueryStatementActivity
Direct Known Subclasses:
CSVQueryStatementActivity, OracleQueryStatementActivity

public class SQLQueryStatementActivity
extends SQLActivity

Handles SQLQueryStatement Elements from a Grid Data Service Document.

The SQLQueryStatementActivity is constructed from an Element corresponding to a statement for execution on a database.

A Context can then be set detailing the environment in which this activity exists. Where to obtain inputs from and send output too.

The credentials of the user should be available to obtain a connection

The activity can then be processed a block at a time. On the request for the first block the activity will obtain a connection from the ConnectionManager, setup and execute the statement and return the first block as defined within ResultSetToWebRowSetXMLStream

Subsequently each block will be returned until last block, at which point the statement is closed the connection is returned to the ConnectionManager and the ouput closed.

Note: Database needs to support connection.setReadOnly otherwise update could slip through, be committed and only then flag an error Extend this class if the database driver does not support all of the methods and flags used here.

A prepared statement will automatically be used if SQLParameters are specified If expression is read from inputStream and SQLParameters are specified this means PreparedStatement will be recreated after each execution since we have no idea if expression will remain the same


Nested Class Summary
 
Nested classes inherited from class uk.org.ogsadai.activity.sql.SQLActivity
SQLActivity.ParameterInput, SQLActivity.StreamInput, SQLActivity.ValueInput
 
Field Summary
protected  ResultSetToWebRowSetXMLStream mRowset
          WebRowSet data is read from this input stream.
protected  boolean mStatementPrepared
          Indicates whether or not a prepared statement is being used.
 
Fields inherited from class uk.org.ogsadai.activity.sql.SQLActivity
CREATE_DATABASE, DROP_DATABASE, EXPRESSION, mAllInput, mConnection, mConnectionManager, mCredentials, mExpression, mExpressionInput, mInputStreams, mIsTransaction, mNameToInput, mOpenConnection, mOutput, mStatement, RESULT_STREAM, SQL_PARAMETERS, STORED_PROCEDURE, WEB_ROW_SET_STREAM
 
Fields inherited from class uk.org.ogsadai.engine.Activity
mContext, mExternalInputs, mExternalOutputs, mInternalInputs, mInternalOutputs
 
Constructor Summary
SQLQueryStatementActivity(org.w3c.dom.Element element)
          Constructs an instance of the activity configured with the data contained in the specified Element.
 
Method Summary
 void cleanUp()
          Tidy up connections and statements in case the activity is terminated or an error occurred.
protected  void endProcessing()
          This method will complete the processing and tidy up.
protected  boolean getResult()
          Tries to complete the statement with parameters then tries to execute the query and obtain the ResultSet.
 void processBlock()
          This method will return the next block of output on the outputStream No Exceptions are thrown since they will be flagged as a status flag with the activity and the output stream will be closed
protected  void processFirst()
          Starts processing by retrieving the connection and creating a statement.
 
Methods inherited from class uk.org.ogsadai.activity.sql.SQLActivity
initialise, loadNextExpression, parseCommand, parseResultStream, parseSQLParameters, prepareStatement, setupInputStreamNames
 
Methods inherited from class uk.org.ogsadai.engine.Activity
connectsTo, getActivityConfiguration, getName, getObservableStatus, getProperties, getStatus, hasActivityConfiguration, hasProperties, setCompleted, setError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mStatementPrepared

protected boolean mStatementPrepared
Indicates whether or not a prepared statement is being used.


mRowset

protected ResultSetToWebRowSetXMLStream mRowset
WebRowSet data is read from this input stream.

Constructor Detail

SQLQueryStatementActivity

public SQLQueryStatementActivity(org.w3c.dom.Element element)
                          throws ActivityUserException,
                                 ActivitySystemException
Constructs an instance of the activity configured with the data contained in the specified Element.

Parameters:
element - The activity Element, conforming to the associated schema.
Throws:
ActivityUserException - If there is a user problem constructing the activity.
ActivitySystemException - If there is a system problem constructing the activity.
Method Detail

processFirst

protected void processFirst()
Starts processing by retrieving the connection and creating a statement. Note that the connection is not returned or closed until the output is complete. i.e. the last block has been read.

Overrides:
processFirst in class Activity

getResult

protected boolean getResult()
                     throws java.sql.SQLException,
                            ActivitySystemException,
                            ActivityUserException
Tries to complete the statement with parameters then tries to execute the query and obtain the ResultSet.

Overrides:
getResult in class SQLActivity
Returns:
true if it has successfully created a new result set
Throws:
ActivitySystemException
java.sql.SQLException
ActivityUserException

processBlock

public void processBlock()
This method will return the next block of output on the outputStream No Exceptions are thrown since they will be flagged as a status flag with the activity and the output stream will be closed

Specified by:
processBlock in class Activity

endProcessing

protected void endProcessing()
                      throws java.sql.SQLException,
                             ActivitySystemException
This method will complete the processing and tidy up. Assumes that processing of the results completed successfully and that there are no errors. Transactions will be committed.

Overrides:
endProcessing in class SQLActivity
Throws:
java.sql.SQLException
ActivitySystemException - the database connection could not be returned

cleanUp

public void cleanUp()
Tidy up connections and statements in case the activity is terminated or an error occurred.

Overrides:
cleanUp in class Activity