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

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


    }

    public static void initialize(@Nonnull NodeStore store,
                                  @Nonnull RepositoryInitializer initializer,
                                  @Nonnull IndexEditorProvider indexEditor) {
        NodeStoreBranch branch = store.branch();
        NodeState before = branch.getHead();
        branch.setRoot(initializer.initialize(before));
        try {
            branch.merge(new EditorHook(new IndexUpdateProvider(indexEditor)), PostCommitHook.EMPTY);
        } catch (CommitFailedException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here


                                  @Nonnull NodeStore store,
                                  @Nonnull String workspaceName,
                                  @Nonnull IndexEditorProvider indexEditor,
                                  @Nonnull QueryIndexProvider indexProvider,
                                  @Nonnull CommitHook commitHook) {
        NodeStoreBranch branch = store.branch();
        NodeState root = branch.getHead();
        for (WorkspaceInitializer wspInit : initializer) {
            root = wspInit.initialize(root, workspaceName, indexProvider, commitHook);
        }
        branch.setRoot(root);
        try {
            branch.merge(new EditorHook(new IndexUpdateProvider(indexEditor)), PostCommitHook.EMPTY);
        } catch (CommitFailedException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

                    ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES), null);
            // the cost of using the property index for "@primaryType is not null" is very high
            nt.setProperty(IndexConstants.ENTRY_COUNT_PROPERTY_NAME, Long.valueOf(Long.MAX_VALUE));
        }
        NodeStore store = new MemoryNodeStore();
        NodeStoreBranch branch = store.branch();
        branch.setRoot(root.getNodeState());
        try {
            branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
        } catch (CommitFailedException e) {
            throw new RuntimeException(e);
        }
        BuiltInNodeTypes.register(new SystemRoot(store, new EditorHook(new RegistrationEditorProvider())));
        return store.getRoot();
View Full Code Here

    }

    @Before
    public void setUp() throws Exception {
        store = fixture.createNodeStore();
        NodeStoreBranch branch = store.branch();
        NodeBuilder builder = branch.getHead().builder();
        NodeBuilder test = builder.child("test");
        test.setProperty("a", 1);
        test.setProperty("b", 2);
        test.setProperty("c", 3);
        test.child("x");
        test.child("y");
        test.child("z");
        branch.setRoot(builder.getNodeState());
        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
        root = store.getRoot();
    }
View Full Code Here

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

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

        NodeBuilder rootBuilder = branch.getHead().builder();
        NodeBuilder testBuilder = rootBuilder.child("test");
        NodeBuilder newNodeBuilder = testBuilder.child("newNode");

        testBuilder.getChildNode("x").remove();

        newNodeBuilder.setProperty("n", 42);

        // Assert changes are present in the builder
        NodeState testState = rootBuilder.getNodeState().getChildNode("test");
        assertTrue(testState.getChildNode("newNode").exists());
        assertFalse(testState.getChildNode("x").exists());
        assertEquals(42, (long) testState.getChildNode("newNode").getProperty("n").getValue(LONG));

        // Assert changes are not yet present in the branch
        testState = branch.getHead().getChildNode("test");
        assertFalse(testState.getChildNode("newNode").exists());
        assertTrue(testState.getChildNode("x").exists());

        branch.setRoot(rootBuilder.getNodeState());

        // Assert changes are present in the branch
        testState = branch.getHead().getChildNode("test");
        assertTrue(testState.getChildNode("newNode").exists());
        assertFalse(testState.getChildNode("x").exists());
        assertEquals(42, (long) testState.getChildNode("newNode").getProperty("n").getValue(LONG));

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

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

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

        testBuilder.getChildNode("a").remove();

        NodeState newRoot = rootBuilder.getNodeState();

        NodeStoreBranch branch = store.branch();
        branch.setRoot(newRoot);
        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
        store.getRoot(); // triggers the observer

        NodeState before = states[0];
        NodeState after = states[1];
        assertNotNull(before);
View Full Code Here

        testBuilder.getChildNode("a").remove();

        NodeState newRoot = rootBuilder.getNodeState();

        NodeStoreBranch branch = store.branch();
        branch.setRoot(newRoot);
        branch.merge(new CommitHook() {
            @Override
            public NodeState processCommit(NodeState before, NodeState after) {
                NodeBuilder rootBuilder = after.builder();
                NodeBuilder testBuilder = rootBuilder.child("test");
                testBuilder.child("fromHook");
View Full Code Here

        assertEquals(test, store.getRoot().getChildNode("test"));
    }

    @Test
    public void manyChildNodes() throws CommitFailedException {
        NodeStoreBranch branch = store.branch();
        NodeBuilder root = branch.getHead().builder();
        NodeBuilder parent = root.child("parent");
        for (int i = 0; i <= KernelNodeState.MAX_CHILD_NODE_NAMES; i++) {
            parent.child("child-" + i);
        }
        branch.setRoot(root.getNodeState());
        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        NodeState base = store.getRoot();
        branch = store.branch();
        root = branch.getHead().builder();
        parent = root.child("parent");
        parent.child("child-new");
        branch.setRoot(root.getNodeState());
        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        Diff diff = new Diff();
        store.getRoot().compareAgainstBaseState(base, diff);

        assertEquals(0, diff.removed.size());
        assertEquals(1, diff.added.size());
        assertEquals("child-new", diff.added.get(0));

        base = store.getRoot();
        branch = store.branch();
        branch.move("/parent/child-new", "/parent/child-moved");
        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        diff = new Diff();
        store.getRoot().compareAgainstBaseState(base, diff);

        assertEquals(1, diff.removed.size());
        assertEquals("child-new", diff.removed.get(0));
        assertEquals(1, diff.added.size());
        assertEquals("child-moved", diff.added.get(0));

        base = store.getRoot();
        branch = store.branch();
        root = branch.getHead().builder();
        parent = root.child("parent");
        parent.child("child-moved").setProperty("foo", "value");
        parent.child("child-moved").setProperty(
                new MultiStringPropertyState("bar", Arrays.asList("value")));
        branch.setRoot(root.getNodeState());
        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        diff = new Diff();
        store.getRoot().compareAgainstBaseState(base, diff);

        assertEquals(0, diff.removed.size());
        assertEquals(0, diff.added.size());
        assertEquals(2, diff.addedProperties.size());
        assertTrue(diff.addedProperties.contains("foo"));
        assertTrue(diff.addedProperties.contains("bar"));

        base = store.getRoot();
        branch = store.branch();
        root = branch.getHead().builder();
        parent = root.child("parent");
        parent.setProperty("foo", "value");
        parent.setProperty(new MultiStringPropertyState(
                "bar", Arrays.asList("value")));
        branch.setRoot(root.getNodeState());
        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        diff = new Diff();
        store.getRoot().compareAgainstBaseState(base, diff);

        assertEquals(0, diff.removed.size());
        assertEquals(0, diff.added.size());
        assertEquals(2, diff.addedProperties.size());
        assertTrue(diff.addedProperties.contains("foo"));
        assertTrue(diff.addedProperties.contains("bar"));

        base = store.getRoot();
        branch = store.branch();
        root = branch.getHead().builder();
        parent = root.child("parent");
        parent.getChildNode("child-moved").remove();
        branch.setRoot(root.getNodeState());
        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);

        diff = new Diff();
        store.getRoot().compareAgainstBaseState(base, diff);

        assertEquals(1, diff.removed.size());
View Full Code Here

        assertEquals("child-moved", diff.removed.get(0));
    }

    @Test
    public void moveToSelf() throws CommitFailedException {
        NodeStoreBranch branch = store.branch();
        assertTrue(branch.move("/x", "/x"));
    }
View Full Code Here

            fixture.dispose(store2);
        }
    }

    private static NodeStore init(NodeStore store) throws CommitFailedException {
        NodeStoreBranch branch = store.branch();
        NodeBuilder builder = branch.getHead().builder();
        builder.setChildNode("root");
        branch.setRoot(builder.getNodeState());
        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
        return store;
    }
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.