com.ibm.pdq.runtime.data.handlers

Class XMLResultHandler

  1. java.lang.Object
  2. extended bycom.ibm.pdq.runtime.data.handlers.XMLResultHandler
All implemented interfaces:
ResultHandler<String>

public class XMLResultHandler
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 an XML String. XMLResultHandler 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 XMLResultHandler in the same order in which they are returned from the data source. An instance of XMLResultHandler maintains no state information. Therefore, a single instance of XMLResultHandler can be used for more than one pureQuery method.

The returned String has the following format:

For an example, suppose a data source had three tables, each with just one column:

Table Name Column Name
table1 t1Column1
table2 t2Column2
table3 t3Column3

Then suppose that the following SQL was used to query the data source:

SELECT
     table1.t1Column1 AS t1Column1,
     table2.t2Column2 AS t2Column2,
     table3.t3Column3 AS t3Column3
FROM
     table1, table2, table3
WHERE
     some logic;
Suppose data were returned for four rows as follows:

t1Column1 t2Column2 t3Column3
row1T1Column1Data row1T2Column2Data row1T3Column3Data
row2T1Column1Data row2T2Column2Data row2T3Column3Data
row3T1Column1Data row3T2Column2Data row3T3Column3Data
row4T1Column1Data row4T2Column2Data row4T3Column3Data

With this data, the String returned by handle(ResultSet) would be as follows (in the returned String, the only white space would be a line break after the <result> tag, the line breaks after each <⁄table1> tag, and a tab character before each <table1> tag.).

<result>
     <table1><t1Column1>row1T1Column1Data<⁄t1Column1><t2Column2>row1T2Column2Data<⁄t2Column2><t3Column3>row1T3Column3Data<⁄t3Column3><⁄table1>
     <table1><t1Column1>row2T1Column1Data<⁄t1Column1><t2Column2>row2T2Column2Data<⁄t2Column2><t3Column3>row2T3Column3Data<⁄t3Column3><⁄table1>
     <table1><t1Column1>row3T1Column1Data<⁄t1Column1><t2Column2>row3T2Column2Data<⁄t2Column2><t3Column3>row3T3Column3Data<⁄t3Column3><⁄table1>
     <table1><t1Column1>row4T1Column1Data<⁄t1Column1><t2Column2>row4T2Column2Data<⁄t2Column2><t3Column3>row4T3Column3Data<⁄t3Column3><⁄table1>
<⁄result>


Constructor Summary

Constructor and Description
XMLResultHandler()

Method Summary

Modifier and Type Method and Description
  1. String
handle(ResultSet rs)
Returns the results of an SQL statement as an XML String.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

XMLResultHandler

public XMLResultHandler()

Method Detail

handle

public String handle(ResultSet rs)
Returns the results of an SQL statement as an XML String.

See XMLResultHandler for a description and an example of how the XML is formatted in the String that is returned.

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 XML