Debian Codegraph @

docs/gsg_txn/JAVA/txnindices.html

raw
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>Secondary Indices with Transaction Applications</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="usingtxns.html" title="Chapter 3. Transaction Basics" />
11 <link rel="prev" href="txncursor.html" title="Transactional Cursors" />
12 <link rel="next" href="maxtxns.html" title="Configuring the Transaction Subsystem" />
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">Secondary Indices with Transaction Applications</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="txncursor.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 3. Transaction Basics</th>
26 <td width="20%" align="right"> <a accesskey="n" href="maxtxns.html">Next</a></td>
27 </tr>
28 </table>
29 <hr />
30 </div>
31 <div class="sect1" lang="en" xml:lang="en">
32 <div class="titlepage">
33 <div>
34 <div>
35 <h2 class="title" style="clear: both"><a id="txnindices"></a>Secondary Indices with Transaction Applications</h2>
36 </div>
37 </div>
38 </div>
39 <p>
40 You can use transactions with your secondary indices so long as you
41
42
43
44 <span>
45 open the secondary index so that it is transactional.
46 </span>
47
48
49 </p>
50 <p>
51 All other aspects of using secondary indices with transactions are
52 identical to using secondary indices without transactions. In
53 addition, transaction-protecting
54
55 <span>
56 secondary cursors is performed just as you protect normal
57 cursors — you simply have to make sure the cursor is
58 opened using a transaction handle, and that the cursor is
59 closed before the handle is either either committed or
60 aborted.
61 </span>
62 See <a class="xref" href="txncursor.html" title="Transactional Cursors">Transactional Cursors</a> for details.
63 </p>
64 <p>
65 Note that when you use transactions to protect your database writes, your secondary indices are protected from
66 corruption because updates to the primary and the secondaries are performed in a single atomic transaction.
67 </p>
68 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
69 <h3 class="title">Note</h3>
70 <p>
71 If you are using the DPL, then be aware that
72 you never have to provide a transactional
73 handle when opening an index, be it a primary
74 or a secondary. However, if transactions are
75 enabled for your store, then all of the indexes
76 that you open will be enabled for transactional
77 usage. Moreover, any write operation performed
78 using that index will be done using a
79 transaction, regardless of whether you
80 explicitly provide a transactional handle to the
81 write operation.
82 </p>
83 <p>
84 If you do not explicitly provide a transaction
85 handle to DPL write operations performed on a
86 transactional store, then auto commit is
87 silently used for that operation.
88 </p>
89 </div>
90 <p>
91 For example:
92 </p>
93 <pre class="programlisting">package db.GettingStarted;
94
95 import com.sleepycat.bind.tuple.TupleBinding;
96 import com.sleepycat.db.Database;
97 import com.sleepycat.db.DatabaseType;
98 import com.sleepycat.db.DatabaseConfig;
99 import com.sleepycat.db.DatabaseException;
100 import com.sleepycat.db.Environment;
101 import com.sleepycat.db.EnvironmentConfig;
102 import com.sleepycat.db.SecondaryDatabase;
103 import com.sleepycat.db.SecondaryConfig;
104
105 import java.io.FileNotFoundException;
106
107 ...
108
109 // Environment and primary database opens omitted.
110
111 SecondaryConfig mySecConfig = new SecondaryConfig();
112 mySecConfig.setAllowCreate(true);
113 mySecConfig.setType(DatabaseType.BTREE);
114 mySecConfig.setTransactional(true);
115
116 SecondaryDatabase mySecDb = null;
117 try {
118 // A fake tuple binding that is not actually implemented anywhere.
119 // The tuple binding is dependent on the data in use.
120 // See the Getting Started Guide for details
121 TupleBinding myTupleBinding = new MyTupleBinding();
122
123 // Open the secondary. FullNameKeyCreator is not actually implemented
124 // anywhere. See the Getting Started Guide for details.
125 FullNameKeyCreator keyCreator =
126 new FullNameKeyCreator(myTupleBinding);
127
128 // Set the key creator on the secondary config object.
129 mySecConfig.setKeyCreator(keyCreator);
130
131 // Perform the actual open. Because this database is configured to be
132 // transactional, the open is automatically wrapped in a transaction.
133 // - myEnv is the environment handle.
134 // - myDb is the primary database handle.
135 String secDbName = "mySecondaryDatabase";
136 mySecDb = myEnv.openSecondary(null, secDbName, null, myDb,
137 mySecConfig);
138 } catch (DatabaseException de) {
139 // Exception handling goes here ...
140 } catch (FileNotFoundException fnfe) {
141 // Exception handling goes here ...
142 }</pre>
143 </div>
144 <div class="navfooter">
145 <hr />
146 <table width="100%" summary="Navigation footer">
147 <tr>
148 <td width="40%" align="left"><a accesskey="p" href="txncursor.html">Prev</a> </td>
149 <td width="20%" align="center">
150 <a accesskey="u" href="usingtxns.html">Up</a>
151 </td>
152 <td width="40%" align="right"> <a accesskey="n" href="maxtxns.html">Next</a></td>
153 </tr>
154 <tr>
155 <td width="40%" align="left" valign="top">Transactional Cursors </td>
156 <td width="20%" align="center">
157 <a accesskey="h" href="index.html">Home</a>
158 </td>
159 <td width="40%" align="right" valign="top"> Configuring the Transaction Subsystem</td>
160 </tr>
161 </table>
162 </div>
163 </body>
164 </html>