1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Nested Transactions</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" /> 9 <link rel="home" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" /> 10 <link rel="up" href="usingtxns.html" title="Chapter 3. Transaction Basics" /> 11 <link rel="previous" href="autocommit.html" title="Auto Commit" /> 12 <link rel="next" href="txncursor.html" title="Transactional Cursors" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Nested Transactions</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="autocommit.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 3. Transaction Basics</th> 23 <td width="20%" align="right"> <a accesskey="n" href="txncursor.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="nestedtxn"></a>Nested Transactions</h2> 33 </div> 34 </div> 35 <div></div> 36 </div> 37 <p> 38 A <span class="emphasis"><em>nested transaction</em></span> is used to provide a 39 transactional guarantee for a subset of operations performed within 40 the scope of a larger transaction. Doing this allows you to commit 41 and abort the subset of operations independently of the larger 42 transaction. 43 </p> 44 <p> 45 The rules to the usage of a nested transaction are as follows: 46 </p> 47 <div class="itemizedlist"> 48 <ul type="disc"> 49 <li> 50 <p> 51 While the nested (child) transaction is active, the parent 52 transaction may not perform any operations other than to commit 53 or abort, or to create more child transactions. 54 </p> 55 </li> 56 <li> 57 <p> 58 Committing a nested transaction has no effect on the state 59 of the parent transaction. The parent transaction is still 60 uncommitted. However, the parent transaction can now 61 see any modifications made by the child transaction. 62 Those modifications, of course, are still hidden to all 63 other transactions until the parent also commits. 64 </p> 65 </li> 66 <li> 67 <p> 68 Likewise, aborting the nested transaction has no effect on 69 the state of the parent transaction. The only result of the 70 abort is that neither the parent nor any 71 other transactions will see any of the 72 database modifications performed under the protection of the 73 nested transaction. 74 </p> 75 </li> 76 <li> 77 <p> 78 If the parent transaction commits or aborts while it has 79 active children, the child transactions are resolved in the 80 same way as the parent. That is, if the parent aborts, then 81 the child transactions abort as well. If the parent commits, 82 then whatever modifications have been performed by the child 83 transactions are also committed. 84 </p> 85 </li> 86 <li> 87 <p> 88 The locks held by a nested transaction are not released when 89 that transaction commits. Rather, they are now held by the 90 parent transaction until such a time as that parent commits. 91 </p> 92 </li> 93 <li> 94 <p> 95 Any database modifications performed by the nested transaction 96 are not visible outside of the larger encompassing 97 transaction until such a time as that parent transaction is 98 committed. 99 </p> 100 </li> 101 <li> 102 <p> 103 The depth of the nesting that you can achieve with nested 104 transaction is limited only by memory. 105 </p> 106 </li> 107 </ul> 108 </div> 109 <p> 110 To create a nested transaction, simply pass the parent transaction's 111 handle when you created the nested transaction's handle. For 112 example: 113 </p> 114 <pre class="programlisting"> // parent transaction 115 Transaction parentTxn = myEnv.beginTransaction(null, null); 116 // child transaction 117 Transaction childTxn = myEnv.beginTransaction(parentTxn, null); </pre> 118 </div> 119 <div class="navfooter"> 120 <hr /> 121 <table width="100%" summary="Navigation footer"> 122 <tr> 123 <td width="40%" align="left"><a accesskey="p" href="autocommit.html">Prev</a> </td> 124 <td width="20%" align="center"> 125 <a accesskey="u" href="usingtxns.html">Up</a> 126 </td> 127 <td width="40%" align="right"> <a accesskey="n" href="txncursor.html">Next</a></td> 128 </tr> 129 <tr> 130 <td width="40%" align="left" valign="top">Auto Commit </td> 131 <td width="20%" align="center"> 132 <a accesskey="h" href="index.html">Home</a> 133 </td> 134 <td width="40%" align="right" valign="top"> Transactional Cursors</td> 135 </tr> 136 </table> 137 </div> 138 </body> 139</html> 140