【发布时间】:2018-05-07 16:08:41
【问题描述】:
在 Ballerina 中,我们可以在我们提供的“onCommit”和“onAbort”函数中识别交易是否成功。但这使我们脱离了当前的方法。
我希望能够在同一方法中的事务之后的下一行中验证事务是成功还是失败。在我的场景中,我也不能使用全局变量来共享状态。我可以想到一些变通方法,例如在函数内部使用布尔值,但在事务外部使用。
boolean status=true;
transaction with retries = 4, oncommit = onCommitFunction, onabort = onAbortFunction {
status = true;
// any sql statement/s here
var result = client->update("INSERT ....");
match result {
int c => {
io:println("Inserted count: " + c);
if (c == 0) {
status = false;
abort;
}
}
error err => {
status = false;
retry;
}
}
}
// Here I want to know whether the transaction was a success or a failure
if(status) {
// success action
} else {
// Failed action
}
有没有更好更干净的方式让我在如上交易后立即知道交易是否成功?
提前致谢。
【问题讨论】: