From 4b79e98a8b7c3c4939f62d4ac731cca0482c7040 Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 4 Apr 2007 12:50:01 +0000 Subject: [PATCH] * Implement HopObject.onPersist() callback contributed by Kris Leite on helma-user. --- src/helma/objectmodel/db/NodeManager.java | 37 +++++++++++++++++------ 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/helma/objectmodel/db/NodeManager.java b/src/helma/objectmodel/db/NodeManager.java index 27e4efd1..ada2b8e1 100644 --- a/src/helma/objectmodel/db/NodeManager.java +++ b/src/helma/objectmodel/db/NodeManager.java @@ -349,17 +349,15 @@ public final class NodeManager { } // New node is going ot be used, invoke onInit() on it // Invoke onInit() if it is defined by this Node's prototype - if (node.dbmap != null) { - 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); - } - } catch (Exception x) { - app.logError("Error invoking onInit()", x); + 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); } + } catch (Exception x) { + app.logError("Error invoking onInit()", x); } return node; } @@ -421,6 +419,7 @@ public final class NodeManager { */ public void insertNode(IDatabase db, ITransaction txn, Node node) throws IOException, SQLException, ClassNotFoundException { + invokeOnPersist(node); DbMapping dbm = node.getDbMapping(); if ((dbm == null) || !dbm.isRelational()) { @@ -530,6 +529,22 @@ public final class NodeManager { } } + /** + * calls onPersist function for the HopObject + */ + private void invokeOnPersist(Node node) { + try { + // We need to reach deap into helma.framework.core to invoke onPersist(), + // but the functionality is really worth it. + RequestEvaluator reval = app.getCurrentRequestEvaluator(); + if (reval != null) { + reval.invokeDirectFunction(node, "onPersist", RequestEvaluator.EMPTY_ARGS); + } + } catch (Exception x) { + app.logError("Error invoking onPersist()", x); + } + } + /** * Updates a modified node in the embedded db or an external relational database, depending * on its database mapping. @@ -539,6 +554,8 @@ public final class NodeManager { */ public boolean updateNode(IDatabase db, ITransaction txn, Node node) throws IOException, SQLException, ClassNotFoundException { + + invokeOnPersist(node); DbMapping dbm = node.getDbMapping(); boolean markMappingAsUpdated = false;