Berkeley DB Reference Version 5.3.33

Using Stored Collections

Stored Collection and Access Methods

Stored Collections Versus Standard Java Collections

Other Stored Collection Characteristics

Why Java Collections for Berkeley DB

When a stored collection is created it is based on either a Database or a SecondaryDatabase. When a database is used, the primary key of the database is used as the collection key. When a secondary database 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 use of stored collections is constrained in certain respects as described below. 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.

Stored Collections Versus 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 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 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 DB.

Admittedly there are several things about the Java Collections API that don't quite fit with DB or with any transactional database, and therefore there are some new rules for applying the Java Collections API. However, these disadvantages are considered to be smaller than the disadvantages of the alternatives: