Step 3. AutoCommit Mode. Work in the context of two transactions for avoiding DEADLOCK.
pFIBDataSet allows to commit the made changes automatically if you set AutoCommit to True. Now after calling the Post method, pFIBDataSet1 will automatically call pFIBTransaction1.CommitRetaining, saving the changes without closing the query. Such approach decreases the probability of Deadlock, which is possible in the presence of long unclosed transactions, in the context of which were made data changes.
But FIBPlus gives another capability, which practically reduces the probability of Deadlock to zero. TpFIBDataSet can work in the context of two transactions, a long one in the context of which the data are only read and a short one, in the context of which there executed all modifying queries.
Let's rename pFIBTransaction1 into ReadTransaction and add another component called WriteTransaction. After this we set UpdateTransaction of pFIBDataSet1 in WriteTransaction. Thus pFIBDataSet1 is connected to both components of TpFIBTransaction at once:
Figure 13.
Now after calling the Post method pFIBDataSet1 will call Commit of WriteTransaction. But taking into account the fact that the data are read in the context of a different transaction (ReadTransaction), it will not cause close of pFIBDataSet1. So using FIBPlus we have a real AutoCommit mode, which decreases the possibility of Deadlock and does not prevent us from seeing all actual record values. You might know that while using BDE in the AutoCommit mode you cannot get real record values without reopening the query.
See the full example code.
|