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>Release 3.0: the DbEnv class for C++ and Java</title> 7 <link rel="stylesheet" href="gettingStarted.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 Programmer's Reference Guide" /> 10 <link rel="up" href="upgrade_3_0_toc.html" title="Chapter 33. Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0" /> 11 <link rel="prev" href="upgrade_3_0_value_set.html" title="Release 3.0: db_value_set" /> 12 <link rel="next" href="upgrade_3_0_db_cxx.html" title="Release 3.0: the Db class for C++ and Java" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Release 3.0: the DbEnv class for C++ and Java</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="upgrade_3_0_value_set.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 33. Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0</th> 23 <td width="20%" align="right"> <a accesskey="n" href="upgrade_3_0_db_cxx.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="upgrade_3_0_dbenv_cxx"></a>Release 3.0: the DbEnv class for C++ and Java</h2> 33 </div> 34 </div> 35 </div> 36 <p>The DbEnv::appinit() method and two constructors for the DbEnv class are 37gone. There is now a single way to create and initialize the environment. 38The way to create an environment is to use the new DbEnv constructor with 39one argument. After this call, the DbEnv can be configured with various 40set_XXX methods. Finally, a call to DbEnv::open is made to initialize 41the environment.</p> 42 <p>Here's a C++ example creating a Berkeley DB environment using the 2.X interface</p> 43 <pre class="programlisting">int dberr; 44DbEnv *dbenv = new DbEnv(); 45 46dbenv->set_error_stream(&cerr); 47dbenv->set_errpfx("myprog"); 48 49if ((dberr = dbenv->appinit("/database/home", 50 NULL, DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL)) != 0) { 51 cerr << "failure: " << strerror(dberr); 52 exit (1); 53}</pre> 54 <p>In the Berkeley DB 3.0 release, this code would be written as:</p> 55 <pre class="programlisting">int dberr; 56DbEnv *dbenv = new DbEnv(0); 57 58dbenv->set_error_stream(&cerr); 59dbenv->set_errpfx("myprog"); 60 61if ((dberr = dbenv->open("/database/home", 62 NULL, DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL, 0)) != 0) { 63 cerr << "failure: " << dbenv->strerror(dberr); 64 exit (1); 65}</pre> 66 <p>Here's a Java example creating a Berkeley DB environment using the 2.X interface:</p> 67 <pre class="programlisting">int dberr; 68DbEnv dbenv = new DbEnv(); 69 70dbenv.set_error_stream(System.err); 71dbenv.set_errpfx("myprog"); 72 73dbenv.appinit("/database/home", 74 null, Db.DB_CREATE | Db.DB_INIT_LOCK | Db.DB_INIT_MPOOL);</pre> 75 <p>In the Berkeley DB 3.0 release, this code would be written as:</p> 76 <pre class="programlisting">int dberr; 77DbEnv dbenv = new DbEnv(0); 78 79dbenv.set_error_stream(System.err); 80dbenv.set_errpfx("myprog"); 81 82dbenv.open("/database/home", 83 null, Db.DB_CREATE | Db.DB_INIT_LOCK | Db.DB_INIT_MPOOL, 0);</pre> 84 <p>In the Berkeley DB 2.X release, DbEnv had accessors to obtain "managers" of type 85DbTxnMgr, DbMpool, DbLog, DbTxnMgr. If you used any of these managers, 86all their methods are now found directly in the DbEnv class.</p> 87 </div> 88 <div class="navfooter"> 89 <hr /> 90 <table width="100%" summary="Navigation footer"> 91 <tr> 92 <td width="40%" align="left"><a accesskey="p" href="upgrade_3_0_value_set.html">Prev</a> </td> 93 <td width="20%" align="center"> 94 <a accesskey="u" href="upgrade_3_0_toc.html">Up</a> 95 </td> 96 <td width="40%" align="right"> <a accesskey="n" href="upgrade_3_0_db_cxx.html">Next</a></td> 97 </tr> 98 <tr> 99 <td width="40%" align="left" valign="top">Release 3.0: db_value_set </td> 100 <td width="20%" align="center"> 101 <a accesskey="h" href="index.html">Home</a> 102 </td> 103 <td width="40%" align="right" valign="top"> Release 3.0: the Db class for C++ and Java</td> 104 </tr> 105 </table> 106 </div> 107 </body> 108</html> 109