Package com.google.gerrit.server.account
Class AccountsUpdate
java.lang.Object
com.google.gerrit.server.account.AccountsUpdate
- Direct Known Subclasses:
AccountsUpdateNoteDbImpl
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static interface
Account updates are commonly performed by evaluating the current account state and creating a delta to be applied to it in a later step.static class
Data holder for the set of arguments required to update an account. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.eclipse.jgit.lib.PersonIdent
protected final org.eclipse.jgit.lib.PersonIdent
protected final Optional<IdentifiedUser>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AccountsUpdate
(org.eclipse.jgit.lib.PersonIdent serverIdent, Optional<IdentifiedUser> user) -
Method Summary
Modifier and TypeMethodDescriptionabstract void
delete
(String message, Account.Id accountId) Deletes all the account state data.protected abstract com.google.common.collect.ImmutableList<Optional<AccountState>>
executeUpdates
(List<AccountsUpdate.UpdateArguments> updates) abstract AccountState
insert
(String message, Account.Id accountId, AccountsUpdate.ConfigureDeltaFromState init) Inserts a new account.insert
(String message, Account.Id accountId, Consumer<AccountDelta.Builder> init) Likeinsert(String, Account.Id, ConfigureDeltaFromState)
, but using aConsumer
instead, i.e.joinConsumers
(List<Consumer<AccountDelta.Builder>> consumers) Returns an instance that runs all specified consumers.update
(String message, Account.Id accountId, AccountsUpdate.ConfigureDeltaFromState configureDeltaFromState) Gets the account and updates it atomically.update
(String message, Account.Id accountId, Consumer<AccountDelta.Builder> update) Likeupdate(String, Account.Id, ConfigureDeltaFromState)
, but using aConsumer
instead, i.e.com.google.common.collect.ImmutableList<Optional<AccountState>>
updateBatch
(List<AccountsUpdate.UpdateArguments> updates) Updates multiple different accounts atomically.
-
Field Details
-
committerIdent
protected final org.eclipse.jgit.lib.PersonIdent committerIdent -
authorIdent
protected final org.eclipse.jgit.lib.PersonIdent authorIdent -
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
@CanIgnoreReturnValue public AccountState insert(String message, Account.Id accountId, Consumer<AccountDelta.Builder> init) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Likeinsert(String, Account.Id, ConfigureDeltaFromState)
, but using aConsumer
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 benull or empty
accountId
- ID of the new accountinit
- to populate the new account- Returns:
- the newly created account
- Throws:
com.google.gerrit.exceptions.DuplicateKeyException
- if the account already existsIOException
- if creating the user branch fails due to an IO errororg.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 Likeupdate(String, Account.Id, ConfigureDeltaFromState)
, but using aConsumer
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 benull or empty
accountId
- ID of the accountconfigureDeltaFromState
- 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 errorcom.google.gerrit.git.LockFailureException
- if updating the user branch still fails due to concurrent updates after the retry timeout exceededorg.eclipse.jgit.errors.ConfigInvalidException
- if any of the account fields has an invalid value
-
updateBatch
@CanIgnoreReturnValue 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. Allupdates
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 benull or empty
accountId
- ID of the account- Throws:
IOException
- if updating the user branch fails due to an IO errororg.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
-