diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java index a975c9c093..4e45b1ead8 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java @@ -309,16 +309,14 @@ public class PostReview implements RestModifyView } List del = Lists.newArrayList(); - List ins = Lists.newArrayList(); - List upd = Lists.newArrayList(); + List ups = Lists.newArrayList(); for (Map.Entry> ent : in.entrySet()) { String path = ent.getKey(); for (Comment c : ent.getValue()) { String parent = Url.decode(c.inReplyTo); PatchLineComment e = drafts.remove(Url.decode(c.id)); - boolean create = e == null; - if (create) { + if (e == null) { e = new PatchLineComment( new PatchLineComment.Key( new Patch.Key(rsrc.getPatchSet().getId(), path), @@ -340,7 +338,7 @@ public class PostReview implements RestModifyView c.range.endLine, c.range.endCharacter)); } - (create ? ins : upd).add(e); + ups.add(e); } } @@ -355,16 +353,14 @@ public class PostReview implements RestModifyView for (PatchLineComment e : drafts.values()) { e.setStatus(PatchLineComment.Status.PUBLISHED); e.setWrittenOn(timestamp); - upd.add(e); + ups.add(e); } break; } db.get().patchComments().delete(del); - db.get().patchComments().insert(ins); - db.get().patchComments().update(upd); - comments.addAll(ins); - comments.addAll(upd); - return !del.isEmpty() || !ins.isEmpty() || !upd.isEmpty(); + db.get().patchComments().upsert(ups); + comments.addAll(ups); + return !del.isEmpty() || !ups.isEmpty(); } private Map scanDraftComments( @@ -385,8 +381,7 @@ public class PostReview implements RestModifyView } List del = Lists.newArrayList(); - List ins = Lists.newArrayList(); - List upd = Lists.newArrayList(); + List ups = Lists.newArrayList(); Map current = scanLabels(rsrc, del); LabelTypes labelTypes = rsrc.getControl().getLabelTypes(); @@ -412,7 +407,7 @@ public class PostReview implements RestModifyView } else if (c != null && c.getValue() != ent.getValue()) { c.setValue(ent.getValue()); c.setGranted(timestamp); - upd.add(c); + ups.add(c); addLabelDelta(normName, c.getValue()); categories.put(normName, c.getValue()); update.putApproval(ent.getKey(), ent.getValue()); @@ -425,24 +420,23 @@ public class PostReview implements RestModifyView lt.getLabelId()), ent.getValue(), TimeUtil.nowTs()); c.setGranted(timestamp); - ins.add(c); + ups.add(c); addLabelDelta(normName, c.getValue()); categories.put(normName, c.getValue()); update.putApproval(ent.getKey(), ent.getValue()); } } - forceCallerAsReviewer(rsrc, current, ins, upd, del); + forceCallerAsReviewer(rsrc, current, ups, del); db.get().patchSetApprovals().delete(del); - db.get().patchSetApprovals().insert(ins); - db.get().patchSetApprovals().update(upd); - return !del.isEmpty() || !ins.isEmpty() || !upd.isEmpty(); + db.get().patchSetApprovals().upsert(ups); + return !del.isEmpty() || !ups.isEmpty(); } private void forceCallerAsReviewer(RevisionResource rsrc, - Map current, List ins, - List upd, List del) { - if (current.isEmpty() && ins.isEmpty() && upd.isEmpty()) { + Map current, List ups, + List del) { + if (current.isEmpty() && ups.isEmpty()) { // TODO Find another way to link reviewers to changes. if (del.isEmpty()) { // If no existing label is being set to 0, hack in the caller @@ -454,7 +448,7 @@ public class PostReview implements RestModifyView .getLabelId()), (short) 0, TimeUtil.nowTs()); c.setGranted(timestamp); - ins.add(c); + ups.add(c); } else { // Pick a random label that is about to be deleted and keep it. Iterator i = del.iterator(); @@ -462,7 +456,7 @@ public class PostReview implements RestModifyView c.setValue((short) 0); c.setGranted(timestamp); i.remove(); - upd.add(c); + ups.add(c); } } }