From b0723569b237338720ce859b03b5785070400ef6 Mon Sep 17 00:00:00 2001 From: hns Date: Tue, 1 Apr 2008 11:53:46 +0000 Subject: [PATCH] * Do not cache nodes unless there is a request evaluator associated with the current thread and we can invoke onInit() on it. This prevents nodes fetched from other applications to be cached and fixes bug 598 --- src/helma/objectmodel/db/NodeManager.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/helma/objectmodel/db/NodeManager.java b/src/helma/objectmodel/db/NodeManager.java index cb821122..c2eec685 100644 --- a/src/helma/objectmodel/db/NodeManager.java +++ b/src/helma/objectmodel/db/NodeManager.java @@ -333,6 +333,16 @@ public final class NodeManager { */ private Node registerNewNode(Node node, Key secondaryKey) { Key key = node.getKey(); + RequestEvaluator reval = app.getCurrentRequestEvaluator(); + // if no request evaluator is associated with current thread, do not cache node + // as we cannot invoke onInit() on it. + if (reval == null) { + Node old = (Node) cache.get(key); + if (old != null && !old.isNullNode() && old.getState() != INode.INVALID) { + return old; + } + return node; + } synchronized(cache) { Node old = (Node) cache.put(key, node); @@ -352,10 +362,7 @@ public final class NodeManager { try { // We need to reach deap into helma.framework.core to invoke onInit(), // but the functionality is really worth it. - RequestEvaluator reval = app.getCurrentRequestEvaluator(); - if (reval != null) { - reval.invokeDirectFunction(node, "onInit", RequestEvaluator.EMPTY_ARGS); - } + reval.invokeDirectFunction(node, "onInit", RequestEvaluator.EMPTY_ARGS); } catch (Exception x) { app.logError("Error invoking onInit()", x); }