libdb/docs/upgrading/upgrade_3_0_dbenv_cxx.html
2012-11-14 16:35:20 -05:00

111 lines
4.6 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>DbEnv class for C++ and Java</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 Upgrade Guide" />
<link rel="up" href="upgrade_3_0_toc.html" title="Chapter 14. Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0" />
<link rel="prev" href="upgrade_3_0_value_set.html" title="db_value_set" />
<link rel="next" href="upgrade_3_0_db_cxx.html" title="Db class for C++ and Java" />
</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">DbEnv class for C++ and Java</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="upgrade_3_0_value_set.html">Prev</a> </td>
<th width="60%" align="center">Chapter 14. Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0</th>
<td width="20%" align="right"> <a accesskey="n" href="upgrade_3_0_db_cxx.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="upgrade_3_0_dbenv_cxx"></a>DbEnv class for C++ and Java</h2>
</div>
</div>
</div>
<p>The DbEnv::appinit() method and two constructors for the DbEnv class are
gone. There is now a single way to create and initialize the environment.
The way to create an environment is to use the new DbEnv constructor with
one argument. After this call, the DbEnv can be configured with various
set_XXX methods. Finally, a call to DbEnv::open is made to initialize
the environment.</p>
<p>Here's a C++ example creating a Berkeley DB environment using the 2.X interface</p>
<pre class="programlisting">int dberr;
DbEnv *dbenv = new DbEnv();
dbenv-&gt;set_error_stream(&amp;cerr);
dbenv-&gt;set_errpfx("myprog");
if ((dberr = dbenv-&gt;appinit("/database/home",
NULL, DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL)) != 0) {
cerr &lt;&lt; "failure: " &lt;&lt; strerror(dberr);
exit (1);
}</pre>
<p>In the Berkeley DB 3.0 release, this code would be written as:</p>
<pre class="programlisting">int dberr;
DbEnv *dbenv = new DbEnv(0);
dbenv-&gt;set_error_stream(&amp;cerr);
dbenv-&gt;set_errpfx("myprog");
if ((dberr = dbenv-&gt;open("/database/home",
NULL, DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL, 0)) != 0) {
cerr &lt;&lt; "failure: " &lt;&lt; dbenv-&gt;strerror(dberr);
exit (1);
}</pre>
<p>Here's a Java example creating a Berkeley DB environment using the 2.X interface:</p>
<pre class="programlisting">int dberr;
DbEnv dbenv = new DbEnv();
dbenv.set_error_stream(System.err);
dbenv.set_errpfx("myprog");
dbenv.appinit("/database/home",
null, Db.DB_CREATE | Db.DB_INIT_LOCK | Db.DB_INIT_MPOOL);</pre>
<p>In the Berkeley DB 3.0 release, this code would be written as:</p>
<pre class="programlisting">int dberr;
DbEnv dbenv = new DbEnv(0);
dbenv.set_error_stream(System.err);
dbenv.set_errpfx("myprog");
dbenv.open("/database/home",
null, Db.DB_CREATE | Db.DB_INIT_LOCK | Db.DB_INIT_MPOOL, 0);</pre>
<p>In the Berkeley DB 2.X release, DbEnv had accessors to obtain "managers" of type
DbTxnMgr, DbMpool, DbLog, DbTxnMgr. If you used any of these managers,
all their methods are now found directly in the DbEnv class.</p>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="upgrade_3_0_value_set.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="upgrade_3_0_toc.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="upgrade_3_0_db_cxx.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">db_value_set </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> Db class for C++ and Java</td>
</tr>
</table>
</div>
</body>
</html>