Class ExternalIdNotes
VersionedMetaData
subclass to update external IDs.
This is a low-level API. Read/write of external IDs should be done through AccountsUpdate
or AccountConfig
.
On load the note map from refs/meta/external-ids
is read, but the external IDs are not
parsed yet (see onLoad()
).
After loading the note map callers can access single or all external IDs. Only now the requested external IDs are parsed.
After loading the note map callers can stage various external ID updates (insert, upsert, delete, replace).
On save the staged external ID updates are performed (see onSave(CommitBuilder)
).
After committing the external IDs a cache update can be requested which also reindexes the
accounts for which external IDs have been updated (see ExternalIdNotes.ExternalIdNotesLoader.updateExternalIdCacheAndMaybeReindexAccounts(ExternalIdNotes, Collection)
).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
Nested classes/interfaces inherited from class com.google.gerrit.server.git.meta.VersionedMetaData
VersionedMetaData.BatchMetaDataUpdate, VersionedMetaData.PathInfo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Function<ExternalId,
org.eclipse.jgit.lib.ObjectId> Fields inherited from class com.google.gerrit.server.git.meta.VersionedMetaData
inserter, newTree, projectName, reader, revision, rw
-
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.collect.ImmutableSet<ExternalId>
all()
Parses and returns all external IDs.static Account.Id
checkSameAccount
(Iterable<ExternalId> extIds, Account.Id accountId) Checks that all specified external IDs belong to specified account.org.eclipse.jgit.revwalk.RevCommit
commit
(MetaDataUpdate update) Update this metadata branch, recording a new commit on its reference.void
delete
(Account.Id accountId, ExternalId.Key extIdKey) Delete an external ID by key.void
delete
(Account.Id accountId, Collection<ExternalId.Key> extIdKeys) Delete external IDs by external ID key.void
delete
(ExternalId extId) Deletes an external ID.void
delete
(Collection<ExternalId> extIds) Deletes external IDs.void
deleteByKeys
(Collection<ExternalId.Key> extIdKeys) Delete external IDs by external ID key.get
(ExternalId.Key key) Parses and returns the specified external ID.get
(Collection<ExternalId.Key> keys) Parses and returns the specified external IDs.protected org.eclipse.jgit.lib.ObjectId
getNoteId
(ExternalId.Key key) protected String
Returns name of the reference storing this configuration.org.eclipse.jgit.lib.Repository
void
insert
(ExternalId extId) Inserts a new external ID.void
insert
(Collection<ExternalId> extIds) Inserts new external IDs.static ExternalIdNotes
load
(AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo, ExternalIdFactoryNoteDbImpl externalIdFactory, boolean isUserNameCaseInsensitiveMigrationMode) Loads the external ID notes for updates.static ExternalIdNotes
loadReadOnly
(AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo, org.eclipse.jgit.lib.ObjectId rev, ExternalIdFactoryNoteDbImpl externalIdFactory, boolean isUserNameCaseInsensitiveMigrationMode) Loads the external ID notes for reading only.protected void
onLoad()
Set up the metadata, parsing any state from the loaded revision.protected boolean
onSave
(org.eclipse.jgit.lib.CommitBuilder commit) Save any changes to the metadata in a commit.void
replace
(Account.Id accountId, Collection<ExternalId.Key> toDelete, Collection<ExternalId> toAdd) void
replace
(Account.Id accountId, Collection<ExternalId.Key> toDelete, Collection<ExternalId> toAdd, Function<ExternalId, org.eclipse.jgit.lib.ObjectId> noteIdResolver) Replaces external IDs for an account by external ID keys.void
replace
(ExternalId toDelete, ExternalId toAdd) Replaces an external ID.void
replace
(Collection<ExternalId> toDelete, Collection<ExternalId> toAdd) Replaces external IDs.void
replace
(Collection<ExternalId> toDelete, Collection<ExternalId> toAdd, Function<ExternalId, org.eclipse.jgit.lib.ObjectId> noteIdResolver) Replaces external IDs.void
replaceByKeys
(Collection<ExternalId.Key> toDelete, Collection<ExternalId> toAdd) Replaces external IDs for an account by external ID keys.setAfterReadRevision
(Runnable afterReadRevision) void
upsert
(ExternalId extId) Inserts or updates an external ID.void
upsert
(Collection<ExternalId> extIds) Inserts or updates external IDs.Methods inherited from class com.google.gerrit.server.git.meta.VersionedMetaData
commit, commitToNewRef, getObjectId, getPathInfos, getRevision, load, load, load, load, load, openUpdate, openUpdate, readConfig, readConfig, readFile, readTree, readUTF8, saveConfig, saveFile, saveUTF8, set, set, set
-
Field Details
-
defaultNoteIdResolver
-
-
Method Details
-
loadReadOnly
public static ExternalIdNotes loadReadOnly(AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo, org.eclipse.jgit.lib.ObjectId rev, ExternalIdFactoryNoteDbImpl externalIdFactory, boolean isUserNameCaseInsensitiveMigrationMode) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Loads the external ID notes for reading only. The external ID notes are loaded from the specified revision of therefs/meta/external-ids
branch.- Parameters:
rev
- the revision from which the external ID notes should be loaded, ifnull
the external ID notes are loaded from the current tip, ifObjectId.zeroId()
it's assumed that therefs/meta/external-ids
branch doesn't exist and the loaded external IDs will be empty- Returns:
- read-only
ExternalIdNotes
instance - Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
load
public static ExternalIdNotes load(AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo, ExternalIdFactoryNoteDbImpl externalIdFactory, boolean isUserNameCaseInsensitiveMigrationMode) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Loads the external ID notes for updates. The external ID notes are loaded from the current tip of therefs/meta/external-ids
branch.Use this only from init, schema upgrades and tests.
Metrics are disabled.
- Returns:
ExternalIdNotes
instance that doesn't updates caches on save- Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
setAfterReadRevision
-
getRepository
public org.eclipse.jgit.lib.Repository getRepository() -
getRefName
Description copied from class:VersionedMetaData
Returns name of the reference storing this configuration.- Specified by:
getRefName
in classVersionedMetaData
-
get
public Optional<ExternalId> get(ExternalId.Key key) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Parses and returns the specified external ID.- Parameters:
key
- the key of the external ID- Returns:
- the external ID,
Optional.empty()
if it doesn't exist - Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
getNoteId
- Throws:
IOException
-
get
public Set<ExternalId> get(Collection<ExternalId.Key> keys) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Parses and returns the specified external IDs.- Parameters:
keys
- the keys of the external IDs- Returns:
- the external IDs
- Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
all
Parses and returns all external IDs.Invalid external IDs are ignored.
- Returns:
- all external IDs
- Throws:
IOException
-
insert
Inserts a new external ID.- Throws:
IOException
- on IO error while checking if external ID already existsDuplicateExternalIdKeyException
- if the external ID already exists
-
insert
public void insert(Collection<ExternalId> extIds) throws IOException, DuplicateExternalIdKeyException Inserts new external IDs.- Throws:
IOException
- on IO error while checking if external IDs already existDuplicateExternalIdKeyException
- if any of the external ID already exists
-
upsert
public void upsert(ExternalId extId) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Inserts or updates an external ID.If the external ID already exists, it is overwritten, otherwise it is inserted.
- Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
upsert
public void upsert(Collection<ExternalId> extIds) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Inserts or updates external IDs.If any of the external IDs already exists, it is overwritten. New external IDs are inserted.
- Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
delete
Deletes an external ID.- Throws:
IllegalStateException
- is thrown if there is an existing external ID that has the same key, but otherwise doesn't match the specified external ID.
-
delete
Deletes external IDs.- Throws:
IllegalStateException
- is thrown if there is an existing external ID that has the same key as any of the external IDs that should be deleted, but otherwise doesn't match the that external ID.
-
delete
Delete an external ID by key.- Throws:
IllegalStateException
- is thrown if the external ID does not belong to the specified account.
-
delete
Delete external IDs by external ID key.- Throws:
IllegalStateException
- is thrown if any of the external IDs does not belong to the specified account.
-
deleteByKeys
Delete external IDs by external ID key.The external IDs are deleted regardless of which account they belong to.
-
replace
public void replace(Account.Id accountId, Collection<ExternalId.Key> toDelete, Collection<ExternalId> toAdd) throws IOException, DuplicateExternalIdKeyException -
replace
public void replace(Account.Id accountId, Collection<ExternalId.Key> toDelete, Collection<ExternalId> toAdd, Function<ExternalId, org.eclipse.jgit.lib.ObjectId> noteIdResolver) throws IOException, DuplicateExternalIdKeyExceptionReplaces external IDs for an account by external ID keys.Deletion of external IDs is done before adding the new external IDs. This means if an external ID key is specified for deletion and an external ID with the same key is specified to be added, the old external ID with that key is deleted first and then the new external ID is added (so the external ID for that key is replaced).
- Throws:
IllegalStateException
- is thrown if any of the specified external IDs does not belong to the specified account.IOException
DuplicateExternalIdKeyException
-
replaceByKeys
public void replaceByKeys(Collection<ExternalId.Key> toDelete, Collection<ExternalId> toAdd) throws IOException, DuplicateExternalIdKeyException Replaces external IDs for an account by external ID keys.Deletion of external IDs is done before adding the new external IDs. This means if an external ID key is specified for deletion and an external ID with the same key is specified to be added, the old external ID with that key is deleted first and then the new external ID is added (so the external ID for that key is replaced).
The external IDs are replaced regardless of which account they belong to.
-
replace
public void replace(ExternalId toDelete, ExternalId toAdd) throws IOException, DuplicateExternalIdKeyException Replaces an external ID.- Throws:
IllegalStateException
- is thrown if the specified external IDs belong to different accounts.IOException
DuplicateExternalIdKeyException
-
replace
public void replace(Collection<ExternalId> toDelete, Collection<ExternalId> toAdd) throws IOException, DuplicateExternalIdKeyException Replaces external IDs.Deletion of external IDs is done before adding the new external IDs. This means if an external ID is specified for deletion and an external ID with the same key is specified to be added, the old external ID with that key is deleted first and then the new external ID is added (so the external ID for that key is replaced).
- Throws:
IllegalStateException
- is thrown if the specified external IDs belong to different accounts.IOException
DuplicateExternalIdKeyException
-
replace
public void replace(Collection<ExternalId> toDelete, Collection<ExternalId> toAdd, Function<ExternalId, org.eclipse.jgit.lib.ObjectId> noteIdResolver) throws IOException, DuplicateExternalIdKeyExceptionReplaces external IDs.Deletion of external IDs is done before adding the new external IDs. This means if an external ID is specified for deletion and an external ID with the same key is specified to be added, the old external ID with that key is deleted first and then the new external ID is added (so the external ID for that key is replaced).
- Throws:
IllegalStateException
- is thrown if the specified external IDs belong to different accounts.IOException
DuplicateExternalIdKeyException
-
onLoad
Description copied from class:VersionedMetaData
Set up the metadata, parsing any state from the loaded revision.- Specified by:
onLoad
in classVersionedMetaData
- Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
commit
@CanIgnoreReturnValue public org.eclipse.jgit.revwalk.RevCommit commit(MetaDataUpdate update) throws IOException Description copied from class:VersionedMetaData
Update this metadata branch, recording a new commit on its reference. This method mutates its receiver.- Overrides:
commit
in classVersionedMetaData
- Parameters:
update
- helper information to define the update that will occur.- Returns:
- the commit that was created
- Throws:
IOException
- if there is a storage problem and the update cannot be executed as requested or if it failed because of a concurrent update to the same reference
-
onSave
protected boolean onSave(org.eclipse.jgit.lib.CommitBuilder commit) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Description copied from class:VersionedMetaData
Save any changes to the metadata in a commit.- Specified by:
onSave
in classVersionedMetaData
- Returns:
- true if the commit should proceed, false to abort.
- Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
checkSameAccount
@CanIgnoreReturnValue public static Account.Id checkSameAccount(Iterable<ExternalId> extIds, Account.Id accountId) Checks that all specified external IDs belong to specified account. If no account is specified it is checked that all specified external IDs belong to the same account.- Returns:
- the ID of the account to which all specified external IDs belong.
-