lazy creation of cache node.

reintroduced created and lastmodified properities as
__internal__ props.
This commit is contained in:
hns 2001-08-25 20:00:23 +00:00
parent ca54d3fccc
commit 974407a516

View file

@ -23,16 +23,22 @@ import java.util.*;
public class ESNode extends ObjectPrototype { public class ESNode extends ObjectPrototype {
INode node; INode node;
// the cache node - persistent nodes have a transient property as a commodity to
// store temporary stuff.
INode cache; INode cache;
// the ecmascript wrapper for the cache.
ESObject cacheWrapper;
// The handle of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node. // The handle of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node.
NodeHandle handle; NodeHandle handle;
DbMapping dbmap; DbMapping dbmap;
ESObject cacheWrapper;
Throwable lastError = null; Throwable lastError = null;
RequestEvaluator eval; RequestEvaluator eval;
// used to create cache nodes /**
* Constructor used to create transient cache nodes
*/
protected ESNode (INode node, RequestEvaluator eval) { protected ESNode (INode node, RequestEvaluator eval) {
super (eval.esNodePrototype, eval.evaluator); super (eval.esNodePrototype, eval.evaluator);
this.eval = eval; this.eval = eval;
@ -40,11 +46,8 @@ public class ESNode extends ObjectPrototype {
cache = null; cache = null;
cacheWrapper = null; cacheWrapper = null;
// set node handle to wrapped node // this is a transient node, set node handle to null
if (node instanceof helma.objectmodel.db.Node) handle = null;
handle = ((helma.objectmodel.db.Node) node).getHandle ();
else
handle = null;
} }
public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) { public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) {
@ -60,14 +63,14 @@ public class ESNode extends ObjectPrototype {
else else
node = new TransientNode (obj.toString ()); node = new TransientNode (obj.toString ());
// set node handle to wrapped node // set node handle to wrapped node
if (node instanceof helma.objectmodel.db.Node) if (node instanceof Node)
handle = ((helma.objectmodel.db.Node) node).getHandle (); handle = ((Node) node).getHandle ();
else else
handle = null; handle = null;
// get transient cache Node // cache Node is initialized on demend when it is needed
cache = node.getCacheNode (); cache = null;
cacheWrapper = new ESNode (cache, eval); cacheWrapper = null;
} }
/** /**
@ -94,9 +97,9 @@ public class ESNode extends ObjectPrototype {
else else
handle = null; handle = null;
eval.objectcache.put (node, this); eval.objectcache.put (node, this);
// get transient cache Node // reset cache Node - will be reinitialized when needed
cache = node.getCacheNode (); cache = null;
cacheWrapper = new ESNode (cache, eval); cacheWrapper = null;
} }
} }
@ -297,14 +300,21 @@ public class ESNode extends ObjectPrototype {
public ESValue getProperty(String propertyName, int hash) throws EcmaScriptException { public ESValue getProperty(String propertyName, int hash) throws EcmaScriptException {
checkNode (); checkNode ();
// eval.app.logEvent ("get property called: "+propertyName); // eval.app.logEvent ("get property called: "+propertyName);
ESValue retval = super.getProperty (propertyName, hash); ESValue retval = super.getProperty (propertyName, hash);
if (! (retval instanceof ESUndefined)) if (! (retval instanceof ESUndefined))
return retval; return retval;
if ("cache".equalsIgnoreCase (propertyName) && cache != null) // persistent or persistent capable nodes have a cache property that's a transient node.
return cacheWrapper; // it it hasn't requested before, initialize it now
if ("cache".equalsIgnoreCase (propertyName) && node instanceof Node) {
if (cacheWrapper == null) {
cache = node.getCacheNode ();
cacheWrapper = new ESNode (cache, eval);
}
return cacheWrapper;
}
if ("subnodeRelation".equalsIgnoreCase (propertyName)) { if ("subnodeRelation".equalsIgnoreCase (propertyName)) {
String rel = node.getSubnodeRelation (); String rel = node.getSubnodeRelation ();
return rel == null ? (ESValue) ESNull.theNull : new ESString (rel); return rel == null ? (ESValue) ESNull.theNull : new ESString (rel);
@ -394,6 +404,11 @@ public class ESNode extends ObjectPrototype {
return new ESString (""+node.hashCode ()); return new ESString (""+node.hashCode ());
if ("__node__".equals (propertyName)) if ("__node__".equals (propertyName))
return new ESWrapper (node, evaluator); return new ESWrapper (node, evaluator);
if ("__created__".equalsIgnoreCase (propertyName))
return new DatePrototype (evaluator, node.created ());
if ("__lastmodified__".equalsIgnoreCase (propertyName))
return new DatePrototype (evaluator, node.lastModified ());
return ESNull.theNull; return ESNull.theNull;
} }