diff --git a/src/helma/objectmodel/db/Node.java b/src/helma/objectmodel/db/Node.java index 95fa4997..fe4322c1 100644 --- a/src/helma/objectmodel/db/Node.java +++ b/src/helma/objectmodel/db/Node.java @@ -199,8 +199,9 @@ public final class Node implements INode, Serializable { this.nmgr = nmgr; this.prototype = prototype; dbmap = nmgr.getDbMapping (prototype); - // the id is only generated when the node is actually checked into db. - // id = nmgr.generateID (dbmap); + // the id is only generated when the node is actually checked into db, + // or when it's explicitly requested. + id = null; this.name = n == null ? "" : n; created = lastmodified = System.currentTimeMillis (); adoptName = true; @@ -401,22 +402,24 @@ public final class Node implements INode, Serializable { */ public String getID () { - if (state == TRANSIENT) { - Thread.dumpStack (); - throw new RuntimeException ("getID called on transient Node: "+this); - } + // if we are transient, we generate an id on demand. It's possible that we'll never need + // it, but if we do it's important to keep the one we have. + if (state == TRANSIENT && id == null) + id = nmgr.generateID (dbmap); return id; } - protected void setID (String id) { - this.id = id; - ((Transactor) Thread.currentThread()).visitCleanNode (this); - } - + /** + * Returns true if this node is accessed by id from its aprent, false if it + * is accessed by name + */ public boolean isAnonymous () { return anonymous; } + /** + * Return this node' name, which may or may not have some meaning + */ public String getName () { return name; } @@ -1660,7 +1663,9 @@ public final class Node implements INode, Serializable { protected void makePersistentCapable () { if (state == TRANSIENT) { state = NEW; - id = nmgr.generateID (dbmap); + // generate a real, persistent ID for this object, if it doesn't have one already. + if (id == null) + id = nmgr.generateID (dbmap); getHandle ().becomePersistent (); Transactor current = (Transactor) Thread.currentThread (); current.visitNode (this); diff --git a/src/helma/objectmodel/db/NodeHandle.java b/src/helma/objectmodel/db/NodeHandle.java index 101b118c..3908d0e3 100644 --- a/src/helma/objectmodel/db/NodeHandle.java +++ b/src/helma/objectmodel/db/NodeHandle.java @@ -77,7 +77,7 @@ public final class NodeHandle implements INodeState, Serializable { */ public String getID () { if (key == null) - throw new RuntimeException ("getID called on transient Node"); + return node.getID (); return key.getID (); }