Move DeleteChangeOp.unwrap to BatchUpdateReviewDb

Change-Id: I859f7999638aa69af625b7f8f3fa43a6c3d65001
This commit is contained in:
Han-Wen Nienhuys 2017-12-19 20:38:43 +01:00
parent 493c71bc3b
commit c64ebb94dd
3 changed files with 16 additions and 13 deletions

View File

@ -52,6 +52,7 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdateOp;
import com.google.gerrit.server.update.BatchUpdateReviewDb;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.RepoContext;
import com.google.gerrit.server.update.RetryHelper;
@ -667,7 +668,7 @@ public class ConsistencyChecker {
public boolean updateChange(ChangeContext ctx)
throws OrmException, PatchSetInfoNotAvailableException {
// Delete dangling key references.
ReviewDb db = DeleteChangeOp.unwrap(ctx.getDb());
ReviewDb db = BatchUpdateReviewDb.unwrap(ctx.getDb());
accountPatchReviewStore.get().clearReviewed(psId);
db.changeMessages().delete(db.changeMessages().byChange(psId.getParentKey()));
db.patchSetApprovals().delete(db.patchSetApprovals().byPatchSet(psId));

View File

@ -23,7 +23,6 @@ import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.StarredChangesUtil;
import com.google.gerrit.server.project.NoSuchChangeException;
@ -47,16 +46,6 @@ class DeleteChangeOp implements BatchUpdateOp {
return cfg.getBoolean("change", "allowDrafts", true);
}
static ReviewDb unwrap(ReviewDb db) {
// This is special. We want to delete exactly the rows that are present in
// the database, even when reading everything else from NoteDb, so we need
// to bypass the write-only wrapper.
if (db instanceof BatchUpdateReviewDb) {
db = ((BatchUpdateReviewDb) db).unsafeGetDelegate();
}
return ReviewDbUtil.unwrapDb(db);
}
private final PatchSetUtil psUtil;
private final StarredChangesUtil starredChangesUtil;
private final DynamicItem<AccountPatchReviewStore> accountPatchReviewStore;
@ -123,7 +112,11 @@ class DeleteChangeOp implements BatchUpdateOp {
private void deleteChangeElementsFromDb(ChangeContext ctx, Change.Id id) throws OrmException {
// Only delete from ReviewDb here; deletion from NoteDb is handled in
// BatchUpdate.
ReviewDb db = unwrap(ctx.getDb());
//
// This is special. We want to delete exactly the rows that are present in
// the database, even when reading everything else from NoteDb, so we need
// to bypass the write-only wrapper.
ReviewDb db = BatchUpdateReviewDb.unwrap(ctx.getDb());
db.patchComments().delete(db.patchComments().byChange(id));
db.patchSetApprovals().delete(db.patchSetApprovals().byChange(id));
db.patchSets().delete(db.patchSets().byChange(id));

View File

@ -17,6 +17,7 @@ package com.google.gerrit.server.update;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.server.ChangeAccess;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
import com.google.gerrit.reviewdb.server.ReviewDbWrapper;
import com.google.gwtorm.server.AtomicUpdate;
@ -28,6 +29,14 @@ public class BatchUpdateReviewDb extends ReviewDbWrapper {
changesWrapper = new BatchUpdateChanges(delegate.changes());
}
/** @return the underlying delegate. Supports BatchUpdateReviewDb too. */
public static ReviewDb unwrap(ReviewDb db) {
if (db instanceof BatchUpdateReviewDb) {
db = ((BatchUpdateReviewDb) db).unsafeGetDelegate();
}
return ReviewDbUtil.unwrapDb(db);
}
public ReviewDb unsafeGetDelegate() {
return delegate;
}