-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathexamples.html
More file actions
353 lines (324 loc) · 10.8 KB
/
Copy pathexamples.html
File metadata and controls
353 lines (324 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Berkeley DB Java Edition Examples</title>
</head>
<body>
<p align=center>
<img src="images/Oracle_BerkeleyDB_small.png" alt="Oracle">
</p>
<center><h1>Berkeley DB Java Edition<br>Examples</h1></center>
<p>The JE distribution comes with examples that illustrate:</p>
<ul>
<li>using the JE programming interfaces to perform basic database
operations</li>
<li>scenarios from the Getting Started Guide and Writing Transactional
Applications</li>
<li>using the Direct Persistence Layer to implement common SQL
queries</li>
<li>using JE High Availability</li>
</ul>
<hr noshade="noshade" size="1">
<a href="#examples">Building and running JE examples</a><br>
<a href="#basicexample">Basic Example</a><br>
<a href="#gsg">Getting Started Examples</a><br>
<a href="#txn">Writing Transactional Applications Examples</a><br>
<a href="#sql">Translating SQL Queries</a><br>
<a href="#exampleList">Examples List</a><br>
<h3><a name="basicexample">Building and Running a Basic Example</a></h3>
<p>Compiling and running a simple example can serve as a sanity check of the
installation. Follow the instructions below to compile and run the
PersonExample.</p>
<p>You can find the source for this example at:</p>
<blockquote>
<pre>JE_HOME/examples/persist/PersonExample.java</pre>
</blockquote>
<p>Assuming you have installed the JavaSE JDK and have verified that you
have a working Java compiler, you can build <code>PersonExample</code>
as follows.</p>
<ol>
<li>Change to the
<pre>JE_HOME/examples</pre> directory.</li>
<br>
<li>Set your CLASSPATH to include both <pre>JE_HOME/lib/je-M.N.P.jar</pre>
and the <pre>JE_HOME/examples</pre> directory.</li>
<br>
<li>Compile <code>PersonExample.java</code> with the following command:
<pre>javac persist/PersonExample.java</pre> or on Windows:
<pre>javac persist\PersonExample.java</pre>
</li>
</ol>
<p>To run <code>PersonExample</code> , use the following command, specifying an
environment directory for the data generated by the example:</p>
<blockquote>
<pre>java persist.PersonExample -h <environment directory></pre>
</blockquote>
<p>For example, using <code>"."</code> for the second parameter will write
the database files into the current directory. You'll notice that a
<code>00000000.jdb</code> file and and <code>je.lck</code> file are
created. This is the first log file in the environment and a lock
file. If you need to delete the environment for running a different
example, simply delete these two files.</p>
<p>When you run the program you'll see the following output. While this is not
a very entertaining program, it is enough to test that you have installed JE
correctly.</p>
<pre>222-22-2222 Jack Smith
333-33-3333 Mary Smith</pre>
<p>The other JE examples are compiled and run similarly. How to run
the examples from the Getting Started Guide and Writing Transactional
Applications is described in the sections below, as well as how to run
the Translating SQL Queries examples. Instructions for running other
examples are contained in the example's source file.</p>
<h3><a name="gsg">Running the Getting Started Examples</a></h3>
<p>As described in the <em>Berkeley DB Java Edition Getting Started
Guide</em>, the final examples in every chapter exist in the JE
package. You can build and run these examples as follows:</p>
<ul>
<li>Change to the
<pre>JE_HOME/examples</pre>
directory.</li>
<br>
<li>Set your CLASSPATH to include both
<pre>JE_HOME/lib/je-M.N.P.jar</pre>
and the
<pre>JE_HOME/examples</pre>
directories.</li>
<br>
<li>Compile the Getting Started examples with the following commands:
<pre>javac je/gettingStarted/*.java</pre>
or on Windows:
<pre>javac je\gettingStarted\*.java</pre>
</li>
<li>Make a directory to contain your database environment:
<pre>mkdir gsgEnv</pre>
</li>
<li>Load your sample database:
<pre>java je.gettingStarted.ExampleDatabasePut -h gsgEnv -i je/gettingStarted/inventory.txt -v je/gettingStarted/vendors.txt</pre>
</li>
<li>Perform queries against your database. To see everything in the
database, use:
<pre>java je.gettingStarted.ExampleInventoryRead -h gsgEnv</pre>
To perform a query based on an inventory item's name, use:
<pre>java je.gettingStarted.ExampleInventoryRead -h gsgEnv -s Upo</pre>
</li>
</ul>
<h3><a name="txn">Running the Writing Transactional Applications
Examples</a></h3>
<p>The examples in <em>Writing Transactional Applications with
Berkeley DB, Java Edition guide</em> exist in the JE package. You
can build and run these examples as follows:</p>
<ul>
<li>Change to the
<pre>JE_HOME/examples</pre>
directory.</li>
<br>
<li>Set your CLASSPATH to include both
<pre>JE_HOME/lib/je-M.N.P.jar</pre>
and the
<pre>JE_HOME/examples</pre>
directories.</li>
<br>
<li>Compile the Transactional Applications examples with the following commands:
<pre>javac je/txn/*.java</pre>
or on Windows:
<pre>javac je\txn\*.java</pre>
</li>
<li>Make a directory to contain your database environment:
<pre>mkdir txnEx</pre>
</li>
<li>Run the transactional example.
<pre>java je.txn.TxnGuide -h txnEx</pre>
</li>
</ul>
<h3><a name="sql">Running the Translating SQL Query Examples</a></h3>
<p>This example shows how some common SQL queries can be implemented
using the Direct Persistence Layer. It's meant to help users who are
more familiar with SQL translate those approaches to the DPL. These
queries include:</p>
<dl>
<dt>Basic data retrieval:</dt><br>
<dd><code>SELECT * FROM tab ORDER BY col ASC;</code></dd><br>
<dt>A prefix query:</dt><br>
<dd><code>SELECT * FROM tab WHERE col LIKE 'prefix%';</code></dd><br>
<dt>A range query, where the data type of A (as well as B) may be an
int, a float, a String, etc:</dt><br>
<dd><code>SELECT * FROM tab WHERE col gt;= A AND col <= B;</code></dd><br>
<dt>An equi-join on a single primary database:</dt><br>
<dd><code>SELECT * FROM tab WHERE col1 = A AND col2 =B;</code></dd><br>
<dt>An equi-join on two primary databases combined
with a filtering on "t2.col2". Note that if "t2.col2" is a secondary key, the
filtering does a index lookup. Otherwise the filtering is done through
database scanning:</dt><br>
<dd><code>SELECT t1.* FROM table1 t1, table2 t2 WHERE t1.col1 = t2.col1
AND t2.col2 = A;</code></dd>
</dl>
<p>You can build and run these examples as follows:</p>
<ul>
<li>Change to the
<pre>JE_HOME/examples</pre>
directory.</li>
<br>
<li>Set your CLASSPATH to include both
<pre>JE_HOME/lib/je-M.N.P.jar</pre>
and the
<pre>JE_HOME/examples</pre>
directories.</li>
<br>
<li>Compile the SQL query examples with the following commands:
<pre>javac persist/sqlapp/*.java</pre>
or on Windows:
<pre>javac persist\sqlapp\*.java</pre>
</li>
<li>Make a directory to contain your database environment:
<pre>mkdir sqlEnv</pre>
</li>
<li>Run the SQL query examples:
<pre>java persist.sqlapp.SQLApp -h sqlEnv</pre>
To delete database files after the example exits, do:
<pre>java persist.sqlapp.SQLApp -h sqlEnv -d</pre>
</li>
</ul>
<h3><a name="exampleList">List of Examples</a></h3>
<table border="1" cellpadding="4">
<tr>
<th>Example</th>
<th>Location</th>
<th>API</th>
<th>Description</th>
</tr>
<tr>
<td>Getting Started Guide</td>
<td>examples/persist/ gettingStarted</td>
<td>DPL</td>
<td>scenarios using the Direct Persistence Layer from the Getting Started
Guide</td>
</tr>
<tr>
<td>Writing Transactional Applications</td>
<td>examples/persist/txn</td>
<td>DPL</td>
<td>scenarios using the Direct Persistence Layer from Writing Transactional
Applications</td>
</tr>
<tr>
<td>Writing Transactional Applications</td>
<td>examples/je/txn</td>
<td>Base</td>
<td>scenarios using the Base API from Writing Transactional
Applications</td>
</tr>
<tr>
<td>Translating SQL Queries</td>
<td>examples/persist/sqlApp</td>
<td>DPL</td>
<td>shows how some common SQL queries can be implemented using the Direct
Persistence Layer</td>
</tr>
<tr>
<td>PersonExample</td>
<td>examples/persist</td>
<td>DPL</td>
<td>demonstrates basic use of the Direct Persistence Layer</td>
</tr>
<tr>
<td>ScalaPersonExample</td>
<td>examples/persist</td>
<td>DPL</td>
<td>demonstrates using JE with the Scala programming language</td>
</tr>
<tr>
<td>EventExample EventExampleDPL</td>
<td>examples/persist</td>
<td>DPL</td>
<td>contrasts the Base API and the Direct Persistence Layer with an
example of storing event objects</td>
</tr>
<tr>
<td>CustomKeyOrderExample</td>
<td>examples/persist</td>
<td>DPL</td>
<td>shows how to use a Comparable to specify key order</td>
</tr>
<tr>
<td>DplDump</td>
<td>examples/persist</td>
<td>DPL</td>
<td>dumps objects stored using the Direct Persistence Layer in XML
format</td>
</tr>
<tr>
<td>HelloDatabaseWorld</td>
<td>examples/collections/hello</td>
<td>Collections</td>
<td>trivial example using the Collections API</td>
</tr>
<tr>
<td>AccessExample</td>
<td>examples/collections/access</td>
<td>Collections</td>
<td>reimplementation of the Base API AccessExample using the Collections
API</td>
</tr>
<tr>
<td>Shipments</td>
<td>examples/collections/ship</td>
<td>Collections</td>
<td>series of examples based on a shipment database</td>
</tr>
<tr>
<td>SimpleExample</td>
<td>examples/je</td>
<td>Base</td>
<td>does basic data insertion and retrieval</td>
</tr>
<tr>
<td>BindingExample</td>
<td>examples/je</td>
<td>Base</td>
<td>shows how to use com.sleepycat.bind to convert between Java objects and
JE data records</td>
</tr>
<tr>
<td>SecondaryExample</td>
<td>examples/je</td>
<td>Base</td>
<td>illustrates the use of secondary indices</td>
</tr>
<tr>
<td>SequenceExample</td>
<td>examples/je</td>
<td>Base</td>
<td>demonstrates the use of Sequence objects</td>
</tr>
<tr>
<td>ToManyExample</td>
<td>examples/je</td>
<td>Base</td>
<td>shows how to use multi-key secondary indices to support many-many and
one-many primary/secondary key relationships</td>
</tr>
<tr>
<td>MeasureInsertSize</td>
<td>examples/je</td>
<td>Base</td>
<td>inserts a given set of key/value pairs in order to measure the disk
space consumed by a given data set</td>
</tr>
<tr>
<td>JCA</td>
<td>examples/jca</td>
<td>Base</td>
<td>shows how to use the J2EE Connector Architecture with JE</td>
</tr>
<tr>
<td>StockQuotes</td>
<td><a href="examples/je/rep/quote/package-summary.html">examples/je/rep/quote</a></td>
<td>High Availability/Replication</td>
<td>shows how to use BDB JE High Availability</td>
</tr>
</table>
<hr noshade="noshade" size="1">
<p><a href="sleepycat/legal.html">Copyright (c) 2002, 2017</a> Oracle and/or its affiliates.
All rights reserved.</font></p>
</body>
</html>