by sebas77 » August 28th, 2013, 5:49 pm
by sebas77 » August 30th, 2013, 2:34 pm
public void IncrementMonstersKilled(var inc) {
//Load the object MonsterStats from the GameStats table
PlayerIO.BigDB.Load("GameStats", "MonsterStats",
delegate(DatabaseObject result) {
//Add inc to the Killed value.
var killed = result.Get("Killed");
result.Set("Killed", killed + inc);
result.Save(true, null, delegate(PlayerIOError error) {
if (error.ErrorCode == ErrorCode.StaleVersion) {
//If someone else updated before us, try again
IncrementMonstersKilled(inc);
}
});
}
);
}
by Henrik » September 1st, 2013, 6:33 am
sebas77 wrote:thanks, but I wonder if I should use the one with the optimistic lock instead, like this one
sebas77 wrote:Also I wonder if the optimistic lock makes sense only if the same property is overwritten or it must be used also if a whole object change. Example, I have an object with property1 and property2, one piece of code modifies and changes property1, the other piece of code modifies and changes property2, both pieces of code save the same object.
sebas77 wrote:also, as long as we talk about server side code, do you think it is wise to keep on retrying for ever until the saving worked?
sebas77 wrote:and as last question, will an existing databaseobject be saved if I call save but the properties are actually not modified?
by sebas77 » September 2nd, 2013, 3:33 pm
Henrik wrote:sebas77 wrote:thanks, but I wonder if I should use the one with the optimistic lock instead, like this one
If you have several instances of the same object floating around, for example if I can be on a different game server, load up your object, and make changes to it, while you are on your game server, changing your object as well, then you need optimistic locking to ensure that we don't overwrite each other's changes.
But if you're manipulating a single instance from different threads, then you won't need optimistic locking, since all changes happen in the same place, and whoever calls Save() will send whatever changes everyone has done to the object for saving.