use of org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff in project jackrabbit-oak by apache.
the class Commit method apply.
/**
* Apply the changes represented by this commit to the passed {@code base}
* node state.
*
* @param base
* the base node state to apply this commit to
* @return the resulting state from applying this commit to {@code base}.
* @throws CommitFailedException
* if the commit cannot be applied to {@code base}. (e.g.
* because of a conflict.)
*/
public SegmentNodeState apply(SegmentNodeState base) throws CommitFailedException {
SegmentNodeBuilder builder = base.builder();
if (SegmentNodeState.fastEquals(changes.getBaseState(), base.getChildNode(ROOT))) {
// use a shortcut when there are no external changes
NodeState before = changes.getBaseState();
NodeState after = changes.getNodeState();
builder.setChildNode(ROOT, hook.processCommit(before, after, info));
} else {
// there were some external changes, so do the full rebase
ConflictAnnotatingRebaseDiff diff = new ConflictAnnotatingRebaseDiff(builder.child(ROOT));
changes.getNodeState().compareAgainstBaseState(changes.getBaseState(), diff);
// apply commit hooks on the rebased changes
builder.setChildNode(ROOT, hook.processCommit(builder.getBaseState().getChildNode(ROOT), builder.getNodeState().getChildNode(ROOT), info));
}
return builder.getNodeState();
}
use of org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff in project jackrabbit-oak by apache.
the class DocumentRootBuilder method rebase.
//------------------------------------------------------------< internal >---
/**
* Rebase this builder on top of the head of the underlying store
*/
NodeState rebase() {
NodeState head = super.getNodeState();
NodeState inMemBase = super.getBaseState();
// Rebase branch
branch.rebase();
// Rebase in memory changes on top of the head of the rebased branch
super.reset(branch.getHead());
updates = 0;
head.compareAgainstBaseState(inMemBase, new ConflictAnnotatingRebaseDiff(this));
// Set new base and return rebased head
base = branch.getBase();
return super.getNodeState();
}
use of org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff in project jackrabbit-oak by apache.
the class SegmentNodeStore method rebase.
@Override
@Nonnull
public NodeState rebase(@Nonnull NodeBuilder builder) {
checkArgument(builder instanceof SegmentNodeBuilder);
SegmentNodeBuilder snb = (SegmentNodeBuilder) builder;
NodeState root = getRoot();
NodeState before = snb.getBaseState();
if (!SegmentNodeState.fastEquals(before, root)) {
SegmentNodeState after = snb.getNodeState();
snb.reset(root);
after.compareAgainstBaseState(before, new ConflictAnnotatingRebaseDiff(snb));
}
return snb.getNodeState();
}
use of org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff in project jackrabbit-oak by apache.
the class MemoryNodeStore method rebase.
/**
* This implementation is equal to applying the differences between the builders base state
* and its head state to a fresh builder on the stores root state using
* {@link org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff} for resolving
* conflicts.
* @param builder the builder to rebase
* @return the node state resulting from the rebase.
* @throws IllegalArgumentException if the builder is not acquired from a root state of
* this store
*/
@Override
public NodeState rebase(@Nonnull NodeBuilder builder) {
checkArgument(builder instanceof MemoryNodeBuilder);
NodeState head = checkNotNull(builder).getNodeState();
NodeState base = builder.getBaseState();
NodeState newBase = getRoot();
if (base != newBase) {
((MemoryNodeBuilder) builder).reset(newBase);
head.compareAgainstBaseState(base, new ConflictAnnotatingRebaseDiff(builder));
head = builder.getNodeState();
}
return head;
}
Aggregations