libdb/docs/programmer_reference/stl_txn_usage.html
2012-11-14 16:35:20 -05:00

108 lines
4.9 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Using transactions in dbstl</title>
<link rel="stylesheet" href="gettingStarted.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
<link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
<link rel="up" href="stl.html" title="Chapter 7. Standard Template Library API" />
<link rel="prev" href="stl_db_advanced_usage.html" title="Using advanced Berkeley DB features with dbstl" />
<link rel="next" href="stl_mt_usage.html" title="Using dbstl in multithreaded applications" />
</head>
<body>
<div xmlns="" class="navheader">
<div class="libver">
<p>Library Version 11.2.5.3</p>
</div>
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">Using transactions in dbstl</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="stl_db_advanced_usage.html">Prev</a> </td>
<th width="60%" align="center">Chapter 7. Standard Template Library API</th>
<td width="20%" align="right"> <a accesskey="n" href="stl_mt_usage.html">Next</a></td>
</tr>
</table>
<hr />
</div>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="stl_txn_usage"></a>Using transactions in dbstl</h2>
</div>
</div>
</div>
<p>
When using transactions with dbstl, you must call the dbstl transaction
functions instead of the corresponding methods from the Berkeley DB C
or C++ transaction API. That is, you must use
<code class="methodname">dbstl::begin_txn()</code>,
<code class="methodname">dbstl::commit_txn()</code> and
<code class="methodname">dbstl::abort_txn()</code> in order to
begin/commit/abort transactions.
</p>
<p>
A container can be configured to use auto commit by setting the
<a href="../api_reference/C/envset_flags.html#envset_flags_DB_AUTO_COMMIT" class="olink">DB_AUTO_COMMIT</a> flag when the environment or database handle is
opened. In this case, any container method that supports auto commit
will automatically form an independent transaction if the method
is not in an external transactional context; Otherwise,
the operation will become part of that transaction.
</p>
<p>
You can configure the flags used internally by dbstl when it is
creating and committing these independent transactions required by auto
commit. To do so, use the
<code class="methodname">db_container::set_txn_begin_flags()</code> and/or
<code class="methodname">db_container::set_commit_flags()</code> methods.
</p>
<p>
When a transaction is committed or aborted, dbstl will automatically
close any cursors opened for use by the transaction. For this reason,
any iterators opened within the transaction context should not be used
after the transaction commits or aborts.
</p>
<p>
You can use nested transactions explicitly and externally, by calling
<code class="methodname">dbstl::begin_txn()</code> in a context already
operating under the protection of a transaction. But you can not
designate which transaction is the parent transaction. The parent
transaction is automatically the most recently created and unresolved
transaction in current thread.
</p>
<p>
It is also acceptable to use explicit transactions in a container
configured for auto commit. The operation performed by the method will
become part of the provided external transaction.
</p>
<p>
Finally, transactions and iterators cannot be shared among multiple
threads. That is, they are not free-threaded, or thread-safe.
</p>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="stl_db_advanced_usage.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="stl.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="stl_mt_usage.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Using advanced Berkeley DB features with dbstl </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> Using dbstl in multithreaded applications</td>
</tr>
</table>
</div>
</body>
</html>