= Query
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

For use by repository implementations, representing the values of a query.

The implementations of these objects are be provided by the underlying persistor/object store; consult its documentation.

Implementations are expected to implement the _#getRange()_ method, which is used to support range / paging the data. Returned result sets are expected to start from index "start", and no more than "count" items are expected.

 *Note:* not every object store will necessarily support this interface. In particular, the in-memory object store does not. For this, you can use the _Predicate_ interface to similar effect, for example in _RepositoryService#allMatches(Class, Predicate, long, long)_ ). *Note:* that the predicate is applied within the xref:refguide:applib:index/services/repository/RepositoryService.adoc[RepositoryService] (ie client-side) rather than being pushed back to the object store.

== API

[source,java]
.Query.java
----
interface Query<T> {
  Class<T> getResultType()     // <.>
  String getDescription()     // <.>
  QueryRange getRange()     // <.>
  Query<T> withRange(QueryRange range)
  Query<T> withRange(long... range)
  Query<T> withStart(long start)
  Query<T> withLimit(long limit)
  Query<T> allInstances(Class<T> resultType)
  NamedQuery<T> named(Class<T> resultType, String queryName)
}
----

<.> xref:#getResultType_[getResultType()]
+
--
The _Class_ of the objects returned by this query.
--
<.> xref:#getDescription_[getDescription()]
+
--
A human-readable representation of this query and its values.
--
<.> xref:#getRange_[getRange()]
+
--
Returns a model with start index into the set table and maximal number of items to return.
--

== Members

[#getResultType_]
=== getResultType()

The _Class_ of the objects returned by this query.

[#getDescription_]
=== getDescription()

A human-readable representation of this query and its values.

[#getRange_]
=== getRange()

Returns a model with start index into the set table and maximal number of items to return.
