public class InternalQuery<T,Q extends InternalQuery<T,Q>> extends Object
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.
Modifier and Type | Field and Description |
---|---|
protected IndexConfig |
indexConfig |
Modifier | Constructor and Description |
---|---|
protected |
InternalQuery(QueryProcessor<T> queryProcessor,
IndexCollection<?,T,? extends Index<?,T>> indexes,
IndexConfig indexConfig) |
Modifier and Type | Method and Description |
---|---|
Q |
enforceVisibility(boolean enforce) |
Q |
noFields() |
List<List<T>> |
query(List<Predicate<T>> queries)
Run multiple queries in parallel.
|
List<T> |
query(Predicate<T> p) |
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) |
protected final IndexConfig indexConfig
protected InternalQuery(QueryProcessor<T> queryProcessor, IndexCollection<?,T,? extends Index<?,T>> indexes, IndexConfig indexConfig)
protected final Q self()
public final Q setLimit(int n)
public final Q enforceVisibility(boolean enforce)
@SafeVarargs public final Q setRequestedFields(FieldDef<T,?>... fields)
public final Q noFields()
public final List<List<T>> query(List<Predicate<T>> queries)
If a limit was specified using setLimit(int)
, that limit is applied to each query
independently.
queries
- list of queries.protected static <T> com.google.common.collect.ImmutableList<T> queryExhaustively(Supplier<? extends InternalQuery<T,?>> querySupplier, Predicate<T> predicate)
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.
T
- result type.querySupplier
- supplier for queries. Callers will generally pass a lambda that invokes an
underlying Provider<InternalFooQuery>
, since the instances are not reusable. The
lambda may also call additional methods on the newly-created query, such as enforceVisibility(boolean)
.predicate
- predicate to search for.