Subject Re: [IBO] Transactions
Author Jason Wharton
Isildo,

> I'm using the BDE compatible components.
> I use an explicit transaction for my connection.
> I start this transaction when the user press the
> Insert, Edit or Delete button in the navigator
> and I close the transaction when the user press
> the buttons Post (Commit) or Cancel (Rollback) or
> when he closes the form and the transaction is still open.
>
> The problem is that the user can open a form and he
> starts a transaction without close it and the form
> remains open to. Then he opens another form. With the
> InTransaction method I can see if there is a transaction open.
> If it is I don't call the StartTransaction method. But if
> the user closes the transaction in the second form, the
> transaction in the first form it's closed too. If the user
> in the first form adds several records but he didn't commit
> the changes, and in the second form he makes a rollback, he
> loses the changes in the first form too.
>
> How can I solve this?

It all depends on what you consider a single unit of work. This is more an
issue of how your user needs to interact with the data and the business
rules of your application.

I think it is a safe rule of thumb to limit the context of a single
transaction to a single form and any modal forms it may branch to.

If you have many multiple forms in a single transaction it should be that
way globally for the whole application and the user should be able to see
somewhere very clearly what their transaction status is and never should
closing a form lead to an ambiguous handling of the transaction.

I tend to use the transactions EndWithConfirm method in the form's
OnCloseQuery event and pass in CanClose the result of whether the
transaction was resolved or not.

> It's possible to start more than one explicit transaction?

Yes, drop additional TIB_Transaction components into your application. You
have one for each form if you like but be aware that changes in one form
will not be visible until the other commits and it refreshes subsequently.

> What should I use? Implicited or explicited transactions?

That's a mighty tough question to answer that I don't have sufficient
information to base a response on. Nor do I have the time right now to write
the book it would require to explain it all in generic terms.

> What's the use for explicites transaction component?

More than one concurrent transaction in your application.

HTH,
Jason Wharton
CPS - Mesa AZ
http://www.ibobjects.com