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>Chapter 13. The DbTxn Handle</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="index.html" title="Berkeley DB C++ API Reference" /> 11 <link rel="prev" href="seqstat_print.html" title="DbSequence::stat_print()" /> 12 <link rel="next" href="dbget_transactional.html" title="Db::get_transactional()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Chapter 13. 19 The DbTxn Handle 20 </th> 21 </tr> 22 <tr> 23 <td width="20%" align="left"><a accesskey="p" href="seqstat_print.html">Prev</a> </td> 24 <th width="60%" align="center"> </th> 25 <td width="20%" align="right"> <a accesskey="n" href="dbget_transactional.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="chapter" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title"><a id="txn"></a>Chapter 13. 35 The DbTxn Handle 36 </h2> 37 </div> 38 </div> 39 </div> 40 <pre class="programlisting">#include <db_cxx.h> 41 42class DbTxn { 43public: 44 DB_TXN *DbTxn::get_DB_TXN(); 45 const DB_TXN *DbTxn::get_const_DB_TXN() const; 46 static DbTxn *DbTxn::get_DbTxn(DB_TXN *txn); 47 static const DbTxn *DbTxn::get_const_DbTxn(const DB_TXN *txn); 48 ... 49 50}; </pre> 51 <p> 52 The <code class="classname">DbTxn</code> object is the handle for a transaction. Methods of 53 the <code class="classname">DbTxn</code> handle are used to configure, abort and commit the 54 transaction. <code class="classname">DbTxn</code> handles are provided to 55 <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> methods in order 56 to transactionally protect those database operations. 57 </p> 58 <p> 59 <code class="classname">DbTxn</code> handles are not free-threaded; transactions handles 60 may be used by multiple threads, but only serially, that is, the application must 61 serialize access to the <code class="classname">DbTxn</code> handle. Once the 62 <a class="xref" href="txnabort.html" title="DbTxn::abort()">DbTxn::abort()</a> or 63 <a class="xref" href="txncommit.html" title="DbTxn::commit()">DbTxn::commit()</a> methods are called, the handle 64 may not be accessed again, regardless of the method's return. In addition, parent 65 transactions may not issue any Berkeley DB operations while they have active child 66 transactions (child transactions that have not yet been committed or aborted) except for 67 <a class="xref" href="txnbegin.html" title="DbEnv::txn_begin()">DbEnv::txn_begin()</a>, 68 <a class="xref" href="txnabort.html" title="DbTxn::abort()">DbTxn::abort()</a> and 69 <a class="xref" href="txncommit.html" title="DbTxn::commit()">DbTxn::commit()</a>. 70 </p> 71 <p> 72 Each <code class="classname">DbTxn</code> object has an associated 73 <code class="literal">DB_TXN</code> struct, which is used by the underlying 74 implementation of Berkeley DB and its 75 76 <span>C++ language</span> 77 API. The <code class="methodname">DbTxn::get_DB_TXN()</code> method 78 returns a pointer to this struct. Given a const <code class="literal">DbTxn</code> object, 79 <code class="methodname">txnMget_const_DB_TXN()</code> 80 returns a const pointer to the same struct. 81 </p> 82 <p> 83 Given a <code class="literal">DB_TXN</code> struct, the <code class="methodname">DbTxn::get_DbTxn()</code> 84 method returns the corresponding <code class="classname">DbTxn</code> object, if there is 85 one. If the <code class="literal">DB_TXN</code> object was not associated with a 86 <code class="classname">DbTxn</code> (that is, it was not returned from a call to 87 <code class="methodname">DbTxn::get_DB_TXN()</code>), then the result of 88 <code class="methodname">DbTxn::get_DbTxn</code> is undefined. Given a const 89 <code class="literal">DB_TXN</code> struct, <code class="methodname">DbTxn::get_const_DbTxn()</code> 90 returns the associated const <code class="literal">DbTxn</code> object, if there is one. 91 </p> 92 <p> 93 These methods may be useful for Berkeley DB applications including both C and C++ 94 language software. It should not be necessary to use these calls in a purely C++ 95 application. 96 </p> 97 <div class="sect1" lang="en" xml:lang="en"> 98 <div class="titlepage"> 99 <div> 100 <div> 101 <h2 class="title" style="clear: both"><a id="txnlist"></a>Transaction Subsystem and Related Methods</h2> 102 </div> 103 </div> 104 </div> 105 <div class="navtable"> 106 <table border="1" width="80%"> 107 <thead> 108 <tr> 109 <th>Transaction Subsystem and Related Methods</th> 110 <th>Description</th> 111 </tr> 112 </thead> 113 <tbody> 114 <tr> 115 <td> 116 <a class="xref" href="txncheckpoint.html" title="DbEnv::txn_checkpoint()">DbEnv::txn_checkpoint()</a> 117 </td> 118 <td>Checkpoint the transaction subsystem</td> 119 </tr> 120 <tr> 121 <td> 122 <a class="xref" href="txnrecover.html" title="DbEnv::txn_recover()">DbEnv::txn_recover()</a> 123 </td> 124 <td>Distributed transaction recovery</td> 125 </tr> 126 <tr> 127 <td> 128 <a class="xref" href="txnset_timeout.html" title="DbTxn::set_timeout()">DbTxn::set_timeout()</a> 129 </td> 130 <td>Set transaction timeout</td> 131 </tr> 132 <tr> 133 <td> 134 <a class="xref" href="txnstat.html" title="DbEnv::txn_stat()">DbEnv::txn_stat()</a> 135 </td> 136 <td>Return transaction subsystem statistics</td> 137 </tr> 138 <tr> 139 <td> 140 <a class="xref" href="txnstat_print.html" title="DbEnv::txn_stat_print()">DbEnv::txn_stat_print()</a> 141 </td> 142 <td>Print transaction subsystem statistics</td> 143 </tr> 144 <tr> 145 <td colspan="2"> 146 <span class="bold"> 147 <strong>Transaction Subsystem Configuration</strong> 148 </span> 149 </td> 150 </tr> 151 <tr> 152 <td><a class="xref" href="envset_timeout.html" title="DbEnv::set_timeout()">DbEnv::set_timeout()</a>, <a class="xref" href="envget_timeout.html" title="DbEnv::get_timeout()">DbEnv::get_timeout()</a></td> 153 <td>Set/get lock and transaction timeout</td> 154 </tr> 155 <tr> 156 <td> 157 <a class="xref" href="dbget_transactional.html" title="Db::get_transactional()">Db::get_transactional()</a> 158 </td> 159 <td>Does the Db have transaction support</td> 160 </tr> 161 <tr> 162 <td> 163 <a class="xref" href="envcdsgroup_begin.html" title="DbEnv::cdsgroup_begin()">DbEnv::cdsgroup_begin()</a> 164 </td> 165 <td>Get a locker ID in Berkeley DB Concurrent Data Store</td> 166 </tr> 167 <tr> 168 <td><a class="xref" href="envset_tx_max.html" title="DbEnv::set_tx_max()">DbEnv::set_tx_max()</a>, <a class="xref" href="envget_tx_max.html" title="DbEnv::get_tx_max()">DbEnv::get_tx_max()</a></td> 169 <td>Set/get maximum number of transactions</td> 170 </tr> 171 <tr> 172 <td><a class="xref" href="envset_tx_timestamp.html" title="DbEnv::set_tx_timestamp()">DbEnv::set_tx_timestamp()</a>, <a class="xref" href="envget_tx_timestamp.html" title="DbEnv::get_tx_timestamp()">DbEnv::get_tx_timestamp()</a></td> 173 <td>Set/get recovery timestamp</td> 174 </tr> 175 <tr> 176 <td colspan="2"> 177 <span class="bold"> 178 <strong>Transaction Operations</strong> 179 </span> 180 </td> 181 </tr> 182 <tr> 183 <td> 184 <a class="xref" href="txnabort.html" title="DbTxn::abort()">DbTxn::abort()</a> 185 </td> 186 <td>Abort a transaction</td> 187 </tr> 188 <tr> 189 <td> 190 <a class="xref" href="txnbegin.html" title="DbEnv::txn_begin()">DbEnv::txn_begin()</a> 191 </td> 192 <td>Begin a transaction</td> 193 </tr> 194 <tr> 195 <td> 196 <a class="xref" href="txncommit.html" title="DbTxn::commit()">DbTxn::commit()</a> 197 </td> 198 <td>Commit a transaction</td> 199 </tr> 200 <tr> 201 <td> 202 <a class="xref" href="txndiscard.html" title="DbTxn::discard()">DbTxn::discard()</a> 203 </td> 204 <td>Discard a prepared but not resolved transaction handle</td> 205 </tr> 206 <tr> 207 <td> 208 <a class="xref" href="txnid.html" title="DbTxn::id()">DbTxn::id()</a> 209 </td> 210 <td>Return a transaction's ID</td> 211 </tr> 212 <tr> 213 <td> 214 <a class="xref" href="txnprepare.html" title="DbTxn::prepare()">DbTxn::prepare()</a> 215 </td> 216 <td>Prepare a transaction for commit</td> 217 </tr> 218 <tr> 219 <td><a class="xref" href="txnset_name.html" title="DbTxn::set_name()">DbTxn::set_name()</a>, <a class="xref" href="txnget_name.html" title="DbTxn::get_name()">DbTxn::get_name()</a></td> 220 <td>Associate a string with a transaction</td> 221 </tr> 222 </tbody> 223 </table> 224 </div> 225 </div> 226 </div> 227 <div class="navfooter"> 228 <hr /> 229 <table width="100%" summary="Navigation footer"> 230 <tr> 231 <td width="40%" align="left"><a accesskey="p" href="seqstat_print.html">Prev</a> </td> 232 <td width="20%" align="center"> </td> 233 <td width="40%" align="right"> <a accesskey="n" href="dbget_transactional.html">Next</a></td> 234 </tr> 235 <tr> 236 <td width="40%" align="left" valign="top">DbSequence::stat_print() </td> 237 <td width="20%" align="center"> 238 <a accesskey="h" href="index.html">Home</a> 239 </td> 240 <td width="40%" align="right" valign="top"> Db::get_transactional()</td> 241 </tr> 242 </table> 243 </div> 244 </body> 245</html> 246