All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gerrit.server.query.InternalQuery Maven / Gradle / Ivy

There is a newer version: 3.10.0-rc4
Show newest version
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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;
import com.google.gerrit.server.index.Schema;
import com.google.gwtorm.server.OrmException;
import java.util.List;
import java.util.Set;

/**
 * Execute a single query over a secondary index, for use by Gerrit internals.
 *
 * 

By default, visibility of returned entities is not enforced (unlike in {@link * 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. */ public class InternalQuery { private final QueryProcessor queryProcessor; private final IndexCollection> indexes; protected final IndexConfig indexConfig; protected InternalQuery( QueryProcessor queryProcessor, IndexCollection> indexes, IndexConfig indexConfig) { this.queryProcessor = queryProcessor.enforceVisibility(false); this.indexes = indexes; this.indexConfig = indexConfig; } public InternalQuery setLimit(int n) { queryProcessor.setLimit(n); return this; } public InternalQuery enforceVisibility(boolean enforce) { queryProcessor.enforceVisibility(enforce); return this; } public InternalQuery setRequestedFields(Set fields) { queryProcessor.setRequestedFields(fields); return this; } public InternalQuery noFields() { queryProcessor.setRequestedFields(ImmutableSet.of()); return this; } public List query(Predicate p) throws OrmException { try { return queryProcessor.query(p).entities(); } catch (QueryParseException e) { throw new OrmException(e); } } /** * Run multiple queries in parallel. * *

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> query(List> queries) throws OrmException { try { return Lists.transform(queryProcessor.query(queries), QueryResult::entities); } catch (QueryParseException e) { throw new OrmException(e); } } protected Schema schema() { Index index = indexes != null ? indexes.getSearchIndex() : null; return index != null ? index.getSchema() : null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy