Esempio n. 1
0
 /**
  * Returns the number of nodes in this iterator. Note: The number returned by this method may
  * differ from the number of nodes actually returned by calls to hasNext() / getNextNode()! This
  * is because this iterator works on a lazy instantiation basis and while iterating over the nodes
  * some of them might have been deleted in the meantime. Those will not be returned by
  * getNextNode(). As soon as an invalid node is detected, the size of this iterator is adjusted.
  *
  * @return the number of node in this iterator.
  * @see javax.jcr.RangeIterator#getSize()
  */
 public long getSize() {
   if (rows.getSize() != -1) {
     return rows.getSize() - invalid;
   } else {
     return -1;
   }
 }
Esempio n. 2
0
  /**
   * Clears {@link #next} and tries to fetch the next Node instance. When this method returns {@link
   * #next} refers to the next available node instance in this iterator. If {@link #next} is null
   * when this method returns, then there are no more valid element in this iterator.
   */
  private void fetchNext() {
    // reset
    next = null;
    nextScore = 0;

    while (next == null && rows.hasNext()) {
      try {
        QueryResultRow row = (QueryResultRow) rows.next();
        nextId = row.getNodeId(null);
        Item tmp = itemMgr.getItem(hierarchyMgr.getNodeEntry(nextId));

        if (tmp.isNode()) {
          next = (Node) tmp;
          nextScore = row.getScore(null);
        } else {
          log.warn("Item with Id is not a Node: " + nextId);
          // try next
          invalid++;
          pos++;
        }
      } catch (Exception e) {
        log.warn("Exception retrieving Node with Id: " + nextId);
        // try next
        invalid++;
        pos++;
      }
    }
    pos++;
  }
Esempio n. 3
0
 /**
  * Skip a number of <code>Node</code>s in this iterator.
  *
  * @param skipNum the non-negative number of <code>Node</code>s to skip
  * @throws NoSuchElementException if skipped past the last <code>Node</code> in this iterator.
  * @see javax.jcr.NodeIterator#skip(long)
  */
 public void skip(long skipNum) throws NoSuchElementException {
   if (skipNum < 0) {
     throw new IllegalArgumentException("skipNum must not be negative");
   }
   if (skipNum == 0) {
     // do nothing
   } else {
     rows.skip(skipNum - 1);
     pos += skipNum - 1;
     fetchNext();
   }
 }