uk.org.ogsadai.client.toolkit.activity.sql
Class SQLQuery

java.lang.Object
  |
  +--uk.org.ogsadai.client.toolkit.activity.RequestComponent
        |
        +--uk.org.ogsadai.client.toolkit.activity.Activity
              |
              +--uk.org.ogsadai.client.toolkit.activity.ParameterizedActivity
                    |
                    +--uk.org.ogsadai.client.toolkit.activity.sql.SQLQuery

public class SQLQuery
extends ParameterizedActivity

This activity evaluates an SQL statement that generates a single result set. It has no input and one output. The format of the output is WebRowSet XML, a standard XML representation for a result set.

Queries can be parameterized by using the '?' token in the query expression. These tokens can be replaced with parameter values hence allowing an activity to be reused with a slightly different configuration.

For example, the activity may have the following query expression:
SELECT * FROM MyTable WHERE id > ? AND id < ?
This query has two parameters whose values can be set using the setParameter method, for example: myActivity.setParameter( 1, "10" );
myActivity.setParameter( 2, "20" );
Would be equilavent to the query expression:
SELECT * FROM MyTable WHERE id > 10 AND id < 20

The getResultSet() method can be used to obtain a ResultSet object containing the results of this query, after it has been executed. This can be either of type ResultSet.TYPE_FORWARD_ONLY or ResultSet.TYPE_SCROLL_INSENSITIVE (with the former being more memory efficient), specified by using the setResultSetType(int) method.

Should you wish to obtain a "disconnected" result set, which only reads rows from the data service as they are required, rather than receiving all the results data from the data service and storing it locally, you should use an OutputStreamActivity activity and connect its input to this activity's output. The OutputStreamActivity class has a getResultSet method which can be used to obtain such a result set.

Author:
The OGSA-DAI Project Team

Constructor Summary
SQLQuery(java.lang.String expression)
          Constructs a query with the given query expression.
 
Method Summary
protected  java.lang.String generateXML()
          Generates the XML representing the activity.
 java.lang.String getExpression()
          Gets the SQL query expression.
 ActivityOutput getOutput()
          Gets the activity's only output.
 java.sql.ResultSet getResultSet()
          Gets the result set containing the result of processing the query.
 int getResultSetType()
          Return the type of ResultSet objects the getResultSet() method returns.
 void setResultSetType(int i)
          Set the type of ResultSet objects the getResultSet() method returns.
 
Methods inherited from class uk.org.ogsadai.client.toolkit.activity.ParameterizedActivity
clearParameters, generateParametersXML, setParameter, setParameter
 
Methods inherited from class uk.org.ogsadai.client.toolkit.activity.Activity
addInput, addOutput, addOutputs, getDataResourceID, getDataServiceStub, getInputParameters, getOutputParameters, getOutputs, replaceSpecialCharacters, setDataResourceID, setDataServiceStub, setInput
 
Methods inherited from class uk.org.ogsadai.client.toolkit.activity.RequestComponent
getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLQuery

public SQLQuery(java.lang.String expression)
Constructs a query with the given query expression.

Parameters:
expression -
Method Detail

getResultSetType

public int getResultSetType()
Return the type of ResultSet objects the getResultSet() method returns.

Returns:
the ResultSet type

setResultSetType

public void setResultSetType(int i)
Set the type of ResultSet objects the getResultSet() method returns.

Parameters:
i - either of ResultSet.TYPE_FORWARD_ONLY or ResultSet.TYPE_SCROLL_INSENSITIVE

getExpression

public java.lang.String getExpression()
Gets the SQL query expression.

Returns:
the SQL query expression

getResultSet

public java.sql.ResultSet getResultSet()
                                throws ActivityOutputException,
                                       DataFormatException
Gets the result set containing the result of processing the query.

Returns:
ResultSet containing query result.
Throws:
DataFormatException - If the output data is not in the expected format.
ActivityOutputException - If there is no output data.

getOutput

public ActivityOutput getOutput()
Gets the activity's only output.

Returns:
the activity output.

generateXML

protected java.lang.String generateXML()
Description copied from class: RequestComponent
Generates the XML representing the activity. This XML can then be inserted into a perform document that is sent to a data service.

Specified by:
generateXML in class Activity
Returns:
the XML for the activity