You are here: Basics Operations & Concepts

Basics Operations & Concepts

This topic gives you an overview of the most important and basic features of db4o. First add db4o to your project. db4o doesn't need a complex setup. It's just a library which you can add to your project. See "Getting Started"

Basic Operations

The basic operations are unsurprisingly, storing, updating, querying and deleting objects. See "The Basic Operations"

ObjectContainer container = Db4oEmbedded.openFile("databaseFile.db4o");
try {
    // store a new pilot
    Pilot pilot = new Pilot("Joe");
    container.store(pilot);

    // query for pilots
    List<Pilot> pilots = container.query(new Predicate<Pilot>() {
        @Override
        public  boolean match(Pilot pilot) {
            return pilot.getName().startsWith("Jo");
        }
    });

    // update pilot
    Pilot toUpdate = pilots.get(0);
    toUpdate.setName("New Name");
    container.store(toUpdate);

    // delete pilot
    container.delete(toUpdate);
} finally {
    container.close();
}
Db4oBasics.java: The basic operations

For more information about queries: See "Querying"

Basic Concepts

There are some basic concepts which are used in db4o. Understanding them helps you to understand how db4o behaves. Some behaviors are common behaviors which you expect from a database, like transactions and ACID properties. See "ACID Properties and Transactions"

db4o manages objects by identity. This means db4o doesn't need additional id-field on your object. See "Identity Concept"

Other concepts are more unique to db4o, like the activation concept, which controls which objects are loaded from the storage to memory. See "Activation Concept". The same principals are also applied when updating (See "Update Concept" ) or deletion objects (See "Delete Behavior"