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>DbTxn::prepare()</title> 7 <link rel="stylesheet" href="apiReference.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Berkeley DB C++ API Reference" /> 10 <link rel="up" href="txn.html" title="Chapter 13. The DbTxn Handle" /> 11 <link rel="prev" href="txnid.html" title="DbTxn::id()" /> 12 <link rel="next" href="txnrecover.html" title="DbEnv::txn_recover()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DbTxn::prepare()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="txnid.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 13. 23 The DbTxn Handle 24 </th> 25 <td width="20%" align="right"> <a accesskey="n" href="txnrecover.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="txnprepare"></a>DbTxn::prepare()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db_cxx.h> 39 40int 41DbTxn::prepare(u_int8_t gid[DB_XIDDATASIZE]);</pre> 42 <p> 43 The <code class="methodname">DbTxn::prepare()</code> method initiates the beginning of a two-phase 44 commit. 45 </p> 46 <p> 47 In a distributed transaction environment, Berkeley DB can be used as a 48 local transaction manager. In this case, the distributed transaction 49 manager must send <span class="emphasis"><em>prepare</em></span> messages to each local 50 manager. The local manager must then issue a <code class="methodname">DbTxn::prepare()</code> and 51 await its successful return before responding to the distributed 52 transaction manager. Only after the distributed transaction manager 53 receives successful responses from all of its 54 <span class="emphasis"><em>prepare</em></span> messages should it issue any 55 <span class="emphasis"><em>commit</em></span> messages. 56 </p> 57 <p> 58 In the case of nested transactions, preparing the parent causes all 59 unresolved children of the parent transaction to be committed. Child 60 transactions should never be explicitly prepared. Their fate will be 61 resolved along with their parent's during global recovery. 62 </p> 63 <p> 64 The <code class="methodname">DbTxn::prepare()</code> <span> 65 66 <span> 67 method either returns a non-zero error value or throws an 68 exception that encapsulates a non-zero error value on 69 failure, and returns 0 on success. 70 </span> 71 </span> 72 </p> 73 <div class="sect2" lang="en" xml:lang="en"> 74 <div class="titlepage"> 75 <div> 76 <div> 77 <h3 class="title"><a id="id1714462"></a>Parameters</h3> 78 </div> 79 </div> 80 </div> 81 <div class="sect3" lang="en" xml:lang="en"> 82 <div class="titlepage"> 83 <div> 84 <div> 85 <h4 class="title"><a id="id1714940"></a>gid</h4> 86 </div> 87 </div> 88 </div> 89 <p> 90 The <span class="bold"><strong>gid</strong></span> parameter specifies the 91 global transaction ID by which this transaction will be known. This 92 global transaction ID will be returned in calls 93 to <a class="xref" href="txnrecover.html" title="DbEnv::txn_recover()">DbEnv::txn_recover()</a> 94 telling the application which global transactions must be resolved. 95 </p> 96 </div> 97 </div> 98 <div class="sect2" lang="en" xml:lang="en"> 99 <div class="titlepage"> 100 <div> 101 <div> 102 <h3 class="title"><a id="id1714463"></a>Class</h3> 103 </div> 104 </div> 105 </div> 106 <p> 107 <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a>, <a class="link" href="txn.html" title="Chapter 13. The DbTxn Handle">DbTxn</a> 108 </p> 109 </div> 110 <div class="sect2" lang="en" xml:lang="en"> 111 <div class="titlepage"> 112 <div> 113 <div> 114 <h3 class="title"><a id="id1714988"></a>See Also</h3> 115 </div> 116 </div> 117 </div> 118 <p> 119 <a class="xref" href="txn.html#txnlist" title="Transaction Subsystem and Related Methods">Transaction Subsystem and Related Methods</a> 120 </p> 121 </div> 122 </div> 123 <div class="navfooter"> 124 <hr /> 125 <table width="100%" summary="Navigation footer"> 126 <tr> 127 <td width="40%" align="left"><a accesskey="p" href="txnid.html">Prev</a> </td> 128 <td width="20%" align="center"> 129 <a accesskey="u" href="txn.html">Up</a> 130 </td> 131 <td width="40%" align="right"> <a accesskey="n" href="txnrecover.html">Next</a></td> 132 </tr> 133 <tr> 134 <td width="40%" align="left" valign="top">DbTxn::id() </td> 135 <td width="20%" align="center"> 136 <a accesskey="h" href="index.html">Home</a> 137 </td> 138 <td width="40%" align="right" valign="top"> DbEnv::txn_recover()</td> 139 </tr> 140 </table> 141 </div> 142 </body> 143</html> 144