Iterator<ResultRowImpl> getRows(String revisionId, NodeState root) {
prepare();
Iterator<ResultRowImpl> it;
if (explain) {
String plan = source.getPlan();
columns = new ColumnImpl[] { new ColumnImpl("explain", "plan", "plan")};
ResultRowImpl r = new ResultRowImpl(this,
new String[0],
new CoreValue[] { getValueFactory().createValue(plan) },
null);
it = Arrays.asList(r).iterator();
} else {
it = new RowIterator(revisionId, root, limit, offset);
long resultCount = 0;
if (orderings != null) {
// TODO "order by" is not necessary if the used index returns
// rows in the same order
ArrayList<ResultRowImpl> list = new ArrayList<ResultRowImpl>();
while (it.hasNext()) {
ResultRowImpl r = it.next();
list.add(r);
}
resultCount = size = list.size();
Collections.sort(list);
it = list.iterator();
} else if (measure) {
while (it.hasNext()) {
resultCount++;
it.next();
}
}
if (measure) {
columns = new ColumnImpl[] {
new ColumnImpl("measure", "selector", "selector"),
new ColumnImpl("measure", "scanCount", "scanCount")
};
ArrayList<ResultRowImpl> list = new ArrayList<ResultRowImpl>();
ResultRowImpl r = new ResultRowImpl(this,
new String[0],
new CoreValue[] {