/** * Create an empty results object. */ private Results() { this.problems = NO_PROBLEMS; this.columns = IndexQueryEngine.ResultColumns.EMPTY; this.statistics = new Statistics(); this.plan = null; this.rows = NodeSequence.emptySequence(0); this.cachedNodes = null; }
/** * Create an empty results object. */ private Results() { this.problems = NO_PROBLEMS; this.columns = IndexQueryEngine.ResultColumns.EMPTY; this.statistics = new Statistics(); this.plan = null; this.rows = NodeSequence.emptySequence(0); this.cachedNodes = null; }
/** * Create a sequence of nodes that iterates over the supplied nodes. Note that the supplied iterator is accessed lazily as the * resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param nodes the iterator over the nodes to be returned; if null, an {@link #emptySequence empty instance} is returned * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @return the sequence of nodes; never null */ public static NodeSequence withNodes( final Collection<CachedNode> nodes, final float score, final String workspaceName ) { if (nodes == null || nodes.isEmpty()) return emptySequence(1); return withNodes(nodes.iterator(), nodes.size(), score, workspaceName); }
/** * Create a sequence of nodes that iterates over the supplied nodes. Note that the supplied iterator is accessed lazily as the * resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param nodes the iterator over the nodes to be returned; if null, an {@link #emptySequence empty instance} is returned * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @return the sequence of nodes; never null */ public static NodeSequence withNodes( final Collection<CachedNode> nodes, final float score, final String workspaceName ) { if (nodes == null || nodes.isEmpty()) return emptySequence(1); return withNodes(nodes.iterator(), nodes.size(), score, workspaceName); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the nodes to be returned; if null, an {@link #emptySequence empty instance} is * returned * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param cache the cache used to access the cached nodes; may be null only if the key sequence is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Collection<NodeKey> keys, final float score, final String workspaceName, final NodeCache cache ) { if (keys == null || keys.isEmpty()) return emptySequence(1); return withNodeKeys(keys.iterator(), keys.size(), score, workspaceName, cache); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the nodes to be returned; if null, an {@link #emptySequence empty instance} is * returned * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param cache the cache used to access the cached nodes; may be null only if the key sequence is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Collection<NodeKey> keys, final float score, final String workspaceName, final NodeCache cache ) { if (keys == null || keys.isEmpty()) return emptySequence(1); return withNodeKeys(keys.iterator(), keys.size(), score, workspaceName, cache); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the nodes to be returned; if null, an {@link #emptySequence empty instance} is * returned * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param repository the repository cache used to access the workspaces and cached nodes; may be null only if the key sequence * is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Collection<NodeKey> keys, final float score, final String workspaceName, final RepositoryCache repository ) { if (keys == null || keys.isEmpty()) return emptySequence(1); return withNodeKeys(keys.iterator(), keys.size(), score, workspaceName, repository); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the nodes to be returned; if null, an {@link #emptySequence empty instance} is * returned * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param repository the repository cache used to access the workspaces and cached nodes; may be null only if the key sequence * is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Collection<NodeKey> keys, final float score, final String workspaceName, final RepositoryCache repository ) { if (keys == null || keys.isEmpty()) return emptySequence(1); return withNodeKeys(keys.iterator(), keys.size(), score, workspaceName, repository); }
/** * Create a sequence of nodes that iterates over the supplied nodes. Note that the supplied iterator is accessed lazily as the * resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param nodes the iterator over the node keys to be returned; if null, an {@link #emptySequence empty instance} is returned * @param nodeCount the number of nodes in the iterator; must be -1 if not known, 0 if known to be empty, or a positive number * if the number of nodes is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @return the sequence of nodes; never null */ public static NodeSequence withNodes( final Iterator<CachedNode> nodes, final long nodeCount, final float score, final String workspaceName ) { assert nodeCount >= -1; if (nodes == null) return emptySequence(1); return withBatch(batchOf(nodes, nodeCount, score, workspaceName)); }
/** * Create a sequence of nodes that iterates over the supplied nodes. Note that the supplied iterator is accessed lazily as the * resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param nodes the iterator over the node keys to be returned; if null, an {@link #emptySequence empty instance} is returned * @param nodeCount the number of nodes in the iterator; must be -1 if not known, 0 if known to be empty, or a positive number * if the number of nodes is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @return the sequence of nodes; never null */ public static NodeSequence withNodes( final Iterator<CachedNode> nodes, final long nodeCount, final float score, final String workspaceName ) { assert nodeCount >= -1; if (nodes == null) return emptySequence(1); return withBatch(batchOf(nodes, nodeCount, score, workspaceName)); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the node keys to be returned; if null, an {@link #emptySequence empty instance} * is returned * @param keyCount the number of node keys in the iterator; must be -1 if not known, 0 if known to be empty, or a positive * number if the number of node keys is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param cache the node cache used to access the cached nodes; may be null only if the key sequence is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Iterator<NodeKey> keys, final long keyCount, final float score, final String workspaceName, final NodeCache cache ) { assert keyCount >= -1; if (keys == null) return emptySequence(1); return withBatch(batchOfKeys(keys, keyCount, score, workspaceName, cache)); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the node keys to be returned; if null, an {@link #emptySequence empty instance} * is returned * @param keyCount the number of node keys in the iterator; must be -1 if not known, 0 if known to be empty, or a positive * number if the number of node keys is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param repository the repository cache used to access the workspaces and cached nodes; may be null only if the key sequence * is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Iterator<NodeKey> keys, final long keyCount, final float score, final String workspaceName, final RepositoryCache repository ) { assert keyCount >= -1; if (keys == null) return emptySequence(1); return withBatch(batchOfKeys(keys, keyCount, score, workspaceName, repository)); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the node keys to be returned; if null, an {@link #emptySequence empty instance} * is returned * @param keyCount the number of node keys in the iterator; must be -1 if not known, 0 if known to be empty, or a positive * number if the number of node keys is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param cache the node cache used to access the cached nodes; may be null only if the key sequence is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Iterator<NodeKey> keys, final long keyCount, final float score, final String workspaceName, final NodeCache cache ) { assert keyCount >= -1; if (keys == null) return emptySequence(1); return withBatch(batchOfKeys(keys, keyCount, score, workspaceName, cache)); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the node keys to be returned; if null, an {@link #emptySequence empty instance} * is returned * @param keyCount the number of node keys in the iterator; must be -1 if not known, 0 if known to be empty, or a positive * number if the number of node keys is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param repository the repository cache used to access the workspaces and cached nodes; may be null only if the key sequence * is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Iterator<NodeKey> keys, final long keyCount, final float score, final String workspaceName, final RepositoryCache repository ) { assert keyCount >= -1; if (keys == null) return emptySequence(1); return withBatch(batchOfKeys(keys, keyCount, score, workspaceName, repository)); }
@Before public void beforeEach() { context = mock(JcrQueryContext.class); query = "SELECT jcr:primaryType, foo:bar FROM nt:unstructured"; graphResult = mock(QueryResults.class); columnTypes = Arrays.asList("STRING", "LONG"); columnNames = Arrays.asList("jcr:primaryType", "foo:bar"); SelectorName tableName = new SelectorName("nt:unstructured"); columns = Arrays.asList(new Column(tableName, columnNames.get(0), columnNames.get(0)), new Column(tableName, columnNames.get(1), columnNames.get(1))); resultColumns = new ScanningQueryEngine.ResultColumns(columns, columnTypes, true, null); when(graphResult.getColumns()).thenReturn(resultColumns); when(graphResult.getRows()).thenReturn(NodeSequence.emptySequence(1)); PlanHints hints = new PlanHints(); result = new XPathQueryResult(context, query, graphResult, hints.restartable, hints.rowsKeptInMemory); }
/** * Obtain a {@link NodeSequence} that returns the (queryable) node at the given path in the workspace, where the node is * assigned the given score. * * @param path the path of the node; may not be null * @param score the score for the node * @return the sequence of node(s); never null */ public NodeSequence singleNode( Path path, float score ) { String workspaceName = getWorkspaceName(path); // Get the node filter to use ... NodeFilter nodeFilter = nodeFilterForWorkspace(workspaceName); if (nodeFilter != null) { // Find the node by path ... NodeCache cache = repo.getWorkspaceCache(workspaceName); CachedNode node = getNodeAtPath(path, cache); if (node != null && nodeFilter.includeNode(node, cache)) { return NodeSequence.withNodes(Collections.singleton(node), score, workspaceName); } } return NodeSequence.emptySequence(1); }
/** * Obtain a {@link NodeSequence} that returns the (queryable) node at the given path in the workspace, where the node is * assigned the given score. * * @param path the path of the node; may not be null * @param score the score for the node * @return the sequence of node(s); never null */ public NodeSequence singleNode( Path path, float score ) { String workspaceName = getWorkspaceName(path); // Get the node filter to use ... NodeFilter nodeFilter = nodeFilterForWorkspace(workspaceName); if (nodeFilter != null) { // Find the node by path ... NodeCache cache = repo.getWorkspaceCache(workspaceName); CachedNode node = getNodeAtPath(path, cache); if (node != null && nodeFilter.includeNode(node, cache)) { return NodeSequence.withNodes(Collections.singleton(node), score, workspaceName); } } return NodeSequence.emptySequence(1); }
/** * Obtain a {@link NodeSequence} that returns the (queryable) descendants of the node at the given path in the workspace, * where each descendant node is assigned the given score. * * @param ancestorPath the path of the ancestor of all descendants; may not be null * @param score the score for the nodes * @return the sequence of nodes; never null */ public NodeSequence descendantNodes( Path ancestorPath, float score ) { String workspaceName = getWorkspaceName(ancestorPath); // Get an iterator over all acceptable nodes in the workspace ... NodeCacheIterator iter = nodes(workspaceName, ancestorPath); if (iter != null) { if (iter.hasNext()) { // Skip the node at our path, which is to be excluded ... NodeKey key = iter.next(); assert ancestorPath.equals(path(workspaceName, key)) : "First node in results does not match the expected path"; } // Finally create and add a batch for this workspace ... return NodeSequence.withNodeKeys(iter, -1, score, workspaceName, repo); } return NodeSequence.emptySequence(1); }
/** * Create a sequence of nodes that skips a specified number of nodes before returning any nodes and that limits the number of * nodes returned. * * @param sequence the original sequence that is to be limited; may be null * @param limitAndOffset the specification of the offset and limit; if null this method simply returns <code>sequence</code> * @return the limitd sequence of nodes; never null */ public static NodeSequence limit( NodeSequence sequence, Limit limitAndOffset ) { if (sequence == null) return emptySequence(0); if (limitAndOffset != null && !limitAndOffset.isUnlimited()) { final int limit = limitAndOffset.getRowLimit(); // Perform the skip first ... if (limitAndOffset.isOffset()) { sequence = skip(sequence, limitAndOffset.getOffset()); } // And then the offset ... if (limit != Integer.MAX_VALUE) { sequence = limit(sequence, limit); } } return sequence; }
@Test public void shouldCreateEmptySequenceOfVariousWidths() { for (int i = 0; i != 10; ++i) { NodeSequence seq = NodeSequence.emptySequence(i); assertThat("Incorrect width for empty sequence", seq.width(), is(i)); assertThat(seq.nextBatch(), is(nullValue())); seq.close(); } }