Package org.apache.jackrabbit.oak.spi.state

Examples of org.apache.jackrabbit.oak.spi.state.NodeStoreBranch


        NodeBuilder builder = oldState.builder();
        builder.setProperty("foo", "bar");
        NodeState newState = builder.getNodeState();

        NodeStoreBranch branch = root.branch();
        branch.setRoot(newState);
        branch.merge(EmptyHook.INSTANCE);

        assertEquals(newState, root.getRoot());
        assertEquals(oldState, left.getRoot());
        assertEquals(oldState, right.getRoot());
View Full Code Here


        NodeBuilder builder = oldState.builder();
        builder.setProperty("foo", "bar");
        NodeState newState = builder.getNodeState();

        NodeStoreBranch branch = left.branch();
        branch.setRoot(newState);
        branch.merge(EmptyHook.INSTANCE);

        assertEquals(oldState, root.getRoot());
        assertEquals(newState, left.getRoot());
        assertEquals(oldState, right.getRoot());
View Full Code Here

        NodeBuilder leftBuilder = oldState.builder();
        leftBuilder.setProperty("foo", "bar");
        NodeState leftState = leftBuilder.getNodeState();

        NodeStoreBranch leftBranch = left.branch();
        leftBranch.setRoot(leftState);
        leftBranch.merge(EmptyHook.INSTANCE);

        assertEquals(oldState, root.getRoot());
        assertEquals(leftState, left.getRoot());
        assertEquals(oldState, right.getRoot());

        store.getJournal("left").merge();
        assertEquals(leftState, root.getRoot());
        assertEquals(leftState, left.getRoot());
        assertEquals(oldState, right.getRoot());

        NodeBuilder rightBuilder = oldState.builder();
        rightBuilder.setProperty("bar", "foo");
        NodeState rightState = rightBuilder.getNodeState();

        NodeStoreBranch rightBranch = right.branch();
        rightBranch.setRoot(rightState);
        rightBranch.merge(EmptyHook.INSTANCE);

        store.getJournal("right").merge();
        NodeState newState = root.getRoot();
        assertEquals("bar", newState.getProperty("foo").getValue(Type.STRING));
        assertEquals("foo", newState.getProperty("bar").getValue(Type.STRING));
View Full Code Here

        init(store);
        run(store);
    }

    private static void init(NodeStore store) throws CommitFailedException {
        NodeStoreBranch branch = store.branch();
        NodeBuilder builder = branch.getHead().builder();
        builder.child("x").child("y").child("z");
        branch.setRoot(builder.getNodeState());
        branch.merge(EmptyHook.INSTANCE);
    }
View Full Code Here

        branch.setRoot(builder.getNodeState());
        branch.merge(EmptyHook.INSTANCE);
    }

    private static void run(NodeStore store) throws CommitFailedException {
        NodeStoreBranch branch = store.branch();
        NodeBuilder builder = branch.getHead().builder();

        assertTrue("child node x should be present", builder.hasChildNode("x"));
        assertTrue("child node x/y should be present", builder.child("x")
                .hasChildNode("y"));
        assertTrue("child node x/y/z should be present", builder.child("x")
                .child("y").hasChildNode("z"));

        builder.removeChildNode("x");
        assertFalse("child node x not should be present",
                builder.hasChildNode("x"));
        assertFalse("child node x/y not should be present", builder.child("x")
                .hasChildNode("y"));

        // See OAK-531
        assertFalse("child node x/y/z not should not be present", builder
                .child("x").child("y").hasChildNode("z"));

        branch.merge(EmptyHook.INSTANCE);
    }
View Full Code Here

    public void testAsync() throws Exception {
        NodeStore store = new MemoryNodeStore();
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(0);
        IndexEditorProvider provider = new PropertyIndexEditorProvider();

        NodeStoreBranch branch = store.branch();
        NodeState root = branch.getHead();
        NodeBuilder builder = root.builder();
        createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
                "rootIndex", true, false, ImmutableSet.of("foo"), null)
                .setProperty(ASYNC_PROPERTY_NAME, true);
        builder.child("testRoot").setProperty("foo", "abc");

        // merge it back in
        branch.setRoot(builder.getNodeState());
        branch.merge(EmptyHook.INSTANCE);

        AsyncIndexUpdate async = new AsyncIndexUpdate(store, executor, provider);
        runIndexing(async, 1);
        root = store.getRoot();
View Full Code Here

    public void testAsyncDouble() throws Exception {
        NodeStore store = new MemoryNodeStore();
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(0);
        IndexEditorProvider provider = new PropertyIndexEditorProvider();

        NodeStoreBranch branch = store.branch();
        NodeState root = branch.getHead();
        NodeBuilder builder = root.builder();
        createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
                "rootIndex", true, false, ImmutableSet.of("foo"), null)
                .setProperty(ASYNC_PROPERTY_NAME, true);
        createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
                "rootIndexSecond", true, false, ImmutableSet.of("bar"), null)
                .setProperty(ASYNC_PROPERTY_NAME, true);

        builder.child("testRoot").setProperty("foo", "abc")
                .setProperty("bar", "def");
        builder.child("testSecond").setProperty("bar", "ghi");

        // merge it back in
        branch.setRoot(builder.getNodeState());
        branch.merge(EmptyHook.INSTANCE);

        AsyncIndexUpdate async = new AsyncIndexUpdate(store, executor, provider);
        runIndexing(async, 1);
        root = store.getRoot();
View Full Code Here

            @Nonnull NodeBuilder builder, @Nonnull CommitHook commitHook,
            @Nullable CommitInfo info) throws CommitFailedException {
        checkArgument(builder instanceof MemoryNodeBuilder);
        checkNotNull(commitHook);
        rebase(builder);
        NodeStoreBranch branch = new MemoryNodeStoreBranch(this, getRoot());
        branch.setRoot(builder.getNodeState());
        NodeState merged = branch.merge(commitHook, info);
        ((MemoryNodeBuilder) builder).reset(merged);
        return merged;
    }
View Full Code Here

                store.getRoot().getChildNode("test").getProperty("any"));
    }

    @Test
    public void branch() throws CommitFailedException {
        NodeStoreBranch branch = store.branch();

        NodeStateBuilder rootBuilder = store.getBuilder(branch.getRoot());
        NodeStateBuilder testBuilder = store.getBuilder(root.getChildNode("test"));

        testBuilder.setNode("newNode", MemoryNodeState.EMPTY_NODE);
        testBuilder.removeNode("x");

        NodeStateBuilder newNodeBuilder = store.getBuilder(
                testBuilder.getNodeState().getChildNode("newNode"));

        CoreValue fortyTwo = store.getValueFactory().createValue(42);
        newNodeBuilder.setProperty("n", fortyTwo);

        testBuilder.setNode("newNode", newNodeBuilder.getNodeState());
        rootBuilder.setNode("test", testBuilder.getNodeState());

        // Assert changes are present in the builder
        NodeState testState = rootBuilder.getNodeState().getChildNode("test");
        assertNotNull(testState.getChildNode("newNode"));
        assertNull(testState.getChildNode("x"));
        assertEquals(fortyTwo, testState.getChildNode("newNode").getProperty("n").getValue());

        // Assert changes are not yet present in the branch
        testState = branch.getRoot().getChildNode("test");
        assertNull(testState.getChildNode("newNode"));
        assertNotNull(testState.getChildNode("x"));

        branch.setRoot(rootBuilder.getNodeState());

        // Assert changes are present in the branch
        testState = branch.getRoot().getChildNode("test");
        assertNotNull(testState.getChildNode("newNode"));
        assertNull(testState.getChildNode("x"));
        assertEquals(fortyTwo, testState.getChildNode("newNode").getProperty("n").getValue());

        // Assert changes are not yet present in the trunk
        testState = store.getRoot().getChildNode("test");
        assertNull(testState.getChildNode("newNode"));
        assertNotNull(testState.getChildNode("x"));

        branch.merge();

        // Assert changes are present in the trunk
        testState = store.getRoot().getChildNode("test");
        assertNotNull(testState.getChildNode("newNode"));
        assertNull(testState.getChildNode("x"));
View Full Code Here

    private void commitWithEditor(NodeState nodeState, CommitEditor editor)
            throws CommitFailedException {

        commitHookDelegate.set(editor);
        try {
            NodeStoreBranch branch = store.branch();
            branch.setRoot(nodeState);
            branch.merge();
        }
        finally {
            commitHookDelegate.set(new EmptyEditor());
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.spi.state.NodeStoreBranch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.