Skip to content

Conversation

noter
Copy link
Contributor

@noter noter commented Sep 6, 2012

This pull request contains optimistic locking implementation based on version field.

Changes:

added Version annotation with points to a version field
change save method on MongoTemplet to detect first time save or update.
If first save occure ((isNew() == true) and entity contains version filed then set this field to 0 and perform normal save.
If update occure (isNew() == false) then perform update with query by id and version and inc(version filed by one), then check writeConcern.getN() and throw OptimisticLockingFailureException if no documents was updated.

Any comments will be welcome.

@odrotbohm
Copy link
Member

Very cool stuff. A tiny thing though: would you mind adding some code that binds the updated version to the current entity? Currently you have to manually load the entity to see the updated version number.

Another thought: would it make sense to update the version property in our code and then du a plain update with the former version constraint? That would solve the binding issue of the new version and probably simplify the construction of the update object a little as you don't have to add an inc(…) operation and manually exclude the version property from the update. As we change a single document only, the operation should be atomic anyway.

@noter
Copy link
Contributor Author

noter commented Sep 6, 2012

Change completed.
Hope we don't go over long value in version :)
or do you have any other incrementation solution ?

@odrotbohm
Copy link
Member

That looks pretty good now. I'll have a detailled look tomorrow, brush it up and might even integrate it already. Would make a nice a addition to the upcoming GA release. Would you mind filling out the contributors agreement and comment the id you get assigned? Thanks a ton already!

@noter
Copy link
Contributor Author

noter commented Sep 7, 2012

My confirmation number is: 33320120907012713

@odrotbohm
Copy link
Member

What's your name actually? Need it to polish up the JavaDoc (author tags etc.).

@noter
Copy link
Contributor Author

noter commented Sep 11, 2012

Ah ok, I updated my account info. So it is Patryk Wasik.

@odrotbohm
Copy link
Member

Polished and merged into master to be included in 1.1 GA. I've removed the MongoOperations enhancements and inlined the modified update(…) method. Added event triggering according to the ones used to from doSave(…).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants