* Implement HopObject.onPersist() callback contributed by

Kris Leite on helma-user.
This commit is contained in:
hns 2007-04-04 12:50:01 +00:00
parent 7ef2a3fcd0
commit 4b79e98a8b

View file

@ -349,7 +349,6 @@ 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.
@ -360,7 +359,6 @@ public final class NodeManager {
} 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;