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.
using (IObjectContainer rootContainer = Db4oEmbedded.OpenFile(DatabaseFileName)) { // open the db4o-session. For example at the beginning for a web-request using (IObjectContainer session = rootContainer.Ext().OpenSession()) { // do the operations on the session-container session.Store(new Person("Joe")); } }
Using rootContainer As IObjectContainer = Db4oEmbedded.OpenFile(DatabaseFileName) ' open the db4o-session. For example at the beginning for a web-request Using session As IObjectContainer = rootContainer.Ext().OpenSession() ' do the operations on the session-container session.Store(New Person("Joe")) End Using End Using
Or you can use embedded clients when your embedded clients.
using (IObjectServer server = Db4oClientServer.OpenServer(DatabaseFileName, 0)) { // open the db4o-embedded client. For example at the beginning for a web-request using (IObjectContainer container = server.OpenClient()) { // do the operations on the session-container container.Store(new Person("Joe")); } }
Using server As IObjectServer = Db4oClientServer.OpenServer(DatabaseFileName, 0) ' open the db4o-embedded client. For example at the beginning for a web-request Using container As IObjectContainer = server.OpenClient() ' do the operations on the session-container container.Store(New Person("Joe")) End Using End Using