## Shipment Samples

The shipment sample programs illustrate the use of BDB API of Berkeley DB with a shipment database, a familiar example from classic database texts.

See samples/db/index.html for information on how to compile and run the samples.

Each shipment sample illustrates the use of different types of bindings and data formats. They build on each other, but at the same time each sample stands alone in terms of both code and comments.

All samples use a modified form of Java serialization for the value bindings. Several samples use tuple format for key bindings since this provides a more compact key and deterministic sort order. Currently no samples show the use of tuples for value bindings although of course this is possible. The highest-level approach is illustrated by factory, which uses a built-in factory to create databases and collections.

### Division of Responsibilities

The shipment samples illustrate a pattern for dividing responsibilities in applications that use BDB API.

1. The SampleDatabase class defines the environment, data stores, data formats, and secondary indexes. KeyExtractor classes are implemented here to derive secondary index keys from data values.
2. The SampleView class defines the bindings and collection views of the database. If bindings are not marshalled (i.e., if they are implemented externally to the key and value classes) then they are implemented here.
3. The key, value and entity classes are the application classes that model the stored data objects. These may implement marshalling interfaces or be used by the external bindings in the SampleView class.
4. The Sample class is the main program that uses the collection views to manage and query the stored objects.

Separating the data store and secondary index definitions from the view definitions is very important. This division allows easily defining more than one set of views on the same stored data.

For a larger program the division above may best be made along package lines rather than along class lines.