Newbie Questions: setabort, setcomplete, autocomplete


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Newbie Questions: setabort, setcomplete, autocomplete

  1. #1
    Paul Guest

    Newbie Questions: setabort, setcomplete, autocomplete


    I'm a newbie and am trying to make sure I understand a few things about MTS
    / COM+ correctly. If anyone could answer the following questions I'd appreciate
    it!:


    1.
    I understand that to take advantage of MTS or COM+'s JIT (just in time) activation
    and deactivation features, you can call the setabort and setcomplete methods
    of the objectcontext to deactivate the object. I've also read it's used
    to control transactions ... this is the part I'm unsure about. Say, for
    instance, I have three objects in the same MTS transaction, all with a transaction
    mode of Required. The first object successfully performs a SQL update, then
    calls a method on the second object which also successfully performs a SQL
    update then calls a method on a third object which is supposed to perform
    yet another SQL update. If the third object encounters an error and I call
    setabort, does this mean the two previous SQL updates are rolled back?


    2.
    What would actually happen if i didn't call SetComplete or SetAbort on an
    object that's in a MTS package or COM+ application and a method on that object
    encounters an error? Can this cause the entire application to hang? I've
    seen cases where my COM+ application isn't working, I go into Component services
    and I see one of my components "spinning", even
    though there is no client accessing it. Stopping and restarting the application
    always fixes this problem.


    3.
    In COM+, if my method has the Autocomplete attribute set to true, how does
    it know when to commit or rollback transactions? Going back to the hypothetical
    example in question 1, would it automatically rollback the transaction if
    the third method encountered an error, and automatically commit the transaction
    if no errors occurred? Right now that's what I'm assuming.


    4.
    Generally speaking, is it better to manually call SetAbort and
    SetComplete myself, or use the AutoComplete feature? Why?


    ----

    thanks in advance to anyone who can help me out
    Share on Google+

  2. #2
    Paul Klanderud Guest

    Re: Newbie Questions: setabort, setcomplete, autocomplete


    Hi Paul,

    You aren't too much of a newbie, because these are good questions you're
    asking. I can answer your first 2 questions, but not the last 2, 'cause I
    haven't worked with COM+ yet.

    >1.
    >I understand that to take advantage of MTS or COM+'s JIT (just in time)

    activation
    >and deactivation features, you can call the setabort and setcomplete methods
    >of the objectcontext to deactivate the object. I've also read it's used
    >to control transactions ... this is the part I'm unsure about. Say, for
    >instance, I have three objects in the same MTS transaction, all with a transaction
    >mode of Required. The first object successfully performs a SQL update, then
    >calls a method on the second object which also successfully performs a SQL
    >update then calls a method on a third object which is supposed to perform
    >yet another SQL update. If the third object encounters an error and I call
    >setabort, does this mean the two previous SQL updates are rolled back?


    Yes, that's correct: everything in the transaction is rolled back. One of
    the main ideas behind MTS and its "object context" is to provide an all-or-nothing
    environment for possibly complex transactions (as in the example you cited).
    As long as you are properly getting references to the existing ObjectContext
    and calling SetComplete when your methods successfully complete -- and, conversely,
    SetAbort in their error-handling routines -- MTS will take care of the entire
    transaction for you.

    So, for example, if you were putting an order into a database and running
    separate SQL statements for the order items, the credit-card data, and the
    customer address data, if you encountered a trappable error anywhere in any
    of these routines and called SetAbort, all transactions would be rolled back.
    (The beauty here is that the entire transaction is treated atomically without
    the programmer having to mess with it.)

    As an aside, one of the reasons you call SetComplete in secondary objects
    is that it tells MTS that they can be released.


    >2.
    >What would actually happen if i didn't call SetComplete or SetAbort on an
    >object that's in a MTS package or COM+ application and a method on that

    object
    >encounters an error? Can this cause the entire application to hang? I've
    >seen cases where my COM+ application isn't working, I go into Component

    services
    >and I see one of my components "spinning", even
    >though there is no client accessing it. Stopping and restarting the application
    >always fixes this problem.


    In certain cases this could cause your app to hang. If, for example, SetAbort
    had been called somewhere along the line, you must raise an error back to
    your root object (the base for the entire transaction) so it will know that
    it should also call SetAbort before passing control back to the client. If
    you fail to call SetAbort in the root object, MTS will still deactivate the
    objects and roll back the transaction, but the root object can be left in
    an unstable state. Subsequent attempts to invoke it may result in MTS errors
    indicating "context aborted" or something along those lines.

    Hope that helps
    Paul K.


    >3.
    >In COM+, if my method has the Autocomplete attribute set to true, how does
    >it know when to commit or rollback transactions? Going back to the hypothetical
    >example in question 1, would it automatically rollback the transaction if
    >the third method encountered an error, and automatically commit the transaction
    >if no errors occurred? Right now that's what I'm assuming.
    >
    >
    >4.
    >Generally speaking, is it better to manually call SetAbort and
    >SetComplete myself, or use the AutoComplete feature? Why?
    >
    >
    >----
    >
    >thanks in advance to anyone who can help me out


    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center