Make NoSuchChangeException inherit from OrmException

More than a few throws and catch clauses already treat
NoSuchChangeException and OrmException identically; the few catch
clauses that actually care about the difference already catch
NoSuchChangeException explicitly. So this change results in a lot less
repeition.

The proximate reason for this change is I want to throw
NoSuchChangeException from ChangeNotes#load(), which is necessarily
called in a lot of places (because lazy-loading needs to be supported
when loading changes from the index with arbitrary
ListChangesOptions). Adding this new exception method is of course
possible but would have rippled out quite far.

The potential downside of this change is that authors of new code
calling a method that throws OrmException might not immediately know
that catching NoSuchChangeException is something they might want to
think about. However, I'm hoping this doesn't come up much in
practice; most callers should already have a loaded ChangeNotes or
similar object, so a NoSuchChangeException that late in the codepath
really is an unexpected error case.

Change-Id: Ibf28414344ebeeb4d37c28576feb14462e7c378a
This commit is contained in:
Dave Borowitz 2016-12-20 13:22:33 -05:00
parent e9070d639d
commit ba6b05d50c
30 changed files with 66 additions and 105 deletions

View File

@ -29,7 +29,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gwtorm.server.OrmException;
@ -343,7 +342,7 @@ public class PushOneCommit {
public void assertChange(Change.Status expectedStatus,
String expectedTopic, TestAccount... expectedReviewers)
throws OrmException, NoSuchChangeException {
throws OrmException {
Change c = getChange().change();
assertThat(c.getSubject()).isEqualTo(resSubj);
assertThat(c.getStatus()).isEqualTo(expectedStatus);
@ -352,7 +351,7 @@ public class PushOneCommit {
}
private void assertReviewers(Change c, TestAccount... expectedReviewers)
throws OrmException, NoSuchChangeException {
throws OrmException {
Iterable<Account.Id> actualIds = approvalsUtil
.getReviewers(db, notesFactory.createChecked(db, c))
.all();

View File

@ -44,7 +44,6 @@ import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.notedb.NotesMigration;
import com.google.gerrit.server.notedb.ReviewerStateInternal;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.util.LabelVote;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@ -248,7 +247,7 @@ public class ApprovalsUtil {
try {
IdentifiedUser user = userFactory.create(accountId);
return changeControlFactory.controlFor(notes, user).isVisible(db);
} catch (OrmException | NoSuchChangeException e) {
} catch (OrmException e) {
log.warn(String.format("Failed to check if account %d can see change %d",
accountId.get(), notes.getChangeId().get()), e);
return false;

View File

@ -82,7 +82,7 @@ public class ChangeFinder {
}
public ChangeControl findOne(Change.Id id, CurrentUser user)
throws OrmException, NoSuchChangeException {
throws OrmException {
List<ChangeControl> ctls = find(id, user);
if (ctls.size() != 1) {
throw new NoSuchChangeException(id);

View File

@ -218,7 +218,7 @@ public class StarredChangesUtil {
}
public void unstarAll(Project.NameKey project, Change.Id changeId)
throws OrmException, NoSuchChangeException {
throws OrmException {
try (Repository repo = repoManager.openRepository(allUsers);
RevWalk rw = new RevWalk(repo)) {
BatchRefUpdate batchUpdate = repo.getRefDatabase().newBatchUpdate();
@ -315,7 +315,7 @@ public class StarredChangesUtil {
}
public ImmutableMultimap<Account.Id, String> byChangeFromIndex(
Change.Id changeId) throws OrmException, NoSuchChangeException {
Change.Id changeId) throws OrmException {
Set<String> fields = ImmutableSet.of(
ChangeField.ID.getName(),
ChangeField.STAR.getName());

View File

@ -67,7 +67,6 @@ import com.google.gerrit.server.change.SubmittedTogether;
import com.google.gerrit.server.change.SuggestChangeReviewers;
import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@ -267,8 +266,7 @@ class ChangeApiImpl implements ChangeApi {
public ChangeApi revert(RevertInput in) throws RestApiException {
try {
return changeApi.id(revert.apply(change, in)._number);
} catch (OrmException | IOException | UpdateException
| NoSuchChangeException e) {
} catch (OrmException | IOException | UpdateException e) {
throw new RestApiException("Cannot revert change", e);
}
}
@ -279,7 +277,7 @@ class ChangeApiImpl implements ChangeApi {
try {
return updateByMerge.apply(change, in).value();
} catch (IOException | UpdateException | InvalidChangeOperationException
| NoSuchChangeException | OrmException e) {
| OrmException e) {
throw new RestApiException("Cannot update change by merge", e);
}
}

View File

@ -22,7 +22,6 @@ import com.google.gerrit.server.change.FileResource;
import com.google.gerrit.server.change.GetContent;
import com.google.gerrit.server.change.GetDiff;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@ -51,7 +50,7 @@ class FileApiImpl implements FileApi {
public BinaryResult content() throws RestApiException {
try {
return getContent.apply(file);
} catch (NoSuchChangeException | IOException | OrmException e) {
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot retrieve file content", e);
}
}

View File

@ -69,7 +69,6 @@ import com.google.gerrit.server.change.TestSubmitType;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@ -257,8 +256,7 @@ class RevisionApiImpl implements RevisionApi {
public ChangeApi rebase(RebaseInput in) throws RestApiException {
try {
return changes.id(rebase.apply(revision, in)._number);
} catch (OrmException | EmailException | UpdateException | IOException
| NoSuchChangeException e) {
} catch (OrmException | EmailException | UpdateException | IOException e) {
throw new RestApiException("Cannot rebase ps", e);
}
}

View File

@ -55,7 +55,6 @@ import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.project.RefControl;
@ -398,7 +397,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
IdentifiedUser user = userFactory.create(accountId);
return changeControlFactory.controlFor(notes, user)
.isVisible(db);
} catch (OrmException | NoSuchChangeException e) {
} catch (OrmException e) {
log.warn(
String.format(
"Failed to check if account %d can see change %d",
@ -411,7 +410,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
}
@Override
public void postUpdate(Context ctx) throws OrmException, NoSuchChangeException {
public void postUpdate(Context ctx) throws OrmException {
if (sendMail
&& (notify != NotifyHandling.NONE || !accountsToNotify.isEmpty())) {
Runnable sender = new Runnable() {

View File

@ -113,7 +113,6 @@ import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.notedb.ReviewerStateInternal;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.SubmitRuleOptions;
import com.google.gerrit.server.query.QueryResult;
@ -277,11 +276,11 @@ public class ChangeJson {
}
public ChangeInfo format(Project.NameKey project, Change.Id id)
throws OrmException, NoSuchChangeException {
throws OrmException {
ChangeNotes notes;
try {
notes = notesFactory.createChecked(db.get(), project, id);
} catch (OrmException | NoSuchChangeException e) {
} catch (OrmException e) {
if (!has(CHECK)) {
throw e;
}

View File

@ -54,7 +54,6 @@ import com.google.gerrit.server.notedb.PatchSetState;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@ -409,7 +408,7 @@ public class ConsistencyChecker {
if (!c.getDest().equals(change().getDest())) {
continue;
}
} catch (OrmException | NoSuchChangeException e) {
} catch (OrmException e) {
warn(e);
// Include this patch set; should cause an error below, which is good.
}
@ -536,8 +535,8 @@ public class ConsistencyChecker {
db.get(), inserter.getChange(), ctl.getUser());
insertPatchSetProblem.status = Status.FIXED;
insertPatchSetProblem.outcome = "Inserted as patch set " + psId.get();
} catch (OrmException | IOException | NoSuchChangeException
| UpdateException | RestApiException e) {
} catch (OrmException | IOException | UpdateException
| RestApiException e) {
warn(e);
for (ProblemInfo pi : currProblems) {
pi.status = Status.FIX_FAILED;

View File

@ -46,7 +46,6 @@ import com.google.gerrit.server.git.MergeUtil;
import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@ -104,8 +103,8 @@ public class CreateMergePatchSet implements
@Override
public Response<ChangeInfo> apply(ChangeResource req, MergePatchSetInput in)
throws NoSuchChangeException, OrmException, IOException,
InvalidChangeOperationException, RestApiException, UpdateException {
throws OrmException, IOException, InvalidChangeOperationException,
RestApiException, UpdateException {
if (in.merge == null) {
throw new BadRequestException("merge field is required");
}

View File

@ -84,7 +84,7 @@ public class GetContent implements RestReadView<FileResource> {
}
private String getMessage(ChangeNotes notes)
throws NoSuchChangeException, OrmException, IOException {
throws OrmException, IOException {
Change.Id changeId = notes.getChangeId();
PatchSet ps = psUtil.current(db.get(), notes);
if (ps == null) {
@ -102,7 +102,7 @@ public class GetContent implements RestReadView<FileResource> {
}
private byte[] getMergeList(ChangeNotes notes)
throws NoSuchChangeException, OrmException, IOException {
throws OrmException, IOException {
Change.Id changeId = notes.getChangeId();
PatchSet ps = psUtil.current(db.get(), notes);
if (ps == null) {

View File

@ -30,7 +30,6 @@ import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.server.edit.ChangeEdit;
import com.google.gerrit.server.edit.ChangeEditUtil;
import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@ -87,8 +86,7 @@ public class PublishChangeEdit implements
@Override
public Response<?> apply(ChangeResource rsrc, PublishChangeEditInput in)
throws NoSuchChangeException, IOException, OrmException,
RestApiException, UpdateException {
throws IOException, OrmException, RestApiException, UpdateException {
Capable r =
rsrc.getControl().getProjectControl().canPushToAtLeastOneRef();
if (r != Capable.OK) {

View File

@ -28,7 +28,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gwtorm.server.OrmException;
@ -93,8 +92,7 @@ public class RebaseUtil {
abstract PatchSet patchSet();
}
Base parseBase(RevisionResource rsrc, String base)
throws OrmException, NoSuchChangeException {
Base parseBase(RevisionResource rsrc, String base) throws OrmException {
ReviewDb db = dbProvider.get();
// Try parsing the base as a ref string.
@ -137,7 +135,7 @@ public class RebaseUtil {
}
private ChangeControl controlFor(RevisionResource rsrc, Change.Id id)
throws OrmException, NoSuchChangeException {
throws OrmException {
if (rsrc.getChange().getId().equals(id)) {
return rsrc.getControl();
}

View File

@ -165,7 +165,6 @@ public class ChangeEditUtil {
* should be sent after the change edit is published.
* @param accountsToNotify Accounts that should be notified after the change
* edit is published.
* @throws NoSuchChangeException
* @throws IOException
* @throws OrmException
* @throws UpdateException
@ -173,8 +172,7 @@ public class ChangeEditUtil {
*/
public void publish(final ChangeEdit edit, NotifyHandling notify,
Multimap<RecipientType, Account.Id> accountsToNotify)
throws NoSuchChangeException, IOException, OrmException,
RestApiException, UpdateException {
throws IOException, OrmException, RestApiException, UpdateException {
Change change = edit.getChange();
try (Repository repo = gitManager.openRepository(change.getProject());
RevWalk rw = new RevWalk(repo);

View File

@ -1029,7 +1029,7 @@ public class BatchUpdate implements AutoCloseable {
}
private ChangeContext newChangeContext(ReviewDb db, Repository repo,
RevWalk rw, Change.Id id) throws OrmException, NoSuchChangeException {
RevWalk rw, Change.Id id) throws OrmException {
Change c = newChanges.get(id);
if (c == null) {
c = ChangeNotes.readOneReviewDbChange(db, id);

View File

@ -34,7 +34,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import org.eclipse.jgit.lib.ObjectId;
@ -101,8 +100,7 @@ public class GroupCollector {
}
private interface Lookup {
List<String> lookup(PatchSet.Id psId)
throws OrmException, NoSuchChangeException;
List<String> lookup(PatchSet.Id psId) throws OrmException;
}
private final Multimap<ObjectId, PatchSet.Id> patchSetsBySha;
@ -119,8 +117,7 @@ public class GroupCollector {
transformRefs(changeRefsById),
new Lookup() {
@Override
public List<String> lookup(PatchSet.Id psId)
throws OrmException, NoSuchChangeException {
public List<String> lookup(PatchSet.Id psId) throws OrmException {
// TODO(dborowitz): Reuse open repository from caller.
ChangeNotes notes =
notesFactory.createChecked(db, project, psId.getParentKey());
@ -233,8 +230,7 @@ public class GroupCollector {
}
}
public SortedSetMultimap<ObjectId, String> getGroups()
throws OrmException, NoSuchChangeException {
public SortedSetMultimap<ObjectId, String> getGroups() throws OrmException {
done = true;
SortedSetMultimap<ObjectId, String> result = MultimapBuilder
.hashKeys(groups.keySet().size())
@ -265,8 +261,7 @@ public class GroupCollector {
}
private Set<String> resolveGroups(ObjectId forCommit,
Collection<String> candidates)
throws OrmException, NoSuchChangeException {
Collection<String> candidates) throws OrmException {
Set<String> actual = Sets.newTreeSet();
Set<String> done = Sets.newHashSetWithExpectedSize(candidates.size());
Set<String> seen = Sets.newHashSetWithExpectedSize(candidates.size());
@ -303,7 +298,7 @@ public class GroupCollector {
}
private Iterable<String> resolveGroup(ObjectId forCommit, String group)
throws OrmException, NoSuchChangeException {
throws OrmException {
ObjectId id = parseGroup(forCommit, group);
if (id != null) {
PatchSet.Id psId = Iterables.getFirst(patchSetsBySha.get(id), null);

View File

@ -32,7 +32,6 @@ import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@ -95,11 +94,10 @@ public class LabelNormalizer {
* type and permissions for the user. Approvals for unknown labels are not
* included in the output, nor are approvals where the user has no
* permissions for that label.
* @throws NoSuchChangeException
* @throws OrmException
*/
public Result normalize(Change change, Collection<PatchSetApproval> approvals)
throws NoSuchChangeException, OrmException {
throws OrmException {
IdentifiedUser user = userFactory.create(change.getOwner());
return normalize(
changeFactory.controlFor(db.get(), change, user), approvals);

View File

@ -1633,14 +1633,14 @@ public class ReceiveCommits {
try {
changeEnt = notesFactory.createChecked(db, project.getNameKey(), changeId)
.getChange();
} catch (OrmException e) {
logError("Cannot lookup existing change " + changeId, e);
reject(cmd, "database error");
return;
} catch (NoSuchChangeException e) {
logError("Change not found " + changeId, e);
reject(cmd, "change " + changeId + " not found");
return;
} catch (OrmException e) {
logError("Cannot lookup existing change " + changeId, e);
reject(cmd, "database error");
return;
}
if (!project.getNameKey().equals(changeEnt.getProject())) {
reject(cmd, "change " + changeId + " does not belong to project " + project.getName());
@ -1910,7 +1910,7 @@ public class ReceiveCommits {
update.groups = ImmutableList.copyOf((groups.get(update.commit)));
}
logDebug("Finished updating groups from GroupCollector");
} catch (OrmException | NoSuchChangeException e) {
} catch (OrmException e) {
logError("Error collecting groups for changes", e);
reject(magicBranch.cmd, "internal server error");
return;

View File

@ -48,7 +48,6 @@ import com.google.gerrit.server.mail.MailUtil.MailRecipients;
import com.google.gerrit.server.mail.send.ReplacePatchSetSender;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.util.RequestScopePropagator;
@ -421,8 +420,7 @@ public class ReplaceOp extends BatchUpdate.Op {
}
}
private void fireCommentAddedEvent(final Context ctx)
throws NoSuchChangeException, OrmException {
private void fireCommentAddedEvent(Context ctx) throws OrmException {
if (approvals.isEmpty()) {
return;
}

View File

@ -147,8 +147,7 @@ public class ReindexAfterUpdate implements GitReferenceUpdatedListener {
}
@Override
protected Void impl(RequestContext ctx)
throws OrmException, IOException, NoSuchChangeException {
protected Void impl(RequestContext ctx) throws OrmException, IOException {
// Reload change, as some time may have passed since GetChanges.
ReviewDb db = ctx.getReviewDbProvider().get();
try {

View File

@ -36,7 +36,6 @@ import com.google.gerrit.server.patch.PatchList;
import com.google.gerrit.server.patch.PatchListEntry;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
@ -325,7 +324,7 @@ public abstract class ChangeEmail extends NotificationEmail {
}
}
}
} catch (OrmException | NoSuchChangeException err) {
} catch (OrmException err) {
// Just don't BCC everyone. Better to send a partial message to those
// we already have queued up then to fail deliver entirely to people
// who have a lower interest in the change.

View File

@ -118,12 +118,12 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
}
public ChangeNotes createChecked(ReviewDb db, Change c)
throws OrmException, NoSuchChangeException {
throws OrmException {
return createChecked(db, c.getProject(), c.getId());
}
public ChangeNotes createChecked(ReviewDb db, Project.NameKey project,
Change.Id changeId) throws OrmException, NoSuchChangeException {
Change.Id changeId) throws OrmException {
Change change = readOneReviewDbChange(db, changeId);
if (change == null || !change.getProject().equals(project)) {
throw new NoSuchChangeException(changeId);
@ -131,8 +131,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
return new ChangeNotes(args, change).load();
}
public ChangeNotes createChecked(Change.Id changeId)
throws OrmException, NoSuchChangeException {
public ChangeNotes createChecked(Change.Id changeId) throws OrmException {
InternalChangeQuery query = queryProvider.get().noFields();
List<ChangeData> changes = query.byLegacyChangeId(changeId);
if (changes.isEmpty()) {

View File

@ -20,7 +20,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.notedb.NoteDbUpdateManager.Result;
import com.google.gerrit.server.notedb.rebuild.ChangeRebuilder;
import com.google.gerrit.server.notedb.rebuild.ChangeRebuilderImpl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
@ -55,7 +54,7 @@ public class TestChangeRebuilderWrapper extends ChangeRebuilder {
@Override
public Result rebuild(ReviewDb db, Change.Id changeId)
throws NoSuchChangeException, IOException, OrmException {
throws IOException, OrmException {
if (failNextUpdate.getAndSet(false)) {
throw new IOException("Update failed");
}
@ -68,8 +67,7 @@ public class TestChangeRebuilderWrapper extends ChangeRebuilder {
@Override
public Result rebuild(NoteDbUpdateManager manager,
ChangeBundle bundle) throws NoSuchChangeException, IOException,
OrmException {
ChangeBundle bundle) throws IOException, OrmException {
// stealNextUpdate doesn't really apply in this case because the IOException
// would normally come from the manager.execute() method, which isn't called
// here.
@ -78,15 +76,14 @@ public class TestChangeRebuilderWrapper extends ChangeRebuilder {
@Override
public NoteDbUpdateManager stage(ReviewDb db, Change.Id changeId)
throws NoSuchChangeException, IOException, OrmException {
throws IOException, OrmException {
// Don't inspect stealNextUpdate; that happens in execute() below.
return delegate.stage(db, changeId);
}
@Override
public Result execute(ReviewDb db, Change.Id changeId,
NoteDbUpdateManager manager) throws NoSuchChangeException, OrmException,
IOException {
NoteDbUpdateManager manager) throws OrmException, IOException {
if (failNextUpdate.getAndSet(false)) {
throw new IOException("Update failed");
}

View File

@ -21,7 +21,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.notedb.ChangeBundle;
import com.google.gerrit.server.notedb.NoteDbUpdateManager;
import com.google.gerrit.server.notedb.NoteDbUpdateManager.Result;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.SchemaFactory;
@ -57,19 +56,17 @@ public abstract class ChangeRebuilder {
}
public abstract Result rebuild(ReviewDb db, Change.Id changeId)
throws NoSuchChangeException, IOException, OrmException;
throws IOException, OrmException;
public abstract Result rebuild(NoteDbUpdateManager manager,
ChangeBundle bundle) throws NoSuchChangeException, IOException,
OrmException;
ChangeBundle bundle) throws IOException, OrmException;
public abstract void buildUpdates(NoteDbUpdateManager manager,
ChangeBundle bundle) throws IOException, OrmException;
public abstract NoteDbUpdateManager stage(ReviewDb db, Change.Id changeId)
throws NoSuchChangeException, IOException, OrmException;
throws IOException, OrmException;
public abstract Result execute(ReviewDb db, Change.Id changeId,
NoteDbUpdateManager manager) throws NoSuchChangeException, OrmException,
IOException;
NoteDbUpdateManager manager) throws OrmException, IOException;
}

View File

@ -153,7 +153,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
@Override
public Result rebuild(ReviewDb db, Change.Id changeId)
throws NoSuchChangeException, IOException, OrmException {
throws IOException, OrmException {
db = ReviewDbUtil.unwrapDb(db);
// Read change just to get project; this instance is then discarded so we
// can read a consistent ChangeBundle inside a transaction.
@ -179,7 +179,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
@Override
public NoteDbUpdateManager stage(ReviewDb db, Change.Id changeId)
throws NoSuchChangeException, IOException, OrmException {
throws IOException, OrmException {
db = ReviewDbUtil.unwrapDb(db);
Change change =
checkNoteDbState(ChangeNotes.readOneReviewDbChange(db, changeId));
@ -195,8 +195,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
@Override
public Result execute(ReviewDb db, Change.Id changeId,
NoteDbUpdateManager manager) throws NoSuchChangeException, OrmException,
IOException {
NoteDbUpdateManager manager) throws OrmException, IOException {
db = ReviewDbUtil.unwrapDb(db);
Change change =
checkNoteDbState(ChangeNotes.readOneReviewDbChange(db, changeId));

View File

@ -187,9 +187,8 @@ public class PatchScriptFactory implements Callable<PatchScript> {
}
@Override
public PatchScript call() throws OrmException, NoSuchChangeException,
LargeObjectException, AuthException,
InvalidChangeOperationException, IOException {
public PatchScript call() throws OrmException, LargeObjectException,
AuthException, InvalidChangeOperationException, IOException {
if (parentNum < 0) {
validatePatchSetId(psa);
}

View File

@ -58,13 +58,12 @@ public class ChangeControl {
}
public ChangeControl controlFor(ReviewDb db, Project.NameKey project,
Change.Id changeId, CurrentUser user)
throws NoSuchChangeException, OrmException {
Change.Id changeId, CurrentUser user) throws OrmException {
return controlFor(notesFactory.create(db, project, changeId), user);
}
public ChangeControl controlFor(ReviewDb db, Change change,
CurrentUser user) throws NoSuchChangeException, OrmException {
CurrentUser user) throws OrmException {
final Project.NameKey projectKey = change.getProject();
try {
return projectControl.controlFor(projectKey, user)
@ -88,12 +87,12 @@ public class ChangeControl {
}
public ChangeControl validateFor(ReviewDb db, Change.Id changeId,
CurrentUser user) throws NoSuchChangeException, OrmException {
CurrentUser user) throws OrmException {
return validateFor(db, notesFactory.createChecked(changeId), user);
}
public ChangeControl validateFor(ReviewDb db, ChangeNotes notes,
CurrentUser user) throws NoSuchChangeException, OrmException {
CurrentUser user) throws OrmException {
ChangeControl c = controlFor(notes, user);
if (!c.isVisible(db)) {
throw new NoSuchChangeException(c.getId());

View File

@ -15,16 +15,17 @@
package com.google.gerrit.server.project;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwtorm.server.OrmException;
/** Indicates the change does not exist. */
public class NoSuchChangeException extends Exception {
public class NoSuchChangeException extends OrmException {
private static final long serialVersionUID = 1L;
public NoSuchChangeException(final Change.Id key) {
public NoSuchChangeException(Change.Id key) {
this(key, null);
}
public NoSuchChangeException(final Change.Id key, final Throwable why) {
public NoSuchChangeException(Change.Id key, Throwable why) {
super(key.toString(), why);
}
}

View File

@ -86,8 +86,7 @@ public class Schema_108 extends SchemaVersion {
}
private void updateProjectGroups(ReviewDb db, Repository repo, RevWalk rw,
Set<Change.Id> changes, UpdateUI ui)
throws OrmException, IOException, NoSuchChangeException {
Set<Change.Id> changes, UpdateUI ui) throws OrmException, IOException {
// Match sorting in ReceiveCommits.
rw.reset();
rw.sort(RevSort.TOPO);
@ -133,8 +132,7 @@ public class Schema_108 extends SchemaVersion {
}
private static void updateGroups(ReviewDb db, GroupCollector collector,
Multimap<ObjectId, PatchSet.Id> patchSetsBySha)
throws OrmException, NoSuchChangeException {
Multimap<ObjectId, PatchSet.Id> patchSetsBySha) throws OrmException {
Map<PatchSet.Id, PatchSet> patchSets =
db.patchSets().toMap(db.patchSets().get(patchSetsBySha.values()));
for (Map.Entry<ObjectId, Collection<String>> e