Add parent nodes with updated child collections to NodeChangeListener protocol.

Make Node.setLastSubnodeChange() public.
This commit is contained in:
hns 2004-11-25 14:17:01 +00:00
parent f042bbd36a
commit d1b5b820ad
5 changed files with 33 additions and 19 deletions

View file

@ -324,7 +324,7 @@ public final class Node implements INode, Serializable {
* Called by the transactor on registered parent nodes to mark the * Called by the transactor on registered parent nodes to mark the
* child index as changed * child index as changed
*/ */
void setLastSubnodeChange(long t) { public void setLastSubnodeChange(long t) {
lastSubnodeChange = t; lastSubnodeChange = t;
} }

View file

@ -21,9 +21,9 @@ import java.util.List;
public interface NodeChangeListener { public interface NodeChangeListener {
/** /**
* Called when a transaction is committed that has created, modified or * Called when a transaction is committed that has created, modified,
* deleted one or more nodes. * deleted or changed the child collection one or more nodes.
*/ */
public void nodesChanged(List inserted, List updated, List deleted); public void nodesChanged(List inserted, List updated, List deleted, List parents);
} }

View file

@ -1829,12 +1829,12 @@ public final class NodeManager {
/** /**
* Called by transactors after committing. * Called by transactors after committing.
*/ */
protected void fireNodeChangeEvent(List inserted, List updated, List deleted) { protected void fireNodeChangeEvent(List inserted, List updated, List deleted, List parents) {
int l = listeners.size(); int l = listeners.size();
for (int i=0; i<l; i++) { for (int i=0; i<l; i++) {
try { try {
((NodeChangeListener) listeners.get(i)).nodesChanged(inserted, updated, deleted); ((NodeChangeListener) listeners.get(i)).nodesChanged(inserted, updated, deleted, parents);
} catch (Error e) { } catch (Error e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {

View file

@ -102,10 +102,11 @@ public class Replicator implements Runnable, NodeChangeListener {
/** /**
* Called when a transaction is committed that has created, modified or * Called when a transaction is committed that has created, modified,
* deleted one or more nodes. * deleted or changed the child collection one or more nodes.
*/ */
public synchronized void nodesChanged(List inserted, List updated, List deleted) { public synchronized void nodesChanged(List inserted, List updated,
List deleted, List parents) {
add.addAll(inserted); add.addAll(inserted);
add.addAll(updated); add.addAll(updated);
delete.addAll(deleted); delete.addAll(deleted);

View file

@ -225,15 +225,23 @@ public class Transactor extends Thread {
int updated = 0; int updated = 0;
int deleted = 0; int deleted = 0;
if (!dirtyNodes.isEmpty()) { ArrayList insertedNodes = null;
Object[] dirty = dirtyNodes.values().toArray(); ArrayList updatedNodes = null;
ArrayList deletedNodes = null;
ArrayList insertedNodes = new ArrayList(); ArrayList modifiedParentNodes = null;
ArrayList updatedNodes = new ArrayList();
ArrayList deletedNodes = new ArrayList();
// if nodemanager has listeners collect dirty nodes // if nodemanager has listeners collect dirty nodes
boolean hasListeners = nmgr.hasNodeChangeListeners(); boolean hasListeners = nmgr.hasNodeChangeListeners();
if (hasListeners) {
insertedNodes = new ArrayList();
updatedNodes = new ArrayList();
deletedNodes = new ArrayList();
modifiedParentNodes = new ArrayList();
}
if (!dirtyNodes.isEmpty()) {
Object[] dirty = dirtyNodes.values().toArray();
// the set to collect DbMappings to be marked as changed // the set to collect DbMappings to be marked as changed
HashSet dirtyDbMappings = new HashSet(); HashSet dirtyDbMappings = new HashSet();
@ -307,9 +315,6 @@ public class Transactor extends Thread {
nmgr.idgen.dirty = false; nmgr.idgen.dirty = false;
} }
if (hasListeners) {
nmgr.fireNodeChangeEvent(insertedNodes, updatedNodes, deletedNodes);
}
} }
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -319,8 +324,16 @@ public class Transactor extends Thread {
for (Iterator i = parentNodes.iterator(); i.hasNext(); ) { for (Iterator i = parentNodes.iterator(); i.hasNext(); ) {
Node node = (Node) i.next(); Node node = (Node) i.next();
node.setLastSubnodeChange(now); node.setLastSubnodeChange(now);
if (hasListeners) {
modifiedParentNodes.add(node);
} }
} }
}
if (hasListeners) {
nmgr.fireNodeChangeEvent(insertedNodes, updatedNodes,
deletedNodes, modifiedParentNodes);
}
// clear the node collections // clear the node collections
dirtyNodes.clear(); dirtyNodes.clear();