in

CodeSmith Community

Your Code. Your Way. Faster!

Save and AcceptChanges

Last post 05-09-2008 9:40 AM by jjs. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 05-07-2008 7:25 AM

    • jjs
    • Not Ranked
    • Joined on 05-07-2008
    • Posts 3
    • Points 75

    Save and AcceptChanges

    When saving a list to the database I have the following code: 

    Using Trans As TransactionManager = DataRepository.Provider.CreateTransaction()
       Trans.BeginTransaction()               ' begin a transaction
       Try
          Save(Trans, List)                   ' save the changed records
          Trans.Commit()                      ' commit the transaction and accept changes

       Catch ex As Exception
          Trans.Rollback()                    ' rollback the transaction
          ExceptionPolicy.HandleException

       End Try
    End Using

    If there is a problem during the save and an exception is thrown I know that the records to the
    database will be rolled back but how do I revert the list back
    to it's original state since NetTiers has already done the AcceptChanges?

     

    • Post Points: 35
  • 05-09-2008 6:27 AM In reply to

    • blake05
    • Top 50 Contributor
    • Joined on 04-03-2008
    • Wisconsin
    • Posts 74
    • Points 1,205

    Re: Save and AcceptChanges

    Hello,
    There are two things you can do in this situation. The first situation one would do if they want to keep the list contents, but not the actions performed on it, and the second is get the list before all the additions to it were made.
    1.    Create a copy of the list before beginning the transaction. If the transaction fails then set the list back to the copy of the list.
    2.    Call into the data provider again (with caching off) and get the initial list back before the modifications were made.

    Thanks

    -Blake Niemyjski

    Blake Niemyjski
    CodeSmith Tools, LLC
    Support Specialist
    • Post Points: 35
  • 05-09-2008 6:39 AM In reply to

    • jjs
    • Not Ranked
    • Joined on 05-07-2008
    • Posts 3
    • Points 75

    Re: Save and AcceptChanges

    Thank you very much.

    • Post Points: 35
  • 05-09-2008 8:48 AM In reply to

    • SuperJeffe
    • Top 25 Contributor
    • Joined on 05-05-2006
    • Tulsa, Ok
    • Posts 173
    • Points 4,380

    Re: Save and AcceptChanges

    Interesting thread.  At first I didn't understand what you problem is and now I think I get it.  Tell me if I am wrong.

    You have a TList of items you are saving.  If halfway through there is an error, all the previously successful saves from the List have been Accepted.  Well, interesting find.  I think this needs to be on a ToDo list.  I think we should look at fixing this.  It's not a trivial change, but in my code I would want this to work right.  Suprised I haven't come accross this yet.

    jeff

    ---------------------------------------
    Member of the .NetTiers team
    ---------------------------------------
    • Post Points: 35
  • 05-09-2008 8:59 AM In reply to

    • blake05
    • Top 50 Contributor
    • Joined on 04-03-2008
    • Wisconsin
    • Posts 74
    • Points 1,205

    Re: Save and AcceptChanges

     You are correct. I think it would be cool if we could add transaction support to an (TList) object.  I'm pretty sure someone has already done this at the code project as I remember reading about this somewhere. It might be pretty difficult to do...

    Thanks

    -Blake

    Blake Niemyjski
    CodeSmith Tools, LLC
    Support Specialist
    • Post Points: 35
  • 05-09-2008 9:40 AM In reply to

    • jjs
    • Not Ranked
    • Joined on 05-07-2008
    • Posts 3
    • Points 75

    Re: Save and AcceptChanges

    I think that maybe it should be changed to allow the program to AcceptChanges after the transaction.commit.  Accept changes would also have to do things like delete the DeletedItems list etc.

    • Post Points: 5
Page 1 of 1 (6 items)
Copyright © 2007 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems