1.1.1

Table Of Contents
context)
throws SQLException {
String queryString = LOCAL
+ "SELECT * FROM "
+ context.getTableName();
Connection cxn = context.getConnection();
Statement stmt = cxn.createStatement();
ResultSet rs = stmt.executeQuery(queryString);
outResults[0] = rs;
}
}
MergeSortProcessor class
package examples;
import com.vmware.sqlfire.*;
import java.sql.*;
import java.util.*;
public class MergeSortProcessor implements
ProcedureResultProcessor {
private ProcedureProcessorContext context;
public void init(ProcedureProcessorContext context) {
this.context = context;
}
public Object[] getOutParameters() {
throw new AssertionError("this procedure has no out
parameters");
}
public Object[] getNextResultRow(int resultSetNumber)
throws InterruptedException {
// this procedure deals with only result set number 1
assert resultSetNumber == 1;
IncomingResultSet[] inSets =
context.getIncomingResultSets(1);
Object[] lesserRow = null;
Comparator cmp = getComparator();
IncomingResultSet setWithLeastRow = null;
for (IncomingResultSet inSet : inSets) {
Object[] nextRow = inSet.waitPeekRow();
if (nextRow == IncomingResultSet.END_OF_RESULTS) {
// no more rows in this incoming results
continue;
}
// find the least row so far
if (lesserRow == null || cmp.compare(nextRow, lesserRow)
<= 0) {
lesserRow = nextRow;
setWithLeastRow = inSet;
}
}
if (setWithLeastRow != null) {
// consume the lesserRow by removing lesserRow from the
incoming result set
Object[] takeRow = setWithLeastRow.takeRow();
assert takeRow == lesserRow;
467
SQLFire API