Hi all,
ChristopherT asked me if there is a way to determine whether a call to the GetNewOrExistingAutoTransaction / GetNewOrExistingAutoReadTransaction Methods did start a new DB Transaction, or whether the call 'piggy-backed' on an already running DB Transaction.
The answer is YES that is possible, but for the benefit of those of us who were used to the non-AutoTransaction-scheme Method GetNewOrExistingTransaction I will provide a longer explanation!
The non-AutoTransaction-scheme Method GetNewOrExistingTransaction Method overloads feature an out Argument, 'out bool ANewTransaction', so that's the way to tell that if you use those Methods.
When I introduced the AutoTransaction-scheme Methods GetNewOrExistingAutoTransaction / GetNewOrExistingAutoReadTransaction I found out that there is no need to expose that bool Argument anymore as these AutoTransaction Methods (and all their overloads) internally deal with whatever the value of the ANewTransaction Argument of the called GetNewOrExistingTransaction Method overloads is, and so I reckoned I can leave out that out Argument --- If I would have implemented that out Argument, all places where those Methods would get called would have needed to create a bool Variable for that everywhere where those Methods are called.
But how to find out whether a new DB Transaction got started, or whether the Method 'piggy-backs' on an already running DB Transaction?
Easy, but different: I introduced a Property called 'Reused' on the TDBTransaction Class. That allows code such as 'if (!MyTransaction.Reused)' to be written, which will return true if a DB Transaction has been started by any of the GetNewOrExistingAuto(Read)Transaction Methods, and false if those Methods 'piggy-backed' on an already running DB Transaction. As this Property can be inquired not only in the Method that called the the GetNewOrExistingAuto(Read)Transaction Method this is even more useful than the previous out Argument, esp. for DB Transaction handling when DB Transactions span several Methods!
Reference: https://wiki.openpetra.org/index.php/DB_Access_Exception_Handling_Policy#Tips_for_Debugging
Kind regards,
ChristianK