Class InternalQuery<T,​Q extends 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.

    • Method Detail

      • self

        protected final Q self()
      • setLimit

        public final Q setLimit​(int n)
      • enforceVisibility

        public final Q enforceVisibility​(boolean enforce)
      • 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.
      • schema

        protected final Schema<T> schema()
      • 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 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.
        Returns:
        exhaustive list of results, subject to the race condition described above.