Iterator<Counter> elements = labelCounter.values().iterator();
while (elements.hasNext()) {
elements.next().reset(1);
}
try {
_resultSchema = new GroupSchemaNode(-1, "result", null, new TimeSequence(1));
for (SubTreeSelectStatement stmt : _statements) {
SchemaNode schema = stmt.targetPath().lastElement().entity();
String label = null;
if (stmt.label() != null) {
label = stmt.label();
} else {
label = schema.label();
}
if (labelCounter.containsKey(label)) {
Counter counter = labelCounter.get(label);
label = label + Integer.toString(counter.value());
stmt.setLabel(label);
counter.inc();
}
SchemaNode renamedSchema = null;
if (schema.isAttribute()) {
renamedSchema = new AttributeSchemaNode(-1, label, _resultSchema, schema.getTimestamp());
//renamedSchema = new AttributeSchemaNode(schema.id(), label, _resultSchema, schema.getTimestamp());
} else {
renamedSchema = new GroupSchemaNode(-1, label, _resultSchema, schema.getTimestamp());
//renamedSchema = new GroupSchemaNode(schema.id(), label, _resultSchema, schema.getTimestamp());
for (int iChild = 0; iChild < ((GroupSchemaNode)schema).children().size(); iChild++) {
((GroupSchemaNode)renamedSchema).children().add(((GroupSchemaNode)schema).children().get(iChild));
}
}
}
} catch (org.dbwiki.exception.WikiException wikiException) {
wikiException.printStackTrace();
return;
}
}
Vector<DatabaseElementNode> outputNodes = new Vector<DatabaseElementNode>();
for (SubTreeSelectStatement stmt : _statements) {
DatabaseElementNode node = nodeSet.get(stmt.targetPath().variableName());
QueryOutputNodeCollector nodeMarker = null;
if(stmt.label() == null)
nodeMarker = new QueryOutputNodeCollector(outputNodes);
else
try {
nodeMarker = new QueryOutputNodeCollector(outputNodes, _resultSchema.find(stmt.label()));
} catch (WikiException e) {
e.printStackTrace();
}
new RelativeXPathConsumer().consume(node, stmt.targetPath(), nodeMarker);
}
if (outputNodes.size() > 0) {
TimeSequence timestamp = null;
for (int iNode = 0; iNode < outputNodes.size(); iNode++) {
DatabaseElementNode node = outputNodes.get(iNode);
if (timestamp != null) {
timestamp = timestamp.union(node.getTimestamp());
} else {
timestamp = node.getTimestamp();
}
}
DatabaseGroupNode result = new ResultGroupNode(_resultSchema, timestamp);