Search in sources :

Example 1 with BatchUpdateReviewDb

use of com.google.gerrit.server.update.BatchUpdateReviewDb in project gerrit by GerritCodeReview.

the class CommentsUtil method deleteCommentByRewritingHistory.

public void deleteCommentByRewritingHistory(ReviewDb db, ChangeUpdate update, Comment.Key commentKey, PatchSet.Id psId, String newMessage) throws OrmException {
    if (PrimaryStorage.of(update.getChange()).equals(PrimaryStorage.REVIEW_DB)) {
        PatchLineComment.Key key = new PatchLineComment.Key(new Patch.Key(psId, commentKey.filename), commentKey.uuid);
        if (db instanceof BatchUpdateReviewDb) {
            db = ((BatchUpdateReviewDb) db).unsafeGetDelegate();
        }
        db = ReviewDbUtil.unwrapDb(db);
        PatchLineComment patchLineComment = db.patchComments().get(key);
        if (!patchLineComment.getStatus().equals(PUBLISHED)) {
            throw new OrmException(String.format("comment %s is not published", key));
        }
        patchLineComment.setMessage(newMessage);
        db.patchComments().upsert(Collections.singleton(patchLineComment));
    }
    update.deleteCommentByRewritingHistory(commentKey.uuid, newMessage);
}
Also used : BatchUpdateReviewDb(com.google.gerrit.server.update.BatchUpdateReviewDb) PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) OrmException(com.google.gwtorm.server.OrmException) Patch(com.google.gerrit.reviewdb.client.Patch)

Example 2 with BatchUpdateReviewDb

use of com.google.gerrit.server.update.BatchUpdateReviewDb in project gerrit by GerritCodeReview.

the class DeleteReviewerOp method approvals.

private Iterable<PatchSetApproval> approvals(ChangeContext ctx, Account.Id accountId) throws OrmException {
    Change.Id changeId = ctx.getNotes().getChangeId();
    Iterable<PatchSetApproval> approvals;
    PrimaryStorage r = PrimaryStorage.of(ctx.getChange());
    if (migration.readChanges() && r == PrimaryStorage.REVIEW_DB) {
        // Because NoteDb and ReviewDb have different semantics for zero-value
        // approvals, we must fall back to ReviewDb as the source of truth here.
        ReviewDb db = ctx.getDb();
        if (db instanceof BatchUpdateReviewDb) {
            db = ((BatchUpdateReviewDb) db).unsafeGetDelegate();
        }
        db = ReviewDbUtil.unwrapDb(db);
        approvals = db.patchSetApprovals().byChange(changeId);
    } else {
        approvals = approvalsUtil.byChange(ctx.getDb(), ctx.getNotes()).values();
    }
    return Iterables.filter(approvals, psa -> accountId.equals(psa.getAccountId()));
}
Also used : PrimaryStorage(com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage) BatchUpdateReviewDb(com.google.gerrit.server.update.BatchUpdateReviewDb) Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) BatchUpdateReviewDb(com.google.gerrit.server.update.BatchUpdateReviewDb)

Aggregations

BatchUpdateReviewDb (com.google.gerrit.server.update.BatchUpdateReviewDb)2 Change (com.google.gerrit.reviewdb.client.Change)1 Patch (com.google.gerrit.reviewdb.client.Patch)1 PatchLineComment (com.google.gerrit.reviewdb.client.PatchLineComment)1 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)1 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)1 PrimaryStorage (com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage)1 OrmException (com.google.gwtorm.server.OrmException)1