Nested Transactions in Constructors
Example 4.1. Nested Transactions In Constructors AtomicAction A = new AtomicAction(); Object obj1; Object obj2; obj1 = new Object(); // create new object obj2 = new Object("old"); // existing object A.begin(0); obj2.remember(obj1.get_uid()); // obj2 now contains reference to obj1 A.commit(true); // obj2 saved but obj1 is not The two objects are created outside of the control of the top-level action A. obj1 is a new object. obj2 is an old existing object. When the remember operation of obj2 is invoked, the object will be activated and the Uid of obj1 remembered. Since this action commits, the persistent state of obj2 may now contain the Uid of obj1. However, the state of obj1 itself has not been saved since it has not been manipulated under the control of any action. In fact, unless it is modified under the control of an action later in the application, it will never be saved. If, however, the constructor had used an atomic action, the state of obj1 would have automatically been saved at the time it was constructed and this inconsistency could not arise.