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.
This commit is contained in:
stefanp 2002-10-02 10:10:29 +00:00
parent 8f519432b8
commit 6b8d8b426c
3 changed files with 34 additions and 6 deletions

View file

@ -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

View file

@ -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
*/

View file

@ -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));
}
}