You are here: Object Lifecycle > Object Container

Object Container

db4o gives you a simple and straightforward interface to object persistence - ObjectContainer. In .NET versions a conventional name IObjectContainer is used.

Accessing A Database

ObjectContainer is your db4o database.

Java:

ObjectContainer container = Db4o.openFile(filename);

filename is the path to the file, in which you want to store your objects. Normally you should open an ObjectContainer when the application starts and close it, when the session is finished to persist the changes to a physical storage location:

Java:

container.close();

nly the first call against a file can be successful. Subsequent calls that request to open a database file that is already open will get a DatabaseFileLockedException.

Working With Objects

ObjectContainer interface gives you all the basic functionality to work with persistent objects. Normally you can save a new or updated object of any class using objectContainer.store(object)

Deletion is done with the following method:

Java:

container.delete(object)

Through ObjectContainer#get and ObjectContainer#query you get access to objects retrieval functionality.

Object Container Features

The characteristic features of an Object Container are:

Basically Object Container supplies functionality, which is enough for the most common usage of db4o database.

Extended Object Container Interface

Additional db4o features are provided by an interface extending Object Container - ExtObjectContainer/IExtObjectContainer.

The idea of splitting basic and advanced functionality between 2 interfaces is:

Every Object Container object is also an ExtObjectContainer. You can cast it to ExtObjectContainer or you can use ext method to get to the advanced features.