Extended prefetchChildren to push secondary keys into the cache.

This commit is contained in:
hns 2002-09-13 15:45:11 +00:00
parent be1dd61a19
commit 3d6da645c5

View file

@ -823,6 +823,10 @@ public final class NodeManager {
groupbySubnodes = new HashMap(); groupbySubnodes = new HashMap();
} }
String accessProp = null;
if (rel.accessor != null && !rel.usesPrimaryKey ())
accessProp = dbm.columnNameToProperty (rel.accessor);
for (int i=0; i<tds.size (); i++) { for (int i=0; i<tds.size (); i++) {
// create new Nodes. // create new Nodes.
Record rec = tds.getRecord (i); Record rec = tds.getRecord (i);
@ -831,22 +835,36 @@ public final class NodeManager {
// for grouped nodes, collect subnode lists for the intermediary // for grouped nodes, collect subnode lists for the intermediary
// group nodes. // group nodes.
String groupName = null;
if (groupbyProp != null) { if (groupbyProp != null) {
String groupbyName = node.getString (groupbyProp, false); groupName = node.getString (groupbyProp, false);
List sn = (List) groupbySubnodes.get (groupbyName); List sn = (List) groupbySubnodes.get (groupName);
if (sn == null) { if (sn == null) {
sn = new ExternalizableVector (); sn = new ExternalizableVector ();
groupbySubnodes.put (groupbyName, sn); groupbySubnodes.put (groupName, sn);
} }
sn.add (new NodeHandle (primKey)); sn.add (new NodeHandle (primKey));
} }
// if relation doesn't use primary key as accessor, get accessor value
String accessName = null;
if (accessProp != null) {
accessName = node.getString (accessProp, false);
}
// register new nodes with the cache. If an up-to-date copy // register new nodes with the cache. If an up-to-date copy
// existed in the cache, use that. // existed in the cache, use that.
synchronized (cache) { synchronized (cache) {
Node oldnode = (Node) cache.put (primKey, node); Node oldnode = (Node) cache.put (primKey, node);
if (oldnode != null && oldnode.getState() != INode.INVALID) { if (oldnode != null && oldnode.getState() != INode.INVALID) {
// found an ok version in the cache, use it.
cache.put (primKey, oldnode); cache.put (primKey, oldnode);
} else if (accessName != null) {
// put the node into cache with its secondary key
if (groupName != null)
cache.put (new SyntheticKey (new SyntheticKey (home.getKey(), groupName), accessName), node);
else
cache.put (new SyntheticKey (home.getKey(), accessName), node);
} }
} }
} }