@Override public boolean apply(NodeBuilder builder) { return builder.getChildNodeCount(maxNodeCount) < maxNodeCount; } }).setChildNode('N' + itemPrefix + rnd.nextInt(maxNodeCount));
@Override public synchronized long getChildNodeCount(long max) { if (getTreePermission().canReadAll()) { return builder.getChildNodeCount(max); } else { return size(getChildNodeNames()); } }
@Override public synchronized long getChildNodeCount(long max) { if (getTreePermission().canReadAll()) { return builder.getChildNodeCount(max); } else { return size(getChildNodeNames()); } }
@Override public synchronized long getChildNodeCount(long max) { if (getTreePermission().canReadAll()) { return builder.getChildNodeCount(max); } else { return size(getChildNodeNames()); } }
@Override public long getChildNodeCount(final long max) { List<MountedNodeStore> contributingStores = ctx.getContributingStoresForBuilders(getPath(), nodeBuilders); if (contributingStores.isEmpty()) { return 0; // this shouldn't happen } else if (contributingStores.size() == 1) { return getWrappedNodeBuilder().getChildNodeCount(max); } else { // Count the children in each contributing store. return accumulateChildSizes(FluentIterable.from(contributingStores) .transformAndConcat(mns -> { NodeBuilder node = nodeBuilders.get(mns); if (node.getChildNodeCount(max) == MAX_VALUE) { return singleton(STOP_COUNTING_CHILDREN); } else { return FluentIterable.from(node.getChildNodeNames()).filter(e -> belongsToStore(mns, e)); } }), max); } }
/** * Physically prune a list of nodes from the index * * @param index * the current index * @param builders * list of nodes to prune * @param key the key of the index we're processing */ void prune(final NodeBuilder index, final Deque<NodeBuilder> builders, final String key) { for (NodeBuilder node : builders) { if (node.getBoolean("match") || node.getChildNodeCount(1) > 0) { return; } else if (node.exists()) { node.remove(); } } }
/** * Physically prune a list of nodes from the index * * @param index * the current index * @param builders * list of nodes to prune * @param key the key of the index we're processing */ void prune(final NodeBuilder index, final Deque<NodeBuilder> builders, final String key) { for (NodeBuilder node : builders) { if (node.getBoolean("match") || node.getChildNodeCount(1) > 0) { return; } else if (node.exists()) { node.remove(); } } }
/** * Physically prune a list of nodes from the index * * @param index * the current index * @param builders * list of nodes to prune * @param key the key of the index we're processing */ void prune(final NodeBuilder index, final Deque<NodeBuilder> builders, final String key) { for (NodeBuilder node : builders) { if (node.getBoolean("match") || node.getChildNodeCount(1) > 0) { return; } else if (node.exists()) { node.remove(); } } }
private NodeBuilder randomStep(NodeBuilder parent, NodeBuilder node) { int count = (int) node.getChildNodeCount(Long.MAX_VALUE); int k = rnd.nextInt(count + 1); if (k == 0) { return parent; } else { String name = get(node.getChildNodeNames(), k - 1); return node.getChildNode(name); } }
public void leaveNew(NodeState before, NodeState after) throws CommitFailedException { if (countOffsets.isEmpty()) { return; } root.callback.indexUpdate(); for (Map.Entry<Mount, Integer> e : countOffsets.entrySet()) { NodeBuilder builder = getBuilder(e.getKey()); int countOffset = e.getValue(); PropertyState p = builder.getProperty(COUNT_HASH_PROPERTY_NAME); long count = p == null ? 0 : p.getValue(Type.LONG); count += countOffset; if (count <= 0) { if (builder.getChildNodeCount(1) >= 0) { builder.removeProperty(COUNT_HASH_PROPERTY_NAME); } else { builder.remove(); } } else { builder.setProperty(COUNT_HASH_PROPERTY_NAME, count); } } }
private void descent(NodeStore nodeStore, NodeBuilder nodeBuilder) throws IOException { long count = nodeBuilder.getChildNodeCount(Long.MAX_VALUE); if (count > 0) { int c = rnd.nextInt((int) count); String name = Iterables.get(nodeBuilder.getChildNodeNames(), c); modify(nodeStore, nodeBuilder.getChildNode(name)); } }
private String chooseNode(String parentPath) { NodeBuilder node = getNode(parentPath); int numChildren = (int) node.getChildNodeCount(Long.MAX_VALUE); if (numChildren == 0) { return null; } int k = random.nextInt(numChildren); int c = 0; for (String name : node.getChildNodeNames()) { if (c++ == k) { return PathUtils.concat(parentPath, name); } } return null; }
@Test public void builderChildrenCountInRootStore() throws Exception { assertThat("root(childCount)", store.getRoot().builder().getChildNodeCount(100), equalTo(4l)); }
@Test public void builderChildrenCountInMountedStore() { assertThat("root.tmp(childCount)", store.getRoot().builder().getChildNode("tmp").getChildNodeCount(10), equalTo(2l)); }
public void leaveNew(NodeState before, NodeState after) throws CommitFailedException { if (countOffset == 0) { return; } NodeBuilder builder = getBuilder(); PropertyState p = builder.getProperty(COUNT_HASH_PROPERTY_NAME); long count = p == null ? 0 : p.getValue(Type.LONG); count += countOffset; root.callback.indexUpdate(); if (count <= 0) { if (builder.getChildNodeCount(1) >= 0) { builder.removeProperty(COUNT_HASH_PROPERTY_NAME); } else { builder.remove(); } } else { builder.setProperty(COUNT_HASH_PROPERTY_NAME, count); } }
public void leaveNew(NodeState before, NodeState after) throws CommitFailedException { if (countOffset == 0) { return; } NodeBuilder builder = getBuilder(); PropertyState p = builder.getProperty(COUNT_HASH_PROPERTY_NAME); long count = p == null ? 0 : p.getValue(Type.LONG); count += countOffset; root.callback.indexUpdate(); if (count <= 0) { if (builder.getChildNodeCount(1) >= 0) { builder.removeProperty(COUNT_HASH_PROPERTY_NAME); } else { builder.remove(); } } else { builder.setProperty(COUNT_HASH_PROPERTY_NAME, count); } }
public void leaveNew(NodeState before, NodeState after) throws CommitFailedException { if (countOffset == 0) { return; } NodeBuilder builder = getBuilder(); PropertyState p = builder.getProperty(COUNT_HASH_PROPERTY_NAME); long count = p == null ? 0 : p.getValue(Type.LONG); count += countOffset; root.callback.indexUpdate(); if (count <= 0) { if (builder.getChildNodeCount(1) >= 0) { builder.removeProperty(COUNT_HASH_PROPERTY_NAME); } else { builder.remove(); } } else { builder.setProperty(COUNT_HASH_PROPERTY_NAME, count); } }
@Test public void testWriteOnRemoveNode() { for (String name : new String[] {"x", "new"}) { NodeBuilder root = base.builder(); NodeBuilder child = root.child(name); root.getChildNode(name).remove(); try { child.setProperty("q", "w"); fail(); } catch (IllegalStateException e) { // expected } root.child(name); assertEquals(0, child.getChildNodeCount(1)); // reconnect! } }
@Test public void versionStoragePrePopulated() throws Exception { NodeBuilder root = EMPTY_NODE.builder(); new InitialContent().withPrePopulatedVersionStore().initialize(root); NodeBuilder system = root.getChildNode(JCR_SYSTEM); assertTrue(system.exists()); NodeBuilder vs = system.getChildNode(JCR_VERSIONSTORAGE); assertTrue(vs.exists()); // check if two levels of intermediate nodes were created assertTrue(vs.getChildNodeCount(Integer.MAX_VALUE) == 0xff); for (String name : vs.getChildNodeNames()) { assertTrue(vs.child(name).getChildNodeCount(Integer.MAX_VALUE) == 0xff); } }
@Test public void getChildNodeCount() throws Exception { CountingDocumentStore store = new CountingDocumentStore(new MemoryDocumentStore()); DocumentNodeStore ns = builderProvider.newBuilder().setAsyncDelay(0) .setDocumentStore(store).getNodeStore(); NodeBuilder builder = ns.getRoot().builder(); for (int i = 0; i < 100; i++) { builder.child("test").child("node-" + i); } merge(ns, builder); ns.getNodeChildrenCache().invalidateAll(); store.resetCounters(); builder = ns.getRoot().builder(); for (int i = 0; i < 100; i++) { NodeBuilder test = builder.child("test"); test.child("node-" + i).remove(); test.getChildNodeCount(1); } // must read the children of /test only once assertEquals(1, store.getNumQueryCalls(NODES)); }