Chapter 1. Introduction to Berkeley DB Java Edition
Prev |  | Next

## Chapter 1. Introduction to Berkeley DB Java Edition

Welcome to Berkeley DB Java Edition (JE). JE is a general-purpose, transaction-protected, embedded database written in 100% Java (JE makes no JNI calls). As such, it offers the Java developer safe and efficient in-process storage and management of arbitrary data.

JE requires Java J2SE 1.4.2 or later.

### Note

In addition to the APIs described in this book, JE also offers the Direct Persistence Layer (DPL). The DPL is implemented as a layer on top of JE. Using it, you can cause any Java type to be persistent without implementing special interfaces.

We recommend that you use the DPL if all you want is to make classes with relatively static schemas to be persistent.

The only caveat to this recommendation is that the DPL requires Java 1.5, while JE does not. If you want to use Java 1.4, you must use the JE APIs.

You can find a brief introduction to the DPL in the Berkeley DB Java Edition Getting Started with the Direct Persistence Layer guide.

## Features

JE provides an enterprise-class Java-based data management solution. You use JE through a series of Java APIs. All you need to get started is to add a single jar file to your application's classpath. See Getting and Using JE for more information.

JE offers the following major features:

- Large database support. JE databases efficiently scale from one to millions of records. The size of your JE databases are likely to be limited more by hardware resources than by any limits imposed upon you by JE.

  Databases are described in Databases.

- Multiple thread and process support. JE is designed for multiple threads of control. Both read and write operations can be performed by multiple threads. JE uses record-level locking for high concurrency in threaded applications. Further, JE uses timeouts for deadlock detection to help you ensure that two threads of control do not deadlock indefinitely.

  Moreover, JE allows multiple processes to access the same databases. However, in this configuration JE requires that there be no more than one process allowed to write to the database. Read-only processes are guaranteed a consistent, although potentially out of date, view of the stored data as of the time that the environment is opened.

- Database records. All database records are organized as simple key/data pairs. Both keys and data can be anything from primitive Java types to the most complex of Java objects.

  Database records are described in Database Records.

- Transactions. Transactions allow you to treat one or more operations on one or more databases as a single unit of work. JE transactions offer the application developer recoverability, atomicity, and isolation for your database operations.

  Note that transaction protection is optional. Transactions are described in the Berkeley DB Java Edition Getting Started with Transaction Processing guide.

- Indexes. JE allows you to easily create and maintain secondary indices for your primary data through the use of secondary databases. In this way, you can obtain rapid access to your data through the use of an alternative, or secondary, key.

  Indexes are described in Secondary Databases.

- In-memory cache. The cache allows for high speed database access for both read and write operations by avoiding unnecessary disk I/O. The cache will grow on demand up to a pre-configured maximum size. To improve your application's performance immediately after startup time, you can preload your cache in order to avoid disk I/O for production requests of your data.

  Cache management is described in Sizing the Cache.

- Log files. JE databases are stored in one or more sequential numerically-named log files in the environment directory. The log files are write-once and are portable across platforms with different endian-ness.

  Note that unlike other database implementations, there is no distinction between database files (that is, the "material database") and log files. Instead JE employs a log-based storage system to protect database modifications. Before any change is made to a database, JE writes information about the change to the log file.

  Note that JE's log files are not binary compatible with Berkeley DB's database files. However, both products provide dump and load utilities, and the files that these operate on are compatible across product lines.

  JE's log files are described in more detail in Backing up and Restoring Berkeley DB Java Edition Applications. For information on using JE's dump and load utilities, see The Command Line Tools. Finally, for a short list of things to know about log files while you are learning JE, see Six Things Everyone Should Know about JE Log Files.

- Background threads. JE provides several threads that manage internal resources for you. The checkpointer is responsible for flushing database data to disk that was written to cache as the result of a transaction commit (this is done in order to shorten recovery time). The compressor thread removes subtrees from the database that are empty because of deletion activity. Finally, the cleaner thread is responsible for cleaning and removing unneeded log files, thereby helping you to save on disk space.

  Background thread management is described in Managing the Background Threads.

- Database environments. Database environments provide a unit of encapsulation and management for one or more databases. In addition, an environment is the unit of management for internal resources such as the in-memory cache and the background threads. Environments are also used to manage concurrency and transactions. Note that all applications using JE are required to use database environments.

  Database environments are described in Database Environments.

- Backup and restore. JE's backup procedure consists of simply copying JE's log files to a safe location for storage. To recover from a catastrophic failure, you copy your archived log files back to your production location on disk and reopen the JE environment.

  Note that JE always performs normal recovery when it opens a database environment. Normal recovery brings the database to a consistent state based on change information found in the database log files.

  JE's backup and recovery mechanisms are described in Backing up and Restoring Berkeley DB Java Edition Applications.

- JCA. JE provides support for the Java Connector Architecture. See JCA Support for more information.

- JMX. JE provides support for Java Management Extensions. See JMX Support for more information.

Prev | Up | Next
Preface | Home | The JE Application