use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class EffectiveType method getDefaultType.
/**
* Finds the default node type for a child node with the given name.
*
* @param nameWithIndex child node name, possibly with an SNS index
* @return default type, or {@code null} if not found
*/
@CheckForNull
String getDefaultType(@Nonnull String nameWithIndex) {
String name = dropIndexFromName(nameWithIndex);
boolean sns = !name.equals(nameWithIndex);
for (NodeState type : types) {
NodeState named = type.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS).getChildNode(name);
NodeState residual = type.getChildNode(REP_RESIDUAL_CHILD_NODE_DEFINITIONS);
for (ChildNodeEntry entry : concat(named.getChildNodeEntries(), residual.getChildNodeEntries())) {
NodeState definition = entry.getNodeState();
String defaultType = definition.getName(JCR_DEFAULTPRIMARYTYPE);
if (defaultType != null && snsMatch(sns, definition)) {
return defaultType;
}
}
}
return null;
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class NodeCounter method collectCounts.
private void collectCounts(StringBuilder buff, String path, int level) {
long count = getEstimatedNodeCount(path);
if (count > 0) {
if (buff.length() > 0) {
buff.append(",\n");
}
buff.append(path).append(": ").append(count);
}
if (level <= 0) {
return;
}
NodeState s = child(store.getRoot(), PathUtils.elements(path));
if (!s.exists()) {
return;
}
ArrayList<String> names = new ArrayList<String>();
for (ChildNodeEntry c : s.getChildNodeEntries()) {
names.add(c.getName());
}
Collections.sort(names);
for (String cn : names) {
s.getChildNode(cn);
String child = PathUtils.concat(path, cn);
collectCounts(buff, child, level - 1);
}
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class NodeTypeIndexLookup method isIndexed.
/**
* Returns <code>true</code> if a node type index lookup exists at the given
* <code>path</code> or further up the tree.
*
* @param path the path to check.
* @return <code>true</code> if a node type index exists; <code>false</code>
* otherwise.
*/
public boolean isIndexed(String path, Filter f) {
PropertyIndexLookup lookup = new PropertyIndexLookup(root, mountInfoProvider);
if (lookup.isIndexed(JCR_PRIMARYTYPE, path, f) && lookup.isIndexed(JCR_MIXINTYPES, path, f)) {
return true;
}
if (path.startsWith("/")) {
path = path.substring(1);
}
int slash = path.indexOf('/');
if (slash == -1) {
return false;
}
NodeState child = root.getChildNode(path.substring(0, slash));
return new NodeTypeIndexLookup(child, mountInfoProvider).isIndexed(path.substring(slash), f);
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class NodeStoreDiffTest method testDiff.
/**
* This testcase demonstrates that diff logic in merge part traverses node path
* which are not affected by the commit
* @throws Exception
*/
@Test
public void testDiff() throws Exception {
createNodes("/oak:index/prop-a", "/oak:index/prop-b", "/etc/workflow");
//1. Make some other changes so as to bump root rev=3
createNodes("/fake/a");
createNodes("/fake/b");
//2 - Start change
NodeBuilder b2 = ns.getRoot().builder();
createNodes(b2, "/etc/workflow/instance1");
tds.reset();
//3. Merge which does a rebase
ns.merge(b2, new CommitHook() {
@Nonnull
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
NodeBuilder rb = after.builder();
createNodes(rb, "/oak:index/prop-a/a1");
//2.1 Commit some change under prop-
//This cause diff in lastRev of base node state in ModifiedNodeState for
//oak:index due to which when the base state is compared in ModifiedNodeState
//then it fetches the new DocumentNodeState whose lastRev is greater than this.base.lastRev
//but less then lastRev of the of readRevision. Where readRevision is the rev of root node when
//rebase was performed
// remember paths accessed so far
List<String> paths = Lists.newArrayList(tds.paths);
//This is not to be done in actual cases as CommitHooks are invoked in critical sections
//and creating nodes from within CommitHooks would cause deadlock. This is done here to ensure
//that changes are done when rebase has been performed and merge is about to happen
createNodes("/oak:index/prop-b/b1");
// reset accessed paths
tds.reset();
tds.paths.addAll(paths);
return rb.getNodeState();
}
}, CommitInfo.EMPTY);
//Assert that diff logic does not traverse to /oak:index/prop-b/b1 as
//its not part of commit
assertFalse(tds.paths.contains("/oak:index/prop-b/b1"));
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class NodeStoreDiffTest method merge.
private NodeState merge(NodeBuilder nb) throws CommitFailedException {
NodeState result = ns.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
prRev(result);
ops();
return result;
}
Aggregations