summaryrefslogtreecommitdiffstats
path: root/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/SaveDraft.java
diff options
context:
space:
mode:
Diffstat (limited to 'gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/SaveDraft.java')
-rw-r--r--gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/SaveDraft.java81
1 files changed, 44 insertions, 37 deletions
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/SaveDraft.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/SaveDraft.java
index 1fbc559416..06c21dff08 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/SaveDraft.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/SaveDraft.java
@@ -15,17 +15,17 @@
package com.google.gerrit.httpd.rpc.patch;
import com.google.gerrit.httpd.rpc.Handler;
-import com.google.gerrit.reviewdb.Account;
-import com.google.gerrit.reviewdb.Change;
-import com.google.gerrit.reviewdb.Patch;
-import com.google.gerrit.reviewdb.PatchLineComment;
-import com.google.gerrit.reviewdb.PatchSet;
-import com.google.gerrit.reviewdb.ReviewDb;
+import com.google.gerrit.reviewdb.client.Account;
+import com.google.gerrit.reviewdb.client.Change;
+import com.google.gerrit.reviewdb.client.Patch;
+import com.google.gerrit.reviewdb.client.PatchLineComment;
+import com.google.gerrit.reviewdb.client.PatchSet;
+import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
-import com.google.gwtorm.client.OrmException;
+import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -49,7 +49,6 @@ class SaveDraft extends Handler<PatchLineComment> {
this.changeControlFactory = changeControlFactory;
this.db = db;
this.currentUser = currentUser;
-
this.comment = comment;
}
@@ -62,42 +61,50 @@ class SaveDraft extends Handler<PatchLineComment> {
final Patch.Key patchKey = comment.getKey().getParentKey();
final PatchSet.Id patchSetId = patchKey.getParentKey();
final Change.Id changeId = patchKey.getParentKey().getParentKey();
- changeControlFactory.validateFor(changeId);
- if (db.patchSets().get(patchSetId) == null) {
- throw new NoSuchChangeException(changeId);
- }
- final Account.Id me = currentUser.getAccountId();
- if (comment.getKey().get() == null) {
- if (comment.getLine() < 1) {
- throw new IllegalStateException("Comment line must be >= 1, not "
- + comment.getLine());
+ db.changes().beginTransaction(changeId);
+ try {
+ changeControlFactory.validateFor(changeId);
+ if (db.patchSets().get(patchSetId) == null) {
+ throw new NoSuchChangeException(changeId);
}
- if (comment.getParentUuid() != null) {
- final PatchLineComment parent =
- db.patchComments().get(
- new PatchLineComment.Key(patchKey, comment.getParentUuid()));
- if (parent == null || parent.getSide() != comment.getSide()) {
- throw new IllegalStateException("Parent comment must be on same side");
+ final Account.Id me = currentUser.getAccountId();
+ if (comment.getKey().get() == null) {
+ if (comment.getLine() < 1) {
+ throw new IllegalStateException("Comment line must be >= 1, not "
+ + comment.getLine());
}
- }
- final PatchLineComment nc =
- new PatchLineComment(new PatchLineComment.Key(patchKey, ChangeUtil
- .messageUUID(db)), comment.getLine(), me, comment.getParentUuid());
- nc.setSide(comment.getSide());
- nc.setMessage(comment.getMessage());
- db.patchComments().insert(Collections.singleton(nc));
- return nc;
+ if (comment.getParentUuid() != null) {
+ final PatchLineComment parent =
+ db.patchComments().get(
+ new PatchLineComment.Key(patchKey, comment.getParentUuid()));
+ if (parent == null || parent.getSide() != comment.getSide()) {
+ throw new IllegalStateException("Parent comment must be on same side");
+ }
+ }
- } else {
- if (!me.equals(comment.getAuthor())) {
- throw new NoSuchChangeException(changeId);
+ final PatchLineComment nc =
+ new PatchLineComment(new PatchLineComment.Key(patchKey, ChangeUtil
+ .messageUUID(db)), comment.getLine(), me, comment.getParentUuid());
+ nc.setSide(comment.getSide());
+ nc.setMessage(comment.getMessage());
+ db.patchComments().insert(Collections.singleton(nc));
+ db.commit();
+ return nc;
+
+ } else {
+ if (!me.equals(comment.getAuthor())) {
+ throw new NoSuchChangeException(changeId);
+ }
+ comment.updated();
+ db.patchComments().update(Collections.singleton(comment));
+ db.commit();
+ return comment;
}
- comment.updated();
- db.patchComments().update(Collections.singleton(comment));
- return comment;
+ } finally {
+ db.rollback();
}
}
}