protected CachedNode getNodeAtPath( Path path, NodeCache cache ) { CachedNode node = cache.getNode(cache.getRootKey()); for (Segment segment : path) { ChildReference childRef = node.getChildReferences(cache).getChild(segment); if (childRef == null) return null; node = cache.getNode(childRef); } return node; }
protected final WritableSessionCache writableSession( NodeCache cache ) { return (WritableSessionCache)cache.unwrap(); }
protected void shutdownCache( NodeCache cache ) { cache.clear(); }
@Override public void nextRow() { NodeKey key = keys.next(); current = cache.getNode(key); }
@Override public boolean isExternal( NodeCache cache ) { return !getKey().getSourceKey().equals(cache.getRootKey().getSourceKey()); }
@Test public void shouldNavigateFromRootToSystemNode() { CachedNode node = cache.getNode(cache.getRootKey()); ChildReference systemRef = node.getChildReferences(cache).getChild(JcrLexicon.SYSTEM); CachedNode system = cache.getNode(systemRef); print("Time (load): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms"); cache.clear(); nanos = System.nanoTime(); system.getKey(); CachedNode namespacesNode = cache.getNode(namespaces); print("Time (load): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms"); nanos = System.nanoTime();
addNodeWithLeafChildren("node33", "node331", "node332", "node333"); when(cache.getAllNodeKeys()).thenAnswer(new Answer<Iterator<NodeKey>>() { @Override public Iterator<NodeKey> answer( InvocationOnMock invocation ) throws Throwable { when(cache.getAllNodeKeysAtAndBelow((NodeKey)anyObject())).thenAnswer(new Answer<Iterator<NodeKey>>() { @Override public Iterator<NodeKey> answer( InvocationOnMock invocation ) throws Throwable {
protected NodeSequence allNodes( float score, int sizeOfBatches ) { return multipleBatchesOf(cache.getAllNodeKeys(), score, sizeOfBatches); }
protected void assertIterateOverSubtreeWhenUsingHasNextAndNext( NodeKey startingKey ) { Set<NodeKey> expected = findAllNodesAtOrBelow(startingKey); Iterator<NodeKey> iter = cache.getAllNodeKeysAtAndBelow(startingKey); while (iter.hasNext()) { NodeKey key = iter.next(); assertThat(key, is(notNullValue())); assertThat(expected.remove(key), is(true)); } assertThat(expected.isEmpty(), is(true)); }
@Override public void nextRow() { NodeKey key = keys.next(); current = cache.getNode(key); }
@Override public boolean isExternal( NodeCache cache ) { return !getKey().getSourceKey().equals(cache.getRootKey().getSourceKey()); }
@Test public void shouldIterateOverAllNodeKeysInTheCacheWhenUsingHasNextAndNext() { Set<NodeKey> expected = new HashSet<NodeKey>(allKeys); Iterator<NodeKey> iter = cache.getAllNodeKeys(); while (iter.hasNext()) { NodeKey key = iter.next(); assertThat(key, is(notNullValue())); assertThat(expected.remove(key), is(true)); } assertThat(expected.isEmpty(), is(true)); }
protected void assertIterateOverSubtreeWhenUsingOnlyNext( NodeKey startingKey ) { Set<NodeKey> expected = findAllNodesAtOrBelow(startingKey); Iterator<NodeKey> iter = cache.getAllNodeKeysAtAndBelow(startingKey); long size = expected.size(); for (int i = 0; i != size; ++i) { NodeKey key = iter.next(); assertThat(key, is(notNullValue())); assertThat(expected.remove(key), is(true)); } assertThat(expected.isEmpty(), is(true)); try { iter.next(); fail("Should have thrown a NoSuchElementException"); } catch (NoSuchElementException e) { // expected } }
protected CachedNode getNodeAtPath( Path path, NodeCache cache ) { CachedNode node = cache.getNode(cache.getRootKey()); for (Segment segment : path) { ChildReference childRef = node.getChildReferences(cache).getChild(segment); if (childRef == null) return null; node = cache.getNode(childRef); } return node; }
@Override public void nextRow() { NodeKey key = keys.next(); current = cache.getNode(key); Float score = scores.next(); this.score = score != null ? score.floatValue() : 1.0f; }
@Override public boolean isExternal( NodeCache cache) { return !getKey().getSourceKey().equals(cache.getRootKey().getSourceKey()); }
protected final WritableSessionCache writableSession( NodeCache cache ) { return (WritableSessionCache)cache.unwrap(); }
protected NodeSequence allNodes( float score ) { return NodeSequence.withNodeKeys(cache.getAllNodeKeys(), -1, score, workspaceName(), cache); }
if (NodeKey.isValidFormat(identifier)) { NodeKey key = new NodeKey(identifier); CachedNode node = cache.getNode(key); if (node != null && nodeFilter.includeNode(node, cache)) { return NodeSequence.withNodes(Collections.singleton(node), score, workspaceName); NodeKey key = cache.getRootKey().withId(identifier); CachedNode node = cache.getNode(key); if (node != null && nodeFilter.includeNode(node, cache)) { return NodeSequence.withNodes(Collections.singleton(node), score, workspaceName);
@Override public void nextRow() { NodeKey key = keys.next(); current = cache.getNode(key); Float score = scores.next(); this.score = score != null ? score.floatValue() : 1.0f; }