From 2a4d03ac13aedffdbf3ebf10adcc9bd9f9442e81 Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 12 Sep 2002 17:18:45 +0000 Subject: [PATCH] Implemented experimental prefetchChildren method on nodes. Try calling prefetchChildren(start, length) on internal node objects. Works also on nodes with groupby-collections. Null columns from the DB are now set to Properties, which required some fixes when converting a string (or other) property to a node reference. --- src/helma/objectmodel/db/Node.java | 62 ++++++---- src/helma/objectmodel/db/NodeManager.java | 132 +++++++++++++++++++--- src/helma/objectmodel/db/Property.java | 35 ++++-- src/helma/objectmodel/db/Relation.java | 21 +++- 4 files changed, 205 insertions(+), 45 deletions(-) diff --git a/src/helma/objectmodel/db/Node.java b/src/helma/objectmodel/db/Node.java index 811999cc..3233b9ac 100644 --- a/src/helma/objectmodel/db/Node.java +++ b/src/helma/objectmodel/db/Node.java @@ -127,16 +127,16 @@ public final class Node implements INode, Serializable { /** * used by Xml deserialization */ - public void setPropMap (Hashtable propMap) { + public void setPropMap (Hashtable propMap) { this.propMap = propMap; - } + } /** * used by Xml deserialization */ - public void setSubnodes (List subnodes) { + public void setSubnodes (List subnodes) { this.subnodes = subnodes; -} + } private transient String prototype; @@ -282,12 +282,14 @@ public final class Node implements INode, Serializable { Value val = rec.getValue (rel.getDbField ()); - if (val.isNull ()) - continue; + // if (val.isNull ()) + // continue; Property newprop = new Property (rel.propName, this); - switch (val.type ()) { + if (val.isNull ()) + newprop.setStringValue (null); + else switch (val.type ()) { case Types.BIT: newprop.setBooleanValue (val.asBoolean()); @@ -335,7 +337,9 @@ public final class Node implements INode, Serializable { break; case Types.NULL: - continue; + newprop.setStringValue (null); + break; + // continue; default: newprop.setStringValue (val.asString()); @@ -345,15 +349,17 @@ public final class Node implements INode, Serializable { if(propMap == null) propMap = new Hashtable (); propMap.put (rel.propName.toLowerCase(), newprop); - // mark property as clean, since it's fresh from the db - newprop.dirty = false; // if the property is a pointer to another node, change the property type to NODE if (rel.reftype == Relation.REFERENCE && rel.usesPrimaryKey ()) { // FIXME: References to anything other than the primary key are not supported - newprop.nhandle = new NodeHandle (new DbKey (rel.otherType, newprop.getStringValue ())); - newprop.type = IProperty.NODE; + newprop.convertToNodeReference (rel.otherType); + // newprop.nhandle = new NodeHandle (new DbKey (rel.otherType, newprop.getStringValue ())); + // newprop.type = IProperty.NODE; } + + // mark property as clean, since it's fresh from the db + newprop.dirty = false; } // again set created and lastmodified. This is because // lastmodified has been been updated, and we want both values to @@ -916,7 +922,7 @@ public final class Node implements INode, Serializable { Node retval = null; if (subid != null) { - + loadNodes (); if (subnodes == null || subnodes.size() == 0) return null; @@ -1109,7 +1115,7 @@ public final class Node implements INode, Serializable { if (propMap != null) { for (Enumeration e2 = propMap.elements (); e2.hasMoreElements (); ) { Property p = (Property) e2.nextElement (); - if (p != null && p.type == Property.NODE) + if (p != null && p.getType() == Property.NODE) p.unregisterNode (); } } @@ -1215,6 +1221,23 @@ public final class Node implements INode, Serializable { } } + public void prefetchChildren (int startIndex, int length) throws Exception { + if (length < 1) + return; + if (startIndex < 0) + return; + loadNodes (); + if (subnodes == null) + return; + int l = Math.min (subnodes.size()-startIndex, length); + if (l < 1) + return; + Key[] keys = new Key[l]; + for (int i=startIndex; i 0) { + TableDataSet tds = new TableDataSet (dbm.getConnection (), + dbm.getSchema (), + dbm.getKeyDef ()); + try { + String idfield = rel.groupby != null ? rel.groupby : dbm.getIDField (); + boolean needsQuotes = dbm.needsQuotes (idfield); + StringBuffer whereBuffer = new StringBuffer (idfield); + whereBuffer.append (" in ("); + boolean first = true; + for (int i=0; i