A first look at Berkeley DB Java Edition

15 Apr 2004

Sleepycat Software are the purveyors of the super-slick Berkeley DB, which is a native C based embedded database library. For quite a while, there has even been a Java API for Berkeley DB; but it is a JNI wrapper, so not a real 100% Java solution.

However, Sleepycat have been hard at work and have released a 100% Java embedded database library. This provides the same basic functionality as Berkeley DB, but Berkeley DB Java Edition (BDBJE) is a complete re-write in Java.

A first look

Firstly, if you've never come across Berkley DB before: it is not a Relational DBMS. It simply provides disk-based B-Tree and H-Tree. So it is not relational, but it does provide proper database management, including ACID transactions, scalability, locking, etc.

The core BDBJE API is simple enough; you can create databases, open transactions, and insert, update, delete, retrieve and iterate rows (key/value pairs). You can store any serialized object in BDBJE, plus it has some additional (efficient) support for Strings and native types.

But one of the funkiest things BDBJE does is provide an implementation of java.util.Map and java.util.SortedMap, backed by a BDBJE database. You can call all the methods on these objects and they will work as expected (including .values(), .keySet(), etc.).

(The one gotcha is if you get an Iterator from one of these Collections. Such an iterator is backed by a BDBJE cursor, which needs to be closed when you are finished. You can do this either by casting it to a StoredIterator and calling the close method, or by passing it to the static StoredIterator.close(Iterator) util method.)

I've been playing around with BDBJE on a multi-gigabyte database (serialized POJOs), and it has been performing extremely well. It is definitely worth a look if you need any kind of on-disk persistence.

BDBJE is still in beta, and requires JDK1.4+ (it is implemented on top of NIO).

  • Home
  • Blog