Search in sources :

Example 1 with NodeDiff

use of org.apache.cayenne.graph.NodeDiff in project cayenne by apache.

the class ObjectStore method nodeRemoved.

/**
 * @since 1.2
 */
@Override
public void nodeRemoved(Object nodeId) {
    NodeDiff diff = new NodeDeleteOperation(nodeId);
    if (lifecycleEventInducedChanges != null) {
        registerLifecycleEventInducedChange(diff);
    }
    registerDiff(nodeId, diff);
}
Also used : NodeDiff(org.apache.cayenne.graph.NodeDiff) NodeDeleteOperation(org.apache.cayenne.graph.NodeDeleteOperation)

Example 2 with NodeDiff

use of org.apache.cayenne.graph.NodeDiff in project cayenne by apache.

the class ObjectStore method nodeCreated.

/**
 * @since 1.2
 */
@Override
public void nodeCreated(Object nodeId) {
    NodeDiff diff = new NodeCreateOperation(nodeId);
    if (lifecycleEventInducedChanges != null) {
        registerLifecycleEventInducedChange(diff);
    }
    registerDiff(nodeId, diff);
}
Also used : NodeCreateOperation(org.apache.cayenne.graph.NodeCreateOperation) NodeDiff(org.apache.cayenne.graph.NodeDiff)

Example 3 with NodeDiff

use of org.apache.cayenne.graph.NodeDiff in project cayenne by apache.

the class ObjectStore method arcCreated.

/**
 * @since 1.2
 */
@Override
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
    NodeDiff diff = new ArcOperation(nodeId, targetNodeId, arcId.toString(), false);
    if (lifecycleEventInducedChanges != null) {
        registerLifecycleEventInducedChange(diff);
    }
    registerDiff(nodeId, diff);
}
Also used : ArcOperation(org.apache.cayenne.access.ObjectDiff.ArcOperation) NodeDiff(org.apache.cayenne.graph.NodeDiff)

Example 4 with NodeDiff

use of org.apache.cayenne.graph.NodeDiff in project cayenne by apache.

the class ObjectStoreGraphDiff method resolveDiff.

/**
 * Converts diffs organized by ObjectId in a collection of diffs sorted by
 * diffId (same as creation order).
 */
private void resolveDiff() {
    // changed the the last time we cached the changes.
    if (resolvedDiff == null || lastSeenDiffId < objectStore.currentDiffId) {
        CompoundDiff diff = new CompoundDiff();
        Map<Object, ObjectDiff> changes = getChangesByObjectId();
        if (!changes.isEmpty()) {
            List<NodeDiff> allChanges = new ArrayList<>(changes.size() * 2);
            for (final ObjectDiff objectDiff : changes.values()) {
                objectDiff.appendDiffs(allChanges);
            }
            Collections.sort(allChanges);
            diff.addAll(allChanges);
        }
        this.lastSeenDiffId = objectStore.currentDiffId;
        this.resolvedDiff = diff;
    }
}
Also used : NodeDiff(org.apache.cayenne.graph.NodeDiff) ArrayList(java.util.ArrayList) CompoundDiff(org.apache.cayenne.graph.CompoundDiff)

Example 5 with NodeDiff

use of org.apache.cayenne.graph.NodeDiff in project cayenne by apache.

the class DeleteRulesIT method assertJoinDeleted.

private void assertJoinDeleted(DeleteRuleFlatA a, DeleteRuleFlatB b) {
    ObjectDiff changes = context.getObjectStore().changes.get(a.getObjectId());
    assertNotNull(changes);
    Collection<NodeDiff> diffs = new ArrayList<NodeDiff>();
    changes.appendDiffs(diffs);
    Iterator<?> it = diffs.iterator();
    while (it.hasNext()) {
        Object diff = it.next();
        if (diff instanceof ArcOperation) {
            ArcOperation arcDelete = (ArcOperation) diff;
            if (arcDelete.getNodeId().equals(a.getObjectId()) && arcDelete.getTargetNodeId().equals(b.getObjectId()) && arcDelete.getArcId().equals(DeleteRuleFlatA.FLAT_B.getName()) && arcDelete.isDelete()) {
                return;
            }
        }
    }
    fail("Join was not deleted for flattened relationship");
}
Also used : ArcOperation(org.apache.cayenne.access.ObjectDiff.ArcOperation) NodeDiff(org.apache.cayenne.graph.NodeDiff) ArrayList(java.util.ArrayList)

Aggregations

NodeDiff (org.apache.cayenne.graph.NodeDiff)7 ArcOperation (org.apache.cayenne.access.ObjectDiff.ArcOperation)4 ArrayList (java.util.ArrayList)3 CompoundDiff (org.apache.cayenne.graph.CompoundDiff)1 NodeCreateOperation (org.apache.cayenne.graph.NodeCreateOperation)1 NodeDeleteOperation (org.apache.cayenne.graph.NodeDeleteOperation)1