Tuesday, September 2, 2014

Dexterity - modified Transaction template for when you require a transaction

This is from the Microsoft Dexterity Help 12.0b2 in the Transaction template page. I have modified it so that it only proceeds with the logic if it can start a transaction. 

A good, clean design has error handling separated from the business logic, so it calls DoLogic() which does the actual business logic. Errors bubble up to this error handler. This keeps the transaction / error handling away from the logic and really clarifies the business logic as well as the error handling.


{The Transaction Template}
local integer retry_count;
local integer MAXRETRIES = 3;
local long sleeptime;

retry_count = 0;
    if CanStartTransaction() then
        transaction begin;
  if DoLogic() then
                 transaction commit;
   transaction rollback;
  end if;
  warning "DoLogic() must be executed within a transaction, but one cannot be started."
    end if;

     if retry_count < MAXRETRIES then
         sleeptime = Timer_Sleep(10);
         increment retry_count;
         restart try;
     end if;
    transaction rollback;
    error "An exception occurred. Class: " + str(Exception_Class()) + " Subclass: " + str(Exception_SubClass()) + " Message:" + Exception_Message();
end try;

No comments:

Post a Comment