Update Recordset

For each of our middle-tier components, we will need two specific methods: a public

Return. ..Recordset method and a private Update ...RS method. The class diagram above shows, as examples of these, ReturnCustomersRecordset and UpdateCustomersRS methods; we would also need a ReturnOrdersRecordset and an UpdateOrdersRS method, and so on. The Return. .. methods are public, and can be called directly from our managing class to retrieve a recordset for a specific object from the database. However, the Update. . . methods are private, because we have a generic public UpdateRecordset method, which calls the appropriate specific function.

Our decision to use MTS for transaction processing means that we must have some way of telling MTS whether or not the operations within the transaction have succeeded. If all operations succeed, we can 'commit' the transaction: that is, we can tell the database that all the operations within the transaction can actually be performed. We do this through an MTS object known as the ObjectContext object. Every object running under MTS has an associated ObjectContext object, and it provides methods for committing a transaction:

Public Sub SetComplete()

If Not m_objContext Is Nothing Then m_objContext.SetComplete End If End Sub

Similarly, we need to inform MTS if anything goes wrong and the transaction needs to be aborted or 'rolled back', canceling all the operations within it. Again, we must use the ObjectContext object:

Public Sub SetAbort()

If Not m_objContext Is Nothing Then m_objContext.SetAbort End If End Sub

The other methods are used mostly for handling our ADO connection to the database: we have separate methods for opening and closing the connection, and for retrieving an existing Connection object. Extracting this functionality into separate methods avoids having to write the same code for each of the Update. .. and Return.. . methods. We can just call the method whenever we need to open or close a connection. These methods are all private, because only our server component may have direct access to the database.

365 Days Of Motivation

365 Days Of Motivation

Stop Wasting Time And Learn How To Stay Motivated. Finally! Discover How To Stop Your Mind From Wandering, And Upgrade Your Motivation. You Can Hack Your Motivation Levels, Allowing You To Take Your Life To The Next Level.

Get My Free Ebook


Post a comment