Apama 10.7.2 | Developing Apama Applications | Developing Apama Applications in EPL | Using EPL Plug-ins | Using the MemoryStore | Steps for using the MemoryStore | Determining which commit action to call
 
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 optimizing 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 { row.update(); }
}
The 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);
The above example is equivalent to the previous one, both in behavior and performance. Which to use is a matter of context, style and personal preference.
If you want to simply overwrite the whole Row rather than updating the row based on the current value, then using forceCommit() would be more appropriate. It commits the local Row content to the table even if it was modified after you obtained the Row event:
Row row := tbl.get("foo");
row.setInteger("a", 123);
row.forceCommit()