Class AccountsUpdate

java.lang.Object
com.google.gerrit.server.account.AccountsUpdate
Direct Known Subclasses:
AccountsUpdateNoteDbImpl

public abstract class AccountsUpdate extends Object
Creates and updates accounts.

This interface should be used for all account updates. See AccountDelta for what can be updated.

For creating a new account a new account ID can be retrieved from Sequences.nextAccountId().

See the implementing classes for more information.

  • Field Details

    • committerIdent

      protected final org.eclipse.jgit.lib.PersonIdent committerIdent
    • authorIdent

      protected final org.eclipse.jgit.lib.PersonIdent authorIdent
    • currentUser

      protected final Optional<IdentifiedUser> currentUser
  • Constructor Details

    • AccountsUpdate

      protected AccountsUpdate(org.eclipse.jgit.lib.PersonIdent serverIdent, Optional<IdentifiedUser> user)
  • Method Details

    • joinConsumers

      public static AccountsUpdate.ConfigureDeltaFromState joinConsumers(List<Consumer<AccountDelta.Builder>> consumers)
      Returns an instance that runs all specified consumers.
    • insert

      public AccountState insert(String message, Account.Id accountId, Consumer<AccountDelta.Builder> init) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
      Like insert(String, Account.Id, ConfigureDeltaFromState), but using a Consumer instead, i.e. the update does not depend on the current account state (which, for insertion, would only contain the account ID).
      Throws:
      IOException
      org.eclipse.jgit.errors.ConfigInvalidException
    • insert

      public abstract AccountState insert(String message, Account.Id accountId, AccountsUpdate.ConfigureDeltaFromState init) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
      Inserts a new account.
      Parameters:
      message - commit message for the account creation, must not be null or empty
      accountId - ID of the new account
      init - to populate the new account
      Returns:
      the newly created account
      Throws:
      com.google.gerrit.exceptions.DuplicateKeyException - if the account already exists
      IOException - if creating the user branch fails due to an IO error
      org.eclipse.jgit.errors.ConfigInvalidException - if any of the account fields has an invalid value
    • update

      @CanIgnoreReturnValue public Optional<AccountState> update(String message, Account.Id accountId, Consumer<AccountDelta.Builder> update) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
      Like update(String, Account.Id, ConfigureDeltaFromState), but using a Consumer instead, i.e. the update does not depend on the current account state.
      Throws:
      IOException
      org.eclipse.jgit.errors.ConfigInvalidException
    • update

      @CanIgnoreReturnValue public Optional<AccountState> update(String message, Account.Id accountId, AccountsUpdate.ConfigureDeltaFromState configureDeltaFromState) 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:
      message - commit message for the account update, must not be null or empty
      accountId - ID of the account
      configureDeltaFromState - deltaBuilder to update the account, only invoked if the account exists
      Returns:
      the updated account, Optional.empty() if the account doesn't exist
      Throws:
      IOException - if updating the user branch fails due to an IO error
      com.google.gerrit.git.LockFailureException - if updating the user branch still fails due to concurrent updates after the retry timeout exceeded
      org.eclipse.jgit.errors.ConfigInvalidException - if any of the account fields has an invalid value
    • updateBatch

      public com.google.common.collect.ImmutableList<Optional<AccountState>> updateBatch(List<AccountsUpdate.UpdateArguments> updates) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
      Updates multiple different accounts atomically. This will only store a single new value (aka set of all external IDs of the host) in the external ID cache, which is important for storage economy. All updates must be for different accounts.

      NOTE on error handling: Since updates are executed in multiple stages, with some stages resulting from the union of all individual updates, we cannot point to the update that caused the error. Callers should be aware that a single "update of death" (or a set of updates that together have this property) will always prevent the entire batch from being executed.

      Throws:
      IOException
      org.eclipse.jgit.errors.ConfigInvalidException
    • delete

      public abstract void delete(String message, Account.Id accountId) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
      Deletes all the account state data.
      Parameters:
      message - commit message for the account update, must not be null or empty
      accountId - ID of the account
      Throws:
      IOException - if updating the user branch fails due to an IO error
      org.eclipse.jgit.errors.ConfigInvalidException - if any of the account fields has an invalid value
    • executeUpdates

      protected abstract com.google.common.collect.ImmutableList<Optional<AccountState>> executeUpdates(List<AccountsUpdate.UpdateArguments> updates) throws org.eclipse.jgit.errors.ConfigInvalidException, IOException
      Throws:
      org.eclipse.jgit.errors.ConfigInvalidException
      IOException