i am using db4o in a asp.net web application, as you know when db4o returns a list of objects they are not ordered.
in my website, i run a query and get the last object in the results and work on it (some processing and then update one of its fields).
my question is, if when i am working on that object , if another user arrive and run that query again , the same object returns to him, and both of users get same object.
i don’t want to allow this to happen. how can i prevent it from happening ?
Not sure if DB4O provides anything like this out of the box, but could implement some kind of pessimistic lock yourself, whereby the same object either won’t be returned or will be returned in a read-only mode. You’d need to maintain a list of objects being edited, and check this list each time you return your objects. But then there are problems such as users leaving and object getting stuck in ‘edit mode’ etc. You generally need some kind of service involving a timeout mechanism to deal with that. It can get complicated.
Or do it optimistically, e.g. let both users edit it but only save changes from the first user, and give the second user a warning when they try to save it. Usually done with a timestamp.
Edit
To provide a concrete example, this C# code provides a basic way to ‘lock’ an object so it isn’t brought back every time. In real life it will be more complex though.