Question

I found call store without commit or call commit without store both can write data into disk. In my opinion, store is used to update object in container or put new created obj into container. commit do the disk write job.

I have not use TP & TA, I set enough updateDepth & minimumActivationDepth level. I observed that when I call store(obj), there are java.io.RandomAccessFile methods called. Data should be written into disk.

So what is the purpose to make 2 functions: store and commit? Why not just make a single api, say: save() ?

Was it helpful?

Solution

Those methods have two distinct tasks:

Store(): Tell db4o that you want to store / update this object. However this only enlists the changes to the transaction.

Commit(): Make all changes permanent and start a new transaction. Without the commit call the Store method will have no effect. (Note that .commit is implicitly called by close/dispose). In case you think a mistake happen or on a error you can call .Rollback instead to undo all your changes.

You can read more about transactions on the net, tons of examples around.

This is nothing special and many databases use this kind of semantics. Almost all SQL, Object and other databases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top