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;
}
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());
}
Aggregations