From 55e58ab509d6e353a4f07e8d4352d37e42139a7b Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 13 Aug 2001 17:04:07 +0000 Subject: [PATCH] making nodes transient that do have child nodes should now work, because loadnodes no longer throws the existing nodes away to see if there are some in the database. dump stack traces on getKey and getID for transient nodes. --- src/helma/objectmodel/db/Node.java | 55 +++++++++++++++++------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/helma/objectmodel/db/Node.java b/src/helma/objectmodel/db/Node.java index 9ee3370a..52699608 100644 --- a/src/helma/objectmodel/db/Node.java +++ b/src/helma/objectmodel/db/Node.java @@ -410,8 +410,10 @@ public final class Node implements INode, Serializable { */ public String getID () { - if (state == TRANSIENT) + if (state == TRANSIENT) { + Thread.dumpStack (); throw new RuntimeException ("getID called on transient Node: "+this); + } return id; } @@ -536,8 +538,10 @@ public final class Node implements INode, Serializable { } public Key getKey () { - if (state == TRANSIENT) + if (state == TRANSIENT) { + Thread.dumpStack (); throw new RuntimeException ("getKey called on transient Node: "+this); + } if (dbmap == null && prototype != null && nmgr != null) dbmap = nmgr.getDbMapping (prototype); if (primaryKey == null) @@ -1178,6 +1182,10 @@ public final class Node implements INode, Serializable { * ID index or the actual nodes. */ protected void loadNodes () { + // Don't do this for transient nodes which don't have an explicit subnode relation set + if ((state == TRANSIENT || state == NEW) && subnodeRelation == null) + return; + DbMapping smap = dbmap == null ? null : dbmap.getSubnodeMapping (); if (smap != null && smap.isRelational ()) { // check if subnodes need to be reloaded @@ -1647,16 +1655,17 @@ public final class Node implements INode, Serializable { prop.nhandle = new NodeHandle (new DbKey (n.getDbMapping (), kval, rel.getRemoteField ())); } - String nID = n.getID(); - - // check node in with transactor cache - Transactor tx = (Transactor) Thread.currentThread (); - tx.visitCleanNode (new DbKey (nmap, nID), n); - // if the field is not the primary key of the property, also register it - if (rel != null && rel.direction == Relation.DIRECT) { - Key secKey = new SyntheticKey (getKey (), propname); - nmgr.evictKey (secKey); - tx.visitCleanNode (secKey, n); + if (n.state != TRANSIENT) { + // check node in with transactor cache + String nID = n.getID(); + Transactor tx = (Transactor) Thread.currentThread (); + tx.visitCleanNode (new DbKey (nmap, nID), n); + // if the field is not the primary key of the property, also register it + if (rel != null && rel.direction == Relation.DIRECT) { + Key secKey = new SyntheticKey (getKey (), propname); + nmgr.evictKey (secKey); + tx.visitCleanNode (secKey, n); + } } lastmodified = System.currentTimeMillis (); @@ -1781,19 +1790,19 @@ public final class Node implements INode, Serializable { Transactor current = (Transactor) Thread.currentThread (); current.visitNode (this); current.visitCleanNode (this); - } - for (Enumeration e = getSubnodes (); e.hasMoreElements (); ) { - Node n = (Node) e.nextElement (); - if (n.state == TRANSIENT) - n.makePersistentCapable (); - } - for (Enumeration e = properties (); e.hasMoreElements (); ) { - IProperty next = get ((String) e.nextElement (), false); - if (next != null && next.getType () == IProperty.NODE) { - Node n = (Node) next.getNodeValue (); - if (n != null && n.state == TRANSIENT) + for (Enumeration e = getSubnodes (); e.hasMoreElements (); ) { + Node n = (Node) e.nextElement (); + if (n.state == TRANSIENT) n.makePersistentCapable (); } + for (Enumeration e = properties (); e.hasMoreElements (); ) { + IProperty next = get ((String) e.nextElement (), false); + if (next != null && next.getType () == IProperty.NODE) { + Node n = (Node) next.getNodeValue (); + if (n != null && n.state == TRANSIENT) + n.makePersistentCapable (); + } + } } }