003 File Manager
Current Path:
/usr/local/share/doc/db5/gsg_txn/CXX
usr
/
local
/
share
/
doc
/
db5
/
gsg_txn
/
CXX
/
๐
..
๐
BerkeleyDB-Core-Cxx-Txn.pdf
(1007.21 KB)
๐
abortresults.html
(3.37 KB)
๐
apireq.html
(8.15 KB)
๐
architectrecovery.html
(25.01 KB)
๐
autocommit.html
(7.71 KB)
๐
backuprestore.html
(18.35 KB)
๐
blocking_deadlocks.html
(32.31 KB)
๐
deadlock.jpg
(12.3 KB)
๐
enabletxn.html
(45 KB)
๐
envopen.html
(7.22 KB)
๐
exclusivelock.html
(4.61 KB)
๐
filemanagement.html
(14.08 KB)
๐
gettingStarted.css
(1.13 KB)
๐
hotfailover.html
(8.94 KB)
๐
index.html
(18.38 KB)
๐
inmem_txnexample_c.html
(21.47 KB)
๐
introduction.html
(8.39 KB)
๐
isolation.html
(32.43 KB)
๐
lockingsubsystem.html
(25.48 KB)
๐
logconfig.html
(17.96 KB)
๐
logfileremoval.html
(8.78 KB)
๐
maxtxns.html
(9.02 KB)
๐
moreinfo.html
(6.36 KB)
๐
multithread-intro.html
(4.45 KB)
๐
nestedtxn.html
(5.97 KB)
๐
nodurabletxn.html
(7.83 KB)
๐
perftune-intro.html
(4.01 KB)
๐
preface.html
(6.63 KB)
๐
readblock.jpg
(10.26 KB)
๐
readmodifywrite.html
(4.85 KB)
๐
recovery-intro.html
(4.7 KB)
๐
recovery.html
(11.66 KB)
๐
reversesplit.html
(6.29 KB)
๐
rwlocks1-pdf.jpg
(187.63 KB)
๐
rwlocks1.jpg
(7.25 KB)
๐
simplelock-pdf.jpg
(126.26 KB)
๐
simplelock.jpg
(4.35 KB)
๐
sysfailure.html
(5.7 KB)
๐
txn_ccursor.html
(7.34 KB)
๐
txnconcurrency.html
(13.8 KB)
๐
txncursor.html
(4.68 KB)
๐
txnexample_c.html
(27.19 KB)
๐
txnindices.html
(5.22 KB)
๐
txnnowait.html
(3.48 KB)
๐
usingtxns.html
(15.01 KB)
๐
wrapup.html
(10.26 KB)
๐
writeblock.jpg
(6.22 KB)
Editing: envopen.html
<?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>Opening a Transactional Environment and Database</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="Getting Started with Berkeley DB Transaction Processing" /> <link rel="up" href="enabletxn.html" title="Chapterย 2.ย Enabling Transactions" /> <link rel="prev" href="enabletxn.html" title="Chapterย 2.ย Enabling Transactions" /> <link rel="next" href="usingtxns.html" title="Chapterย 3.ย Transaction Basics" /> </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">Opening a Transactional Environment and <span xmlns="http://www.w3.org/1999/xhtml">Database</span> </th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="enabletxn.html">Prev</a>ย </td> <th width="60%" align="center">Chapterย 2.ย Enabling Transactions</th> <td width="20%" align="right">ย <a accesskey="n" href="usingtxns.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="envopen"></a>Opening a Transactional Environment and <span>Database</span> </h2> </div> </div> </div> <p> To enable transactions for your environment, you must initialize the transactional subsystem. Note that doing this also initializes the logging subsystem. In addition, you must initialize the memory pool (in-memory cache). You must also initialize the locking subsystem. <span> For example: </span> </p> <pre class="programlisting">#include "db_cxx.h" ... int main(void) { u_int32_t env_flags = DB_CREATE | // If the environment does not // exist, create it. DB_INIT_LOCK | // Initialize locking DB_INIT_LOG | // Initialize logging DB_INIT_MPOOL | // Initialize the cache DB_INIT_TXN; // Initialize transactions std::string envHome("/export1/testEnv"); DbEnv myEnv(0); try { myEnv.open(envHome.c_str(), env_flags, 0); } catch(DbException &e) { std::cerr << "Error opening database environment: " << envHome << std::endl; std::cerr << e.what() << std::endl; return (EXIT_FAILURE); } try { myEnv.close(0); } catch(DbException &e) { std::cerr << "Error closing database environment: " << envHome << std::endl; std::cerr << e.what() << std::endl; return (EXIT_FAILURE); } return (EXIT_SUCCESS); } </pre> <p> You then create and open your database(s) as you would for a non-transactional system. <span> The only difference is that you must pass the environment handle to the <span> <code class="methodname">DbEnv::open()</code> method, </span> and you must open the database within a transaction. Typically auto commit is used for this purpose. To do so, pass <code class="literal">DB_AUTO_COMMIT</code> to the database open command. It is recommended that you close all your databases before you close your environment. For example: </span> </p> <pre class="programlisting">#include "db_cxx.h" ... int main(void) { u_int32_t env_flags = DB_CREATE | // If the environment does not // exist, create it. DB_INIT_LOCK | // Initialize locking DB_INIT_LOG | // Initialize logging DB_INIT_MPOOL | // Initialize the cache DB_INIT_TXN; // Initialize transactions <strong class="userinput"><code>u_int32_t db_flags = DB_CREATE | DB_AUTO_COMMIT; Db *dbp = NULL; const char *file_name = "mydb.db";</code></strong> std::string envHome("/export1/testEnv"); DbEnv myEnv(0); try { myEnv.open(envHome.c_str(), env_flags, 0); <strong class="userinput"><code>dbp = new Db(&myEnv, 0); dbp->open(NULL, // Txn pointer file_name, // File name NULL, // Logical db name DB_BTREE, // Database type (using btree) db_flags, // Open flags 0); // File mode. Using defaults </code></strong> } catch(DbException &e) { std::cerr << "Error opening database and environment: " << file_name << ", " << envHome << std::endl; std::cerr << e.what() << std::endl; } try { <strong class="userinput"><code>dbp->close(0);</code></strong> myEnv.close(0); } catch(DbException &e) { std::cerr << "Error closing database and environment: " << file_name << ", " << envHome << std::endl; std::cerr << e.what() << std::endl; return (EXIT_FAILURE); } return (EXIT_SUCCESS); } </pre> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p> Never close a database that has active transactions. Make sure all transactions are resolved (either committed or aborted) before closing the database. </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="enabletxn.html">Prev</a>ย </td> <td width="20%" align="center"> <a accesskey="u" href="enabletxn.html">Up</a> </td> <td width="40%" align="right">ย <a accesskey="n" href="usingtxns.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">Chapterย 2.ย Enabling Transactionsย </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top">ย Chapterย 3.ย Transaction Basics</td> </tr> </table> </div> </body> </html>
Upload File
Create Folder