-
Notifications
You must be signed in to change notification settings - Fork 1.1k
DATAMONGO-2195 - Consider version when removing an entity. #641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…e operations. We now make sure to apply the WriteConcern correctly when calling deleteOne on MongoCollection.
We now consider a potential @Version when removing an entity. MongoOperations#remove(Object) and MongoOperations#remove(Object, String) new throw an OptimisticLockingFailureException when the object to remove is versioned and the version of the given entity does not match the one within the store. If no document with matching _id can be found the remove operation passes without an error. MongoRepository now also considers the entities version, following the very same logic as MongoOperations. To remove an entity without version check use MongoOperations#remove(Query,…) or MongoRepository#deleteById(…
|
||
}).flatMap(deleteResult -> { | ||
|
||
if (entity != null && entity.hasVersionProperty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please invert the if clauses to use early returns to avoid the heavy nesting.
*/ | ||
default Query getRemoveByQuery() { | ||
|
||
if (isVersionedEntity()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ternary ? true : false. ;)
And guard transaction tests.
7bf6503
to
777d478
Compare
…ly in repositories. OptimisticLockingFailureException is now thrown only when deleting an entity through a repository and no longer when using the Template API.
…e operations. We now make sure to apply the WriteConcern correctly when calling deleteOne on MongoCollection. Original pull request: #641.
We now consider a potential @Version when removing an entity. MongoOperations#remove(Object) and MongoOperations#remove(Object, String) include the version of the object to remove if the entity is versioned. Opposed to save(Object), remove(Object) does not throw OptimisticLockingFailureException if a versioned entity could not be removed. This behavior is subject to be changed in a future release. Throwing OptimisticLockingFailureException on failed delete on Template API level was not introduced to not break existing application code. MongoRepository now also considers the entities version, following the very same logic as MongoOperations. To remove an entity without version check use MongoOperations#remove(Query,…) or MongoRepository#deleteById(…). Original pull request: #641.
…ly in repositories. OptimisticLockingFailureException is now thrown only when deleting an entity through a repository and no longer when using the Template API. Original pull request: #641.
…e operations. We now make sure to apply the WriteConcern correctly when calling deleteOne on MongoCollection. Original pull request: #641.
That's merged, polished and partially backported now. |
Fix stubbing in test that sneaked in through a back port not considering the change which method was used for entity removal. Original pull request: #641.
We now consider a potential
@Version
when removing an entity.MongoOperations#remove(Object)
andMongoOperations#remove(Object, String)
now throw anOptimisticLockingFailureException
when the object to remove is versioned and the version of the given entity does not match the one within the store. If no document with matching_id
can be found the remove operation passes without an error. Same applies to remove operations executed inside an ongoing MongoDB transaction.MongoRepository
now also considers the entities version, following the very same logic asMongoOperations
.To remove an entity without version check use
MongoOperations#remove(Query,…)
orMongoRepository#deleteById(…
This PR also includes a fix (2nd commit) for DATAMONGO-2196 that should be back ported to 2.1.x and 2.0.x.