diff --git a/java/com/google/gerrit/server/change/ConsistencyChecker.java b/java/com/google/gerrit/server/change/ConsistencyChecker.java index a149935fcc..e10197fc04 100644 --- a/java/com/google/gerrit/server/change/ConsistencyChecker.java +++ b/java/com/google/gerrit/server/change/ConsistencyChecker.java @@ -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)); diff --git a/java/com/google/gerrit/server/change/DeleteChangeOp.java b/java/com/google/gerrit/server/change/DeleteChangeOp.java index 8df6e59ed1..130d04076f 100644 --- a/java/com/google/gerrit/server/change/DeleteChangeOp.java +++ b/java/com/google/gerrit/server/change/DeleteChangeOp.java @@ -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; @@ -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)); diff --git a/java/com/google/gerrit/server/update/BatchUpdateReviewDb.java b/java/com/google/gerrit/server/update/BatchUpdateReviewDb.java index 21e1f92581..3b8f871e36 100644 --- a/java/com/google/gerrit/server/update/BatchUpdateReviewDb.java +++ b/java/com/google/gerrit/server/update/BatchUpdateReviewDb.java @@ -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; }