uk.org.ogsadai.activity.sql
Class SQLResultToBytesActivity

java.lang.Object
  |
  +--uk.org.ogsadai.activity.Activity
        |
        +--uk.org.ogsadai.activity.sql.SQLResultToBytesActivity

public class SQLResultToBytesActivity
extends Activity

Activity that converts a single entry in an SQL result set to a binary stream. The specified column value of the first row in the result set will be extracted from the input, converted into binary format and output as a sequence of byte arrays.

This activity is useful when extracting BLOBs from databases for further processing or delivery via other OGSA-DAI activities.

For information on this activity see the OGSA-DAI user doc: OGSA-DAI/doc/interaction/activities/relational/sqlResultToBytes.html

Author:
OGSA-DAI team

Field Summary
static java.lang.String BLOCK_SIZE_ELEMENT
           
static java.lang.String COLUMN_INDEX_ELEMENT
           
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement
static int DEFAULT_BLOCK_SIZE
          Default block size
static java.lang.String FROM_ATTRIBUTE
           
private static DAILogger LOG
          Logger object for logging in this class
protected  java.io.InputStream mBinaryInputStream
          Input stream from which to read the binary data
protected  int mBlockSize
          Size in bytes of output blocks
protected  int mColumnIndex
          Index of the column to extract and convert to bytes
protected  BlockReader mInput
          Reader that provides the activity's only input
protected  java.lang.String mInputStreamName
          Name of the activity's only input stream
protected  BlockWriter mOutput
          Write to which the activity's output is written
protected  java.lang.String mOutputStreamName
          Name of the activity's only output stream
static java.lang.String NAME_ATTRIBUTE
           
static java.lang.String OUTPUT_STREAM_ELEMENT
           
static java.lang.String RESULT_SET_ELEMENT
           
static java.lang.String VALUE_ATTRIBUTE
           
 
Fields inherited from class uk.org.ogsadai.activity.Activity
mContext, mExternalInputs, mExternalOutputs, mInternalInputs, mInternalOutputs
 
Constructor Summary
SQLResultToBytesActivity(org.w3c.dom.Element element)
          Constructs an instance of the SQLResultToBytes activity.
 
Method Summary
 int getBlockSize()
          Gets the block size which specifies the number of bytes that will be included in each output block.
 int getColumnIndex()
          Gets the column index from which the binary data will be extracted.
 java.lang.String getInputStreamName()
          Gets the activity's input stream name.
 java.lang.String getOutputStreamName()
          Gets the activity's output stream name.
protected  java.sql.ResultSet getResultSet(BlockReader inputReader)
          Gets the result set from the input reader.
 void initialise()
          This method should be overridden by subclasses to perform any initialisation they require before the process method invocations begin.
protected  void processBlock()
          Performs an iteration of the processing of an activity.
protected  byte[] readBytesFromInputStream(java.io.InputStream is, int blockSize)
          Reads the specified number of bytes from the given input stream leaving the input stream intact for repeated calling.
 
Methods inherited from class uk.org.ogsadai.activity.Activity
cleanUp, connectsTo, createOutputPipe, getActivityConfiguration, getActivityName, getCause, getName, getObservableStatus, getProperties, getSession, getStatus, hasActivityConfiguration, hasProperties, process, processFirst, setActivityName, setCompleted, setError
 
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


RESULT_SET_ELEMENT

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

OUTPUT_STREAM_ELEMENT

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

COLUMN_INDEX_ELEMENT

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

BLOCK_SIZE_ELEMENT

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

FROM_ATTRIBUTE

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

NAME_ATTRIBUTE

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

VALUE_ATTRIBUTE

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

DEFAULT_BLOCK_SIZE

public static final int DEFAULT_BLOCK_SIZE
Default block size

See Also:
Constant Field Values

mInputStreamName

protected java.lang.String mInputStreamName
Name of the activity's only input stream


mInput

protected BlockReader mInput
Reader that provides the activity's only input


mOutputStreamName

protected java.lang.String mOutputStreamName
Name of the activity's only output stream


mOutput

protected BlockWriter mOutput
Write to which the activity's output is written


mBinaryInputStream

protected java.io.InputStream mBinaryInputStream
Input stream from which to read the binary data


mColumnIndex

protected int mColumnIndex
Index of the column to extract and convert to bytes


mBlockSize

protected int mBlockSize
Size in bytes of output blocks

Constructor Detail

SQLResultToBytesActivity

public SQLResultToBytesActivity(org.w3c.dom.Element element)
                         throws ActivitySpecificationException,
                                ActivityCreationException
Constructs an instance of the SQLResultToBytes activity.

The schema of the input XML element is defined in sql_result_to_bytes.xsd. An example is:

 <sqlResultToBytes name="myActivityInstance">
   <resultSet from="resultSetStream"/>
   <columnIndex value="1"/>
   <blockSize value="2000"/>
   <outputStream name="byteStream"/>
 </sqlResultToBytes>
 
The resultSet element specifies the input to this activity. The columnIndex element specifies which column to tract the data from. The first column has an index of 1. The blockSize element is optional and if present specifies the desired number of bytes in each output block. The outputStream element names the output stream that the blocks will be written to.

Parameters:
element - parameters for the activity expressed in XML format.
Throws:
ActivitySpecificationException - if an error occurs due to the user's incorrect input.
ActivityCreationException - if a error occurs beyond the specification of the input parameters.
Method Detail

initialise

public void initialise()
                throws ActivitySpecificationException,
                       ActivityExecutionException
Description copied from class: Activity
This method should be overridden by subclasses to perform any initialisation they require before the process method invocations begin. This might be used for setting up convenient fields to reference objects contained in the context. It shouldn't be used for opening resources. That should be done in processFirst.

Overrides:
initialise in class Activity
Throws:
ActivityExecutionException - If some system problem prevents the activity from initialising.
ActivitySpecificationException - If a problem with settings provided by a client prevents the activity from initialising.

getInputStreamName

public java.lang.String getInputStreamName()
Gets the activity's input stream name.

Returns:
name of the activity's input stream.

getOutputStreamName

public java.lang.String getOutputStreamName()
Gets the activity's output stream name.

Returns:
name of activity's output stream.

getColumnIndex

public int getColumnIndex()
Gets the column index from which the binary data will be extracted.

Returns:
column index. The first column is specified by an index of 1.

getBlockSize

public int getBlockSize()
Gets the block size which specifies the number of bytes that will be included in each output block. The final block may have fewer bytes than this.

Returns:
block size in bytes.

processBlock

protected void processBlock()
Description copied from class: Activity
Performs an iteration of the processing of an activity. This may involve reading a block of input data and writing a block of output data, or may involve some other kind of processing. When an activity is processed by the OGSA-DAI engine, this method will be invoked repeatedly until the activity either completes or stops due to an error or termination call. An implementation of this method should invoke the setCompleted method to indicate that processing is complete, or the setError method if an error occurs that will prevent the processing from completing.

Specified by:
processBlock in class Activity

readBytesFromInputStream

protected byte[] readBytesFromInputStream(java.io.InputStream is,
                                          int blockSize)
                                   throws java.io.IOException
Reads the specified number of bytes from the given input stream leaving the input stream intact for repeated calling.

Parameters:
is - the input stream to read.
blockSize - number of bytes to read from the stream.
Returns:
an array of bytes read from the input stream. The length of the array will be equal to the specified block size except if the stream finishes before the array is full in which case a reduced sized array will be returned. The receipt of an array that is smaller in length than the block size signals that the stream has been fully read.
Throws:
java.io.IOException - if an error occurs reading from the stream.

getResultSet

protected java.sql.ResultSet getResultSet(BlockReader inputReader)
Gets the result set from the input reader. If the block in the input reader is not of type ResultSet then an error will be set and null null will be returned. If there is no more data setComplete will be called.

Parameters:
inputReader - input from which to read the result set object.
Returns:
the result set object obtained from the input reader or null if there is no more blocks to read or an error has occurred.