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>Application Requirements</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="Getting Started with Berkeley DB Transaction Processing" />
10    <link rel="up" href="introduction.html" title="Chapter 1. Introduction" />
11    <link rel="prev" href="sysfailure.html" title="A Note on System Failure" />
12    <link rel="next" href="multithread-intro.html" title="Multi-threaded and Multi-process Applications" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Application Requirements</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="sysfailure.html">Prev</a> </td>
22          <th width="60%" align="center">Chapter 1. Introduction</th>
23          <td width="20%" align="right"> <a accesskey="n" href="multithread-intro.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="apireq"></a>Application Requirements</h2>
33          </div>
34        </div>
35      </div>
36      <p>
37            In order to use transactions, your application has certain
38            requirements beyond what is required of non-transactional protected
39            applications.  They are:
40        </p>
41      <div class="itemizedlist">
42        <ul type="disc">
43          <li>
44            <p>
45                    Environments.
46                </p>
47            <p>
48                    Environments are optional for non-transactional
49                    applications that use the base API, but they are required for transactional
50                    applications. (Of course, applications that use the
51                    DPL always require the DPL.)
52                </p>
53            <p>
54                    Environment usage is described in detail in 
55                    <a class="xref" href="usingtxns.html" title="Chapter 3. Transaction Basics">Transaction Basics</a>.
56                </p>
57          </li>
58          <li>
59            <p>
60                    Transaction subsystem.
61                </p>
62            <p>
63                    In order to use transactions, you must explicitly
64                    enable the transactional subsystem for your
65                    application, and this must be done at the time that
66                    your environment is first created. 
67                </p>
68          </li>
69          <li>
70            <p>
71                    Logging subsystem.
72                </p>
73            <p>
74                    The logging subsystem is required for recovery purposes, but
75                    its usage also means your application may require a
76                    little more administrative effort than it does when logging
77                    is not in use. See <a class="xref" href="filemanagement.html" title="Chapter 5. Managing DB Files">Managing DB Files</a> for more information.
78                </p>
79          </li>
80          <li>
81            <p>
82                    
83                    
84                    <span>Transaction</span>
85                    
86                    handles.
87                </p>
88            <p>
89                    In order to obtain the atomicity guarantee offered by
90                    the transactional subsystem (that is, combine multiple
91                    operations in a single unit of work), your application must use
92                    transaction handles.  These handles are obtained from your 
93                    
94                    
95                    
96                    <span>Environment</span>
97                    objects. They should normally be short-lived, and their usage is 
98                    reasonably simple. To complete a transaction and save
99                    the work it performed, you 
100                    call its <code class="methodname">commit()</code> method. To
101                    complete a transaction and discard its work, you call its
102                    <code class="methodname">abort()</code> method.
103                </p>
104            <p>
105                    In addition, it is possible to use auto commit if you want
106                    to transactional protect a single write operation. Auto
107                    commit allows a transaction to be used without 
108                    obtaining an explicit transaction handle. See 
109                    <a class="xref" href="autocommit.html" title="Auto Commit">Auto Commit</a>
110                    for information on how to use auto commit.
111                </p>
112          </li>
113          <li>
114            <p>
115                            Entity Store
116                    </p>
117            <p>
118                            If you are using the DPL, then you must
119                            configure your entity stores for transactional
120                            support before opening them (that is, before
121                            obtaining a primary index from them for the first
122                            time).
123                    </p>
124          </li>
125          <li>
126            <p>
127                    Database open requirements.
128                </p>
129            <p>
130
131                    <span>In addition to using 
132                    environments and initializing the
133                    correct subsystems, your</span>
134                    
135
136                    application must transaction protect the database
137
138                    opens<span>,
139                    and any secondary index associations,</span> 
140
141                    if subsequent operations on the databases are to be transaction
142                    protected. The database open and secondary index
143                    association are commonly transaction protected using
144                    auto commit.
145                </p>
146            <p>
147                        Note that if you are using the DPL, you do not
148                        have to explicitly do anything to the underlying
149                        databases unless you want to modify their default
150                        behavior — such as the isolation level that they
151                        use, for example.
152                </p>
153          </li>
154          <li>
155            <p>
156                    Deadlock detection.
157                </p>
158            <p>
159                    Typically transactional applications use multiple
160                    threads of control when accessing the database. 
161                    Any time multiple threads are used on a single resource,
162                    the potential for lock contention arises. In turn, lock
163                    contention can lead to deadlocks. See
164                    <a class="xref" href="blocking_deadlocks.html" title="Locks, Blocks, and Deadlocks">Locks, Blocks, and Deadlocks</a>
165                    for more information.
166                </p>
167            <p>
168                    Therefore, transactional applications must frequently
169                    include code for detecting and responding to deadlocks.
170                    Note that this requirement is not
171                    <span class="emphasis"><em>specific</em></span> to transactions
172                    – you can certainly write concurrent
173                    non-transactional DB applications. Further, not
174                    every transactional application uses concurrency and
175                    so not every transactional application must
176                    manage deadlocks. Still, deadlock management is so
177                    frequently a characteristic of transactional
178                    applications that we discuss it in this
179                    book. See <a class="xref" href="txnconcurrency.html" title="Chapter 4. Concurrency">Concurrency</a>
180                    for more information.
181                </p>
182          </li>
183        </ul>
184      </div>
185    </div>
186    <div class="navfooter">
187      <hr />
188      <table width="100%" summary="Navigation footer">
189        <tr>
190          <td width="40%" align="left"><a accesskey="p" href="sysfailure.html">Prev</a> </td>
191          <td width="20%" align="center">
192            <a accesskey="u" href="introduction.html">Up</a>
193          </td>
194          <td width="40%" align="right"> <a accesskey="n" href="multithread-intro.html">Next</a></td>
195        </tr>
196        <tr>
197          <td width="40%" align="left" valign="top">A Note on System Failure </td>
198          <td width="20%" align="center">
199            <a accesskey="h" href="index.html">Home</a>
200          </td>
201          <td width="40%" align="right" valign="top"> Multi-threaded 
202        <span>and Multi-process</span>
203        Applications</td>
204        </tr>
205      </table>
206    </div>
207  </body>
208</html>
209