StrataFrame Forum

Transactions on Forms

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

By Tim Dol - 10/28/2008

I have a requirement to use transactions on one of my entry forms. Note: I am not using the MaintnenaceFormToolStrip. I have three business objects on a form and some of the fields are bound to controls etc... Pretty standard form.

Do I simply start the transaction in the FORM 'BeforeSave' event on the Form and then commit the transaction in the FORM 'AfterSave' event?

Any assistance would be appeciated.

Thanks,

Tim

By Trent L. Taylor - 10/28/2008

You can, or you could create a method that is called versus calling the Save directly on the form first.  For example, you would create a method that starts the transactions, calls the Save() or the BOs directly, and the commit the transactions after the save.
By Edhy Rijo - 10/28/2008

There is a nice sample in the help file with the topic "Using Transactional Processing"

Public Sub SaveAllOnTransaction()
    '-- Add a try around the transaction processing
    '   This enables the process to call TransactionRollback()
    '   if anything bad happens during the transaction process.
    Try
        '-- Start the transaction
        BusinessLayer.TransactionBegin("", Data.IsolationLevel.ReadCommitted)
       
        '-- Save the business objects on the transaction
        Me.Customers.Save(True)
        Me.Orders.Save(True)
        Me.OrderItems.Save(True)
       
        '-- When business objects are saved on the transaction, the
        '   pending changes to their internal DataTables are NOT saved
        '   until TransactionEnd() is called...
        '-- Call transaction end to commit the transaction queries and
        '   accept the pending changes on all of the business objects
        '   that participated in the transaction.
        BusinessLayer.TransactionCommitt("")
   
    Catch ex As Exception
        '-- If an exception occurs during the saving of the records, then
        '   abort the transaction.
        BusinessLayer.TransactionRollback("")
    End Try
End Sub

 

By Tim Dol - 10/30/2008

Thanks for the help guys, I was able to get things working except for handling of broken rules. Using the example, what if there were broken rules on the orders table - Me.Orders.Save(True) after the transaction was started.  Would you first check all for broken rules on all business objects before calling 'SaveAllOnTransaction' or check the status of each save within the transactions and perform a rollback if a broken rule is found?  At first I thought it would be pretty simple to implement transactions at the form level but I lost some of the power of StataFrame with form level events etc...

Let me know if I'm missing the ball on this or if you have any suggestions on how to handle broken rules etc.. when using transactions.

Thanks

Tim

By Tim Dol - 11/3/2008

Just wondering if I'm headed in the right direction dealing with Transactions within forms. Any input would be appreciated.