Class AccountsUpdate
- java.lang.Object
-
- com.google.gerrit.server.account.AccountsUpdate
-
public class AccountsUpdate extends Object
Updates accounts.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 name, preferred email, status and the active flag. The timestamp of the first commit on a user branch denotes the registration date. The initial commit on the user branch may be empty (since having an 'account.config' is optional). See
AccountConfig
for details of the 'account.config' file format.On updating accounts the accounts are evicted from the account cache and thus reindexed. The eviction from the account cache is done by the
ReindexAfterRefUpdate
class which receives the event about updating the user branch that is triggered by this class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AccountsUpdate.Server
Factory to create an AccountsUpdate instance for updating accounts by the Gerrit server.static class
AccountsUpdate.User
Factory to create an AccountsUpdate instance for updating accounts by the current user.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
delete(Account account)
Deletes the account.void
deleteByKey(Account.Id accountId)
Deletes the account.static void
deleteUserBranch(org.eclipse.jgit.lib.Repository repo, Project.NameKey project, GitReferenceUpdated gitRefUpdated, IdentifiedUser user, org.eclipse.jgit.lib.PersonIdent refLogIdent, Account.Id accountId)
Account
insert(Account.Id accountId, Consumer<Account> init)
Inserts a new account.void
replace(Account account)
Replaces the account.Account
update(Account.Id accountId, Consumer<Account> consumer)
Gets the account and updates it atomically.Account
update(Account.Id accountId, List<Consumer<Account>> consumers)
Gets the account and updates it atomically.
-
-
-
Method Detail
-
insert
public Account insert(Account.Id accountId, Consumer<Account> init) throws com.google.gwtorm.server.OrmDuplicateKeyException, IOException, org.eclipse.jgit.errors.ConfigInvalidException
Inserts a new account.- Parameters:
accountId
- ID of the new accountinit
- consumer to populate the new account- Returns:
- the newly created account
- Throws:
com.google.gwtorm.server.OrmDuplicateKeyException
- if the account already existsIOException
- if updating the user branch failsorg.eclipse.jgit.errors.ConfigInvalidException
- if any of the account fields has an invalid value
-
update
public Account update(Account.Id accountId, Consumer<Account> consumer) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
Gets the account and updates it atomically.Changing the registration date of an account is not supported.
- Parameters:
accountId
- ID of the accountconsumer
- consumer to update the account, only invoked if the account exists- Returns:
- the updated account,
null
if the account doesn't exist - Throws:
IOException
- if updating the user branch failsorg.eclipse.jgit.errors.ConfigInvalidException
- if any of the account fields has an invalid value
-
update
public Account update(Account.Id accountId, List<Consumer<Account>> consumers) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
Gets the account and updates it atomically.Changing the registration date of an account is not supported.
- Parameters:
accountId
- ID of the accountconsumers
- consumers to update the account, only invoked if the account exists- Returns:
- the updated account,
null
if the account doesn't exist - Throws:
IOException
- if updating the user branch failsorg.eclipse.jgit.errors.ConfigInvalidException
- if any of the account fields has an invalid value
-
replace
public void replace(Account account) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
Replaces the account.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
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.
- Parameters:
account
- the new account- Throws:
IOException
- if updating the user branch failsorg.eclipse.jgit.errors.ConfigInvalidException
- if any of the account fields has an invalid value- See Also:
update(com.google.gerrit.reviewdb.client.Account.Id, Consumer)
-
delete
public void delete(Account account) throws IOException
Deletes the account.- Parameters:
account
- the account that should be deleted- Throws:
IOException
- if updating the user branch fails
-
deleteByKey
public void deleteByKey(Account.Id accountId) throws IOException
Deletes the account.- Parameters:
accountId
- the ID of the account that should be deleted- Throws:
IOException
- if updating the user branch fails
-
deleteUserBranch
public static void deleteUserBranch(org.eclipse.jgit.lib.Repository repo, Project.NameKey project, GitReferenceUpdated gitRefUpdated, IdentifiedUser user, org.eclipse.jgit.lib.PersonIdent refLogIdent, Account.Id accountId) throws IOException
- Throws:
IOException
-
-