Package org.infinispan.query.dsl
Interface Query<T>
- All Superinterfaces:
Iterable<T>
,PaginationContext<Query<T>>
,ParameterContext<Query<T>>
public interface Query<T>
extends Iterable<T>, PaginationContext<Query<T>>, ParameterContext<Query<T>>
An immutable object representing both the query and the result. The result is obtained lazily when one of the methods
in this interface is executed first time. The query is executed only once. Further calls will just return the
previously cached results. If you intend to re-execute the query to obtain fresh data you need to build another
instance using a
QueryBuilder
.- Since:
- 6.0
- Author:
- anistor@redhat.com
-
Method Summary
Modifier and TypeMethodDescription<K> CloseableIterator<Map.Entry<K,
T>> Returns aCloseableIterator
over the results, including both key and value.execute()
Executes the query (a SELECT statement).int
Executes a data modifying statement (typically a DELETE) that does not return results; instead it returns an affected entries count.int
Returns the named parameters Map.String[]
Deprecated.since 11.0.Returns the Ickle query string.int
Deprecated.since 10.1.long
boolean
Indicates if the parsed query has projections (a SELECT clause) and consequently the returned results will actually beObject[]
containing the projected values rather than the target entity.hitCountAccuracy
(int hitCountAccuracy) Limit the required accuracy of the hit count for the indexed queries to an upper-bound.iterator()
Returns aCloseableIterator
over the results.list()
Returns the results of a search as a list.local
(boolean local) Set the query execution scopemaxResults
(int maxResults) setParameter
(String paramName, Object paramValue) Sets the value of a named parameter.setParameters
(Map<String, Object> paramValues) Sets multiple named parameters at once.startOffset
(long startOffset) Set the timeout for this query.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
getQueryString
String getQueryString()Returns the Ickle query string. -
list
Returns the results of a search as a list.- Returns:
- list of objects that were found from the search.
-
execute
QueryResult<T> execute()Executes the query (a SELECT statement). Subsequent invocations cause the query to be re-executed.Executing a DELETE is also allowed. No results will be returned in this case but the number of affected entries will be returned as the hit count in the
QueryResult
.- Returns:
QueryResult
with the results.- Since:
- 11.0
-
executeStatement
int executeStatement()Executes a data modifying statement (typically a DELETE) that does not return results; instead it returns an affected entries count. This method cannot be used to execute a SELECT.NOTE: Paging params (firstResult/maxResults) are NOT allowed.
- Returns:
- the number of affected (deleted) entries
-
getResultSize
Deprecated.since 10.1. This will be removed in 12. It's closest replacement isQueryResult.hitCount()
which returns an optional long.Gets the total number of results matching the query, ignoring pagination (startOffset, maxResults).- Returns:
- total number of results.
-
getProjection
Deprecated.since 11.0. This method will be removed in next major version. To find out if a query uses projections usehasProjections()
- Returns:
- the values for query projections or
null
if the query does not have projections.
-
hasProjections
boolean hasProjections()Indicates if the parsed query has projections (a SELECT clause) and consequently the returned results will actually beObject[]
containing the projected values rather than the target entity.- Returns:
true
if it has projections,false
otherwise.
-
getStartOffset
long getStartOffset() -
startOffset
- Specified by:
startOffset
in interfacePaginationContext<T>
-
getMaxResults
int getMaxResults() -
maxResults
- Specified by:
maxResults
in interfacePaginationContext<T>
-
hitCountAccuracy
Integer hitCountAccuracy()- Returns:
- current hitCountAccuracy if present
- See Also:
-
hitCountAccuracy
Limit the required accuracy of the hit count for the indexed queries to an upper-bound. Setting the hit-count-accuracy could improve the performance of queries targeting large data sets.- Parameters:
hitCountAccuracy
- The value to apply- Returns:
this
, for method chaining
-
getParameters
Returns the named parameters Map.- Specified by:
getParameters
in interfaceParameterContext<T>
- Returns:
- the named parameters (unmodifiable) or
null
if the query does not have parameters
-
setParameter
Sets the value of a named parameter.- Specified by:
setParameter
in interfaceParameterContext<T>
- Parameters:
paramName
- the parameters name (non-empty and not null)paramValue
- a non-null value- Returns:
- itself
-
setParameters
Sets multiple named parameters at once. Parameters names cannot be empty ornull
. Parameter values must not benull
.- Specified by:
setParameters
in interfaceParameterContext<T>
- Parameters:
paramValues
- a Map of parameters- Returns:
- itself
-
iterator
CloseableIterator<T> iterator()Returns aCloseableIterator
over the results. Please close the iterator when you are done with processing the results. -
entryIterator
Returns aCloseableIterator
over the results, including both key and value. Please close the iterator when you are done with processing the results. The query cannot use projections.- Returns:
- the results of the query as an iterator.
-
timeout
Set the timeout for this query. If the query hasn't finished processing before the timeout, aSearchTimeoutException
will be thrown. For queries that use the index, the timeout is handled on a best effort basis, and the supplied time is rounded to the nearest millisecond. -
local
Set the query execution scope- Parameters:
local
- if true, query will be restricted to the data present in the local node, ignoring the other members of the clusters
-