// ***** Beginning of the Using Child Transaction Objects example *****
// The parent Transaction is the current Transaction at this point.
// Save the parent read Transaction as parentT1.
Transaction parentT1 = getCurrentTransaction();
// Get the dynamic Source produced by the TopBottomTemplate.
// The next line from this example is commented out because the
// result object was created by the previous example.
//Source result = topNBottom.getSource();
// Create a Cursor and display the results.
println("\nThe current state of the TopBottomTemplate" +
"\nproduces following values:\n");
getContext().displayTopBottomResult(result);
// Begin a child Transaction of parentT1.
tp.beginSubtransaction(); // This is a read Transaction.
// Save the child read Transaction as childT2.
Transaction childT2 = tp.getCurrentTransaction();
// Change the state of the TopBottomTemplate. This starts a
// write Transaction, a child of the read Transaction childT2.
topNBottom.setN(12);
topNBottom.setTopBottomType(TopBottomTemplate.TOP_BOTTOM_TYPE_BOTTOM);
// Save the child write Transaction as writeT3.
Transaction writeT3 = tp.getCurrentTransaction();
// Prepare and commit the write Transaction writeT3.
prepareAndCommit();
// The commit moves the changes made in writeT3 into its parent,
// the read Transaction childT2. The writeT3 Transaction
// disappears. The current Transaction is now childT2
// again but the state of the TopBottomTemplate has changed.
// Create a Cursor and display the results of the changes to the
// TopBottomTemplate that are visible in childT2.
try
{
println("\nIn the child Transaction, the state of the " +
"\nTopBottomTemplate produces the following values:\n");
getContext().displayTopBottomResult(result);
}
catch(Exception e)
{
println("Cannot display the results of the query. " + e);
}
// Begin a grandchild Transaction of the initial parent.
tp.beginSubtransaction(); // This is a read Transaction.
// Save the grandchild read Transaction as grandchildT4.
Transaction grandchildT4 = tp.getCurrentTransaction();
// Change the state of the TopBottomTemplate. This starts another
// write Transaction, a child of grandchildT4.
topNBottom.setTopBottomType(TopBottomTemplate.TOP_BOTTOM_TYPE_TOP);
// Save the write Transaction as writeT5.
Transaction writeT5 = tp.getCurrentTransaction();
// Prepare and commit writeT5.
prepareAndCommit();
// Transaction grandchildT4 is now the current Transaction and the