You are here: Client-Server > Embedded Clients

Embedded Client Server

db4o supports embedded containers or session container. It's a separate object-container with its own transaction and own reference cache. See "Session Containers"

Now if you're using the client-server mode for db4o, you also can create such sessions directly from the server. When you pass a 0 to the open server method, the server only supports embedded clients. With any other port you can connect with regular clients and also create embedded clients.

ObjectServer server = Db4oClientServer.openServer(DATABASE_FILE_NAME, 0);

// open the db4o-embedded client. For example at the beginning for a web-request
ObjectContainer container = server.openClient();
try {
    // do the operations on the session-container
    container.store(new Person("Joe"));
} finally {
    // close the container. For example when the request ends
    container.close();
}
Db4oSessions.java: Embedded client

OpenSession On A Client

You might noted that the open-session is available on any object-container. Normally this creates a session-container with its own transaction and reference cache. However on a db4o-client this is not true. There it only creates a container with new cache, but shares the transaction with the client. The only use case for this is to implement connection pooling.See "Client-Container Pooling"