Debian Codegraph @

docs/programmer_reference/arch_apis.html

raw symbols SCIP
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>Programmatic APIs</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="arch.html" title="Chapter 8.  Berkeley DB Architecture" />
11 <link rel="prev" href="arch_progmodel.html" title="Programming model" />
12 <link rel="next" href="arch_script.html" title="Scripting languages" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Programmatic APIs</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="arch_progmodel.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 8. 
26 Berkeley DB Architecture
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="arch_script.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="arch_apis"></a>Programmatic APIs</h2>
38 </div>
39 </div>
40 </div>
41 <div class="toc">
42 <dl>
43 <dt>
44 <span class="sect2">
45 <a href="arch_apis.html#idp51640232">C</a>
46 </span>
47 </dt>
48 <dt>
49 <span class="sect2">
50 <a href="arch_apis.html#idp51656168">C++</a>
51 </span>
52 </dt>
53 <dt>
54 <span class="sect2">
55 <a href="arch_apis.html#idp51646944">STL</a>
56 </span>
57 </dt>
58 <dt>
59 <span class="sect2">
60 <a href="arch_apis.html#idp51647760">Java</a>
61 </span>
62 </dt>
63 <dt>
64 <span class="sect2">
65 <a href="arch_apis.html#idp51664896">Dbm/Ndbm, Hsearch</a>
66 </span>
67 </dt>
68 </dl>
69 </div>
70 <p>The Berkeley DB subsystems can be accessed through interfaces from multiple
71 languages. Applications can use Berkeley DB via C, C++ or Java, as well as a
72 variety of scripting languages such as Perl, Python, Ruby or Tcl.
73 Environments can be shared among applications written by using any of
74 these interfaces. For example, you might have a local server written
75 in C or C++, a script for an administrator written in Perl or Tcl, and
76 a Web-based user interface written in Java -- all sharing a single
77 database environment.</p>
78 <div class="sect2" lang="en" xml:lang="en">
79 <div class="titlepage">
80 <div>
81 <div>
82 <h3 class="title"><a id="idp51640232"></a>C</h3>
83 </div>
84 </div>
85 </div>
86 <p>The Berkeley DB library is written entirely in ANSI C. C applications use a
87 single include file:</p>
88 <pre class="programlisting">#include &lt;db.h&gt;</pre>
89 </div>
90 <div class="sect2" lang="en" xml:lang="en">
91 <div class="titlepage">
92 <div>
93 <div>
94 <h3 class="title"><a id="idp51656168"></a>C++</h3>
95 </div>
96 </div>
97 </div>
98 <p>The C++ classes provide a thin wrapper around the C API, with the major
99 advantages being improved encapsulation and an optional exception
100 mechanism for errors. C++ applications use a single include file:</p>
101 <pre class="programlisting">#include &lt;db_cxx.h&gt;</pre>
102 <p>The classes and methods are named in a fashion that directly corresponds
103 to structures and functions in the C interface. Likewise, arguments to
104 methods appear in the same order as the C interface, except to remove the
105 explicit <span class="bold"><strong>this</strong></span> pointer. The #defines used for flags are identical
106 between the C and C++ interfaces.</p>
107 <p>As a rule, each C++ object has exactly one structure from the underlying
108 C API associated with it. The C structure is allocated with each
109 constructor call and deallocated with each destructor call. Thus, the
110 rules the user needs to follow in allocating and deallocating structures
111 are the same between the C and C++ interfaces.</p>
112 <p>To ensure portability to many platforms, both new and old, Berkeley DB makes
113 as few assumptions as possible about the C++ compiler and library. For
114 example, it does not expect STL, templates, or namespaces to be
115 available. The newest C++ feature used is exceptions, which are used
116 liberally to transmit error information. Even the use of exceptions
117 can be disabled at runtime.</p>
118 </div>
119 <div class="sect2" lang="en" xml:lang="en">
120 <div class="titlepage">
121 <div>
122 <div>
123 <h3 class="title"><a id="idp51646944"></a>STL</h3>
124 </div>
125 </div>
126 </div>
127 <p>
128 dbstl is an C++ STL style API for Berkeley DB, based on the C++ API above. With it, you can store data/objects of any type into
129 or retrieve them from Berkeley DB databases as if you are using C++ STL containers. The full functionality
130 of Berkeley DB can still be utilized via dbstl with little performance overhead, e.g. you can use all transaction and/or replication functionality of Berkeley DB.
131
132 </p>
133 <p>
134 dbstl container/iterator class templates reside in header files dbstl_vector.h, dbstl_map.h and dbstl_set.h.
135
136 Among them, dbstl_vector.h contains dbstl::db_vector and its iterators;
137 dbstl_map.h contains dbstl::db_map, dbstl::db_multimap and their iterators; dbstl_set.h contains dbstl::db_set and dbstl::db_multiset and their iterators. You should
138 include needed header file(s) to use the container/iterator. Note that we don't use the file name with no extention --- To use dbstl::db_vector, you should do this:
139 </p>
140 <pre class="programlisting">#include "dbstl_vector.h"</pre>
141 <p>
142 rather than this:
143 </p>
144 <pre class="programlisting">#include "dbstl_vector"</pre>
145 <p>
146 And these header files reside in "stl" directory inside Berkeley DB source root directory. If you have installed
147 Berkeley DB, they are also available in the "include" directory in the directory where Berkeley DB is installed.
148 </p>
149 <p>
150 Apart from the above three header files, you may also need to include db_exception.h and db_utility.h files. The db_exception.h file contains all exception classes of dbstl, which
151 integrate seamlessly with Berkeley DB C++ API exceptions and C++ standard exception classes in std namespace. And the db_utility.h file contains the DbstlElemTraits which helps you
152 to store complex objects. These five header files are all that you need to include in order to make use of dbstl.
153 </p>
154 <p>
155 All symbols of dbstl, including classes, class templates, global functions, etc, reside in the namespace "dbstl", so in order to use them, you may also want to do this:
156 </p>
157 <pre class="programlisting">using namespace dbstl;</pre>
158 <p>
159 The dbstl library is always at the same place where Berkeley DB library is located, you will need to build it and link with it to use dbstl.
160 </p>
161 <p>
162 While making use of dbstl, you will probably want to create environment or databases directly, or set/get configurations to Berkeley DB environment or databases, etc. You are allowed to do so via Berkeley DB C/C++ API.
163 </p>
164 </div>
165 <div class="sect2" lang="en" xml:lang="en">
166 <div class="titlepage">
167 <div>
168 <div>
169 <h3 class="title"><a id="idp51647760"></a>Java</h3>
170 </div>
171 </div>
172 </div>
173 <p>The Java classes provide a layer around the C API that is almost identical
174 to the C++ layer. The classes and methods are, for the most part
175 identical to the C++ layer. Berkeley DB constants and #defines are represented as
176 "static final int" values. Error conditions are communicated as Java
177 exceptions.</p>
178 <p>As in C++, each Java object has exactly one structure from the underlying
179 C API associated with it. The Java structure is allocated with each
180 constructor or open call, but is deallocated only by the Java garbage
181 collector. Because the timing of garbage collection is not predictable,
182 applications should take care to do a close when finished with any object
183 that has a close method.</p>
184 </div>
185 <div class="sect2" lang="en" xml:lang="en">
186 <div class="titlepage">
187 <div>
188 <div>
189 <h3 class="title"><a id="idp51664896"></a>Dbm/Ndbm, Hsearch</h3>
190 </div>
191 </div>
192 </div>
193 <p>Berkeley DB supports the standard UNIX <a href="../api_reference/C/dbm.html" class="olink">dbm</a> and <a href="../api_reference/C/hsearch.html" class="olink">hsearch</a> interfaces. After including a new header file and recompiling, programs will run orders of magnitude faster, and underlying databases can grow as large as necessary. Also, historic <a href="../api_reference/C/dbm.html" class="olink">dbm</a> applications can fail once some number of entries are inserted into the database, in which the number depends on the effectiveness of the internal hashing function on the particular data set. This is not a problem with Berkeley DB.</p>
194 </div>
195 </div>
196 <div class="navfooter">
197 <hr />
198 <table width="100%" summary="Navigation footer">
199 <tr>
200 <td width="40%" align="left"><a accesskey="p" href="arch_progmodel.html">Prev</a> </td>
201 <td width="20%" align="center">
202 <a accesskey="u" href="arch.html">Up</a>
203 </td>
204 <td width="40%" align="right"> <a accesskey="n" href="arch_script.html">Next</a></td>
205 </tr>
206 <tr>
207 <td width="40%" align="left" valign="top">Programming model </td>
208 <td width="20%" align="center">
209 <a accesskey="h" href="index.html">Home</a>
210 </td>
211 <td width="40%" align="right" valign="top"> Scripting languages</td>
212 </tr>
213 </table>
214 </div>
215 </body>
216 </html>