private void addPathFromChangeSet(ChangeSet cs) { int maxDepthInChangeSet = cs.getMaxPrefilterPathDepth(); //If maxDepth of ChangeSet being added is less than current //then truncate path in current set to that depth and change //maxPathDepth to one from ChangeSet if (maxDepthInChangeSet < maxPathDepth){ Set<String> existingPathSet = Sets.newHashSet(parentPaths); parentPaths.clear(); for (String existingPath : existingPathSet){ parentPaths.add(getPathWithMaxDepth(existingPath, maxDepthInChangeSet)); } maxPathDepth = maxDepthInChangeSet; } for (String pathFromChangeSet : cs.getParentPaths()){ addParentPath(getPathWithMaxDepth(pathFromChangeSet, maxPathDepth)); } }
private void addPathFromChangeSet(ChangeSet cs) { int maxDepthInChangeSet = cs.getMaxPrefilterPathDepth(); //If maxDepth of ChangeSet being added is less than current //then truncate path in current set to that depth and change //maxPathDepth to one from ChangeSet if (maxDepthInChangeSet < maxPathDepth){ Set<String> existingPathSet = Sets.newHashSet(parentPaths); parentPaths.clear(); for (String existingPath : existingPathSet){ parentPaths.add(getPathWithMaxDepth(existingPath, maxDepthInChangeSet)); } maxPathDepth = maxDepthInChangeSet; } for (String pathFromChangeSet : cs.getParentPaths()){ addParentPath(getPathWithMaxDepth(pathFromChangeSet, maxPathDepth)); } }
private ChangeSetBuilder overflowParentPaths(ChangeSetBuilder builder) { int i = 0; while (!builder.isParentPathOverflown()) { builder.addParentPath("foo" + i++); } return builder; }
@Override public Validator childNodeChanged(String childName, NodeState before, NodeState after) throws CommitFailedException { if (level == support.maxPathDepth) { // then we'll cut off further paths below. // to compensate, add the current path at this level support.changeSetBuilder.addParentPath(path); // however, continue normally to handle names/types/properties // below } // in theory the node type could be changed, so collecting both before and after addToAllNodeType(before); addToAllNodeType(after); return newChildCollector(before, after, childName); }
@Override public Validator childNodeChanged(String childName, NodeState before, NodeState after) throws CommitFailedException { if (level == support.maxPathDepth) { // then we'll cut off further paths below. // to compensate, add the current path at this level support.changeSetBuilder.addParentPath(path); // however, continue normally to handle names/types/properties // below } // in theory the node type could be changed, so collecting both before and after addToAllNodeType(before); addToAllNodeType(after); return newChildCollector(before, after, childName); }
@Override public Validator childNodeChanged(String childName, NodeState before, NodeState after) throws CommitFailedException { if (level == support.maxPathDepth) { // then we'll cut off further paths below. // to compensate, add the current path at this level support.changeSetBuilder.addParentPath(path); // however, continue normally to handle names/types/properties // below } // in theory the node type could be changed, so collecting both before and after addToAllNodeType(before); addToAllNodeType(after); return newChildCollector(before, after, childName); }
@Test public void pathDepth() throws Exception{ ChangeSetBuilder cb = new ChangeSetBuilder(10, 2); cb.addParentPath("/a/b"); cb.addParentPath("/x"); cb.addParentPath("/p/q/r"); ChangeSet cs = cb.build(); assertThat(cs.getParentPaths(), containsInAnyOrder("/a/b", "/x", "/p/q")); }
@Override public void leave(NodeState before, NodeState after) throws CommitFailedException { // first check if we have to add anything to paths and/or nodeNames if (changed && level <= support.maxPathDepth) { support.changeSetBuilder.addParentPath(path); } if (changed && childName != null) { support.changeSetBuilder.addParentNodeName(childName); } if (changed){ addParentNodeType(beforeParentNodeOrNull); addParentNodeType(afterParentNodeOrNull); } // then if we're not at the root, we're done if (!isRoot) { return; } // but if we're at the root, then we add the ChangeSet to the // CommitContext of the CommitInfo CommitContext commitContext = (CommitContext) support.info.getInfo().get(CommitContext.NAME); ChangeSet changeSet = support.changeSetBuilder.build(); commitContext.set(ChangeSet.COMMIT_CONTEXT_OBSERVATION_CHANGESET, changeSet); LOG.debug("Collected changeSet for commit {} is {}", support.info, changeSet); }
@Override public void leave(NodeState before, NodeState after) throws CommitFailedException { // first check if we have to add anything to paths and/or nodeNames if (changed && level <= support.maxPathDepth) { support.changeSetBuilder.addParentPath(path); } if (changed && childName != null) { support.changeSetBuilder.addParentNodeName(childName); } if (changed){ addParentNodeType(beforeParentNodeOrNull); addParentNodeType(afterParentNodeOrNull); } // then if we're not at the root, we're done if (!isRoot) { return; } // but if we're at the root, then we add the ChangeSet to the // CommitContext of the CommitInfo CommitContext commitContext = (CommitContext) support.info.getInfo().get(CommitContext.NAME); ChangeSet changeSet = support.changeSetBuilder.build(); commitContext.set(ChangeSet.COMMIT_CONTEXT_OBSERVATION_CHANGESET, changeSet); LOG.debug("Collected changeSet for commit {} is {}", support.info, changeSet); }
@Override public void leave(NodeState before, NodeState after) throws CommitFailedException { // first check if we have to add anything to paths and/or nodeNames if (changed && level <= support.maxPathDepth) { support.changeSetBuilder.addParentPath(path); } if (changed && childName != null) { support.changeSetBuilder.addParentNodeName(childName); } if (changed){ addParentNodeType(beforeParentNodeOrNull); addParentNodeType(afterParentNodeOrNull); } // then if we're not at the root, we're done if (!isRoot) { return; } // but if we're at the root, then we add the ChangeSet to the // CommitContext of the CommitInfo CommitContext commitContext = (CommitContext) support.info.getInfo().get(CommitContext.NAME); ChangeSet changeSet = support.changeSetBuilder.build(); commitContext.set(ChangeSet.COMMIT_CONTEXT_OBSERVATION_CHANGESET, changeSet); LOG.debug("Collected changeSet for commit {} is {}", support.info, changeSet); }
@Test public void changeSetDepthMoreThanBuilder() throws Exception{ ChangeSetBuilder cb1 = new ChangeSetBuilder(10, 3); cb1.addParentPath("/x"); cb1.addParentPath("/x/y"); cb1.addParentPath("/x/y/z"); ChangeSetBuilder cb2 = new ChangeSetBuilder(10, 8); cb2.addParentPath("/p"); cb2.addParentPath("/p/q"); cb2.addParentPath("/p/q/r"); cb2.addParentPath("/a/b/c/d"); cb2.addParentPath("/a/b/x/y/z"); cb1.add(cb2.build()); ChangeSet cs = cb1.build(); assertThat(cs.getParentPaths(), containsInAnyOrder( "/x", "/x/y", "/x/y/z", "/p", "/p/q", "/p/q/r", "/a/b/c", "/a/b/x" //Chopped paths )); assertEquals(cb1.getMaxPrefilterPathDepth(), cs.getMaxPrefilterPathDepth()); }
@Test public void builderDepthMoreThanChangeSet() throws Exception{ ChangeSetBuilder cb1 = new ChangeSetBuilder(10, 8); cb1.addParentPath("/p"); cb1.addParentPath("/p/q"); cb1.addParentPath("/p/q/r"); cb1.addParentPath("/a/b/c/d"); cb1.addParentPath("/a/b/x/y/z"); ChangeSetBuilder cb2 = new ChangeSetBuilder(10, 2); cb2.addParentPath("/x"); cb2.addParentPath("/x/y"); cb1.add(cb2.build()); ChangeSet cs = cb1.build(); assertThat(cs.getParentPaths(), containsInAnyOrder( "/x", "/x/y", "/p", "/p/q", "/a/b" //Chopped paths )); assertEquals(cb2.getMaxPrefilterPathDepth(), cs.getMaxPrefilterPathDepth()); }
private static void add(ChangeSetBuilder cb, String suffix){ cb.addNodeType("nt-"+suffix) .addParentPath("p-"+suffix) .addParentNodeName("nn-"+suffix) .addParentNodeType("pnt-"+suffix) .addPropertyName("pn-"+suffix); }
@Test public void manyIncludePaths() throws Exception { int numPaths = 50; ChangeSetBuilder builder = newBuilder(50, 9); for (int i = 0; i < numPaths; i++) { builder.addParentPath("/a/b/c/d/e/n" + i); } ChangeSet cs = builder.build(); Set<String> includes = Sets.newHashSet(); for (int i = 0; i < 100; i++) { includes.add("/foo/bar/n-" + i + "/*.jsp"); } ChangeSetFilter filter = new ChangeSetFilterImpl(s(),true, includes, s(), s(), s(), s()); // warm up doManyIncludePaths(filter, cs); // and measure Stopwatch sw = Stopwatch.createStarted(); doManyIncludePaths(filter, cs); LOG.info("manyIncludePaths() took {}", sw.stop()); }
private ChangeSetBuilder sampleBuilder() { ChangeSetBuilder builder = newBuilder(5, 5); builder.addNodeType("nt:file"); builder.addParentNodeType("nt:file"); builder.addParentPath("/bar"); builder.addParentNodeName("bar"); builder.addPropertyName("a"); builder.addPropertyName("b"); return builder; }
private ChangeSet newChangeSet(int maxPathDepth, Set<String> parentPaths, Set<String> parentNodeNames, Set<String> parentNodeTypes, Set<String> propertyNames, Set<String> allNodeTypes) { ChangeSetBuilder changeSetBuilder = new ChangeSetBuilder(Integer.MAX_VALUE, maxPathDepth); for (String path : parentPaths){ changeSetBuilder.addParentPath(path); } for (String nodeName : parentNodeNames){ changeSetBuilder.addParentNodeName(nodeName); } for (String parentNodeType : parentNodeTypes){ changeSetBuilder.addParentNodeType(parentNodeType); } for (String propertyName : propertyNames){ changeSetBuilder.addPropertyName(propertyName); } for (String nodeType : allNodeTypes){ changeSetBuilder.addNodeType(nodeType); } return changeSetBuilder.build(); }
private void doTestDeepPath(String changeSetPath, String includePath, int maxPathDepth, boolean expectExclude) { ChangeSetBuilder builder = newBuilder(5, maxPathDepth); builder.addNodeType("nt:file"); builder.addParentNodeType("nt:file"); builder.addParentPath("/bar"); builder.addParentNodeName("bar"); builder.addPropertyName("a"); builder.addPropertyName("b"); builder.addParentPath(changeSetPath); builder.addParentNodeName(PathUtils.getName(changeSetPath)); ChangeSetFilterImpl prefilter = new ChangeSetFilterImpl(s(includePath), true, null, s("/excluded"), s("foo", "bars", "l"), s("nt:file"), s()); if (expectExclude) { assertTrue(prefilter.excludes(builder.build())); } else { assertFalse(prefilter.excludes(builder.build())); } }
builder.addNodeType("nt:file"); builder.addParentNodeType("nt:file"); builder.addParentPath("/a/b/c/e"); builder.addParentNodeName("d"); builder.addPropertyName("e");