public class ExternalIdNotes extends VersionedMetaData
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 updateCaches()
).
Modifier and Type | Class and Description |
---|---|
static interface |
ExternalIdNotes.ExternalIdNotesLoader |
static class |
ExternalIdNotes.Factory |
static class |
ExternalIdNotes.FactoryNoReindex |
VersionedMetaData.BatchMetaDataUpdate, VersionedMetaData.PathInfo
inserter, newTree, projectName, reader, revision, rw
Modifier and Type | Method and Description |
---|---|
com.google.common.collect.ImmutableSet<ExternalId> |
all()
Parses and returns all external IDs.
|
static Account.Id |
checkSameAccount(java.lang.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,
java.util.Collection<ExternalId.Key> extIdKeys)
Delete external IDs by external ID key.
|
void |
delete(Account.Id accountId,
ExternalId.Key extIdKey)
Delete an external ID by key.
|
void |
delete(java.util.Collection<ExternalId> extIds)
Deletes external IDs.
|
void |
delete(ExternalId extId)
Deletes an external ID.
|
void |
deleteByKeys(java.util.Collection<ExternalId.Key> extIdKeys)
Delete external IDs by external ID key.
|
java.util.Set<ExternalId> |
get(java.util.Collection<ExternalId.Key> keys)
Parses and returns the specified external IDs.
|
java.util.Optional<ExternalId> |
get(ExternalId.Key key)
Parses and returns the specified external ID.
|
protected java.lang.String |
getRefName() |
org.eclipse.jgit.lib.Repository |
getRepository() |
void |
insert(java.util.Collection<ExternalId> extIds)
Inserts new external IDs.
|
void |
insert(ExternalId extId)
Inserts a new external ID.
|
static ExternalIdNotes |
loadNoCacheUpdate(AllUsersName allUsersName,
org.eclipse.jgit.lib.Repository allUsersRepo)
Loads the external ID notes for updates without cache evictions.
|
static ExternalIdNotes |
loadReadOnly(AllUsersName allUsersName,
org.eclipse.jgit.lib.Repository allUsersRepo)
Loads the external ID notes for reading only.
|
static ExternalIdNotes |
loadReadOnly(AllUsersName allUsersName,
org.eclipse.jgit.lib.Repository allUsersRepo,
org.eclipse.jgit.lib.ObjectId rev)
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,
java.util.Collection<ExternalId.Key> toDelete,
java.util.Collection<ExternalId> toAdd)
Replaces external IDs for an account by external ID keys.
|
void |
replace(java.util.Collection<ExternalId> toDelete,
java.util.Collection<ExternalId> toAdd)
Replaces external IDs.
|
void |
replace(ExternalId toDelete,
ExternalId toAdd)
Replaces an external ID.
|
void |
replaceByKeys(java.util.Collection<ExternalId.Key> toDelete,
java.util.Collection<ExternalId> toAdd)
Replaces external IDs for an account by external ID keys.
|
ExternalIdNotes |
setAfterReadRevision(java.lang.Runnable afterReadRevision) |
void |
updateCaches()
Updates the caches (external ID cache, account cache) and reindexes the accounts for which
external IDs were modified.
|
void |
updateCaches(java.util.Collection<Account.Id> accountsToSkip)
Updates the caches (external ID cache, account cache) and reindexes the accounts for which
external IDs were modified.
|
void |
upsert(java.util.Collection<ExternalId> extIds)
Inserts or updates external IDs.
|
void |
upsert(ExternalId extId)
Inserts or updates an external ID.
|
commitToNewRef, getObjectId, getPathInfos, getRevision, load, load, load, load, load, openUpdate, readConfig, readConfig, readFile, readTree, readUTF8, saveConfig, saveFile, saveUTF8, set, set, set
public static ExternalIdNotes loadReadOnly(AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
refs/meta/external-ids
branch.ExternalIdNotes
instancejava.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public static ExternalIdNotes loadReadOnly(AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo, org.eclipse.jgit.lib.ObjectId rev) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
refs/meta/external-ids
branch.rev
- the revision from which the external ID notes should be loaded, if null
the
external ID notes are loaded from the current tip, if ObjectId.zeroId()
it's
assumed that the refs/meta/external-ids
branch doesn't exist and the loaded
external IDs will be emptyExternalIdNotes
instancejava.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public static ExternalIdNotes loadNoCacheUpdate(AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
refs/meta/external-ids
branch.
Use this only from init, schema upgrades and tests.
Metrics are disabled.
ExternalIdNotes
instance that doesn't updates caches on savejava.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public ExternalIdNotes setAfterReadRevision(java.lang.Runnable afterReadRevision)
public org.eclipse.jgit.lib.Repository getRepository()
protected java.lang.String getRefName()
getRefName
in class VersionedMetaData
public java.util.Optional<ExternalId> get(ExternalId.Key key) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
key
- the key of the external IDOptional.empty()
if it doesn't existjava.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public java.util.Set<ExternalId> get(java.util.Collection<ExternalId.Key> keys) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
keys
- the keys of the external IDsjava.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public com.google.common.collect.ImmutableSet<ExternalId> all() throws java.io.IOException
Invalid external IDs are ignored.
java.io.IOException
public void insert(ExternalId extId) throws java.io.IOException, DuplicateExternalIdKeyException
java.io.IOException
- on IO error while checking if external ID already existsDuplicateExternalIdKeyException
- if the external ID already existspublic void insert(java.util.Collection<ExternalId> extIds) throws java.io.IOException, DuplicateExternalIdKeyException
java.io.IOException
- on IO error while checking if external IDs already existDuplicateExternalIdKeyException
- if any of the external ID already existspublic void upsert(ExternalId extId) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
If the external ID already exists, it is overwritten, otherwise it is inserted.
java.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public void upsert(java.util.Collection<ExternalId> extIds) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
If any of the external IDs already exists, it is overwritten. New external IDs are inserted.
java.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public void delete(ExternalId extId)
java.lang.IllegalStateException
- is thrown if there is an existing external ID that has the same
key, but otherwise doesn't match the specified external ID.public void delete(java.util.Collection<ExternalId> extIds)
java.lang.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.public void delete(Account.Id accountId, ExternalId.Key extIdKey)
java.lang.IllegalStateException
- is thrown if the external ID does not belong to the specified
account.public void delete(Account.Id accountId, java.util.Collection<ExternalId.Key> extIdKeys)
java.lang.IllegalStateException
- is thrown if any of the external IDs does not belong to the
specified account.public void deleteByKeys(java.util.Collection<ExternalId.Key> extIdKeys)
The external IDs are deleted regardless of which account they belong to.
public void replace(Account.Id accountId, java.util.Collection<ExternalId.Key> toDelete, java.util.Collection<ExternalId> toAdd) throws java.io.IOException, DuplicateExternalIdKeyException
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).
java.lang.IllegalStateException
- is thrown if any of the specified external IDs does not belong to
the specified account.java.io.IOException
DuplicateExternalIdKeyException
public void replaceByKeys(java.util.Collection<ExternalId.Key> toDelete, java.util.Collection<ExternalId> toAdd) throws java.io.IOException, DuplicateExternalIdKeyException
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.
java.io.IOException
DuplicateExternalIdKeyException
public void replace(ExternalId toDelete, ExternalId toAdd) throws java.io.IOException, DuplicateExternalIdKeyException
java.lang.IllegalStateException
- is thrown if the specified external IDs belong to different
accounts.java.io.IOException
DuplicateExternalIdKeyException
public void replace(java.util.Collection<ExternalId> toDelete, java.util.Collection<ExternalId> toAdd) throws java.io.IOException, DuplicateExternalIdKeyException
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).
java.lang.IllegalStateException
- is thrown if the specified external IDs belong to different
accounts.java.io.IOException
DuplicateExternalIdKeyException
protected void onLoad() throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
VersionedMetaData
onLoad
in class VersionedMetaData
java.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public org.eclipse.jgit.revwalk.RevCommit commit(MetaDataUpdate update) throws java.io.IOException
VersionedMetaData
commit
in class VersionedMetaData
update
- helper information to define the update that will occur.java.io.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 referencepublic void updateCaches() throws java.io.IOException
Must only be called after committing changes.
No-op if this instance was created by loadNoCacheUpdate(AllUsersName, Repository)
.
No eviction from account cache and no reindex if this instance was created by ExternalIdNotes.FactoryNoReindex
.
java.io.IOException
public void updateCaches(java.util.Collection<Account.Id> accountsToSkip) throws java.io.IOException
Must only be called after committing changes.
No-op if this instance was created by loadNoCacheUpdate(AllUsersName, Repository)
.
No eviction from account cache if this instance was created by ExternalIdNotes.FactoryNoReindex
.
accountsToSkip
- set of accounts that should not be evicted from the account cache, in
this case the caller must take care to evict them otherwisejava.io.IOException
protected boolean onSave(org.eclipse.jgit.lib.CommitBuilder commit) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
VersionedMetaData
onSave
in class VersionedMetaData
java.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public static Account.Id checkSameAccount(java.lang.Iterable<ExternalId> extIds, Account.Id accountId)