diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AccountCreator.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AccountCreator.java index 806469ec08..846b85a30e 100644 --- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AccountCreator.java +++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AccountCreator.java @@ -116,7 +116,6 @@ public class AccountCreator { accountsUpdate .create() .insert( - db, id, a -> { a.setFullName(fullName); diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java index 570621f8da..85908c984d 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java @@ -88,7 +88,6 @@ import com.google.gerrit.server.account.externalids.ExternalId; import com.google.gerrit.server.account.externalids.ExternalIds; import com.google.gerrit.server.account.externalids.ExternalIdsUpdate; import com.google.gerrit.server.config.AllUsersName; -import com.google.gerrit.server.extensions.events.GitReferenceUpdated; import com.google.gerrit.server.git.ProjectConfig; import com.google.gerrit.server.notedb.rebuild.ChangeRebuilderImpl; import com.google.gerrit.server.project.RefPattern; @@ -256,32 +255,11 @@ public class AccountIT extends AbstractDaemonTest { Account.Id nonExistingAccountId = new Account.Id(999999); AtomicBoolean consumerCalled = new AtomicBoolean(); Account account = - accountsUpdate.create().update(db, nonExistingAccountId, a -> consumerCalled.set(true)); + accountsUpdate.create().update(nonExistingAccountId, a -> consumerCalled.set(true)); assertThat(account).isNull(); assertThat(consumerCalled.get()).isFalse(); } - @Test - public void updateAccountThatIsMissingInNoteDb() throws Exception { - String name = "bar"; - TestAccount bar = accountCreator.create(name); - assertUserBranch(bar.getId(), name, null); - - // delete user branch - try (Repository repo = repoManager.openRepository(allUsers)) { - AccountsUpdate.deleteUserBranch( - repo, allUsers, GitReferenceUpdated.DISABLED, null, serverIdent.get(), bar.getId()); - assertThat(repo.exactRef(RefNames.refsUsers(bar.getId()))).isNull(); - } - - String status = "OOO"; - Account account = accountsUpdate.create().update(db, bar.getId(), a -> a.setStatus(status)); - assertThat(account).isNotNull(); - assertThat(account.getFullName()).isEqualTo(name); - assertThat(account.getStatus()).isEqualTo(status); - assertUserBranch(bar.getId(), name, status); - } - @Test public void updateAccountWithoutAccountConfigNoteDb() throws Exception { TestAccount anonymousCoward = accountCreator.create(); @@ -289,7 +267,7 @@ public class AccountIT extends AbstractDaemonTest { String status = "OOO"; Account account = - accountsUpdate.create().update(db, anonymousCoward.getId(), a -> a.setStatus(status)); + accountsUpdate.create().update(anonymousCoward.getId(), a -> a.setStatus(status)); assertThat(account).isNotNull(); assertThat(account.getFullName()).isNull(); assertThat(account.getStatus()).isEqualTo(status); @@ -712,7 +690,7 @@ public class AccountIT extends AbstractDaemonTest { String prefix = "foo.preferred"; String prefEmail = prefix + "@example.com"; TestAccount foo = accountCreator.create(name("foo")); - accountsUpdate.create().update(db, foo.id, a -> a.setPreferredEmail(prefEmail)); + accountsUpdate.create().update(foo.id, a -> a.setPreferredEmail(prefEmail)); // verify that the account is still found when using the preferred email to lookup the account ImmutableSet accountsByPrefEmail = emails.getAccountFor(prefEmail); @@ -1287,17 +1265,17 @@ public class AccountIT extends AbstractDaemonTest { // metaId is set when account is created AccountsUpdate au = accountsUpdate.create(); Account.Id accountId = new Account.Id(seq.nextAccountId()); - Account account = au.insert(db, accountId, a -> {}); + Account account = au.insert(accountId, a -> {}); assertThat(account.getMetaId()).isEqualTo(getMetaId(accountId)); // metaId is set when account is updated - Account updatedAccount = au.update(db, accountId, a -> a.setFullName("foo")); + Account updatedAccount = au.update(accountId, a -> a.setFullName("foo")); assertThat(account.getMetaId()).isNotEqualTo(updatedAccount.getMetaId()); assertThat(updatedAccount.getMetaId()).isEqualTo(getMetaId(accountId)); // metaId is set when account is replaced Account newAccount = new Account(accountId, TimeUtil.nowTs()); - au.replace(db, newAccount); + au.replace(newAccount); assertThat(updatedAccount.getMetaId()).isNotEqualTo(newAccount.getMetaId()); assertThat(newAccount.getMetaId()).isEqualTo(getMetaId(accountId)); } diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/change/ConsistencyCheckerIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/change/ConsistencyCheckerIT.java index 4c3a99281a..b99e99d57f 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/change/ConsistencyCheckerIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/change/ConsistencyCheckerIT.java @@ -126,7 +126,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest { public void missingOwner() throws Exception { TestAccount owner = accountCreator.create("missing"); ChangeControl ctl = insertChange(owner); - accountsUpdate.create().deleteByKey(db, owner.getId()); + accountsUpdate.create().deleteByKey(owner.getId()); assertProblems(ctl, null, problem("Missing change owner: " + owner.getId())); } diff --git a/gerrit-gpg/src/test/java/com/google/gerrit/gpg/GerritPublicKeyCheckerTest.java b/gerrit-gpg/src/test/java/com/google/gerrit/gpg/GerritPublicKeyCheckerTest.java index 001c9880d5..07a4fe39a3 100644 --- a/gerrit-gpg/src/test/java/com/google/gerrit/gpg/GerritPublicKeyCheckerTest.java +++ b/gerrit-gpg/src/test/java/com/google/gerrit/gpg/GerritPublicKeyCheckerTest.java @@ -116,7 +116,7 @@ public class GerritPublicKeyCheckerTest { schemaCreator.create(db); userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId(); // Note: does not match any key in TestKeys. - accountsUpdate.create().update(db, userId, a -> a.setPreferredEmail("user@example.com")); + accountsUpdate.create().update(userId, a -> a.setPreferredEmail("user@example.com")); user = reloadUser(); requestContext.setContext( diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/AccountsOnInit.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/AccountsOnInit.java index d81d58ce57..2beb50a03f 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/AccountsOnInit.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/AccountsOnInit.java @@ -17,17 +17,14 @@ package com.google.gerrit.pgm.init; import static com.google.common.base.Preconditions.checkArgument; import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.common.collect.ImmutableSet; import com.google.gerrit.pgm.init.api.AllUsersNameOnInitProvider; import com.google.gerrit.pgm.init.api.InitFlags; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.RefNames; -import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.GerritPersonIdentProvider; import com.google.gerrit.server.account.AccountConfig; import com.google.gerrit.server.account.Accounts; import com.google.gerrit.server.config.SitePaths; -import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import java.io.File; import java.io.IOException; @@ -62,9 +59,7 @@ public class AccountsOnInit { this.allUsers = allUsers.get(); } - public void insert(ReviewDb db, Account account) throws OrmException, IOException { - db.accounts().insert(ImmutableSet.of(account)); - + public void insert(Account account) throws IOException { File path = getPath(); if (path != null) { try (Repository repo = new FileRepository(path); diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitAdminUser.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitAdminUser.java index e4a1cd5ba0..86468c9032 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitAdminUser.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitAdminUser.java @@ -119,7 +119,7 @@ public class InitAdminUser implements InitStep { Account a = new Account(id, TimeUtil.nowTs()); a.setFullName(name); a.setPreferredEmail(email); - accounts.insert(db, a); + accounts.insert(a); AccountGroup adminGroup = groupsOnInit.getExistingGroup(db, new AccountGroup.NameKey("Administrators")); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java index 7d914155ec..32246015aa 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java @@ -144,7 +144,7 @@ public class AccountManager { } // return the identity to the caller. - update(db, who, id); + update(who, id); return new AuthResult(id.accountId(), who.getExternalIdKey(), false); } } catch (OrmException | ConfigInvalidException e) { @@ -152,7 +152,7 @@ public class AccountManager { } } - private void update(ReviewDb db, AuthRequest who, ExternalId extId) + private void update(AuthRequest who, ExternalId extId) throws OrmException, IOException, ConfigInvalidException { IdentifiedUser user = userFactory.create(extId.accountId()); List> accountUpdates = new ArrayList<>(); @@ -188,8 +188,7 @@ public class AccountManager { } if (!accountUpdates.isEmpty()) { - Account account = - accountsUpdateFactory.create().update(db, user.getAccountId(), accountUpdates); + Account account = accountsUpdateFactory.create().update(user.getAccountId(), accountUpdates); if (account == null) { throw new OrmException("Account " + user.getAccountId() + " has been deleted"); } @@ -214,7 +213,6 @@ public class AccountManager { AccountsUpdate accountsUpdate = accountsUpdateFactory.create(); account = accountsUpdate.insert( - db, newId, a -> { a.setFullName(who.getDisplayName()); @@ -224,7 +222,7 @@ public class AccountManager { ExternalId existingExtId = externalIds.get(extId.key()); if (existingExtId != null && !existingExtId.accountId().equals(extId.accountId())) { // external ID is assigned to another account, do not overwrite - accountsUpdate.delete(db, account); + accountsUpdate.delete(account); throw new AccountException( "Cannot assign external ID \"" + extId.key().get() @@ -277,7 +275,7 @@ public class AccountManager { + "\" to account " + newId + "; name already in use."; - handleSettingUserNameFailure(db, account, extId, message, e, false); + handleSettingUserNameFailure(account, extId, message, e, false); } catch (InvalidUserNameException e) { String message = "Cannot assign user name \"" @@ -285,10 +283,10 @@ public class AccountManager { + "\" to account " + newId + "; name does not conform."; - handleSettingUserNameFailure(db, account, extId, message, e, false); + handleSettingUserNameFailure(account, extId, message, e, false); } catch (OrmException e) { String message = "Cannot assign user name"; - handleSettingUserNameFailure(db, account, extId, message, e, true); + handleSettingUserNameFailure(account, extId, message, e, true); } } @@ -302,7 +300,6 @@ public class AccountManager { * deletes the newly created account and throws an {@link AccountUserNameException}. In any case * the error message is logged. * - * @param db the database * @param account the newly created account * @param extId the newly created external id * @param errorMessage the error message @@ -313,12 +310,7 @@ public class AccountManager { * @throws OrmException thrown if cleaning the database failed */ private void handleSettingUserNameFailure( - ReviewDb db, - Account account, - ExternalId extId, - String errorMessage, - Exception e, - boolean logException) + Account account, ExternalId extId, String errorMessage, Exception e, boolean logException) throws AccountUserNameException, OrmException, IOException, ConfigInvalidException { if (logException) { log.error(errorMessage, e); @@ -333,7 +325,7 @@ public class AccountManager { // such an account cannot be used for uploading changes, // this is why the best we can do here is to fail early and cleanup // the database - accountsUpdateFactory.create().delete(db, account); + accountsUpdateFactory.create().delete(account); externalIdsUpdateFactory.create().delete(extId); throw new AccountUserNameException(errorMessage, e); } @@ -350,34 +342,31 @@ public class AccountManager { */ public AuthResult link(Account.Id to, AuthRequest who) throws AccountException, OrmException, IOException, ConfigInvalidException { - try (ReviewDb db = schema.open()) { - ExternalId extId = externalIds.get(who.getExternalIdKey()); - if (extId != null) { - if (!extId.accountId().equals(to)) { - throw new AccountException("Identity in use by another account"); - } - update(db, who, extId); - } else { - externalIdsUpdateFactory - .create() - .insert(ExternalId.createWithEmail(who.getExternalIdKey(), to, who.getEmailAddress())); - - if (who.getEmailAddress() != null) { - accountsUpdateFactory - .create() - .update( - db, - to, - a -> { - if (a.getPreferredEmail() == null) { - a.setPreferredEmail(who.getEmailAddress()); - } - }); - } + ExternalId extId = externalIds.get(who.getExternalIdKey()); + if (extId != null) { + if (!extId.accountId().equals(to)) { + throw new AccountException("Identity in use by another account"); } + update(who, extId); + } else { + externalIdsUpdateFactory + .create() + .insert(ExternalId.createWithEmail(who.getExternalIdKey(), to, who.getEmailAddress())); - return new AuthResult(to, who.getExternalIdKey(), false); + if (who.getEmailAddress() != null) { + accountsUpdateFactory + .create() + .update( + to, + a -> { + if (a.getPreferredEmail() == null) { + a.setPreferredEmail(who.getEmailAddress()); + } + }); + } } + + return new AuthResult(to, who.getExternalIdKey(), false); } /** @@ -437,40 +426,36 @@ public class AccountManager { return; } - try (ReviewDb db = schema.open()) { - List extIds = new ArrayList<>(extIdKeys.size()); - for (ExternalId.Key extIdKey : extIdKeys) { - ExternalId extId = externalIds.get(extIdKey); - if (extId != null) { - if (!extId.accountId().equals(from)) { - throw new AccountException( - "Identity '" + extIdKey.get() + "' in use by another account"); - } - extIds.add(extId); - } else { - throw new AccountException("Identity '" + extIdKey.get() + "' not found"); + List extIds = new ArrayList<>(extIdKeys.size()); + for (ExternalId.Key extIdKey : extIdKeys) { + ExternalId extId = externalIds.get(extIdKey); + if (extId != null) { + if (!extId.accountId().equals(from)) { + throw new AccountException("Identity '" + extIdKey.get() + "' in use by another account"); } + extIds.add(extId); + } else { + throw new AccountException("Identity '" + extIdKey.get() + "' not found"); } + } - externalIdsUpdateFactory.create().delete(extIds); + externalIdsUpdateFactory.create().delete(extIds); - if (extIds.stream().anyMatch(e -> e.email() != null)) { - accountsUpdateFactory - .create() - .update( - db, - from, - a -> { - if (a.getPreferredEmail() != null) { - for (ExternalId extId : extIds) { - if (a.getPreferredEmail().equals(extId.email())) { - a.setPreferredEmail(null); - break; - } + if (extIds.stream().anyMatch(e -> e.email() != null)) { + accountsUpdateFactory + .create() + .update( + from, + a -> { + if (a.getPreferredEmail() != null) { + for (ExternalId extId : extIds) { + if (a.getPreferredEmail().equals(extId.email())) { + a.setPreferredEmail(null); + break; } } - }); - } + } + }); } } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountsUpdate.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountsUpdate.java index f6f791832d..6f11015c6b 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountsUpdate.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountsUpdate.java @@ -17,12 +17,10 @@ package com.google.gerrit.server.account; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.google.gerrit.common.Nullable; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.RefNames; -import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.GerritPersonIdent; import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.config.AllUsersName; @@ -32,7 +30,6 @@ import com.google.gerrit.server.git.MetaDataUpdate; import com.google.gerrit.server.index.change.ReindexAfterRefUpdate; import com.google.gerrit.server.mail.send.OutgoingEmailValidator; import com.google.gwtorm.server.OrmDuplicateKeyException; -import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; @@ -50,7 +47,7 @@ import org.eclipse.jgit.lib.Repository; /** * Updates accounts. * - *

The account updates are written to both ReviewDb and NoteDb. + *

The account updates are written to NoteDb. * *

In NoteDb accounts are represented as user branches in the All-Users repository. Optionally a * user branch can contain a 'account.config' file that stores account properties, such as full @@ -189,24 +186,19 @@ public class AccountsUpdate { /** * Inserts a new account. * - * @param db ReviewDb * @param accountId ID of the new account * @param init consumer to populate the new account * @return the newly created account - * @throws OrmException if updating the database fails * @throws OrmDuplicateKeyException if the account already exists * @throws IOException if updating the user branch fails * @throws ConfigInvalidException if any of the account fields has an invalid value */ - public Account insert(ReviewDb db, Account.Id accountId, Consumer init) - throws OrmException, IOException, ConfigInvalidException { + public Account insert(Account.Id accountId, Consumer init) + throws OrmDuplicateKeyException, IOException, ConfigInvalidException { AccountConfig accountConfig = read(accountId); Account account = accountConfig.getNewAccount(); init.accept(account); - // Create in ReviewDb - db.accounts().insert(ImmutableSet.of(account)); - // Create in NoteDb commitNew(accountConfig); return account; @@ -217,17 +209,15 @@ public class AccountsUpdate { * *

Changing the registration date of an account is not supported. * - * @param db ReviewDb * @param accountId ID of the account * @param consumer consumer to update the account, only invoked if the account exists * @return the updated account, {@code null} if the account doesn't exist - * @throws OrmException if updating the database fails * @throws IOException if updating the user branch fails * @throws ConfigInvalidException if any of the account fields has an invalid value */ - public Account update(ReviewDb db, Account.Id accountId, Consumer consumer) - throws OrmException, IOException, ConfigInvalidException { - return update(db, accountId, ImmutableList.of(consumer)); + public Account update(Account.Id accountId, Consumer consumer) + throws IOException, ConfigInvalidException { + return update(accountId, ImmutableList.of(consumer)); } /** @@ -235,44 +225,26 @@ public class AccountsUpdate { * *

Changing the registration date of an account is not supported. * - * @param db ReviewDb * @param accountId ID of the account * @param consumers consumers to update the account, only invoked if the account exists * @return the updated account, {@code null} if the account doesn't exist - * @throws OrmException if updating the database fails * @throws IOException if updating the user branch fails * @throws ConfigInvalidException if any of the account fields has an invalid value */ - public Account update(ReviewDb db, Account.Id accountId, List> consumers) - throws OrmException, IOException, ConfigInvalidException { + public Account update(Account.Id accountId, List> consumers) + throws IOException, ConfigInvalidException { if (consumers.isEmpty()) { return null; } - // Update in ReviewDb - Account reviewDbAccount = - db.accounts() - .atomicUpdate( - accountId, - a -> { - consumers.stream().forEach(c -> c.accept(a)); - return a; - }); - - // Update in NoteDb AccountConfig accountConfig = read(accountId); Account account = accountConfig.getAccount(); if (account != null) { consumers.stream().forEach(c -> c.accept(account)); commit(accountConfig); - return account; - } else if (reviewDbAccount != null) { - // user branch doesn't exist yet - accountConfig.setAccount(reviewDbAccount); - commitNew(accountConfig); } - return reviewDbAccount; + return account; } /** @@ -281,25 +253,18 @@ public class AccountsUpdate { *

The existing account with the same account ID is overwritten by the given account. Choosing * to overwrite an account means that any updates that were done to the account by a racing * request after the account was read are lost. Updates are also lost if the account was read from - * a stale account index. This is why using {@link #update(ReviewDb, - * com.google.gerrit.reviewdb.client.Account.Id, Consumer)} to do an atomic update is always - * preferred. + * a stale account index. This is why using {@link + * #update(com.google.gerrit.reviewdb.client.Account.Id, Consumer)} to do an atomic update is + * always preferred. * *

Changing the registration date of an account is not supported. * - * @param db ReviewDb * @param account the new account - * @throws OrmException if updating the database fails * @throws IOException if updating the user branch fails * @throws ConfigInvalidException if any of the account fields has an invalid value - * @see #update(ReviewDb, com.google.gerrit.reviewdb.client.Account.Id, Consumer) + * @see #update(com.google.gerrit.reviewdb.client.Account.Id, Consumer) */ - public void replace(ReviewDb db, Account account) - throws OrmException, IOException, ConfigInvalidException { - // Update in ReviewDb - db.accounts().update(ImmutableSet.of(account)); - - // Update in NoteDb + public void replace(Account account) throws IOException, ConfigInvalidException { AccountConfig accountConfig = read(account.getId()); accountConfig.setAccount(account); commit(accountConfig); @@ -308,32 +273,20 @@ public class AccountsUpdate { /** * Deletes the account. * - * @param db ReviewDb * @param account the account that should be deleted - * @throws OrmException if updating the database fails * @throws IOException if updating the user branch fails */ - public void delete(ReviewDb db, Account account) throws OrmException, IOException { - // Delete in ReviewDb - db.accounts().delete(ImmutableSet.of(account)); - - // Delete in NoteDb - deleteUserBranch(account.getId()); + public void delete(Account account) throws IOException { + deleteByKey(account.getId()); } /** * Deletes the account. * - * @param db ReviewDb * @param accountId the ID of the account that should be deleted - * @throws OrmException if updating the database fails * @throws IOException if updating the user branch fails */ - public void deleteByKey(ReviewDb db, Account.Id accountId) throws OrmException, IOException { - // Delete in ReviewDb - db.accounts().deleteKeys(ImmutableSet.of(accountId)); - - // Delete in NoteDb + public void deleteByKey(Account.Id accountId) throws IOException { deleteUserBranch(accountId); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateAccount.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateAccount.java index 70cbb6dffc..87da24b488 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateAccount.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateAccount.java @@ -174,7 +174,6 @@ public class CreateAccount implements RestModifyView { a.setFullName(input.name); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/PutName.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/PutName.java index 792e71de4d..7537230a2c 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/PutName.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/PutName.java @@ -23,7 +23,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.reviewdb.client.Account; -import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.account.PutName.Input; @@ -46,7 +45,6 @@ public class PutName implements RestModifyView { private final Provider self; private final Realm realm; private final PermissionBackend permissionBackend; - private final Provider dbProvider; private final AccountsUpdate.Server accountsUpdate; @Inject @@ -54,12 +52,10 @@ public class PutName implements RestModifyView { Provider self, Realm realm, PermissionBackend permissionBackend, - Provider dbProvider, AccountsUpdate.Server accountsUpdate) { this.self = self; this.realm = realm; this.permissionBackend = permissionBackend; - this.dbProvider = dbProvider; this.accountsUpdate = accountsUpdate; } @@ -74,7 +70,7 @@ public class PutName implements RestModifyView { } public Response apply(IdentifiedUser user, Input input) - throws MethodNotAllowedException, ResourceNotFoundException, OrmException, IOException, + throws MethodNotAllowedException, ResourceNotFoundException, IOException, ConfigInvalidException { if (input == null) { input = new Input(); @@ -86,9 +82,7 @@ public class PutName implements RestModifyView { String newName = input.name; Account account = - accountsUpdate - .create() - .update(dbProvider.get(), user.getAccountId(), a -> a.setFullName(newName)); + accountsUpdate.create().update(user.getAccountId(), a -> a.setFullName(newName)); if (account == null) { throw new ResourceNotFoundException("account not found"); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/PutPreferred.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/PutPreferred.java index 98d4ac5cc6..b3f8fc554c 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/PutPreferred.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/PutPreferred.java @@ -19,7 +19,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.reviewdb.client.Account; -import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.account.PutPreferred.Input; @@ -39,18 +38,15 @@ public class PutPreferred implements RestModifyView self; - private final Provider dbProvider; private final PermissionBackend permissionBackend; private final AccountsUpdate.Server accountsUpdate; @Inject PutPreferred( Provider self, - Provider dbProvider, PermissionBackend permissionBackend, AccountsUpdate.Server accountsUpdate) { this.self = self; - this.dbProvider = dbProvider; this.permissionBackend = permissionBackend; this.accountsUpdate = accountsUpdate; } @@ -66,13 +62,12 @@ public class PutPreferred implements RestModifyView apply(IdentifiedUser user, String email) - throws ResourceNotFoundException, OrmException, IOException, ConfigInvalidException { + throws ResourceNotFoundException, IOException, ConfigInvalidException { AtomicBoolean alreadyPreferred = new AtomicBoolean(false); Account account = accountsUpdate .create() .update( - dbProvider.get(), user.getAccountId(), a -> { if (email.equals(a.getPreferredEmail())) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/PutStatus.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/PutStatus.java index 136fc68a7a..1df67c304a 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/PutStatus.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/PutStatus.java @@ -21,7 +21,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.reviewdb.client.Account; -import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.account.PutStatus.Input; @@ -48,18 +47,15 @@ public class PutStatus implements RestModifyView { } private final Provider self; - private final Provider dbProvider; private final PermissionBackend permissionBackend; private final AccountsUpdate.Server accountsUpdate; @Inject PutStatus( Provider self, - Provider dbProvider, PermissionBackend permissionBackend, AccountsUpdate.Server accountsUpdate) { this.self = self; - this.dbProvider = dbProvider; this.permissionBackend = permissionBackend; this.accountsUpdate = accountsUpdate; } @@ -75,7 +71,7 @@ public class PutStatus implements RestModifyView { } public Response apply(IdentifiedUser user, Input input) - throws ResourceNotFoundException, OrmException, IOException, ConfigInvalidException { + throws ResourceNotFoundException, IOException, ConfigInvalidException { if (input == null) { input = new Input(); } @@ -84,10 +80,7 @@ public class PutStatus implements RestModifyView { Account account = accountsUpdate .create() - .update( - dbProvider.get(), - user.getAccountId(), - a -> a.setStatus(Strings.nullToEmpty(newStatus))); + .update(user.getAccountId(), a -> a.setStatus(Strings.nullToEmpty(newStatus))); if (account == null) { throw new ResourceNotFoundException("account not found"); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/SetInactiveFlag.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/SetInactiveFlag.java index b0487de3fa..169838733f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/SetInactiveFlag.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/SetInactiveFlag.java @@ -19,11 +19,8 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.reviewdb.client.Account; -import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.IdentifiedUser; -import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; -import com.google.inject.Provider; import com.google.inject.Singleton; import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; @@ -32,23 +29,20 @@ import org.eclipse.jgit.errors.ConfigInvalidException; @Singleton public class SetInactiveFlag { - private final Provider dbProvider; private final AccountsUpdate.Server accountsUpdate; @Inject - SetInactiveFlag(Provider dbProvider, AccountsUpdate.Server accountsUpdate) { - this.dbProvider = dbProvider; + SetInactiveFlag(AccountsUpdate.Server accountsUpdate) { this.accountsUpdate = accountsUpdate; } public Response deactivate(IdentifiedUser user) - throws RestApiException, OrmException, IOException, ConfigInvalidException { + throws RestApiException, IOException, ConfigInvalidException { AtomicBoolean alreadyInactive = new AtomicBoolean(false); Account account = accountsUpdate .create() .update( - dbProvider.get(), user.getAccountId(), a -> { if (!a.isActive()) { @@ -67,13 +61,12 @@ public class SetInactiveFlag { } public Response activate(IdentifiedUser user) - throws ResourceNotFoundException, OrmException, IOException, ConfigInvalidException { + throws ResourceNotFoundException, IOException, ConfigInvalidException { AtomicBoolean alreadyActive = new AtomicBoolean(false); Account account = accountsUpdate .create() .update( - dbProvider.get(), user.getAccountId(), a -> { if (a.isActive()) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/receive/ReceiveCommits.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/receive/ReceiveCommits.java index d4e085c8e8..33a6fd418f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/receive/ReceiveCommits.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/receive/ReceiveCommits.java @@ -2726,7 +2726,6 @@ class ReceiveCommits { accountsUpdate .create() .update( - db, user.getAccountId(), a -> { if (Strings.isNullOrEmpty(a.getFullName())) { @@ -2736,7 +2735,7 @@ class ReceiveCommits { if (account != null && Strings.isNullOrEmpty(account.getFullName())) { user.getAccount().setFullName(account.getFullName()); } - } catch (OrmException | IOException | ConfigInvalidException e) { + } catch (IOException | ConfigInvalidException e) { logWarn("Cannot default full_name", e); } finally { defaultName = false; diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/query/account/AbstractQueryAccountsTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/query/account/AbstractQueryAccountsTest.java index 8fec96a0e8..2f84a58709 100644 --- a/gerrit-server/src/test/java/com/google/gerrit/server/query/account/AbstractQueryAccountsTest.java +++ b/gerrit-server/src/test/java/com/google/gerrit/server/query/account/AbstractQueryAccountsTest.java @@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat; import static java.util.stream.Collectors.toList; import static org.junit.Assert.fail; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.gerrit.extensions.api.GerritApi; import com.google.gerrit.extensions.api.accounts.Accounts.QueryRequest; @@ -397,14 +396,9 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests { public void reindex() throws Exception { AccountInfo user1 = newAccountWithFullName("tester", "Test Usre"); - // update account in ReviewDb without reindex so that account index is stale - String newName = "Test User"; + // update account without reindex so that account index is stale Account.Id accountId = new Account.Id(user1._accountId); - Account account = accounts.get(accountId); - account.setFullName(newName); - db.accounts().update(ImmutableSet.of(account)); - - // update account in NoteDb without reindex so that account index is stale + String newName = "Test User"; try (Repository repo = repoManager.openRepository(allUsers)) { MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsers, repo); PersonIdent ident = serverIdent.get(); @@ -499,7 +493,6 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests { accountsUpdate .create() .update( - db, id, a -> { a.setFullName(fullName); diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java index 9ab4db0239..ea9af4c7f3 100644 --- a/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java +++ b/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java @@ -214,7 +214,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests { userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId(); String email = "user@example.com"; externalIdsUpdate.create().insert(ExternalId.createEmail(userId, email)); - accountsUpdate.create().update(db, userId, a -> a.setPreferredEmail(email)); + accountsUpdate.create().update(userId, a -> a.setPreferredEmail(email)); user = userFactory.create(userId); requestContext.setContext(newRequestContext(userId)); } @@ -2469,7 +2469,6 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests { accountsUpdate .create() .update( - db, id, a -> { a.setFullName(fullName); diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/query/group/AbstractQueryGroupsTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/query/group/AbstractQueryGroupsTest.java index 09b2af94af..6b94e02491 100644 --- a/gerrit-server/src/test/java/com/google/gerrit/server/query/group/AbstractQueryGroupsTest.java +++ b/gerrit-server/src/test/java/com/google/gerrit/server/query/group/AbstractQueryGroupsTest.java @@ -323,7 +323,6 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests { accountsUpdate .create() .update( - db, id, a -> { a.setFullName(fullName);