Berkeley DB Reference Guide:
Java API

PrevRefNext

Using Stored Collections

collection_fig_1

The implementation of stored collections and related transactional access methods.

When a stored collection is created it is based on either a DataStore or a DataIndex . When a data store is used, the primary key of the data store is used as the collection key. When a data index is used, the index key is used as the collection key. Indexed collections can be used for reading elements and removing elements but not for adding or updating elements.

Stored Collection and Access Methods

The access method of the data store or index restricts the use of the stored collection in certain respects. Most of these restrictions have to do with List interfaces; for Map interfaces, most all access modes are fully supported since the Berkeley DB model is map-like.

Differences between Stored Collections and Standard Java Collections

Stored collections have the following differences with the standard Java collection interfaces. Some of these are interface contract violations.

The Java collections interface does not support duplicate keys (multi-maps or multi-sets). When the access method allows duplicate keys, the collection interfaces are defined as follows.

Other differences are:

Other Stored Collection Characteristics

The following characteristics of stored collections are extensions of the definitions in the java.util package. These differences do not violate the Java collections interface contract.

Why Java Collections for Berkeley DB?

The Java collections interface was chosen as the best Java API for Berkeley DB given these requirements:

  1. provide the Java developer with an API that is as familiar and easy to use as possible

  2. provide access to all, or a large majority, of the features of the underlying Berkeley DB storage system

  3. compared to the Berkeley DB API, provide a higher-level API that is oriented toward Java developers

  4. for ease of use, support object-to-data bindings, per-thread transactions, and some traditional database features such as foreign keys

  5. provide a thin layer that can be thoroughly tested and which does not significantly impact the reliability and performance of Berkeley DB

Admittedly there are several things about the Java Collections API that don't quite fit with Berkeley DB or with any transactional database, and therefore there are some new rules for applying the Java Collections API. In addition, the Java API data store, index and foreign key APIs are outside the scope of the Java Collections API and are therefore somewhat disjoint. However, these disadvantages are considered to be smaller than the disadvantages of the alternatives:

In fact both of these alternatives were started and then abandoned for the reasons given.


PrevRefNext

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