Clean up methods for doing multiple queries in parallel
Add a method to InternalQuery for multiple queries analogous to the method for one query. Update the Javadoc in both InternalQuery and QueryProcessor to be consistent and correct. Change-Id: Ie91d233519afc0586cb52bdd7c5a657a5b0df0c1
This commit is contained in:
		@@ -15,6 +15,7 @@
 | 
			
		||||
package com.google.gerrit.server.query;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableSet;
 | 
			
		||||
import com.google.common.collect.Lists;
 | 
			
		||||
import com.google.gerrit.server.index.Index;
 | 
			
		||||
import com.google.gerrit.server.index.IndexCollection;
 | 
			
		||||
import com.google.gerrit.server.index.IndexConfig;
 | 
			
		||||
@@ -74,6 +75,25 @@ public class InternalQuery<T> {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Run multiple queries in parallel.
 | 
			
		||||
   * <p>
 | 
			
		||||
   * If a limit was specified using {@link #setLimit(int)}, that limit is
 | 
			
		||||
   * applied to each query independently.
 | 
			
		||||
   *
 | 
			
		||||
   * @param queries list of queries.
 | 
			
		||||
   * @return results of the queries, one list of results per input query, in the
 | 
			
		||||
   *     same order as the input.
 | 
			
		||||
   */
 | 
			
		||||
  public List<List<T>> query(List<Predicate<T>> queries) throws OrmException {
 | 
			
		||||
    try {
 | 
			
		||||
      return Lists.transform(
 | 
			
		||||
          queryProcessor.query(queries), QueryResult::entities);
 | 
			
		||||
    } catch (QueryParseException e) {
 | 
			
		||||
      throw new OrmException(e);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected Schema<T> schema() {
 | 
			
		||||
    Index<?, T> index = indexes != null ? indexes.getSearchIndex() : null;
 | 
			
		||||
    return index != null ? index.getSchema() : null;
 | 
			
		||||
 
 | 
			
		||||
@@ -122,16 +122,12 @@ public abstract class QueryProcessor<T> {
 | 
			
		||||
    return query(ImmutableList.of(query)).get(0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
   * Perform multiple queries over a list of query strings.
 | 
			
		||||
   * <p>
 | 
			
		||||
   * If a limit was specified using {@link #setLimit(int)} this method may
 | 
			
		||||
   * return up to {@code limit + 1} results, allowing the caller to determine if
 | 
			
		||||
   * there are more than {@code limit} matches and suggest to its own caller
 | 
			
		||||
   * that the query could be retried with {@link #setStart(int)}.
 | 
			
		||||
  /**
 | 
			
		||||
   * Perform multiple queries in parallel.
 | 
			
		||||
   *
 | 
			
		||||
   * @param queries the queries.
 | 
			
		||||
   * @return results of the queries, one list per input query.
 | 
			
		||||
   * @param queries list of queries.
 | 
			
		||||
   * @return results of the queries, one QueryResult per input query, in the
 | 
			
		||||
   *     same order as the input.
 | 
			
		||||
   */
 | 
			
		||||
  public List<QueryResult<T>> query(List<Predicate<T>> queries)
 | 
			
		||||
      throws OrmException, QueryParseException {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user