home > documentation > result set converter >

The OGSA-DAI Result Set Converter

Introduction

The OGSA-DAI source code includes a flexible result set converter. This has been designed to convert JDBC ResultSet objects into byte serialisations. Depending on the configuration of the converter, completely different serialisations can be produced, such as WebRowSetXML and CSV representations.


Figure 1: UML class diagram of the result set converter.

The core class is the uk.org.ogsadai.converters.resultset.ResultSetConverter. This is constructed using a java.sql.ResultSet object and an implementation of the uk.org.ogsadai.converters.resultset.ResultSetHandler interface. For example:

ResultSet rs = ...
ResultSetHandler handler = new MyResultSetHandler();
ResultSetConverter converter = new ResultSetConverter(rs, handler);

The ResultSetHandler interface contains a number of call-back methods. These are invoked in the following order during the conversion process:

  • header()
  • For each row:
    • rowStart()
    • For each column:
      • columnStart()
      • field()
      • columnEnd()
    • rowEnd()
  • footer()

The conversion process is performed using the following code:

while (converter.hasNext())
{
    byte[] block = converter.next();
    // do something with converted bytes
}

Extending the Result Set Converter

The only thing that is required to produce a new serialisation, is a new implementation of the ResultSetHandler interface. However, there are a number of additional interfaces and classes that are provided to assist with extending the result set handler. These help to keep the code simple and easy to test by making use of the Strategy and Abstract Factory design patterns.


Figure 2: UML class diagram of the strategic result set handler.

StrategicResultSetHandler

This is an abstract result set handler that uses strategy objects to handle the SQL column types occurring within a result set. The handling of other aspects of a result set is deferred to a sub-class, so your own ResultSetHandler implementation may extend this class and implement the remaining methods of the ResultSetHandler interface.

This class is constructed using a ResultSet object and a ColumnStrategyFactory object. During the construction process, the result set meta-data is analysed to determine which SQL column types are present. The factory is then used to create an appropriate ColumnStrategy object for each column, and these strategies are used for processing the field data during the conversion process.

ColumnStrategy

A column strategy is responsible for converting the data from a single column of a java.sql.ResultSet into byte data. Different implementations can be developed to convert different SQL types into different formats. For example, various implementations are provided with OGSA-DAI, one of which converts BLOB data into Base-64 encoded data.

ColumnStrategyFactory

The factory interface for creating column strategies. This is used by the StrategicResultSetHandler class. An implementation can be written that creates the appropriate ColumnStrategy objects for the conversion process. For example, OGSA-DAI includes one such implementation that creates various different types of ColumnStrategy to produce data suitable for WebRowSetXML.

Please see the OGSA-DAI Javadoc and source code for more details.