public void nodeRemoved(Object nodeId) { setExternalChange(Boolean.TRUE); Persistent object = findObject(nodeId); if (object != null) { try { context.deleteObjects(object); } finally { setExternalChange(Boolean.FALSE); } } else { setExternalChange(Boolean.FALSE); } }
void registerLifecycleEventInducedChange(GraphDiff diff) { if (ChildDiffLoader.isProcessingChildDiff()) { // reset so that subsequent event-induced changes could get registered... ChildDiffLoader.setExternalChange(Boolean.FALSE); } else { lifecycleEventInducedChanges.add(diff); } }
public boolean visitToMany(ToManyProperty property) { // connect reverse arc if the relationship is marked as // "runtime" ArcProperty reverseArc = property.getComplimentaryReverseArc(); boolean autoConnectReverse = reverseArc != null && reverseArc.getRelationship().isRuntime(); Persistent target = findObject(targetNodeId); if (target == null) { // this is usually the case when a NEW object was // deleted and then // its // relationships were manipulated; so try to locate the // object in // the // collection ... // the performance of this is rather dubious of // course... target = findObjectInCollection(targetNodeId, property.readProperty(source)); } if (target == null) { // ignore? } else { property.removeTarget(source, target, autoConnectReverse); } return false; }
@Override public void nodePropertyChanged( Object nodeId, String property, Object oldValue, Object newValue) { super.nodePropertyChanged(nodeId, property, oldValue, newValue); Persistent object = (Persistent) context.getGraphManager().getNode(nodeId); context.propertyChanged(object, property, oldValue, newValue); }
public void nodeCreated(Object nodeId) { setExternalChange(Boolean.TRUE); try { ObjectId id = (ObjectId) nodeId; if (id.getEntityName() == null) { throw new NullPointerException("Null entity name in id " + id); } ObjEntity entity = context.getEntityResolver().getObjEntity(id.getEntityName()); if (entity == null) { throw new IllegalArgumentException("Entity not mapped with Cayenne: " + id); } Persistent dataObject = null; try { dataObject = (Persistent) entity.getJavaClass().newInstance(); } catch (Exception ex) { throw new CayenneRuntimeException("Error instantiating object.", ex); } dataObject.setObjectId(id); context.registerNewObject(dataObject); } finally { setExternalChange(Boolean.FALSE); } }
@Override protected GraphDiff onContextFlush(ObjectContext originatingContext, GraphDiff changes, boolean cascade) { boolean childContext = this != originatingContext && changes != null; try { if (childContext) { getObjectStore().childContextSyncStarted(); changes.apply(new ChildDiffLoader(this)); fireDataChannelChanged(originatingContext, changes); } return (cascade) ? flushToParent(true) : new CompoundDiff(); } finally { if (childContext) { getObjectStore().childContextSyncStopped(); } } }
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) { final Persistent source = findObject(nodeId); final Persistent target = findObject(targetNodeId); ArcProperty property = (ArcProperty) descriptor.getProperty(arcId.toString()); setExternalChange(Boolean.TRUE); try { property.visit(new PropertyVisitor() { setExternalChange(Boolean.FALSE);
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) { // this change is for simple property, so no need to convert targets to // server // objects... Persistent object = findObject(nodeId); ClassDescriptor descriptor = context.getEntityResolver() .getClassDescriptor(((ObjectId) nodeId).getEntityName()); setExternalChange(Boolean.TRUE); try { descriptor.getProperty(property).writeProperty(object, oldValue, newValue); } catch (Exception e) { throw new CayenneRuntimeException("Error setting property: " + property, e); } finally { setExternalChange(Boolean.FALSE); } }
public void arcDeleted(Object nodeId, final Object targetNodeId, Object arcId) { final Persistent source = findObject(nodeId); PropertyDescriptor property = descriptor.getProperty(arcId.toString()); setExternalChange(Boolean.TRUE); try { property.visit(new PropertyVisitor() { setExternalChange(Boolean.FALSE);