Add an AccountsUpdate class to update accounts from a single class

As a first step AccountsUpdate is only responsible for creating new
accounts. Additional functionality to update accounts will be added
later.

This is another step towards migrating accounts from ReviewDb to NoteDb.
In the end all code that needs to update accounts should use
AccountsUpdate. AccountsUpdate can then take care to update the accounts
in ReviewDb and NoteDb.

Change-Id: I77e3a664e23bfa579da7da7c1e86823e7ad905eb
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-04-06 16:13:20 +02:00
parent 6702433385
commit 74ddf290a3
4 changed files with 49 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.AccountByEmailCache;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.AccountsUpdate;
import com.google.gerrit.server.account.GroupCache;
import com.google.gerrit.server.account.VersionedAuthorizedKeys;
import com.google.gerrit.server.account.externalids.ExternalId;
@@ -52,6 +53,7 @@ public class AccountCreator {
private final Map<String, TestAccount> accounts;
private final SchemaFactory<ReviewDb> reviewDbProvider;
private final AccountsUpdate accountsUpdate;
private final VersionedAuthorizedKeys.Accessor authorizedKeys;
private final GroupCache groupCache;
private final SshKeyCache sshKeyCache;
@@ -63,6 +65,7 @@ public class AccountCreator {
@Inject
AccountCreator(
SchemaFactory<ReviewDb> schema,
AccountsUpdate accountsUpdate,
VersionedAuthorizedKeys.Accessor authorizedKeys,
GroupCache groupCache,
SshKeyCache sshKeyCache,
@@ -72,6 +75,7 @@ public class AccountCreator {
ExternalIdsUpdate.Server externalIdsUpdate) {
accounts = new HashMap<>();
reviewDbProvider = schema;
this.accountsUpdate = accountsUpdate;
this.authorizedKeys = authorizedKeys;
this.groupCache = groupCache;
this.sshKeyCache = sshKeyCache;
@@ -110,7 +114,7 @@ public class AccountCreator {
Account a = new Account(id, TimeUtil.nowTs());
a.setFullName(fullName);
a.setPreferredEmail(email);
db.accounts().insert(Collections.singleton(a));
accountsUpdate.insert(db, a);
if (groups != null) {
for (String n : groups) {