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

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


    @Override
    public void initialize(NodeStore store) {
        boolean dirty = false;

        NodeStoreBranch branch = store.branch();
        NodeBuilder root = branch.getRoot().builder();

        NodeBuilder index = root;
        for (String p : PathUtils.elements(path)) {
            if (!index.hasChildNode(p)) {
                dirty = true;
            }
            index = index.child(p);
        }

        if (dirty) {
            index.setProperty(JcrConstants.JCR_PRIMARYTYPE,
                    "oak:queryIndexDefinition", Type.NAME).setProperty("type",
                    "lucene");
            index.setProperty("reindex", true);
            try {
                branch.setRoot(root.getNodeState());
                branch.merge();
            } catch (CommitFailedException e) {
                throw new RuntimeException(e);
            }
        }
    }
View Full Code Here


@Service(RepositoryInitializer.class)
public class InitialContent implements RepositoryInitializer {

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

        NodeBuilder root = branch.getRoot().builder();
        root.setProperty(JCR_PRIMARYTYPE, "rep:root", Type.NAME);

        if (!root.hasChildNode(JCR_SYSTEM)) {
            NodeBuilder system = root.child(JCR_SYSTEM);
            system.setProperty(JCR_PRIMARYTYPE, "rep:system", Type.NAME);

            system.child(JCR_VERSIONSTORAGE)
                .setProperty(JCR_PRIMARYTYPE, "rep:versionStorage", Type.NAME);
            system.child("jcr:nodeTypes")
                .setProperty(JCR_PRIMARYTYPE, "rep:nodeTypes", Type.NAME);
            system.child("jcr:activities")
                .setProperty(JCR_PRIMARYTYPE, "rep:Activities", Type.NAME);
        }

        if (!root.hasChildNode("oak:index")) {
            NodeBuilder index = root.child("oak:index");
            index.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME); // TODO: use proper node type
            index.child("uuid")
                .setProperty(JCR_PRIMARYTYPE, "oak:queryIndexDefinition", Type.NAME)
                .setProperty("type", "p2")
                .setProperty("propertyNames", "jcr:uuid")
                .setProperty("reindex", true)
                .setProperty("unique", true);
            index.child("nodetype")
                .setProperty(JCR_PRIMARYTYPE, "oak:queryIndexDefinition", Type.NAME)
                .setProperty("type", "p2")
                .setProperty("reindex", true)
                .setProperty(PropertyStates.createProperty(
                        "propertyNames",
                        ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES),
                        Type.STRINGS));
        }
        try {
            branch.setRoot(root.getNodeState());
            branch.merge();
        } catch (CommitFailedException e) {
            throw new RuntimeException(e); // TODO: shouldn't need the wrapper
        }

        BuiltInNodeTypes.register(new RootImpl(store));
View Full Code Here

        // This means that the RepositoryInitializer should receive a
        // NodeStoreBranch as a param

        initializer.initialize(store);

        NodeStoreBranch branch = store.branch();
        NodeBuilder root = branch.getRoot().builder();
        try {
            branch.setRoot(IndexHookManager.of(indexHook).processCommit(
                    MemoryNodeState.EMPTY_NODE, root.getNodeState()));
            branch.merge();
        } catch (CommitFailedException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

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

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

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

        testBuilder.removeNode("x");

        newNodeBuilder.setProperty("n", 42);

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

        // 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(42, (long) testState.getChildNode("newNode").getProperty("n").getValue(LONG));

        // 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

        testBuilder.removeNode("a");

        NodeState newRoot = rootBuilder.getNodeState();

        NodeStoreBranch branch = store.branch();
        branch.setRoot(newRoot);
        branch.merge();
        store.getRoot(); // triggers the observer

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

        testBuilder.removeNode("a");

        NodeState newRoot = rootBuilder.getNodeState();

        NodeStoreBranch branch = store.branch();
        branch.setRoot(newRoot);
        branch.merge();

        NodeState test = store.getRoot().getChildNode("test");
        assertNotNull(test.getChildNode("newNode"));
        assertNotNull(test.getChildNode("fromHook"));
        assertNull(test.getChildNode("a"));
View Full Code Here

        new InitialContent().initialize(store);
    }

    @Test
    public void nodeType() throws Exception {
        NodeStoreBranch branch = store.branch();
        NodeBuilder root = branch.getRoot().builder();

        root.removeNode("rep:security"); // interferes with tests
        addFolder(root, "folder-1");
        addFolder(root, "folder-2");
        addFile(root, "file-1");

        branch.setRoot(root.getNodeState());
        branch.merge();

        NodeState rootState = store.getRoot();
        NodeTypeIndex index = new NodeTypeIndex();
        FilterImpl filter = new FilterImpl(null, null);
View Full Code Here

    private NodeState state;

    @Before
    public void setUp() throws CommitFailedException {
        NodeStore store = new KernelNodeStore(new MicroKernelImpl());
        NodeStoreBranch branch = store.branch();

        NodeBuilder builder = branch.getRoot().builder();
        builder.setProperty("a", 1);
        builder.setProperty("b", 2);
        builder.setProperty("c", 3);
        builder.child("x");
        builder.child("y");
        builder.child("z");
        branch.setRoot(builder.getNodeState());

        state = branch.merge();
    }
View Full Code Here

    private NodeState state;

    @Before
    public void setUp() throws CommitFailedException {
        NodeStore store = new KernelNodeStore(new MicroKernelImpl());
        NodeStoreBranch branch = store.branch();

        NodeBuilder builder = branch.getRoot().builder();
        builder.setProperty("a", 1);
        for (int i = 0; i <= N; i++) {
            builder.child("x" + i);
        }
        branch.setRoot(builder.getNodeState());

        state = branch.merge();
    }
View Full Code Here

        init(store);
        run(store);
    }

    private static void init(NodeStore store) throws CommitFailedException {
        NodeStoreBranch branch = store.branch();
        NodeBuilder builder = branch.getRoot().builder();
        builder.child("x").child("y").child("z");
        branch.setRoot(builder.getNodeState());
        branch.merge();
    }
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.