Class 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.

    • 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 account
        init - consumer to populate the new account
        Returns:
        the newly created account
        Throws:
        com.google.gwtorm.server.OrmDuplicateKeyException - if the account already exists
        IOException - if updating the user branch fails
        org.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 account
        consumer - 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 fails
        org.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 account
        consumers - 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 fails
        org.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 fails
        org.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