/** * This implementation is equal resetting the builder to the root of the store and returning * the resulting node state from the builder. * @param builder the builder to reset * @return the node state resulting from the reset. * @throws IllegalArgumentException if the builder is not acquired from a root state of * this store */ @Override public NodeState reset(@NotNull NodeBuilder builder) { checkArgument(builder instanceof MemoryNodeBuilder); NodeState head = getRoot(); ((MemoryNodeBuilder) builder).reset(head); return head; }
/** * This implementation is equal resetting the builder to the root of the store and returning * the resulting node state from the builder. * @param builder the builder to reset * @return the node state resulting from the reset. * @throws IllegalArgumentException if the builder is not acquired from a root state of * this store */ @Override public NodeState reset(@Nonnull NodeBuilder builder) { checkArgument(builder instanceof MemoryNodeBuilder); NodeState head = getRoot(); ((MemoryNodeBuilder) builder).reset(head); return head; }
/** * This implementation is equal to first rebasing the builder and then applying it to a * new branch and immediately merging it back. * @param builder the builder whose changes to apply * @param commitHook the commit hook to apply while merging changes * @return the node state resulting from the merge. * @throws CommitFailedException * @throws IllegalArgumentException if the builder is not acquired from a root state of * this store */ @Override public synchronized NodeState merge( @NotNull NodeBuilder builder, @NotNull CommitHook commitHook, @NotNull CommitInfo info) throws CommitFailedException { checkArgument(builder instanceof MemoryNodeBuilder); MemoryNodeBuilder mnb = (MemoryNodeBuilder) builder; checkArgument(mnb.isRoot()); checkNotNull(commitHook); rebase(builder); NodeStoreBranch branch = new MemoryNodeStoreBranch(this, getRoot()); branch.setRoot(builder.getNodeState()); NodeState merged = branch.merge(commitHook, info); mnb.reset(merged); return merged; }
/** * This implementation is equal to first rebasing the builder and then applying it to a * new branch and immediately merging it back. * @param builder the builder whose changes to apply * @param commitHook the commit hook to apply while merging changes * @return the node state resulting from the merge. * @throws CommitFailedException * @throws IllegalArgumentException if the builder is not acquired from a root state of * this store */ @Override public synchronized NodeState merge( @Nonnull NodeBuilder builder, @Nonnull CommitHook commitHook, @Nonnull CommitInfo info) throws CommitFailedException { checkArgument(builder instanceof MemoryNodeBuilder); MemoryNodeBuilder mnb = (MemoryNodeBuilder) builder; checkArgument(mnb.isRoot()); checkNotNull(commitHook); rebase(builder); NodeStoreBranch branch = new MemoryNodeStoreBranch(this, getRoot()); branch.setRoot(builder.getNodeState()); NodeState merged = branch.merge(commitHook, info); mnb.reset(merged); return merged; }
/** * 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(@NotNull 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; }
/** * 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; }
@Test public void testReset2() { NodeBuilder root = base.builder(); NodeBuilder x = root.child("x"); x.child("y"); ((MemoryNodeBuilder) root).reset(base); assertTrue(root.hasChildNode("x")); assertFalse(x.hasChildNode("y")); }
@Test public void testReset() { NodeBuilder root = base.builder(); NodeBuilder child = root.child("x"); child.child("new"); assertTrue(child.hasChildNode("new")); assertTrue(root.child("x").hasChildNode("new")); ((MemoryNodeBuilder) root).reset(base); assertFalse(child.hasChildNode("new")); assertFalse(root.child("x").hasChildNode("new")); }