In most web-application multiple concurrent request are processes. You want to isolate the request from each other. db4o supports transactions, which are perfect for this kind of isolation. Each unit of work gets its own transaction, for example each request. You can create a new session object container for this purpose. Such a session-container brings its own transaction and reference-system. This ensures that the session container is isolated from other operations on the database.
ObjectContainer rootContainer = Db4oEmbedded.openFile(DATABASE_FILE_NAME); // open the db4o-session. For example at the beginning for a web-request ObjectContainer session = rootContainer.ext().openSession(); try { // do the operations on the session-container session.store(new Person("Joe")); } finally { // close the container. For example when the request ends session.close(); }
Or you can use embedded clients when your 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(); }