From 6b8d8b426ce98685a502c925314cbdf2c37da841 Mon Sep 17 00:00:00 2001 From: stefanp Date: Wed, 2 Oct 2002 10:10:29 +0000 Subject: [PATCH] extended invalidate() method: object.invalidate (key) searches for a child object with the given primary key or accessname and evicts this object from the cache. if the object isn't loaded nothing is done. --- src/helma/objectmodel/db/Node.java | 18 ++++++++++++++++++ src/helma/scripting/fesi/ESNode.java | 15 +++++++++++++++ src/helma/scripting/fesi/HopExtension.java | 7 +------ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/helma/objectmodel/db/Node.java b/src/helma/objectmodel/db/Node.java index f87c33a6..eb13aa7e 100644 --- a/src/helma/objectmodel/db/Node.java +++ b/src/helma/objectmodel/db/Node.java @@ -437,6 +437,24 @@ public final class Node implements INode, Serializable { nmgr.evictNode (this); } + /** + * Check for a child mapping and evict the object specified by key from the cache + */ + public void invalidateNode (String key) { + // This doesn't make sense for transient nodes + if (state == TRANSIENT || state == NEW) + return; + checkWriteLock (); // ?? necessary ?? + Relation rel = getDbMapping ().getSubnodeRelation (); + if (rel != null) { + if (rel.usesPrimaryKey()) { + nmgr.evictKey (new DbKey (getDbMapping().getSubnodeMapping(), key)); + } else { + nmgr.evictKey (new SyntheticKey (getKey(), key)); + } + } + } + /** * Get the ID of this Node. This is the primary database key and used as part of the diff --git a/src/helma/scripting/fesi/ESNode.java b/src/helma/scripting/fesi/ESNode.java index 0f65ebbf..401b363b 100644 --- a/src/helma/scripting/fesi/ESNode.java +++ b/src/helma/scripting/fesi/ESNode.java @@ -177,6 +177,21 @@ public class ESNode extends ObjectPrototype { return true; } + /** + * Invalidate the node itself or a subnode + */ + public boolean invalidate (ESValue args[]) { + if (node instanceof helma.objectmodel.db.Node) { + if (args.length == 0) { + ((helma.objectmodel.db.Node) node).invalidate (); + } else { + ((helma.objectmodel.db.Node) node).invalidateNode (args[0].toString ()); + } + } + return true; + } + + /** * Check if node is contained in subnodes */ diff --git a/src/helma/scripting/fesi/HopExtension.java b/src/helma/scripting/fesi/HopExtension.java index 0ad21fac..318c5fbd 100644 --- a/src/helma/scripting/fesi/HopExtension.java +++ b/src/helma/scripting/fesi/HopExtension.java @@ -236,12 +236,7 @@ public final class HopExtension { } public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException { ESNode esn = (ESNode) thisObject; - INode node = esn.getNode (); - if (node instanceof helma.objectmodel.db.Node) { - ((helma.objectmodel.db.Node) node).invalidate (); - esn.checkNode (); - } - return ESBoolean.makeBoolean (true); + return ESBoolean.makeBoolean (esn.invalidate (arguments)); } }