org.qi4j.api.query

## Interface Query<T>

- All Superinterfaces:
    Iterable<T>, Serializable

      public interface Query<T>
      extends Iterable<T>, Serializable

  This represents a Query in an indexing system. It is created from a `QueryBuilder`, which decides the "where" clause in the query.

  Additional limitations, such as paging, ordering, and variables, can be set on a Query before it is executed by calling one of find(), iterator(), or count().

  DDD tip: typically Queries are created in the Domain Model and passed to the UI, which sets the order and paging before executing it.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `long` | `count()` Count how many results would be returned by this Query.
    `T` | `find()` Get the first Entity that matches the criteria.
    `Query<T>` | `firstResult(int firstResult)` Set the index of the first result.
    `<V> V` | `getVariable(String name)` Get the value of a named variable.
    `Query<T>` | `maxResults(int maxResults)` Set how many results should be returned.
    `Query<T>` | `orderBy(OrderBy... segments)` Set the ordering rules.
    `Query<T>` | `orderBy(Property<?> property)` Append an ascending ordering rule to the existing segments.
    `Query<T>` | `orderBy(Property<?> property, OrderBy.Order order)` Append an ordering rule to the existing segments.
    `Class<T>` | `resultType()` Get the result type of this Query
    `Query<T>` | `setVariable(String name, Object value)` Set the value of a named variable.

    - ### Methods inherited from interface java.lang.Iterable

      `iterator`

- - ### Method Detail

    - #### orderBy

          Query<T> orderBy(OrderBy... segments)

      Set the ordering rules. If many segments are used for ordering then they will be applied in order.
      Parameters:
        `segments` - the segments to order by
      Returns:
        the Query

    - #### orderBy

          Query<T> orderBy(Property<?> property,
                         OrderBy.Order order)

      Append an ordering rule to the existing segments.
      Parameters:
        `property` - the property to order by
        `order` - the order to apply
      Returns:
        the Query

    - #### orderBy

          Query<T> orderBy(Property<?> property)

      Append an ascending ordering rule to the existing segments.
      Parameters:
        `property` - the property to order by
      Returns:
        the Query

    - #### firstResult

          Query<T> firstResult(int firstResult)

      Set the index of the first result. Default is 0 (zero).
      Parameters:
        `firstResult` - which index to use as the first one
      Returns:
        the Query

    - #### maxResults

          Query<T> maxResults(int maxResults)

      Set how many results should be returned. Default is that there is no limit set.
      Parameters:
        `maxResults` - that shouldbe returned
      Returns:
        the query

    - #### find

          T find()
                 throws QueryExecutionException

      Get the first Entity that matches the criteria. This executes the Query.
      Returns:
        the first found Entity or null if none were found
      Throws:
        `QueryExecutionException` - if the query fails

    - #### setVariable

          Query<T> setVariable(String name,
                             Object value)

      Set the value of a named variable.
      Parameters:
        `name` - of the variable
        `value` - of the variable
      Returns:
        the query

    - #### getVariable

          <V> V getVariable(String name)

      Get the value of a named variable.
      Parameters:
        `name` - of the variable
      Returns:
        value of the variable

    - #### resultType

          Class<T> resultType()

      Get the result type of this Query
      Returns:
        the result type

    - #### count

          long count()
                     throws QueryExecutionException

      Count how many results would be returned by this Query. This executes the Query.
      Returns:
        result count
      Throws:
        `QueryExecutionException` - if the query fails