private ChangeSetBuilder newChangeSetBuilder() { return new ChangeSetBuilder(changeSetMaxItems, changeSetMaxDepth); }
private static void add(ChangeSetBuilder cb, String suffix){ cb.addNodeType("nt-"+suffix) .addParentPath("p-"+suffix) .addParentNodeName("nn-"+suffix) .addParentNodeType("pnt-"+suffix) .addPropertyName("pn-"+suffix); }
void addChangeSet(@Nullable ChangeSet changeSet){ if (changeSet == null){ if (LOG.isDebugEnabled()) { LOG.debug("Null changeSet found for caller. ChangeSetBuilder would be set to overflow mode", new Exception()); } } changeSetBuilder.add(changeSet); }
public ChangeSetBuilder addParentPath(String path){ path = getPathWithMaxDepth(path, maxPathDepth); parentPathOverflow = addAndCheckOverflow(parentPaths, path, maxItems, parentPathOverflow); return this; }
private void addToAllNodeType(NodeState state) { String primaryType = state.getName(JcrConstants.JCR_PRIMARYTYPE); if (primaryType != null) { support.changeSetBuilder.addNodeType(primaryType); } support.changeSetBuilder.addNodeTypes(state.getNames(JcrConstants.JCR_MIXINTYPES)); }
@Test public void addedChangeSetAlreadyOverflown() throws Exception{ ChangeSetBuilder cb1 = new ChangeSetBuilder(5, 2); add(cb1, "1"); ChangeSet cs1 = new ChangeSet(2, null, of("nn-2"), of("nt-2"), of("pn-2"), of("nt-2")); ChangeSet mcs1 = cb1.add(cs1).build(); assertNull(mcs1.getParentPaths()); assertThat(mcs1.getAllNodeTypes(), containsInAnyOrder("nt-1", "nt-2")); }
parentPathOverflow = true; } else { addPathFromChangeSet(cs); } else { for (String parentNodeName : cs.getParentNodeNames()){ addParentNodeName(parentNodeName); } else { for (String parentNodeType : cs.getParentNodeTypes()){ addParentNodeType(parentNodeType); } else { for (String propertyName : cs.getPropertyNames()){ addPropertyName(propertyName); } else { for (String nodeType : cs.getAllNodeTypes()){ addNodeType(nodeType);
@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 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")); }
UpdateOp asUpdateOp(@NotNull Revision revision) { String id = asId(revision); UpdateOp op = new UpdateOp(id, true); op.set(CHANGES, getChanges().serialize()); //For branch commits builder would be null if (changeSetBuilder != null) { op.set(CHANGE_SET, changeSetBuilder.build().asString()); } if (journalPropertyHandler != null){ journalPropertyHandler.addTo(op); } // OAK-3085 : introduce a timestamp property // for later being used by OAK-3001 op.set(MODIFIED, revision.getTimestamp()); String bc = (String) get(BRANCH_COMMITS); if (bc != null) { op.set(BRANCH_COMMITS, bc); } String inv = (String) get(INVALIDATE_ONLY); if (inv != null) { op.set(INVALIDATE_ONLY, inv); } return op; }
private void addParentNodeType(@Nullable NodeState state) { if (state == null){ return; } String primaryType = state.getName(JcrConstants.JCR_PRIMARYTYPE); if (primaryType != null) { support.changeSetBuilder.addParentNodeType(primaryType); } support.changeSetBuilder.addParentNodeTypes(state.getNames(JcrConstants.JCR_MIXINTYPES)); }
@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 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 addPropertyName(PropertyState after) { changed = true; support.changeSetBuilder.addPropertyName(after.getName()); }
@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); }
private ChangeSetBuilder overflowParentPaths(ChangeSetBuilder builder) { int i = 0; while (!builder.isParentPathOverflown()) { builder.addParentPath("foo" + i++); } return builder; }
private ChangeSetBuilder overflowPropertyNames(ChangeSetBuilder builder) { int i = 0; while (!builder.isPropertyNameOverflown()) { builder.addPropertyName("foo" + i++); } return builder; }
private ChangeSetBuilder overflowParentNodeNames(ChangeSetBuilder builder) { int i = 0; while (!builder.isParentNodeNameOverflown()) { builder.addParentNodeName("foo" + i++); } return builder; }
private ChangeSetBuilder overflowAllNodeTypes(ChangeSetBuilder builder) { int i = 0; while (!builder.isAllNodeTypeOverflown()) { builder.addNodeType("foo" + i++); } return builder; }