* 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,17 +349,15 @@ public final class NodeManager {
} }
// New node is going ot be used, invoke onInit() on it // New node is going ot be used, invoke onInit() on it
// Invoke onInit() if it is defined by this Node's prototype // Invoke onInit() if it is defined by this Node's prototype
if (node.dbmap != null) { try {
try { // We need to reach deap into helma.framework.core to invoke onInit(),
// We need to reach deap into helma.framework.core to invoke onInit(), // but the functionality is really worth it.
// but the functionality is really worth it. RequestEvaluator reval = app.getCurrentRequestEvaluator();
RequestEvaluator reval = app.getCurrentRequestEvaluator(); if (reval != null) {
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);
} }
} catch (Exception x) {
app.logError("Error invoking onInit()", x);
} }
return node; return node;
} }
@ -421,6 +419,7 @@ public final class NodeManager {
*/ */
public void insertNode(IDatabase db, ITransaction txn, Node node) public void insertNode(IDatabase db, ITransaction txn, Node node)
throws IOException, SQLException, ClassNotFoundException { throws IOException, SQLException, ClassNotFoundException {
invokeOnPersist(node);
DbMapping dbm = node.getDbMapping(); DbMapping dbm = node.getDbMapping();
if ((dbm == null) || !dbm.isRelational()) { 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 * Updates a modified node in the embedded db or an external relational database, depending
* on its database mapping. * on its database mapping.
@ -539,6 +554,8 @@ public final class NodeManager {
*/ */
public boolean updateNode(IDatabase db, ITransaction txn, Node node) public boolean updateNode(IDatabase db, ITransaction txn, Node node)
throws IOException, SQLException, ClassNotFoundException { throws IOException, SQLException, ClassNotFoundException {
invokeOnPersist(node);
DbMapping dbm = node.getDbMapping(); DbMapping dbm = node.getDbMapping();
boolean markMappingAsUpdated = false; boolean markMappingAsUpdated = false;