StrataFrame Forum

Transaction between Business Objects

http://forum.strataframe.net/Topic23934.aspx

By Milton Abe - 7/28/2009

Hello! Say that you have two tables and for each table you have a Business Object. What If I want to put both tables in a transaction? Is there a way to control this (Transaction between these 2 BO's), or should I control transactions on stored procedures in one custom method in one of the BO's?

Thank you!

By Peter Jones - 7/28/2009

Hi Milton,



My view is that if a transaction can be done in the database then that is best place it. I'm a great fan of SF but, when it comes to something like a transaction, I just think the database is the safer and more efficient alternative. Although, I have to say, this view has meant that I have never looked at the transaction facilities in SF in any detail.



Cheers, Peter
By Trent L. Taylor - 7/29/2009

Peter has a good approach, but really SF gives you more ultimate control on saving. So you will, in this particular case, want to create a transaction with a key and then use the same key for both saves. When you call the Save method of a BO, you can provide the transaction key, which means that you can choose which BOs to save on a tran and which to save off of a tran. So in this example, you would call the Save method on the BOs and supply the same transaction for both:



BusinessLayer.TransactionBegin("MyTranKey", Data.IsolationLevel.ReadCommitted);



MyBO1.Save(True, "MyTranKey");

MyBO2.Save(True, "MyTranKey");



BusinessLayer.TransactionCommit("MyTranKey");
By Milton Abe - 7/29/2009

In other words you still think that SF might has a better approach than transactions in DB? Or is there any particular case that you would recommend transactions in DB?
By Trent L. Taylor - 7/29/2009

The only time that I ever recommend wrapping up transactions in the DB is when all INSERT logic, etc. will be server side, otherwise doing the transaction on the DB is more work and requires more code client side if this isn't the case. So yes, I would recommend doing this within the BO since this logic is tied into the BO.