Add ChangeMessagesUtil to assist with notedb migration
Like ApprovalsUtil, we added an abstraction layer to assist in the migration to notedb. This utility class helps to write to either the notedb or the reviewdb depending on the state of the NotesMigration instance. Additionally, in this change, I modified all callers of ChangeMessageAccess (which uses the ReviewDb) to instead use ChangeMessagesUtil. Change-Id: Id007ed8e01bd1318f70d804124e1f482a77234fd
This commit is contained in:
@@ -25,10 +25,12 @@ import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.change.PutTopic.Input;
|
||||
import com.google.gerrit.server.index.ChangeIndexer;
|
||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.util.TimeUtil;
|
||||
import com.google.gwtorm.server.AtomicUpdate;
|
||||
@@ -38,7 +40,6 @@ import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@Singleton
|
||||
class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
@@ -46,6 +47,8 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final ChangeIndexer indexer;
|
||||
private final ChangeHooks hooks;
|
||||
private final ChangeUpdate.Factory updateFactory;
|
||||
private final ChangeMessagesUtil cmUtil;
|
||||
|
||||
static class Input {
|
||||
@DefaultInput
|
||||
@@ -54,10 +57,13 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
|
||||
@Inject
|
||||
PutTopic(Provider<ReviewDb> dbProvider, ChangeIndexer indexer,
|
||||
ChangeHooks hooks) {
|
||||
ChangeHooks hooks, ChangeUpdate.Factory updateFactory,
|
||||
ChangeMessagesUtil cmUtil) {
|
||||
this.dbProvider = dbProvider;
|
||||
this.indexer = indexer;
|
||||
this.hooks = hooks;
|
||||
this.updateFactory = updateFactory;
|
||||
this.cmUtil = cmUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,6 +100,7 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
currentUser.getAccountId(), TimeUtil.nowTs(),
|
||||
change.currentPatchSetId());
|
||||
cmsg.setMessage(summary);
|
||||
ChangeUpdate update;
|
||||
|
||||
db.changes().beginTransaction(change.getId());
|
||||
try {
|
||||
@@ -106,11 +113,16 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
return change;
|
||||
}
|
||||
});
|
||||
db.changeMessages().insert(Collections.singleton(cmsg));
|
||||
|
||||
//TODO(yyonas): atomic update was not propagated
|
||||
update = updateFactory.create(control);
|
||||
cmUtil.addChangeMessage(db, update, cmsg);
|
||||
|
||||
db.commit();
|
||||
} finally {
|
||||
db.rollback();
|
||||
}
|
||||
update.commit();
|
||||
CheckedFuture<?, IOException> indexFuture =
|
||||
indexer.indexAsync(change.getId());
|
||||
hooks.doTopicChangedHook(change, currentUser.getAccount(),
|
||||
|
||||
Reference in New Issue
Block a user