" AND v2.n_entry=v1.entry" +
" ORDER BY n_id, t_start, a_id ");
DatabaseNode node = null;
int i=0;
while (rs.next()) {
i++;
int id = rs.getInt(ViewDataColNodeID);
// System.out.println(id);
// The following condition allows information about nodes to be built up
// incrementally when spread across multiple rows.
//
// It relies on the results being ordered first by node id.
//
// A single node id may appear in consecutive rows if the
// node has existed in multiple time intervals, or if it has
// multiple annotations.
if (node == null || ((NodeIdentifier)node.identifier()).nodeID() != id) {
int schema = rs.getInt(ViewDataColNodeSchema);
int parent = rs.getInt(ViewDataColNodeParent);
int pre = rs.getInt(ViewDataColNodePre);
int post = rs.getInt(ViewDataColNodePost);
if (schema != RelDataColSchemaValUnknown) {
// FIXME #database: This seems to assume that the nodes are in parent-child order.
// The following logic seems rather fragile.
// It isn't at all clear that things will
// work properly if a child node is encountered
// in the result set before its parent.
//
// There doesn't appear to be any code for
// connecting up parents to children later on.
//
// It may be that the problematic situation
// never occurs. This seems quite likely, as
// child nodes are always going to be created
// after their parents, and ids are assigned
// in sequence. If this is the case, then
// the constraint should be explicitly stated
// in the data model, we should implement code
// for checking that the constraint hasn't been
// violated, and the following null-checking code
// should be removed.
RDBMSDatabaseGroupNode parentNode = null;
if (parent != RelDataColParentValUnknown) {
parentNode = (RDBMSDatabaseGroupNode)nodeIndex.get(new Integer(parent));
}
SchemaNode schemaNode = database.schema().get(schema);
if (schemaNode.isAttribute()) {
node = new RDBMSDatabaseAttributeNode(id, (AttributeSchemaNode)schemaNode, parentNode, pre, post);
} else {
node = new RDBMSDatabaseGroupNode(id, (GroupSchemaNode)schemaNode, parentNode, pre, post);
}
if (parentNode != null) {
parentNode.children().add((DatabaseElementNode)node);
}
} else {
RDBMSDatabaseAttributeNode parentNode = (RDBMSDatabaseAttributeNode)nodeIndex.get(new Integer(parent));
node = new RDBMSDatabaseTextNode(id, parentNode, rs.getString(ViewDataColNodeValue));
parentNode.value().add((DatabaseTextNode)node);
}
nodeIndex.put(new Integer(id), node);
}
int end = RelTimestampColEndValOpen;
int start = rs.getInt(ViewDataColTimestampStart);
if (!rs.wasNull()) {
end = rs.getInt(ViewDataColTimestampEnd);
if (!node.hasTimestamp()) {
node.setTimestamp(new TimeSequence(start, end));
} else {
node.getTimestamp().elongate(start, end);
}
}
int annotationID = rs.getInt(ViewDataColAnnotationID);
if (!rs.wasNull()) {
if (!node.annotation().contains(annotationID)) {
node.annotation().add(new Annotation(annotationID, rs.getString(ViewDataColAnnotationText), rs.getString(ViewDataColAnnotationDate), database.users().get(rs.getInt(ViewDataColAnnotationUser))));
}
}
}
System.out.println(i);
rs.close();