21.12.2007, 12:30 | #1 |
Участник
|
Holzheys: X++ Transactions, exceptions and updateconflicts.
Источник: http://holzhey.isa-geek.com/blog/pos...conflicts.aspx
============== In September, I posted an article on x++ transactions unique behaviors. I am following up now with another case where they are even more unique, and where it is an exception to the transaction exception behavior. In the event that you running under a transaction and in nested try-catch blocks the catch block nearest to a updateconflict exception that catches that exception is allowed to correct that error and continue. Example code below: X++: 1: static void RetrysWithException() 2: { 3: CustTable custTable; 4: int retryCount; 5: ; 6: 7: 8: ttsbegin; 9: 10: 11: 12: 13: select forupdate custTable where custTable.AccountNum == 'S135' && custTable.CustGroup == '00'; 14: retryCount = 0; 15: 16: 17: 18: 19: try // The ttslevel for this try-catch block is one 20: { 21: custTable.CreditRating = strfmt("%1",str2int(custTable.CreditRating)+1); 22: custTable.update(); // The UpdateConflict will be thrown inside this method. 23: info(strfmt("CreditRating = %1", custTable.CreditRating)); 24: } 25: catch (Exception::UpdateConflict) 26: { 27: if( retryCount < 4) 28: { 29: retryCount ++; 30: 31: 32: 33: 34: // reread the row without rolling back the transaction 35: custTable.reread(); 36: retry; 37: } else // no more than 5 retries allowed; 38: // may be the business logic requires a try here 39: if (appl.ttslevel() == 0) 40: retry; 41: else 42: throw Exception::UpdateConflict; 43: } 44: } 45: ttscommit; 46: }
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|