uk.org.ogsadai.activity.sql
Class SQLActivity

java.lang.Object
  |
  +--uk.org.ogsadai.engine.Activity
        |
        +--uk.org.ogsadai.activity.sql.SQLActivity
Direct Known Subclasses:
RelationalResourceManagementActivity, SQLBulkLoadRowSetActivity, SQLQueryStatementActivity, SQLStoredProcedureActivity, SQLUpdateStatementActivity

public abstract class SQLActivity
extends Activity

An Abstract class to hold common functions for Activities relate to relational database access.

The SQLStatementActivity 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 activity must be able to decide the DataResource over which to carryout the statement. It must be given a ConnectionManager

The credentials of the user should be available from the context

The activity can then be processed a block at a time.

Author:
The OGSA-DAI Project Team

Nested Class Summary
protected  class SQLActivity.ParameterInput
          ParameterInput inner class.
 class SQLActivity.StreamInput
          StreamInput inner class.
 class SQLActivity.ValueInput
          ValueInput inner class.
 
Field Summary
static java.lang.String CREATE_DATABASE
           
static java.lang.String DROP_DATABASE
           
static java.lang.String EXPRESSION
           
protected  SQLActivity.ParameterInput[] mAllInput
           
protected  java.sql.Connection mConnection
           
protected  JDBCConnectionManager mConnectionManager
           
protected  java.lang.String mCredentials
           
protected  java.lang.String mExpression
           
protected  SQLActivity.ParameterInput mExpressionInput
           
protected  java.util.Set mInputStreams
           
protected  boolean mIsTransaction
           
protected  java.util.Map mNameToInput
           
protected  boolean mOpenConnection
           
protected  BlockWriter mOutput
           
protected  java.sql.Statement mStatement
           
static java.lang.String RESULT_STREAM
           
static java.lang.String SQL_PARAMETERS
           
static java.lang.String STORED_PROCEDURE
           
static java.lang.String WEB_ROW_SET_STREAM
           
 
Fields inherited from class uk.org.ogsadai.engine.Activity
mContext, mExternalInputs, mExternalOutputs, mInternalInputs, mInternalOutputs
 
Constructor Summary
SQLActivity(org.w3c.dom.Element element)
          Constructor : This constructor doesn't do much.
 
Method Summary
protected  void endProcessing()
          This method will complete the processing and tidy up
protected  boolean getResult()
          This method will try and complete the statement with parameters Then try and execute the query and obtain the resultSet
 void initialise()
          Completes initialisation of Activity.
protected  boolean loadNextExpression()
          Helper method to retrieve expression from an input stream or value.
protected  void parseCommand(org.w3c.dom.NodeList commandNL)
          This method will find the command appropriate for this actiivity, can be SQLStatement or a StoredProcedure.
protected  void parseResultStream(org.w3c.dom.NodeList resultStreamNL)
          This method will find the webRowSetStream appropriate for this activity.
protected  void parseSQLParameters(org.w3c.dom.NodeList sqlParameterNL)
          This method will find the SQLParameters appropriate for this activity if any are specified.
protected  boolean prepareStatement()
          Helper method to prepare parameters for prepared statements This method runs through all parameters and retrieves the value from an input stream or the contents of an SQLParameter.
protected  void setupInputStreamNames()
          Sets up the InputStream Names.
 
Methods inherited from class uk.org.ogsadai.engine.Activity
cleanUp, connectsTo, getActivityConfiguration, getName, getObservableStatus, getProperties, getStatus, hasActivityConfiguration, hasProperties, processBlock, processFirst, setCompleted, setError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXPRESSION

public static final java.lang.String EXPRESSION
See Also:
Constant Field Values

STORED_PROCEDURE

public static final java.lang.String STORED_PROCEDURE
See Also:
Constant Field Values

CREATE_DATABASE

public static final java.lang.String CREATE_DATABASE
See Also:
Constant Field Values

DROP_DATABASE

public static final java.lang.String DROP_DATABASE
See Also:
Constant Field Values

SQL_PARAMETERS

public static final java.lang.String SQL_PARAMETERS
See Also:
Constant Field Values

WEB_ROW_SET_STREAM

public static final java.lang.String WEB_ROW_SET_STREAM
See Also:
Constant Field Values

RESULT_STREAM

public static final java.lang.String RESULT_STREAM
See Also:
Constant Field Values

mOutput

protected BlockWriter mOutput

mNameToInput

protected java.util.Map mNameToInput

mAllInput

protected SQLActivity.ParameterInput[] mAllInput

mExpressionInput

protected SQLActivity.ParameterInput mExpressionInput

mExpression

protected java.lang.String mExpression

mInputStreams

protected java.util.Set mInputStreams

mOpenConnection

protected boolean mOpenConnection

mIsTransaction

protected boolean mIsTransaction

mStatement

protected java.sql.Statement mStatement

mConnection

protected java.sql.Connection mConnection

mCredentials

protected java.lang.String mCredentials

mConnectionManager

protected JDBCConnectionManager mConnectionManager
Constructor Detail

SQLActivity

public SQLActivity(org.w3c.dom.Element element)
            throws ActivityUserException,
                   ActivitySystemException
Constructor : This constructor doesn't do much. Calls Activity constructor.

Parameters:
element - Element containing Statement conforming to schema for a SQLQueryStatement. It is assumed schema checks have been carried out.
Throws:
ActivityUserException
ActivitySystemException
Method Detail

parseSQLParameters

protected void parseSQLParameters(org.w3c.dom.NodeList sqlParameterNL)
                           throws ActivityUserException
This method will find the SQLParameters appropriate for this activity if any are specified.

These SQLParameters could be values or Input Streams and sqlParameters array at position x will hold the value for the sqlParameter at position x, while the sqlParametersAsInputStream array at position x will hold the name of the inputStream from which to read the value Further the same input stream could provide input for more than one parameter i.e. a datastore

Parameters:
sqlParameterNL - A nodeList correposnding to elements with Tag SQL_PARAMETERS
Throws:
ActivityUserException - if SQL parameter is out of range, specified twice or complicated value

parseCommand

protected void parseCommand(org.w3c.dom.NodeList commandNL)
                     throws ActivityUserException,
                            ActivitySystemException
This method will find the command appropriate for this actiivity, can be SQLStatement or a StoredProcedure.

This command could be a value or Input Stream and command will hold the value for the command or commandAsInputStream will hold the name of the inputStream from which to read the value

Parameters:
commandNL - A nodeList corresponding to elements with a command tag, either EXPRESSION or STORED_PROCEDURE
Throws:
ActivityUserException - on complicated command, specifying both value and inputstream
ActivitySystemException

parseResultStream

protected void parseResultStream(org.w3c.dom.NodeList resultStreamNL)
                          throws ActivityUserException
This method will find the webRowSetStream appropriate for this activity. Input parameter resultStream indicates the OutputStream name to use

Parameters:
resultStreamNL - A nodeList corresponding to elements with a tag WEB_ROW_SET_STREAM
Throws:
ActivityUserException

setupInputStreamNames

protected void setupInputStreamNames()
Sets up the InputStream Names.


initialise

public void initialise()
                throws ActivityUserException
Completes initialisation of Activity.

Overrides:
initialise in class Activity
Throws:
ActivityUserException - If a user problem prevents the activity from initialising.

loadNextExpression

protected boolean loadNextExpression()
Helper method to retrieve expression from an input stream or value.


prepareStatement

protected boolean prepareStatement()
                            throws ActivitySystemException,
                                   ActivityUserException,
                                   java.sql.SQLException
Helper method to prepare parameters for prepared statements This method runs through all parameters and retrieves the value from an input stream or the contents of an SQLParameter.

Throws:
ActivityUserException - if input streams don't end at the same time
ActivitySystemException
java.sql.SQLException

getResult

protected boolean getResult()
                     throws java.sql.SQLException,
                            ActivitySystemException,
                            ActivityUserException
This method will try and complete the statement with parameters Then try and execute the query and obtain the resultSet

Returns:
true if it has successfully created a new result
Throws:
ActivityUserException
ActivitySystemException
java.sql.SQLException

endProcessing

protected void endProcessing()
                      throws java.sql.SQLException,
                             ActivitySystemException
This method will complete the processing and tidy up

Throws:
java.sql.SQLException
ActivitySystemException