BatchUpdate: Always bump rowVersion when dirty

When any Op returns true from updateChange, we need to bump the
rowVersion so we get a new ETag.

Add a regression test based on PostReviewers, which was the
manifestation reported by one of our internal users.

Change-Id: Ibe1e69430e2e24b5bcbb85cb24a032d820fdd10e
This commit is contained in:
Dave Borowitz
2016-02-17 15:12:55 -05:00
parent bf55fa403a
commit 3f2bde19ef
4 changed files with 44 additions and 16 deletions

View File

@@ -589,26 +589,23 @@ public class BatchUpdate implements AutoCloseable {
for (Op op : e.getValue()) {
dirty |= op.updateChange(ctx);
}
ctx.getChange().setLastUpdatedOn(ctx.getWhen());
Iterable<Change> changes = Collections.singleton(ctx.getChange());
if (!dirty) {
return;
}
if (newChanges.containsKey(id)) {
db.changes().insert(changes);
db.changes().insert(bumpLastUpdatedOn(ctx));
} else if (ctx.saved) {
db.changes().update(changes);
db.changes().update(bumpLastUpdatedOn(ctx));
} else if (ctx.deleted) {
db.changes().delete(changes);
}
if (dirty) {
db.commit();
db.changes().delete(bumpLastUpdatedOn(ctx));
} else {
db.changes().update(bumpRowVersionNotLastUpdatedOn(ctx));
}
db.commit();
} finally {
db.rollback();
}
if (!dirty) {
return;
}
if (ctx.deleted) {
if (notesMigration.writeChanges()) {
new ChangeDelete(plcUtil, getRepository(), ctx.getNotes()).delete();
@@ -636,6 +633,17 @@ public class BatchUpdate implements AutoCloseable {
}
}
private static Iterable<Change> bumpLastUpdatedOn(ChangeContext ctx) {
Change c = ctx.getChange();
c.setLastUpdatedOn(ctx.getWhen());
return Collections.singleton(c);
}
private static Iterable<Change> bumpRowVersionNotLastUpdatedOn(
ChangeContext ctx) {
return Collections.singleton(ctx.getChange());
}
private ChangeContext newChangeContext(Change.Id id) throws Exception {
Change c = newChanges.get(id);
if (c == null) {