NodeHandle is now notified when its Node switches

from transient to persistent state so it doesn't have
to  check itself each time the node is accessed.
This commit is contained in:
hns 2001-08-05 19:29:55 +00:00
parent 0332e4c430
commit a22bde81ad

View file

@ -58,18 +58,8 @@ public final class NodeHandle implements INodeState, Serializable {
* Get the node described by this node handle
*/
public Node getNode (WrappedNodeManager nodemgr) {
if (node != null) {
int state = node.getState ();
if (state == TRANSIENT)
if (node != null)
return node;
else {
// this node went from TRANSIENT to some other state.
// It's time to say goodby to the direct reference, from now on
// we'll have to fetch let the node manager fetch it.
key = node.getKey ();
node = null;
}
}
return nodemgr.getNode (key);
}
@ -91,22 +81,10 @@ public final class NodeHandle implements INodeState, Serializable {
return key.getID ();
}
public DbMapping getDbMapping (WrappedNodeManager nmgr) {
if (dbmap == null) {
if (node != null)
dbmap = node.getDbMapping ();
else
dbmap = nmgr.getDbMapping (key.getStorageName ());
}
return dbmap;
}
private Object getObject () {
if (node != null) {
if (node.getState () != TRANSIENT)
return node.getKey ();
if (node != null)
return node;
}
else
return key;
}
@ -118,13 +96,22 @@ public final class NodeHandle implements INodeState, Serializable {
}
}
public String toString () {
/**
* This is to notify the handle that the underlying node is becoming
* persistent and we have to refer to it via the key from now on.
*/
protected void becomePersistent () {
if (node != null) {
if (node.getState () == TRANSIENT)
key = node.getKey ();
node = null;
}
}
public String toString () {
if (node != null)
return "NodeHandle[transient:"+node+"]";
else
key = node.getKey ();
}
return "NodeHandle["+key+"]";
}