Getting Started with Berkeley DB Java Edition

Legal Notice

This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit or send a letter to:

     Creative Commons
     559 Nathan Abbott Way
     StanfordCalifornia 94305

The text and example code included in this document are distributed under the Creative Commons license.

Sleepycat Software, Berkeley DB, Berkeley DB XML and the Sleepycat logo are trademarks or service marks of Sleepycat Software, Inc. All rights to these marks are reserved. No third-party use is permitted without the express prior written consent of Sleepycat Software, Inc.

Java™ and all Java-based marks are a trademark or registered trademark of Sun Microsystems, Inc, in the United States and other countries.

To obtain a copy of this document's original source code, please write to .


Table of Contents

Conventions Used in this Book
1. Introduction to Berkeley DB Java Edition
The JE Application
Databases and Database Environments
Database Records
Putting and Getting Database Records
Duplicate Data
Replacing and Deleting Entries
Secondary Databases
JE Resources
Application Considerations
JE Backup and Restore
Getting and Using JE
JE Exceptions
2. Database Environments
Opening Database Environments
Closing Database Environments
Environment Properties
The EnvironmentConfig Class
Environment Statistics
Database Environment Example
3. Databases
Opening Databases
Closing Databases
Database Properties
Administrative Methods
Database Example
4. Database Records
Using Database Records
Reading and Writing Database Records
Writing Records to the Database
Getting Records from the Database
Deleting Records
Data Persistence
Using the BIND APIs
Numerical and String Objects
Serializeable Complex Objects
Custom Tuple Bindings
Using Comparators
Writing Comparators
Setting Comparators
Database Record Example
5. Using Cursors
Opening and Closing Cursors
Getting Records Using the Cursor
Searching for Records
Working with Duplicate Records
Putting Records Using Cursors
Deleting Records Using Cursors
Replacing Records Using Cursors
Cursor Example
6. Secondary Databases
Opening and Closing Secondary Databases
Implementing Key Creators
Secondary Database Properties
Reading Secondary Databases
Deleting Secondary Database Entries
Using Secondary Cursors
Database Joins
Using Join Cursors
JoinCursor Properties
Secondary Database Example
Opening Secondary Databases with MyDbEnv
Using Secondary Databases with ExampleInventoryRead
7. Transactions
Enabling and Starting Transactions
Committing and Aborting Transactions
Aborting Transactions
Using Autocommit
Transactional Cursors
Configuring Dirty Reads
Transactions and Concurrency
Transactions and Deadlocks
Performance Considerations
Transactions Example
8. Backing up and Restoring Berkeley DB Java Edition Applications
Databases and Log Files
Log File Overview
Cleaning the Log Files
The BTree
Database Modifications
Normal Recovery
Performing Backups
Performing a Partial Backup
Performing a Complete Backup
Performing Catastrophic Recovery
Hot Standby
9. Administering Berkeley DB Java Edition Applications
The JE Properties File
Managing the Background Threads
The Cleaner Thread
The Evictor Thread
The Checkpointer Thread
Sizing the Cache
The Command Line Tools
A. Concurrent Processing in Berkeley DB Java Edition
Multithreaded Applications
Multiprocess Applications

List of Examples

2.1. Database Environment Management Class
3.1. Database Management with MyDbEnv
4.4. Stored Class Catalog Management with MyDbEnv
6.2. SecondaryDatabase Management with MyDbEnv
6.3. SecondaryDatabase usage with ExampleInventoryRead
7.1. Transaction Management with MyDbEnv
7.2. Using Transactions in ExampleDatabasePut