Line data Source code
1 : // Copyright (C) 2016 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.account.externalids; 16 : 17 : import com.google.common.collect.ImmutableSet; 18 : import com.google.common.collect.ImmutableSetMultimap; 19 : import com.google.gerrit.entities.Account; 20 : import java.io.IOException; 21 : import java.util.Optional; 22 : import org.eclipse.jgit.lib.ObjectId; 23 : 24 : /** 25 : * Caches external IDs of all accounts. Note that the granularity is "revision" only, so each update 26 : * will cache a new value containing <b>all</b> external IDs. 27 : * 28 : * <p>On each cache access the SHA1 of the refs/meta/external-ids branch is read to verify that the 29 : * cache is up to date. 30 : * 31 : * <p>All returned collections are unmodifiable. 32 : */ 33 : public interface ExternalIdCache { 34 : Optional<ExternalId> byKey(ExternalId.Key key) throws IOException; 35 : 36 : ImmutableSet<ExternalId> byAccount(Account.Id accountId) throws IOException; 37 : 38 : ImmutableSet<ExternalId> byAccount(Account.Id accountId, ObjectId rev) throws IOException; 39 : 40 : ImmutableSetMultimap<Account.Id, ExternalId> allByAccount() throws IOException; 41 : 42 : ImmutableSetMultimap<String, ExternalId> byEmails(String... emails) throws IOException; 43 : 44 : ImmutableSetMultimap<String, ExternalId> allByEmail() throws IOException; 45 : 46 : default ImmutableSet<ExternalId> byEmail(String email) throws IOException { 47 108 : return byEmails(email).get(email); 48 : } 49 : }