com.thinkaurelius.titan.graphdb.query

## Class QueryProcessor<Q extends ElementQuery<R,B>,R extends TitanElement,B extends BackendQuery<B>>

- java.lang.Object
- - com.thinkaurelius.titan.graphdb.query.QueryProcessor<Q,R,B>

- All Implemented Interfaces:
    Iterable<R>

      public class QueryProcessor<Q extends ElementQuery<R,B>,R extends TitanElement,B extends BackendQuery<B>>
      extends Object
      implements Iterable<R>

  Executes a given `ElementQuery` against a provided `QueryExecutor` to produce the result set of elements. The QueryProcessor creates a number of stacked iterators. At the highest level, the OuterIterator ensures that the correct (up to the given limit) number of elements is returned. It also provides the implementation of remove() by calling the element's remove() method. The OuterIterator wraps the "unfolded" iterator which is a combination of the individual result set iterators of the sub-queries of the given query (see `ElementQuery.getSubQuery(int)`. The unfolded iterator combines this iterators by checking whether 1) the result sets need additional filtering (if so, a filter iterator is wrapped around it) and 2) whether the final result set needs to be sorted and in what order. If the result set needs to be sorted and the individual sub-query result sets aren't, then a PreSortingIterator is wrapped around the iterator which effectively iterates the result set out, sorts it and then returns an iterator (i.e. much more expensive than exploiting existing sort orders). In this way, the individual sub-result sets are prepared and then merged together the MergeSortIterator (which conserves sort order if present). The semantics of the queries is OR, meaning the result sets are combined. However, when `ElementQuery.hasDuplicateResults()` is true (which assumes that the result set is sorted) then the merge sort iterator filters out immediate duplicates.
  Author:
    Matthias Broecheler (me@matthiasb.com)

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `QueryProcessor(Q query, QueryExecutor<Q,R,B> executor)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Iterator<R>` | `iterator()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### QueryProcessor

          public QueryProcessor(Q query,
                        QueryExecutor<Q,R,B> executor)

  - ### Method Detail

    - #### iterator

          public Iterator<R> iterator()

      Specified by:
        `iterator` in interface `Iterable<R extends TitanElement>`

Copyright © 2012–2014. All rights reserved.