在 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
}
有没有更好更干净的方法让我在上述交易后立即知道交易是否成功?
提前致谢。