Class InternalQuery<T,Q extends InternalQuery<T,Q>>
- java.lang.Object
-
- com.google.gerrit.index.query.InternalQuery<T,Q>
-
- Direct Known Subclasses:
InternalAccountQuery
,InternalChangeQuery
,InternalGroupQuery
public class InternalQuery<T,Q extends InternalQuery<T,Q>> extends Object
Execute a single query over a secondary index, for use by Gerrit internals.By default, visibility of returned entities is not enforced (unlike in
QueryProcessor
). The methods in this class are not typically used by user-facing paths, but rather by internal callers that need to process all matching results.Instances are one-time-use. Other singleton classes should inject a Provider rather than holding on to a single instance.
-
-
Field Summary
Fields Modifier and Type Field Description protected IndexConfig
indexConfig
-
Constructor Summary
Constructors Modifier Constructor Description protected
InternalQuery(QueryProcessor<T> queryProcessor, IndexCollection<?,T,? extends Index<?,T>> indexes, IndexConfig indexConfig)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Q
enforceVisibility(boolean enforce)
Q
noFields()
List<T>
query(Predicate<T> p)
List<List<T>>
query(List<Predicate<T>> queries)
Run multiple queries in parallel.protected static <T> com.google.common.collect.ImmutableList<T>
queryExhaustively(Supplier<? extends InternalQuery<T,?>> querySupplier, Predicate<T> predicate)
Query a predicate repeatedly until all results are exhausted.protected Schema<T>
schema()
protected Q
self()
Q
setLimit(int n)
Q
setRequestedFields(FieldDef<T,?>... fields)
-
-
-
Field Detail
-
indexConfig
protected final IndexConfig indexConfig
-
-
Constructor Detail
-
InternalQuery
protected InternalQuery(QueryProcessor<T> queryProcessor, IndexCollection<?,T,? extends Index<?,T>> indexes, IndexConfig indexConfig)
-
-
Method Detail
-
self
protected final Q self()
-
setLimit
public final Q setLimit(int n)
-
enforceVisibility
public final Q enforceVisibility(boolean enforce)
-
setRequestedFields
@SafeVarargs public final Q setRequestedFields(FieldDef<T,?>... fields)
-
noFields
public final Q noFields()
-
query
public final List<List<T>> query(List<Predicate<T>> queries)
Run multiple queries in parallel.If a limit was specified using
setLimit(int)
, that limit is applied to each query independently.- Parameters:
queries
- list of queries.- Returns:
- results of the queries, one list of results per input query, in the same order as the input.
-
queryExhaustively
protected static <T> com.google.common.collect.ImmutableList<T> queryExhaustively(Supplier<? extends InternalQuery<T,?>> querySupplier, Predicate<T> predicate)
Query a predicate repeatedly until all results are exhausted.Capable of iterating through all results regardless of limits. The passed
querySupplier
may choose to pre-set limits or not; this only affects the number of queries that may be issued, not the size of the final results.Since multiple queries may be issued, this method is subject to races when the result set changes mid-iteration. This may result in skipped results, if an entity gets modified to jump to the front of the list after this method has passed it. It may also result in duplicate results, if an entity at the end of one batch of results gets pushed back further, putting it at the beginning of the next batch. This race cannot be avoided unless we change the underlying index interface to support true continuation tokens.
- Type Parameters:
T
- result type.- Parameters:
querySupplier
- supplier for queries. Callers will generally pass a lambda that invokes an underlyingProvider<InternalFooQuery>
, since the instances are not reusable. The lambda may also call additional methods on the newly-created query, such asenforceVisibility(boolean)
.predicate
- predicate to search for.- Returns:
- exhaustive list of results, subject to the race condition described above.
-
-