Berkeley DB Reference Guide:
Java API Tutorial

PrevRefNext

Introduction to the Java API tutorial

The Java API is a Java persistence framework based on the standard Java collections API. This tutorial illustrates the use of the Java API with a shipment database, a familiar example from classic database texts.

The examples illustrate the following concepts of the Java API:

The examples build on each other, but at the same time the source code for each example stands alone.

The shipment database consists of three database stores: the part store, the supplier store, and the shipment store. Each store contains a number of records, and each record consists of a key and a value.

StoreKeyValue
PartPart NumberName, Color, Weight, City
SupplierSupplier NumberName, Status, City
ShipmentPart Number, Supplier NumberQuantity

In the example programs, Java classes containing the fields above are defined for the key and value of each store: PartKey, PartValue, SupplierKey, SupplierValue, ShipmentKey and ShipmentValue. In addition, because the Part's Weight field is itself composed of two fields -- the weight value and the unit of measure -- it is represented by a separate Weight class. These classes will be defined in the first example program.

In general the Java API uses formats and bindings to describe how Java objects are stored. A format defines the stored data syntax, and a binding defines the mapping between a Java object and the stored data. The example programs show how to create different types of formats and bindings, and explains the characteristics of each type.

The following tables contain the record values that are used in all the example programs in the tutorial.

Part Records

NumberNameColorWeightCity
P1NutRed12.0 gramsLondon
P2BoltGreen17.0 gramsParis
P3ScrewBlue17.0 gramsRome
P4ScrewRed14.0 gramsLondon
P5CamBlue12.0 gramsParis
P6CogRed19.0 gramsLondon

Supplier Records

NumberNameStatusCity
S1Smith20London
S2Jones10Paris
S3Blake30Paris
S4Clark20London
S5Adams30Athens

Shipment Records

Part NumberSupplier NumberQuantity
P1S1300
P1S2300
P2S1200
P2S2400
P2S3200
P2S4200
P3S1400
P4S1200
P4S4300
P5S1100
P5S4400
P6S1100

PrevRefNext

Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.