A compact Java key/value store backed by Oracle Berkeley DB Java Edition. It provides a small UTF-8 and binary API while retaining Berkeley DB's durable, transactional storage engine.
- Persistent string keys with string or binary values
- Atomic overwrite and put-if-absent operations
- Key existence checks and deletion
- Configurable environment folder and logical database name
- Customizable environment lifecycle through dependency injection
- Thread-safe Berkeley DB access and deterministic resource cleanup
- Java 8-compatible API with try-with-resources support
- JDK 8 or newer
- Maven 3.6 or newer
mvn clean verifyThe compiled JAR is written to target/berkeley-db-1.0.jar.
import org.exoplatform.berkeley.BerkeleyStore;
try (BerkeleyStore store = new BerkeleyStore("data/customers", "customer-cache")) {
store.put("customer:42:name", "Ada Lovelace");
store.put("customer:42:avatar", avatarBytes);
String name = store.get("customer:42:name");
byte[] avatar = store.getBytes("customer:42:avatar");
boolean created = store.putIfAbsent(
"customer:42:status",
"active");
boolean removed = store.delete("customer:42:avatar");
}The no-argument constructor stores data in ./db under the logical database
name berkeley. For application-specific durability, caching, or database
settings, subclass BerkeleyEnvironment and pass it to the injectable
BerkeleyStore constructor.
Operations throw BerkeleyException for invalid input, closed-store access,
and Berkeley DB failures. Store construction fails immediately when its
environment cannot be opened, so callers never receive a partially initialized
instance.
GNU Affero General Public License v3.0 or later, matching the source headers.