Java Reference
In-Depth Information
subTest += token;
}
}
if(subTest.trim().length()>0){
where.addElement(subTest.trim());
}
return where;
}
// prune to include only selected fields
private void pruneFields(Node record){
Vector fieldClauses = splitFields(fields);
NodeList nodes = record.getChildNodes();
for(int i=0;i<nodes.getLength();i++){
Node n = nodes.item(i);
if(n.getNodeType()==Node.ELEMENT_NODE){
String tagName = ((Element)n).getTagName();
if(!fieldClauses.contains(tagName))record.removeChild(n);
}
}
}
}
After creating the XMLQuery object, the XMLStatement calls XMLQuery 's processDocument()
method, passing it a reference to the document being queried.
XMLQuery.processDocument() handles the actual processing of the query. It does this by first
creating an XMLResultSet and then retrieving the XML elements corresponding to the table and
evaluating them against the WHERE clause.
Since the database is contained in an XML document, the XMLResultSet is also returned as an XML
document. XML elements that match the WHERE clause are imported into the newly created document
and pruned of element nodes that are not itemized in the column list of the SQL query. Attribute nodes,
on the other hand, are returned without pruning in this implementation, though, of course, you can easily
change this if you wish.
The final step is to append the selected and pruned node to the root element of the XMLResultSet .
Once the entire XMLResultSet has been created, it is returned in the normal way.
The XMLWhereEvaluator class
The SQL query engine itself is implemented in the XMLWhereEvaluator class, shown later in this
section. The protected element record contains the record currently being tested, and the vector
testVector contains the Strings representing the individual subtests. For example, a SQL query might
look like this:
"SELECT * FROM CUSTOMER
WHERE ( FIRST_NAME LIKE 'M%' OR CUSTOMER_NUMBER = '102' )"
The WHERE clause is split into subtests as follows:
(
Search WWH ::




Custom Search