Line data Source code
1 : // Copyright (C) 2017 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.index.group; 16 : 17 : import com.google.gerrit.entities.AccountGroup; 18 : import com.google.gerrit.entities.InternalGroup; 19 : import com.google.gerrit.index.Index; 20 : import com.google.gerrit.index.IndexConfig; 21 : import com.google.gerrit.index.QueryOptions; 22 : import com.google.gerrit.index.query.DataSource; 23 : import com.google.gerrit.index.query.IndexedQuery; 24 : import com.google.gerrit.index.query.Predicate; 25 : import com.google.gerrit.index.query.QueryParseException; 26 : import java.util.HashSet; 27 : import java.util.Set; 28 : 29 : /** 30 : * Wrapper around {@link Predicate}s that are returned by the {@link 31 : * com.google.gerrit.index.IndexRewriter}. See {@link IndexedQuery}. 32 : */ 33 : public class IndexedGroupQuery extends IndexedQuery<AccountGroup.UUID, InternalGroup> 34 : implements DataSource<InternalGroup> { 35 : 36 : public static QueryOptions createOptions( 37 : IndexConfig config, int start, int pageSize, int limit, Set<String> fields) { 38 : // Always include GroupField.UUID since it is needed to load the group from NoteDb. 39 4 : if (!fields.contains(GroupField.UUID_FIELD_SPEC.getName())) { 40 0 : fields = new HashSet<>(fields); 41 0 : fields.add(GroupField.UUID_FIELD_SPEC.getName()); 42 : } 43 4 : return QueryOptions.create(config, start, pageSize, limit, fields); 44 : } 45 : 46 : public IndexedGroupQuery( 47 : Index<AccountGroup.UUID, InternalGroup> index, 48 : Predicate<InternalGroup> pred, 49 : QueryOptions opts) 50 : throws QueryParseException { 51 150 : super(index, pred, opts.convertForBackend()); 52 150 : } 53 : }