switch from one nullNode for all to one per cache entry in order to check validity

This commit is contained in:
hns 2001-05-25 14:17:06 +00:00
parent af75604e00
commit 3bdb0e3598

View file

@ -40,7 +40,7 @@ public final class NodeManager {
public final WrappedNodeManager safe; public final WrappedNodeManager safe;
// an instance of Node that's used to cache null values // an instance of Node that's used to cache null values
private Node nullNode; // private Node nullNode;
public NodeManager (Application app, String dbHome, Properties props) throws DbException { public NodeManager (Application app, String dbHome, Properties props) throws DbException {
this.app = app; this.app = app;
@ -51,7 +51,7 @@ public final class NodeManager {
app.logEvent ("set up node cache ("+cacheSize+")"); app.logEvent ("set up node cache ("+cacheSize+")");
safe = new WrappedNodeManager (this); safe = new WrappedNodeManager (this);
nullNode = new Node ("nullNode", "nullNode", null, safe); // nullNode = new Node ("nullNode", "nullNode", null, safe);
String replicationUrl = props.getProperty ("replicationUrl"); String replicationUrl = props.getProperty ("replicationUrl");
if (replicationUrl != null) if (replicationUrl != null)
@ -172,7 +172,7 @@ public final class NodeManager {
if (node != null) { if (node != null) {
synchronized (cache) { synchronized (cache) {
Node oldnode = (Node) cache.put (node.getKey (), node); Node oldnode = (Node) cache.put (node.getKey (), node);
if (oldnode != null && oldnode.getState () != Node.INVALID && oldnode != nullNode) { if (oldnode != null && oldnode.getState () != Node.INVALID && !(oldnode instanceof NullNode)) {
cache.put (node.getKey (), oldnode); cache.put (node.getKey (), oldnode);
node = oldnode; node = oldnode;
} }
@ -222,8 +222,8 @@ public final class NodeManager {
// we need further checks for subnodes fetched by name if the subnodes were changed. // we need further checks for subnodes fetched by name if the subnodes were changed.
if (rel.subnodesAreProperties && node != null && node.getState() != Node.INVALID) { if (rel.subnodesAreProperties && node != null && node.getState() != Node.INVALID) {
// check if node is null node (cached null) // check if node is null node (cached null)
if (node == nullNode) if (node instanceof NullNode && node.created() < rel.other.lastDataChange)
; // TODO: perform null validity test node = null; // cached null not valid anymore
else if (home.contains (node) < 0) else if (home.contains (node) < 0)
node = null; node = null;
} }
@ -243,7 +243,7 @@ public final class NodeManager {
// check if node is already in cache with primary key // check if node is already in cache with primary key
Node oldnode = (Node) cache.put (primKey, node); Node oldnode = (Node) cache.put (primKey, node);
// no need to check for oldnode != node because we fetched a new node from db // no need to check for oldnode != node because we fetched a new node from db
if (oldnode != null && oldnode != nullNode && oldnode.getState () != Node.INVALID) { if (oldnode != null && !(oldnode instanceof NullNode) && oldnode.getState () != Node.INVALID) {
cache.put (primKey, oldnode); cache.put (primKey, oldnode);
if (!keyIsPrimary) { if (!keyIsPrimary) {
cache.put (key, oldnode); cache.put (key, oldnode);
@ -257,9 +257,9 @@ public final class NodeManager {
} else { } else {
// node fetched from db is null, cache result using nullNode // node fetched from db is null, cache result using nullNode
synchronized (cache) { synchronized (cache) {
Node oldnode = (Node) cache.put (key, nullNode); Node oldnode = (Node) cache.put (key, new NullNode ());
// for the rare case that some other thread created the node in the meantime // for the rare case that some other thread created the node in the meantime
if (oldnode != null && oldnode != nullNode && oldnode.getState () != Node.INVALID) { if (oldnode != null && !(oldnode instanceof NullNode) && oldnode.getState () != Node.INVALID) {
Key primKey = oldnode.getKey (); Key primKey = oldnode.getKey ();
boolean keyIsPrimary = primKey.equals (key); boolean keyIsPrimary = primKey.equals (key);
cache.put (oldnode.getKey (), oldnode); cache.put (oldnode.getKey (), oldnode);
@ -272,7 +272,7 @@ public final class NodeManager {
} }
} }
} }
} else if (node == nullNode) { } else if (!(node instanceof NullNode)) {
// the nullNode caches a null value, i.e. an object that doesn't exist // the nullNode caches a null value, i.e. an object that doesn't exist
return null; return null;
} else { } else {
@ -619,7 +619,7 @@ public final class NodeManager {
// if these are groupby nodes, evict nullNode keys // if these are groupby nodes, evict nullNode keys
if (rel.groupby != null) { if (rel.groupby != null) {
Key key = new Key ((String) null, home.getKey ().getVirtualID (kstr)); Key key = new Key ((String) null, home.getKey ().getVirtualID (kstr));
if (cache.get (key) == nullNode) if (cache.get (key) instanceof NullNode)
evictKey (key); evictKey (key);
} }
} }
@ -983,6 +983,7 @@ public final class NodeManager {
DbMapping dbm = app.getDbMapping (n.getPrototype ()); DbMapping dbm = app.getDbMapping (n.getPrototype ());
if (dbm != null) if (dbm != null)
dbm.lastDataChange = System.currentTimeMillis (); dbm.lastDataChange = System.currentTimeMillis ();
n.lastParentSet = -1;
n.setDbMapping (dbm); n.setDbMapping (dbm);
n.nmgr = safe; n.nmgr = safe;
cache.put (n.getKey(), n); cache.put (n.getKey(), n);