1<!--$Id: faq.so,v 10.6 2006/05/01 15:32:01 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB Reference Guide: Environment FAQ</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<a name="2"><!--meow--></a> 12<table width="100%"><tr valign=top> 13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Environment</dl></b></td> 14<td align=right><a href="/env/remote.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/cam/intro.html"><img src="/images/next.gif" alt="Next"></a> 15</td></tr></table> 16<p align=center><b>Environment FAQ</b></p> 17<ol> 18<p><li><b>I'm using multiple processes to access an Berkeley DB database 19environment; is there any way to ensure that two processes don't run 20transactional recovery at the same time, or that all processes have 21exited the database environment so that recovery can be run?</b> 22<p>See <a href="/ref/transapp/fail.html">Handling failure in 23Transactional Data Store applications</a> and 24<a href="/ref/transapp/app.html">Architecting Transactional Data Store 25applications</a> for a full discussion of this topic.</p> 26<p><li><b>How can I associate application information with a <a href="/api_c/db_class.html">DB</a> 27or <a href="/api_c/env_class.html">DB_ENV</a> handle?</b> 28<p>In the C API, the <a href="/api_c/db_class.html">DB</a> and <a href="/api_c/env_class.html">DB_ENV</a> structures each contain 29an "app_private" field intended to be used to reference 30application-specific information. See the <a href="/api_c/db_class.html">db_create</a> and 31<a href="/api_c/env_class.html">db_env_create</a> documentation for more information.</p> 32<p>In the C++ or Java APIs, the easiest way to associate 33application-specific data with a handle is to subclass the <a href="/api_cxx/db_class.html">Db</a> 34or <a href="/api_cxx/env_class.html">DbEnv</a>, for example subclassing <a href="/api_cxx/db_class.html">Db</a> to get MyDb. 35Objects of type MyDb will still have the Berkeley DB API methods available on 36them, and you can put any extra data or methods you want into the MyDb 37class. If you are using "callback" APIs that take <a href="/api_cxx/db_class.html">Db</a> or 38<a href="/api_cxx/env_class.html">DbEnv</a> arguments (for example, <a href="/api_cxx/db_set_bt_compare.html">Db::set_bt_compare</a>) 39these will always be called with the <a href="/api_cxx/db_class.html">Db</a> or <a href="/api_cxx/env_class.html">DbEnv</a> 40objects you create. So if you always use MyDb objects, you will be able 41to take the first argument to the callback function and cast it to a 42MyDb (in C++, cast it to (MyDb*)). That will allow you to access your 43data members or methods.</p> 44</ol> 45<table width="100%"><tr><td><br></td><td align=right><a href="/env/remote.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/cam/intro.html"><img src="/images/next.gif" alt="Next"></a> 46</td></tr></table> 47<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 48</body> 49</html> 50