Beispiel #1
0
  /**
   * Computes the number of results.
   *
   * @param qc query context (may be @code null)
   * @return number of results
   */
  private long size(final QueryContext qc) {
    final Value rt = initial(qc);
    // skip computation if value is not a document node
    if (rt == null || rt.type != NodeType.DOC) return -1;
    final Data data = rt.data();
    // skip computation if no database instance is available, is out-of-date or
    // if context does not contain all database nodes
    if (data == null || !data.meta.uptodate || data.resources.docs().size() != rt.size()) return -1;

    ArrayList<PathNode> nodes = data.paths.root();
    long m = 1;
    final int sl = steps.length;
    for (int s = 0; s < sl; s++) {
      final Step curr = axisStep(s);
      if (curr != null) {
        nodes = curr.nodes(nodes, data);
        if (nodes == null) return -1;
      } else if (s + 1 == sl) {
        m = steps[s].size();
      } else {
        // stop if a non-axis step is not placed last
        return -1;
      }
    }

    long sz = 0;
    for (final PathNode pn : nodes) sz += pn.stats.count;
    return sz * m;
  }
Beispiel #2
0
  /**
   * Returns the path nodes that will result from this path.
   *
   * @param qc query context
   * @return path nodes, or {@code null} if nodes cannot be evaluated
   */
  public final ArrayList<PathNode> pathNodes(final QueryContext qc) {
    final Value init = initial(qc);
    final Data data = init != null && init.type == NodeType.DOC ? init.data() : null;
    if (data == null || !data.meta.uptodate) return null;

    ArrayList<PathNode> nodes = data.paths.root();
    final int sl = steps.length;
    for (int s = 0; s < sl; s++) {
      final Step curr = axisStep(s);
      if (curr == null) return null;
      nodes = curr.nodes(nodes, data);
      if (nodes == null) return null;
    }
    return nodes;
  }