From a56cdaee59abaa428b3351b6aab91d0cf32dace5 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 14 Aug 2009 11:42:42 +0000 Subject: [PATCH] * Reenable prefetchChildren() for grouped subnodes. * Make Subnodelist.add()/get() type-safe by using NodeHandle instead of java.lang.Object. --- src/helma/objectmodel/db/Node.java | 2 +- src/helma/objectmodel/db/NodeManager.java | 44 +++++++------------ .../objectmodel/db/SegmentedSubnodeList.java | 20 ++++----- src/helma/objectmodel/db/SubnodeList.java | 25 +++++------ 4 files changed, 39 insertions(+), 52 deletions(-) diff --git a/src/helma/objectmodel/db/Node.java b/src/helma/objectmodel/db/Node.java index d2f8b65d..c30ecd29 100644 --- a/src/helma/objectmodel/db/Node.java +++ b/src/helma/objectmodel/db/Node.java @@ -1119,7 +1119,7 @@ public final class Node implements INode, Serializable { for (int i = 0; i < l; i++) try { - NodeHandle shandle = (NodeHandle) subnodes.get(i); + NodeHandle shandle = subnodes.get(i); if (subid.equals(shandle.getID())) { // System.err.println ("FOUND SUBNODE: "+shandle); diff --git a/src/helma/objectmodel/db/NodeManager.java b/src/helma/objectmodel/db/NodeManager.java index 4660e15a..f7a0322f 100644 --- a/src/helma/objectmodel/db/NodeManager.java +++ b/src/helma/objectmodel/db/NodeManager.java @@ -1039,7 +1039,7 @@ public final class NodeManager { protected List collectMissingKeys(SubnodeList list, int start, int length) { List retval = null; for (int i = start; i < start + length; i++) { - NodeHandle handle = (NodeHandle) list.get(i); + NodeHandle handle = list.get(i); if (handle != null && !cache.containsKey(handle.getKey())) { if (retval == null) { retval = new ArrayList(); @@ -1121,18 +1121,25 @@ public final class NodeManager { // group nodes. String groupName = null; - /* if (groupbyProp != null) { + if (groupbyProp != null) { groupName = node.getString(groupbyProp); + if (groupName != null) { + Node groupNode = (Node) groupbySubnodes.get(groupName); - SubnodeList sn = (SubnodeList) groupbySubnodes.get(groupName); + if (groupNode == null) { + groupNode = home.getGroupbySubnode(groupName, true); + groupbySubnodes.put(groupName, groupNode); + } - if (sn == null) { - sn = new SubnodeList(safe, rel); - groupbySubnodes.put(groupName, sn); + SubnodeList subnodes = groupNode.getSubnodeList(); + if (subnodes == null) { + subnodes = groupNode.createSubnodeList(); + // mark subnodes as up-to-date + subnodes.lastSubnodeFetch = subnodes.getLastSubnodeChange(); + } + subnodes.add(new NodeHandle(key)); } - - sn.add(new NodeHandle(key)); - } */ + } // if relation doesn't use primary key as accessName, get secondary key if (accessProp != null) { @@ -1151,28 +1158,9 @@ public final class NodeManager { // register new nodes with the cache. If an up-to-date copy // existed in the cache, use that. registerNewNode(node, secondaryKey); - fetchJoinedNodes(rs, joins, columns.length); } - // If these are grouped nodes, build the intermediary group nodes - // with the subnod lists we created - /* if (groupbyProp != null) { - for (Iterator i = groupbySubnodes.keySet().iterator(); - i.hasNext();) { - String groupname = (String) i.next(); - - if (groupname == null) { - continue; - } - - Node groupnode = home.getGroupbySubnode(groupname, true); - - groupnode.setSubnodes((SubnodeList) groupbySubnodes.get(groupname)); - groupnode.lastSubnodeFetch = - groupnode.getLastSubnodeChange(groupnode.dbmap.getSubnodeRelation()); - } - } */ } catch (Exception x) { app.logError("Error in prefetchNodes()", x); } finally { diff --git a/src/helma/objectmodel/db/SegmentedSubnodeList.java b/src/helma/objectmodel/db/SegmentedSubnodeList.java index 2441012b..01d1d2cb 100644 --- a/src/helma/objectmodel/db/SegmentedSubnodeList.java +++ b/src/helma/objectmodel/db/SegmentedSubnodeList.java @@ -33,34 +33,34 @@ public class SegmentedSubnodeList extends SubnodeList { * Adds the specified object to this list performing * custom ordering * - * @param obj element to be inserted. + * @param handle element to be inserted. */ - public synchronized boolean add(Object obj) { + public synchronized boolean add(NodeHandle handle) { if (!hasRelationalNodes() || segments == null) { - return super.add(obj); + return super.add(handle); } if (subnodeCount == -1) { update(); } subnodeCount++; segments[segments.length - 1].length += 1; - return list.add(obj); + return list.add(handle); } /** * Adds the specified object to the list at the given position * @param index the index to insert the element at - * @param obj the object t add + * @param handle the object to add */ - public synchronized void add(int index, Object obj) { + public synchronized void add(int index, NodeHandle handle) { if (!hasRelationalNodes() || segments == null) { - super.add(index, obj); + super.add(index, handle); return; } if (subnodeCount == -1) { update(); } subnodeCount++; - list.add(index, obj); + list.add(index, handle); // shift segment indices by one int s = getSegment(index); segments[s].length += 1; @@ -69,7 +69,7 @@ public class SegmentedSubnodeList extends SubnodeList { } } - public Object get(int index) { + public NodeHandle get(int index) { if (!hasRelationalNodes() || segments == null) { return super.get(index); } @@ -77,7 +77,7 @@ public class SegmentedSubnodeList extends SubnodeList { return null; } loadSegment(getSegment(index), false); - return list.get(index); + return (NodeHandle) list.get(index); } public synchronized boolean contains(Object object) { diff --git a/src/helma/objectmodel/db/SubnodeList.java b/src/helma/objectmodel/db/SubnodeList.java index 8c6f5985..b01e3dea 100644 --- a/src/helma/objectmodel/db/SubnodeList.java +++ b/src/helma/objectmodel/db/SubnodeList.java @@ -50,30 +50,30 @@ public class SubnodeList implements Serializable { * Adds the specified object to this list performing * custom ordering * - * @param obj element to be inserted. + * @param handle element to be inserted. */ - public boolean add(Object obj) { - return list.add(obj); + public boolean add(NodeHandle handle) { + return list.add(handle); } /** * Adds the specified object to the list at the given position * @param idx the index to insert the element at - * @param obj the object t add + * @param handle the object to add */ - public void add(int idx, Object obj) { - list.add(idx, obj); + public void add(int idx, NodeHandle handle) { + list.add(idx, handle); } - public Object get(int index) { + public NodeHandle get(int index) { if (index < 0 || index >= list.size()) { return null; } - return list.get(index); + return (NodeHandle) list.get(index); } public Node getNode(int index) { Node retval = null; - NodeHandle handle = (NodeHandle) get(index); + NodeHandle handle = get(index); if (handle != null) { retval = handle.getNode(node.nmgr); @@ -149,12 +149,11 @@ public class SubnodeList implements Serializable { } DbMapping dbmap = getSubnodeMapping(); - Relation rel = getSubnodeRelation(); - if (!dbmap.isRelational() || rel.getGroup() != null) { - return; + if (dbmap.isRelational()) { + Relation rel = getSubnodeRelation(); + node.nmgr.prefetchNodes(node, rel, this, start, length); } - node.nmgr.prefetchNodes(node, rel, this, start, length); } /**