if (!dirtyNodes.isEmpty()) {
Object[] dirty = dirtyNodes.values().toArray();
// the set to collect DbMappings to be marked as changed
HashSet dirtyDbMappings = new HashSet();
Log eventLog = nmgr.app.getEventLog();
for (int i = 0; i < dirty.length; i++) {
Node node = (Node) dirty[i];
// update nodes in db
int nstate = node.getState();
if (nstate == Node.NEW) {
nmgr.insertNode(nmgr.db, txn, node);
dirtyDbMappings.add(node.getDbMapping());
node.setState(Node.CLEAN);
// register node with nodemanager cache
nmgr.registerNode(node);
if (hasListeners) {
insertedNodes.add(node);
}
inserted++;
if (eventLog.isDebugEnabled()) {
eventLog.debug("inserted node: " + node.getPrototype() + "/" +
node.getID());
}
} else if (nstate == Node.MODIFIED) {
// only mark DbMapping as dirty if updateNode returns true
if (nmgr.updateNode(nmgr.db, txn, node)) {
dirtyDbMappings.add(node.getDbMapping());
}
node.setState(Node.CLEAN);
// update node with nodemanager cache
nmgr.registerNode(node);
if (hasListeners) {
updatedNodes.add(node);
}
updated++;
if (eventLog.isDebugEnabled()) {
eventLog.debug("updated node: " + node.getPrototype() + "/" +
node.getID());
}
} else if (nstate == Node.DELETED) {
nmgr.deleteNode(nmgr.db, txn, node);
dirtyDbMappings.add(node.getDbMapping());
// remove node from nodemanager cache
nmgr.evictNode(node);
if (hasListeners) {
deletedNodes.add(node);
}
deleted++;
if (eventLog.isDebugEnabled()) {
eventLog.debug("removed node: " + node.getPrototype() + "/" +
node.getID());
}
}
node.clearWriteLock();