Determining which commit action to call
If you are certain that you are the only user of a table and if it is okay for your monitor instance to be killed if you are wrong, you can use commit().
If you want to use a simple loop like the one below, or if you intend to give up if your attempt to commit fails, then use tryCommit().
boolean done := false;
while not done {
Row row := tbl.get("foo");
row.setInteger("a",123);
done := row.tryCommit();
}
However, the loop above calls tbl.get() every time around. If you think there might be a high collision rate, it is worth optimising to the following, more efficient design:
Row row := tbl.get("foo");
boolean done := false;
while not done {
row.setInteger("a",123);
done := row.tryCommit();
if not done then { row.update(); }
}
The row.tryCommitOrUpdate() action makes the example above a little simpler and considerably more efficient:
Row row := tbl.get("foo");
boolean done := false;
while not done {
row.setInteger("a",123);
done := row.tryCommitOrUpdate();
}
Alternatively, there is a packaged form of that loop that you might find more convenient:
action doSomeStuff(Row row) {
row.setInteger("a",123);
}
tbl.mutate("foo", doSomeStuff);
This example is equivalent to the previous one, both in behavior and performance. Which to use is a matter of context, style and personal preference.