Menu

start a transaction

T.Mo
2005-04-13
2013-03-07
  • T.Mo

    T.Mo - 2005-04-13

    trying to get some info abt transaction from help file. quite confusing. Please give some advise for my case:

    I need to save two db entries, and both must be saved successfully, either one fail, all shall be aborted. here is my code, please let me know whether i put it right:

    try
    {
    pbroker.starttransaction();

    obj1.save();

    obj2.save();

    pbroker.commit();
    }
    catch
    {
    pbroker.rollback();
    }

    and how to use the "isolationLevel" parameter here?

    Thanks!

     
    • victor Saquicela

      Hi.
      Use:

        Dim p as AToMSFramework.CPersistenceBroker = New AToMSFramework.CPersistenceBroker
              p = AToMSFramework.getPersistenceBrokerInstance()
      p.startTransaction(IsolationLevel.RepeatableRead) 'Inicia transaccion

      obj.save()
      obj1.save()

      .....

      p.commit()

      ....

      p.rollBack()

       
    • Richard Banks

      Richard Banks - 2005-04-13

      Hi Timothy,

      Victor's answer is correct.  Be aware that if you are just saving, you don't really need to use the isolation level - you'd only use that if you are doing pessimistic locking.

      To save using optimistic locking only; your original code is correct.

       

Log in to post a comment.