Merge "BatchUpdate: Always bump rowVersion when dirty"

This commit is contained in:
Dave Borowitz
2016-02-18 20:10:27 +00:00
committed by Gerrit Code Review
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) {