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

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


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

    private static void run(NodeStore store) throws CommitFailedException {
        NodeStoreBranch branch = store.branch();
        NodeBuilder builder = branch.getRoot().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.removeNode("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();
    }
View Full Code Here


            JCR_WRITE, new String[] {JCR_MODIFY_PROPERTIES, JCR_ADD_CHILD_NODES, JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE},
            REP_WRITE, new String[] {JCR_WRITE, JCR_NODE_TYPE_MANAGEMENT});

    @Override
    public void initialize(NodeStore store) {
        NodeStoreBranch branch = store.branch();

        NodeBuilder root = branch.getRoot().builder();
        NodeBuilder system = root.child(JcrConstants.JCR_SYSTEM);
        system.setProperty(JcrConstants.JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_SYSTEM, Type.NAME);

        if (!system.hasChildNode(REP_PRIVILEGES)) {
            NodeBuilder privileges = system.child(REP_PRIVILEGES);
            privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME);

            try {
                branch.setRoot(root.getNodeState());
                branch.merge();
            } catch (CommitFailedException e) {
                log.error("Failed to initialize privilege content ", e);
                throw new RuntimeException(e);
            }
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

            return;
        }

        preAsyncRun(store);

        NodeStoreBranch branch = store.branch();
        NodeBuilder builder = branch.getHead().builder();
        NodeBuilder async = builder.child(ASYNC);

        NodeState before = null;
        final PropertyState state = async.getProperty(name);
        if (state != null && state.getType() == STRING) {
            before = store.retrieve(state.getValue(STRING));
        }
        if (before == null) {
            before = MISSING_NODE;
        }

        CommitFailedException exception = EditorDiff.process(new IndexUpdate(
                provider, name, after, builder), before, after);
        if (exception == null) {
            try {
                async.setProperty(name, checkpoint);
                postAsyncRunStatus(builder);
                branch.setRoot(builder.getNodeState());
                branch.merge(new CommitHook() {
                    @Override
                    @Nonnull
                    public NodeState processCommit(NodeState before,
                            NodeState after) throws CommitFailedException {
                        // check for concurrent updates by this async task
View Full Code Here

            failing = false;
        }
    }

    private void preAsyncRun(NodeStore store) {
        NodeStoreBranch branch = store.branch();
        NodeBuilder builder = branch.getHead().builder();
        preAsyncRunStatus(builder);
        branch.setRoot(builder.getNodeState());
        try {
            branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
        } catch (CommitFailedException e) {
            log.warn("Index status update {} failed", name, e);
        }
    }
View Full Code Here

    @Test
    public void testAsync() throws Exception {
        NodeStore store = new MemoryNodeStore();
        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, "async");
        builder.child("testRoot").setProperty("foo", "abc");

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

        AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
        async.run();
        root = store.getRoot();
View Full Code Here

    @Test
    public void testAsyncDouble() throws Exception {
        NodeStore store = new MemoryNodeStore();
        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, "async");
        createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
                "rootIndexSecond", true, false, ImmutableSet.of("bar"), null)
                .setProperty(ASYNC_PROPERTY_NAME, "async");

        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, PostCommitHook.EMPTY);

        AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
        async.run();
        root = store.getRoot();
View Full Code Here

    @Test
    public void testAsyncDoubleSubtree() throws Exception {
        NodeStore store = new MemoryNodeStore();
        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, "async");
        createIndexDefinition(
                builder.child("newchild").child("other")
                        .child(INDEX_DEFINITIONS_NAME), "subIndex", true,
                false, ImmutableSet.of("foo"), null)
                .setProperty(ASYNC_PROPERTY_NAME, "async");

        builder.child("testRoot").setProperty("foo", "abc");
        builder.child("newchild").child("other").child("testChild")
                .setProperty("foo", "xyz");

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

        AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
        async.run();
        root = store.getRoot();
View Full Code Here

        NodeStore store = new SegmentNodeStore(new MemoryStore());

        assertFalse(store.getRoot().hasProperty("foo"));
        assertFalse(store.getRoot().hasProperty("bar"));

        NodeStoreBranch a = store.branch();
        a.setRoot(a.getHead().builder().setProperty("foo", "abc").getNodeState());
        a.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        assertTrue(store.getRoot().hasProperty("foo"));
        assertFalse(store.getRoot().hasProperty("bar"));

        NodeStoreBranch b = store.branch();
        b.setRoot(b.getHead().builder().setProperty("bar", "xyz").getNodeState());
        b.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        assertTrue(store.getRoot().hasProperty("foo"));
        assertTrue(store.getRoot().hasProperty("bar"));
    }
View Full Code Here

    @Test
    public void testOptimisticMerge() throws CommitFailedException {
        NodeStore store = new SegmentNodeStore(new MemoryStore());

        NodeStoreBranch a = store.branch();
        a.setRoot(a.getHead().builder().setProperty("foo", "abc").getNodeState());

        NodeStoreBranch b = store.branch();
        b.setRoot(b.getHead().builder().setProperty("bar", "xyz").getNodeState());

        assertFalse(store.getRoot().hasProperty("foo"));
        assertFalse(store.getRoot().hasProperty("bar"));

        a.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        assertTrue(store.getRoot().hasProperty("foo"));
        assertFalse(store.getRoot().hasProperty("bar"));

        b.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        assertTrue(store.getRoot().hasProperty("foo"));
        assertTrue(store.getRoot().hasProperty("bar"));
    }
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.