com.ibm.pdq.runtime.data.handlers
Class JSONResultHandler

java.lang.Object
  extended by com.ibm.pdq.runtime.data.handlers.JSONResultHandler
All Implemented Interfaces:
ResultHandler<String>

public class JSONResultHandler
extends Object
implements ResultHandler<String>

An implementation of ResultHandler that can be specified to cause pureQuery to return content of the results of an SQL query as a String in the JSON format, which is described at http://www.json.org. JSONResultHandler is provided to be an example of how a ResultHandler may be written to process the contents of a ResultSet. See ResultHandler for a description of how an implementation of ResultHandler can be specified to a pureQuery method.

The rows are returned by the JSONResultHandler in the same order in which they are returned from the data source. An instance of JSONResultHandler maintains no state information. Therefore, a single instance of JSONResultHandler can be used for more than one pureQuery method.

The returned String, which is described at http://www.json.org, has the following format:

For example, suppose a data source returned the contents of three columns:

Suppose data was returned for four rows as follows:

column1 column2 column3
row1Column1Data row1Column2Data row1Column3Data
row2Column1Data row2Column2Data row2Column3Data
row3Column1Data row3Column2Data row3Column3Data
row4Column1Data row4Column2Data row4Column3Data

With this data, the String returned by handle(ResultSet) would be as follows (except that there would be no spaces, line breaks, or other white space in the actual returned String):

[
{"column1":"row1Column1Data","column2":"row1Column2Data","column3":"row1Column3Data"},
{"column1":"row2Column1Data","column2":"row2Column2Data","column3":"row2Column3Data"},
{"column1":"row3Column1Data","column2":"row3Column2Data","column3":"row3Column3Data"},
{"column1":"row4Column1Data","column2":"row4Column2Data","column3":"row4Column3Data"}
]

Constructor Summary

Constructor Summary
Constructor and Description
JSONResultHandler()

Method Summary

Method Summary
Return Data TypeMethod Name and Description
String handle(ResultSet rs)
Returns the results of an SQL statement as a String in the JSON format.

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

JSONResultHandler

public JSONResultHandler()

Method Detail

handle

public String handle(ResultSet rs)
Returns the results of an SQL statement as a String in the JSON format.

See JSONResultHandler for a description of the JSON format and for an example of the JSON format representation of a ResultSet.

Specified by:
handle in interface ResultHandler<String>
Parameters:
rs - a ResultSet that represents the results from an SQL statement
Returns:
a String that contains the entire contents of resultSet in the JSON format