ObjectExtender User's Guide and Reference

Using the TransactedVariable part

The first example of using the transacted variable part will be to make the TstDepartmentView transaction safe, that is, it will work in the correct transaction regardless of whatever else is going on around it.

Making TstDepartmentView transaction safe

We will change the TstDepartmentView created earlier such that it shows details of the department in both the top-level transaction and also the shared transaction.

The part TransactedVariable is a special type of variable part. It has all the behavior of a variable except that it has an additional attribute transaction. When a variable is given a transaction it will ensure that all actions, events and attributes performed on the variable are within that transaction. For the TstDepartmentView we need two transacted variables, one that has the department within the shared transaction, and one that has the department within the top-level transaction.

  1. Reopen the Composition Editor on TstDepartmentView.
  2. Select Add Part from the Options menu, and type TstDepartment for the class name.
  3. Select Transacted Variable, under Part Type.


    Figure pgs3trv0 not displayed.

  4. Move the connections you made for the TstDepartment1 variable part to the transacted variable part, then delete the TstDepartment1 variable part.
  5. Connect the self attribute of the TopLevelTransaction2 variable to the transaction attribute of the transacted variable.

    This will ensure that the variable TstDepartment1 always sets the attribute values of its contents, the transaction, in the top-level transaction.


Figure pgs3trv1 not displayed.

Now, test the view. Switch to the Transcript and get the shared transaction to resume itself as described earlier. When you go back to the view and edit some attributes of the selected department, the earlier walkback, caused by attempting to update the shared transaction, no longer occurs. This is because of the connection from the TopLevelTransaction variable to the transaction attribute of the TstDepartment variable. This ensures that access to the variable's value is always done in the context of the specified transaction.

Go back to the System Transcript and look at the current transaction using the method

 
 
     Transaction current.
 
 
 

Note that it will be the top-level transaction (if you took the step to resume the shared transaction earlier). The transacted variable part will ensure its contents are always accessed in the context of its specified transaction but it will not change the current transaction.

In addition to specifying the transaction in which the TstDepartment1 variable should operate, we should also specify the same for the department home collection. When the New is clicked, it performs the create action, thus the new department should be created in the top-level transaction.

To create a transacted variable that contains the TstDepartmentHome1 part

  1. Select the TstDepartmentHome1 part, and from its pop-up menu, select Create Transacted Variable, then drop the transacted variable on the free-form surface.

    The transacted variable is then added for you and the connection from the self attribute of the TstDepartmentHome1 part to the new variable that will be named transacted TstDepartmentHome1.

  2. Connect the self attribute of the TopLevelTransaction1 variable to the transaction attribute of this transacted variable and move all the connections from the TstDepartmentHome1 part to the newly created transacted TstDepartmentHome1 variable (except for the connection from the part to the variable itself).

As was the case earlier, make sure that the ordering of the committed events from the TopLevelTransaction are such that the connection to the SharedTransaction part is first.


Figure pgs3trv2 not displayed.

This view now ensures that the TstDepartment1 variable and the transacted TstDepartment1 variable are always accessed within the context of the transaction within the TopLevelTransaction1 variable, regardless of whatever else is going on around the view in terms of which is the current transaction.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]