private void runWithEventsDisabled(Runnable closure) { synchronized (context.internalGraphManager()) { boolean changeEventsEnabled = context.internalGraphManager().changeEventsEnabled; context.internalGraphManager().changeEventsEnabled = false; boolean lifecycleEventsEnabled = context.internalGraphManager().lifecycleEventsEnabled; context.internalGraphManager().lifecycleEventsEnabled = false; try { closure.run(); } finally { context.internalGraphManager().changeEventsEnabled = changeEventsEnabled; context.internalGraphManager().lifecycleEventsEnabled = lifecycleEventsEnabled; } } } }
private void runWithEventsDisabled(Runnable closure) { synchronized (context.internalGraphManager()) { boolean changeEventsEnabled = context.internalGraphManager().changeEventsEnabled; context.internalGraphManager().changeEventsEnabled = false; boolean lifecycleEventsEnabled = context.internalGraphManager().lifecycleEventsEnabled; context.internalGraphManager().lifecycleEventsEnabled = false; try { closure.run(); } finally { context.internalGraphManager().changeEventsEnabled = changeEventsEnabled; context.internalGraphManager().lifecycleEventsEnabled = lifecycleEventsEnabled; } } } }
public void run() { context.internalGraphManager().graphReverted(); } });
public void nodeIdChanged(Object nodeId, Object newId) { // do not unregister the node just yet... only put replaced id in deadIds to // remove it later. Otherwise stored operations will not work Object node = context.internalGraphManager().getNode(nodeId); if (node != null) { context.internalGraphManager().deadIds().add(nodeId); context.internalGraphManager().registerNode(newId, node); if (node instanceof Persistent) { // inject new id ((Persistent) node).setObjectId((ObjectId) newId); } } }
public void nodeIdChanged(Object nodeId, Object newId) { // do not unregister the node just yet... only put replaced id in deadIds to // remove it later. Otherwise stored operations will not work Object node = context.internalGraphManager().getNode(nodeId); if (node != null) { context.internalGraphManager().deadIds().add(nodeId); context.internalGraphManager().registerNode(newId, node); if (node instanceof Persistent) { // inject new id ((Persistent) node).setObjectId((ObjectId) newId); } } }
public void nodeRemoved(Object nodeId) { Object object = context.internalGraphManager().getNode(nodeId); if (object != null) { context.deleteObject((Persistent) object); } }
public void run() { if (e.getDiff() != null) { e.getDiff().apply(CayenneContextMergeHandler.this); } if (!hadChanges) { context.internalGraphManager().stateLog.graphCommitted(); context.internalGraphManager().reset(); } } });
void repostAfterMerge(GraphEvent originalEvent) { // though the subject is CHANGE, "merge" events are really lifecycle. if (context.isLifecycleEventsEnabled()) { context.internalGraphManager().send( originalEvent.getDiff(), DataChannel.GRAPH_CHANGED_SUBJECT, originalEvent.getSource()); } }
public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) { // null source or target likely means the object is not faulted yet... Faults // shouldn't get disturbed by adding/removing arcs Object source = context.internalGraphManager().getNode(nodeId); if (source == null) { // no need to disconnect non-existent object return; } // (see "TODO" in 'arcCreated') ArcProperty p = (ArcProperty) propertyForId(nodeId, arcId.toString()); if (p.isFault(source)) { return; } Object target = context.internalGraphManager().getNode(targetNodeId); if (target == null) { target = context.createFault((ObjectId) targetNodeId); } try { if (p instanceof ToManyProperty) { ((ToManyProperty) p).removeTargetDirectly(source, target); } else { p.writePropertyDirectly(source, target, null); } } finally { } }
public void graphRolledback(final GraphEvent e) { if (shouldProcessEvent(e)) { // do we need to merge anything? if (context.internalGraphManager().hasChanges()) { runWithEventsDisabled(new Runnable() { public void run() { context.internalGraphManager().graphReverted(); } }); // post event outside of "execute" to make sure it is sent repostAfterMerge(e); } } }
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) { // null source or target likely means the object is not faulted yet... Faults // shouldn't get disturbed by adding/removing arcs Object source = context.internalGraphManager().getNode(nodeId); if (source == null) { // no need to connect non-existent object return; } // TODO (Andrus, 10/17/2005) - check for local modifications to avoid // overwriting... ArcProperty p = (ArcProperty) propertyForId(nodeId, arcId.toString()); if (p.isFault(source)) { return; } Object target = context.internalGraphManager().getNode(targetNodeId); if (target == null) { target = context.createFault((ObjectId) targetNodeId); } try { if (p instanceof ToManyProperty) { ((ToManyProperty) p).addTargetDirectly(source, target); } else { p.writePropertyDirectly(source, null, target); } } finally { } }
public void nodePropertyChanged( Object nodeId, String property, Object oldValue, Object newValue) { Object object = context.internalGraphManager().getNode(nodeId); if (object != null) { // do not override local changes.... PropertyDescriptor p = propertyForId(nodeId, property); if (Util.nullSafeEquals(p.readPropertyDirectly(object), oldValue)) { p.writePropertyDirectly(object, oldValue, newValue); } } }
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) { // null source or target likely means the object is not faulted yet... Faults // shouldn't get disturbed by adding/removing arcs Object source = context.internalGraphManager().getNode(nodeId); if (source == null) { source = context.createFault((ObjectId) nodeId); } Object target = context.internalGraphManager().getNode(targetNodeId); if (target == null) { target = context.createFault((ObjectId) targetNodeId); } // TODO (Andrus, 10/17/2005) - check for local modifications to avoid // overwriting... ArcProperty p = (ArcProperty) propertyForId(nodeId, arcId.toString()); try { context.internalGraphAction().handleArcPropertyChange( (Persistent) source, p, null, target); } finally { context.internalGraphAction().setArcChangeInProcess(false); } }
public void graphFlushed(final GraphEvent e) { // TODO (Andrus, 10/17/2005) - there are a few problems with commit processing: // 1. Event mechanism reliability: // - events may come out of order (commit and then preceeding flush) // - events may be missing all together (commit arrived, while prior flush did // not) // Possible solution - an "event_version_id" to be used for optimistic locking // 2. We don't know if our own dirty objects were committed or not... // For now we will simply merge the changes, and keep the context dirty if (shouldProcessEvent(e)) { final boolean hadChanges = context.internalGraphManager().hasChanges(); runWithEventsDisabled(new Runnable() { public void run() { if (e.getDiff() != null) { e.getDiff().apply(CayenneContextMergeHandler.this); } if (!hadChanges) { context.internalGraphManager().stateLog.graphCommitted(); context.internalGraphManager().reset(); } } }); // post event outside of "execute" to make sure it is sent repostAfterMerge(e); } }
public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) { // null source or target likely means the object is not faulted yet... Faults // shouldn't get disturbed by adding/removing arcs Object source = context.internalGraphManager().getNode(nodeId); if (source == null) { source = context.createFault((ObjectId) nodeId); } Object target = context.internalGraphManager().getNode(targetNodeId); if (target == null) { target = context.createFault((ObjectId) targetNodeId); } // (see "TODO" in 'arcCreated') ArcProperty p = (ArcProperty) propertyForId(nodeId, arcId.toString()); p.writePropertyDirectly(source, target, null); try { context.internalGraphAction().handleArcPropertyChange( (Persistent) source, p, target, null); } finally { context.internalGraphAction().setArcChangeInProcess(false); } }
.internalGraphManager(); if (cache) {
invalidateLocally(context.internalGraphManager(), context .internalGraphManager() .registeredNodes() .iterator()); if (objects != null && !objects.isEmpty()) { invalidateLocally(context.internalGraphManager(), objects.iterator());
public void nodePropertyChanged( Object nodeId, String property, Object oldValue, Object newValue) { Object object = context.internalGraphManager().getNode(nodeId); if (object != null) { // do not override local changes.... Property p = propertyForId(nodeId, property); if (Util.nullSafeEquals(p.readPropertyDirectly(object), oldValue)) { p.writePropertyDirectly(object, oldValue, newValue); context.internalGraphAction().handleSimplePropertyChange( (Persistent) object, property, oldValue, newValue); } } }