In Ballerina we can identify whether a transaction was successful within "onCommit" and "onAbort" functions we provide. But this takes us away from the current method.
I want to be able to verify whether the transaction was successful or failed in the very next line after the transaction within the same method. In my scenario, I cannot have global variables to share states as well. I can think of workarounds such as using a boolean within the function, but outside the transaction.
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
}
Is there a better and cleaner way for me to know whether the transaction was successful right after the transaction as above?
Thanks in advance.