com.ibm.pdq.runtime.data.handlers
Class XMLResultHandler
- java.lang.Object
com.ibm.pdq.runtime.data.handlers.XMLResultHandler
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:
- A <result> tag indicates the start of the
ResultSet
, and a <⁄result> tag indicates the end of theResultSet
. A line break occurs after the <result> tag. - Inside the result tags, the rows are listed in the order that they are listed in the
ResultSet
. Each row is on a line by itself, and the start of each row is indented one tab character. The start and end of each row are indicated by tags that are the name of the table to which the contents of the first column belong. For example, if tablename is the name of that table, the tag that indicates the start of that row would be <tablename>, and the tag that indicates the end of that row would be <⁄tablename>. - For each row, the columns are listed within the tablename tags in the order that they are returned from the data source, with no separation between columns or between either column and the tablename tags next to it.
- Each column is indicated by tags that are the name of the column. For example, if the name of a column is
column, the start tag for that column would be <column> and the end tag would be <⁄column>.
The
String
representation of the contents of the column is between the tags, with no spaces separating it from the tags.
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:
SELECTSuppose data were returned for four rows as follows:
table1.t1Column1 AS t1Column1,
table2.t2Column2 AS t2Column2,
table3.t3Column3 AS t3Column3
FROM
table1, table2, table3
WHERE
some logic;
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 |
---|---|
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)
handle
in interface ResultHandler<String>
rs
- a ResultSet
that represents the results from an SQL statement String
that contains the entire contents of resultSet
in XML
String
.See
XMLResultHandler
for a description and an example of how the XML is formatted in theString
that is returned.