COM+ Transaction 70-320 exam question
-
COM+ Transaction 70-320 exam question [Transaction(TransactionOption.Required)] [SecurityRole("Admin")] public class SalesProcessor { public void PlaceOrder() { //STEP 1: Code here to insert order to order table, calling method on another COM+ component participating in the transaction. objCOM1.InsertOrder(...); //STEP 2: Code here to update shipping table. Again, calling method on a second COM+ component participating in the transaction. objCOM2.UpdateShipping(...); } } The question is, what do you need to add in order for the transaction initiated by PlaceOrder to be executed properly. You options are: a. Add [AutoComplete(true)] to PlaceOrder b. Add EnableCommit( ) to "End" of PlaceOrder method. c. ... not viable option ... d. ... not viable option ... The model answer is "EnableCommit" (That's option *b*). But I don't understand why. I never used EnableCommit( ) before, never had to. If I don't use [AutoComplete(true)] to automatically call SetComplete and SetAbort, I'd do it manually: public void PlaceOrder() { ContextUtil.EnableCommit( ); //Is this how you use EnableCommit()? But "option b" suggested that it should be added at the END of the method after the processing... That's weird. try { objCOM1.InsertOrder(...); objCOM2.UpdateShipping(...); ContextUtil.SetComplete(...); } catch(Exception er) { ... exception prcessing ... ContextUtil.SetAbort( ); } } Otherwise, [AutoComplete(true)] would do the job: [AutoComplete(true)] public void PlaceOrder() { objCOM1.InsertOrder(...); objCOM2.UpdateShipping(...); } Thanks.
-
COM+ Transaction 70-320 exam question [Transaction(TransactionOption.Required)] [SecurityRole("Admin")] public class SalesProcessor { public void PlaceOrder() { //STEP 1: Code here to insert order to order table, calling method on another COM+ component participating in the transaction. objCOM1.InsertOrder(...); //STEP 2: Code here to update shipping table. Again, calling method on a second COM+ component participating in the transaction. objCOM2.UpdateShipping(...); } } The question is, what do you need to add in order for the transaction initiated by PlaceOrder to be executed properly. You options are: a. Add [AutoComplete(true)] to PlaceOrder b. Add EnableCommit( ) to "End" of PlaceOrder method. c. ... not viable option ... d. ... not viable option ... The model answer is "EnableCommit" (That's option *b*). But I don't understand why. I never used EnableCommit( ) before, never had to. If I don't use [AutoComplete(true)] to automatically call SetComplete and SetAbort, I'd do it manually: public void PlaceOrder() { ContextUtil.EnableCommit( ); //Is this how you use EnableCommit()? But "option b" suggested that it should be added at the END of the method after the processing... That's weird. try { objCOM1.InsertOrder(...); objCOM2.UpdateShipping(...); ContextUtil.SetComplete(...); } catch(Exception er) { ... exception prcessing ... ContextUtil.SetAbort( ); } } Otherwise, [AutoComplete(true)] would do the job: [AutoComplete(true)] public void PlaceOrder() { objCOM1.InsertOrder(...); objCOM2.UpdateShipping(...); } Thanks.
I don't think I would call EnableCommit as a matter of course (for example, as the first line of code in PlaceHolder). What that says is, "Regardless of what I do with the code in PlaceHolder that may impact my transaction, I choose to vote for committing it anyway." That is to say, in general, you call EnableCommit *after* the body of your transaction-aware code has executed, to tell other participants in the transaction that your code is unaware of any reason not to commit. Second (and I am not a COM+ transaction authority), my understanding of AutoComplete versus EnableCommit is that AutoComplete is used to both ensure the creation of a transaction, and ensure that SetComplete is called if the tagged method returns normally(PlaceHolder in this case). Marking the method as AutoComplete(true) suggests that PlaceHolder is the first and last bit of logic to use the created transaction. Can't tell by your question, but I must assume there may be other methods called either before or after PlaceHolder that also intend to use the transaction. SetComplete sets both the IsConsistent and IsDone bits on a transaction context, indicating that the transaction should proceed with the act of committing itself (bad news if other logic needs the transaction), while EnableCommit only sets the IsConsistent bit, allowing further code to use the transaction instead of trying to commit it immediately. If PlaceHolder actually sits in the middle of other methods, all of which are intended for use in the same transaction context, setting EnableCommit at the end of PlaceHolder's execution would be the right choice with regards to transaction integrity.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’