use of com.google.gwtorm.server.OrmConcurrencyException in project gerrit by GerritCodeReview.
the class NoteDbUpdateManager method checkExpectedState.
private void checkExpectedState() throws OrmException, IOException {
if (!checkExpectedState) {
return;
}
// that got passed into the ChangeUpdate.
for (Collection<ChangeUpdate> us : changeUpdates.asMap().values()) {
ChangeUpdate u = us.iterator().next();
NoteDbChangeState expectedState = NoteDbChangeState.parse(u.getChange());
if (expectedState == null) {
// MismatchedStateException.
continue;
}
if (expectedState.getPrimaryStorage() == PrimaryStorage.NOTE_DB) {
// NoteDb is primary, no need to compare state to ReviewDb.
continue;
}
if (!expectedState.isChangeUpToDate(changeRepo.cmds.getRepoRefCache())) {
throw new MismatchedStateException(u.getId(), expectedState);
}
}
for (Collection<ChangeDraftUpdate> us : draftUpdates.asMap().values()) {
ChangeDraftUpdate u = us.iterator().next();
NoteDbChangeState expectedState = NoteDbChangeState.parse(u.getChange());
if (expectedState == null || expectedState.getPrimaryStorage() == PrimaryStorage.NOTE_DB) {
// See above.
continue;
}
Account.Id accountId = u.getAccountId();
if (!expectedState.areDraftsUpToDate(allUsersRepo.cmds.getRepoRefCache(), accountId)) {
ObjectId expectedDraftId = firstNonNull(expectedState.getDraftIds().get(accountId), ObjectId.zeroId());
throw new OrmConcurrencyException(String.format("cannot apply NoteDb updates for change %s;" + " draft ref for account %s does not match %s", u.getId(), accountId, expectedDraftId.name()));
}
}
}
Aggregations