Class NoteDbUpdateManager
- java.lang.Object
-
- com.google.gerrit.server.notedb.NoteDbUpdateManager
-
- All Implemented Interfaces:
AutoCloseable
public class NoteDbUpdateManager extends Object implements AutoCloseable
Object to manage a single sequence of updates to NoteDb.Instances are one-time-use. Handles updating both the change repo and the All-Users repo for any affected changes, with proper ordering.
To see the state that would be applied prior to executing the full sequence of updates, use
stage()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
NoteDbUpdateManager.Factory
static class
NoteDbUpdateManager.MismatchedStateException
static class
NoteDbUpdateManager.OpenRepo
static class
NoteDbUpdateManager.Result
static class
NoteDbUpdateManager.StagedResult
-
Field Summary
Fields Modifier and Type Field Description static String
CHANGES_READ_ONLY
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(ChangeDraftUpdate draftUpdate)
void
add(ChangeUpdate update)
Add an update to the list of updates to execute.void
close()
void
deleteChange(Change.Id id)
org.eclipse.jgit.lib.BatchRefUpdate
execute()
org.eclipse.jgit.lib.BatchRefUpdate
execute(boolean dryrun)
void
flush()
NoteDbUpdateManager.OpenRepo
getAllUsersRepo()
NoteDbUpdateManager.OpenRepo
getChangeRepo()
NoteDbUpdateManager
setAllUsersRepo(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectInserter ins, ChainedReceiveCommands cmds)
NoteDbUpdateManager
setAtomicRefUpdates(boolean atomicRefUpdates)
Set whether to use atomic ref updates.NoteDbUpdateManager
setChangeRepo(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectInserter ins, ChainedReceiveCommands cmds)
NoteDbUpdateManager
setCheckExpectedState(boolean checkExpectedState)
NoteDbUpdateManager
setPushCertificate(org.eclipse.jgit.transport.PushCertificate pushCert)
Set a push certificate for the push that originally triggered this NoteDb update.NoteDbUpdateManager
setRefLogIdent(org.eclipse.jgit.lib.PersonIdent ident)
NoteDbUpdateManager
setRefLogMessage(String message)
NoteDbUpdateManager
setSaveObjects(boolean saveObjects)
Set whether to save objects and make them available inNoteDbUpdateManager.StagedResult
s.Map<Change.Id,NoteDbUpdateManager.StagedResult>
stage()
Stage updates in the manager's internal list of commands.NoteDbUpdateManager.Result
stageAndApplyDelta(Change change)
-
-
-
Field Detail
-
CHANGES_READ_ONLY
public static final String CHANGES_READ_ONLY
- See Also:
- Constant Field Values
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
setChangeRepo
public NoteDbUpdateManager setChangeRepo(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectInserter ins, ChainedReceiveCommands cmds)
-
setAllUsersRepo
public NoteDbUpdateManager setAllUsersRepo(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectInserter ins, ChainedReceiveCommands cmds)
-
setCheckExpectedState
public NoteDbUpdateManager setCheckExpectedState(boolean checkExpectedState)
-
setSaveObjects
public NoteDbUpdateManager setSaveObjects(boolean saveObjects)
Set whether to save objects and make them available inNoteDbUpdateManager.StagedResult
s.If set, all objects inserted into all repos managed by this instance will be buffered in memory, and the
NoteDbUpdateManager.StagedResult
s will return non-null lists fromNoteDbUpdateManager.StagedResult.changeObjects()
andNoteDbUpdateManager.StagedResult.allUsersObjects()
.Not recommended if modifying a large number of changes with a single manager.
- Parameters:
saveObjects
- whether to save objects; defaults to true.- Returns:
- this
-
setAtomicRefUpdates
public NoteDbUpdateManager setAtomicRefUpdates(boolean atomicRefUpdates)
Set whether to use atomic ref updates.Can be set to false when the change updates represented by this manager aren't logically related, e.g. when the updater is only used to group objects together with a single inserter.
- Parameters:
atomicRefUpdates
- whether to use atomic ref updates; defaults to true.- Returns:
- this
-
setRefLogMessage
public NoteDbUpdateManager setRefLogMessage(String message)
-
setRefLogIdent
public NoteDbUpdateManager setRefLogIdent(org.eclipse.jgit.lib.PersonIdent ident)
-
setPushCertificate
public NoteDbUpdateManager setPushCertificate(org.eclipse.jgit.transport.PushCertificate pushCert)
Set a push certificate for the push that originally triggered this NoteDb update.The pusher will not necessarily have specified any of the NoteDb refs explicitly, such as when processing a push to
refs/for/master
. That's fine; this is just passed to the underlyingBatchRefUpdate
, and the implementation decides what to do with it.The cert should be associated with the main repo. There is currently no way of associating a push cert with the
All-Users
repo, since it is not currently possible to update draft changes via push.- Parameters:
pushCert
- push certificate; may be null.- Returns:
- this
-
getChangeRepo
public NoteDbUpdateManager.OpenRepo getChangeRepo() throws IOException
- Throws:
IOException
-
getAllUsersRepo
public NoteDbUpdateManager.OpenRepo getAllUsersRepo() throws IOException
- Throws:
IOException
-
add
public void add(ChangeUpdate update)
Add an update to the list of updates to execute.Updates should only be added to the manager after all mutations have been made, as this method may eagerly access the update.
- Parameters:
update
- the update to add.
-
add
public void add(ChangeDraftUpdate draftUpdate)
-
deleteChange
public void deleteChange(Change.Id id)
-
stage
public Map<Change.Id,NoteDbUpdateManager.StagedResult> stage() throws com.google.gwtorm.server.OrmException, IOException
Stage updates in the manager's internal list of commands.- Returns:
- map of the state that would get written to the applicable repo(s) for each affected change.
- Throws:
com.google.gwtorm.server.OrmException
- if a database layer error occurs.IOException
- if a storage layer error occurs.
-
stageAndApplyDelta
public NoteDbUpdateManager.Result stageAndApplyDelta(Change change) throws com.google.gwtorm.server.OrmException, IOException
- Throws:
com.google.gwtorm.server.OrmException
IOException
-
flush
public void flush() throws IOException
- Throws:
IOException
-
execute
public org.eclipse.jgit.lib.BatchRefUpdate execute() throws com.google.gwtorm.server.OrmException, IOException
- Throws:
com.google.gwtorm.server.OrmException
IOException
-
execute
public org.eclipse.jgit.lib.BatchRefUpdate execute(boolean dryrun) throws com.google.gwtorm.server.OrmException, IOException
- Throws:
com.google.gwtorm.server.OrmException
IOException
-
-