The JE distribution comes with examples that illustrate:
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.
You can find the source for this example at:
JE_HOME/examples/persist/PersonExample.java
Assuming you have installed the JavaSE JDK and have verified that you
have a working Java compiler, you can build PersonExample
as follows.
JE_HOME/examplesdirectory.
JE_HOME/lib/je-M.N.P.jarand the
JE_HOME/examplesdirectory.
PersonExample.java
with the following command:
javac persist/PersonExample.javaor on Windows:
javac persist\PersonExample.java
To run PersonExample
, use the following command, specifying an
environment directory for the data generated by the example:
java persist.PersonExample -h <environment directory>
For example, using "."
for the second parameter will write
the database files into the current directory. You'll notice that a
00000000.jdb
file and and je.lck
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.
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.
222-22-2222 Jack Smith 333-33-3333 Mary Smith
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.
As described in the Berkeley DB Java Edition Getting Started Guide, the final examples in every chapter exist in the JE package. You can build and run these examples as follows:
JE_HOME/examplesdirectory.
JE_HOME/lib/je-M.N.P.jarand the
JE_HOME/examplesdirectories.
javac je/gettingStarted/*.javaor on Windows:
javac je\gettingStarted\*.java
mkdir gsgEnv
java je.gettingStarted.ExampleDatabasePut -h gsgEnv -i je/gettingStarted/inventory.txt -v je/gettingStarted/vendors.txt
java je.gettingStarted.ExampleInventoryRead -h gsgEnvTo perform a query based on an inventory item's name, use:
java je.gettingStarted.ExampleInventoryRead -h gsgEnv -s Upo
The examples in Writing Transactional Applications with Berkeley DB, Java Edition guide exist in the JE package. You can build and run these examples as follows:
JE_HOME/examplesdirectory.
JE_HOME/lib/je-M.N.P.jarand the
JE_HOME/examplesdirectories.
javac je/txn/*.javaor on Windows:
javac je\txn\*.java
mkdir txnEx
java je.txn.TxnGuide -h txnEx
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:
SELECT * FROM tab ORDER BY col ASC;
SELECT * FROM tab WHERE col LIKE 'prefix%';
SELECT * FROM tab WHERE col gt;= A AND col <= B;
SELECT * FROM tab WHERE col1 = A AND col2 =B;
SELECT t1.* FROM table1 t1, table2 t2 WHERE t1.col1 = t2.col1
AND t2.col2 = A;
You can build and run these examples as follows:
JE_HOME/examplesdirectory.
JE_HOME/lib/je-M.N.P.jarand the
JE_HOME/examplesdirectories.
javac persist/sqlapp/*.javaor on Windows:
javac persist\sqlapp\*.java
mkdir sqlEnv
java persist.sqlapp.SQLApp -h sqlEnvTo delete database files after the example exits, do:
java persist.sqlapp.SQLApp -h sqlEnv -d
Example | Location | API | Description |
---|---|---|---|
Getting Started Guide | examples/persist/ gettingStarted | DPL | scenarios using the Direct Persistence Layer from the Getting Started Guide |
Writing Transactional Applications | examples/persist/txn | DPL | scenarios using the Direct Persistence Layer from Writing Transactional Applications |
Writing Transactional Applications | examples/je/txn | Base | scenarios using the Base API from Writing Transactional Applications |
Translating SQL Queries | examples/persist/sqlApp | DPL | shows how some common SQL queries can be implemented using the Direct Persistence Layer |
PersonExample | examples/persist | DPL | demonstrates basic use of the Direct Persistence Layer |
ScalaPersonExample | examples/persist | DPL | demonstrates using JE with the Scala programming language |
EventExample EventExampleDPL | examples/persist | DPL | contrasts the Base API and the Direct Persistence Layer with an example of storing event objects |
CustomKeyOrderExample | examples/persist | DPL | shows how to use a Comparable to specify key order |
DplDump | examples/persist | DPL | dumps objects stored using the Direct Persistence Layer in XML format |
HelloDatabaseWorld | examples/collections/hello | Collections | trivial example using the Collections API |
AccessExample | examples/collections/access | Collections | reimplementation of the Base API AccessExample using the Collections API |
Shipments | examples/collections/ship | Collections | series of examples based on a shipment database |
SimpleExample | examples/je | Base | does basic data insertion and retrieval |
BindingExample | examples/je | Base | shows how to use com.sleepycat.bind to convert between Java objects and JE data records |
SecondaryExample | examples/je | Base | illustrates the use of secondary indices |
SequenceExample | examples/je | Base | demonstrates the use of Sequence objects |
ToManyExample | examples/je | Base | shows how to use multi-key secondary indices to support many-many and one-many primary/secondary key relationships |
MeasureInsertSize | examples/je | Base | inserts a given set of key/value pairs in order to measure the disk space consumed by a given data set |
JCA | examples/jca | Base | shows how to use the J2EE Connector Architecture with JE |
StockQuotes | examples/je/rep/quote | High Availability/Replication | shows how to use BDB JE High Availability |
Copyright (c) 2002, 2017 Oracle and/or its affiliates. All rights reserved.