Search in sources :

Example 6 with DocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeState in project jackrabbit-oak by apache.

the class BundledDocumentDiffer method diff.

/**
     * Performs diff for bundled nodes. The passed state can be DocumentNodeState or
     * one from secondary nodestore i.e. {@code DelegatingDocumentNodeState}. So the
     * passed states cannot be cast down to DocumentNodeState
     *
     * @param from from state
     * @param to to state
     * @param w jsop diff
     * @return true if the diff needs to be continued. In case diff is complete it would return false
     */
public boolean diff(AbstractDocumentNodeState from, AbstractDocumentNodeState to, JsopWriter w) {
    boolean fromBundled = BundlorUtils.isBundledNode(from);
    boolean toBundled = BundlorUtils.isBundledNode(to);
    //Neither of the nodes bundled
    if (!fromBundled && !toBundled) {
        return true;
    }
    DocumentNodeState fromDocState = getDocumentNodeState(from);
    DocumentNodeState toDocState = getDocumentNodeState(to);
    diffChildren(fromDocState.getBundledChildNodeNames(), toDocState.getBundledChildNodeNames(), w);
    //If all child nodes are bundled then diff is complete
    if (fromDocState.hasOnlyBundledChildren() && toDocState.hasOnlyBundledChildren()) {
        return false;
    }
    return true;
}
Also used : DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)

Example 7 with DocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeState in project jackrabbit-oak by apache.

the class DocumentBundlingTest method saveAndReadNtFile.

@Test
public void saveAndReadNtFile() throws Exception {
    NodeBuilder builder = store.getRoot().builder();
    NodeBuilder fileNode = newNode("nt:file");
    fileNode.child("jcr:content").setProperty("jcr:data", "foo");
    builder.child("test").setChildNode("book.jpg", fileNode.getNodeState());
    merge(builder);
    NodeState root = store.getRoot();
    NodeState fileNodeState = root.getChildNode("test");
    assertTrue(fileNodeState.getChildNode("book.jpg").exists());
    NodeState contentNode = fileNodeState.getChildNode("book.jpg").getChildNode("jcr:content");
    assertTrue(contentNode.exists());
    assertEquals("jcr:content", getBundlingPath(contentNode));
    assertEquals(1, contentNode.getPropertyCount());
    assertEquals(1, Iterables.size(contentNode.getProperties()));
    assertNull(getNodeDocument("/test/book.jpg/jcr:content"));
    assertNotNull(getNodeDocument("/test/book.jpg"));
    assertTrue(hasNodeProperty("/test/book.jpg", concat("jcr:content", DocumentBundlor.META_PROP_BUNDLING_PATH)));
    AssertingDiff.assertEquals(fileNode.getNodeState(), fileNodeState.getChildNode("book.jpg"));
    DocumentNodeState dns = asDocumentState(fileNodeState.getChildNode("book.jpg"));
    AssertingDiff.assertEquals(fileNode.getNodeState(), dns.withRootRevision(dns.getRootRevision(), true));
    AssertingDiff.assertEquals(fileNode.getNodeState(), dns.fromExternalChange());
}
Also used : DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractNodeState(org.apache.jackrabbit.oak.spi.state.AbstractNodeState) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)5 Test (org.junit.Test)5 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)2 ReadPreference (com.mongodb.ReadPreference)1 AbstractMongoConnectionTest (org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)1 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)1 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)1 DocumentReadPreference (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore.DocumentReadPreference)1 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)1