Panache MongoDB - Optimistic lock control
See original GitHub issueHi guys, hope you are doing well.
I was thinking about something I’ve commented in another ticket some time ago, but in that ticket we are talking about MongoDB migrations. What about we include in MongoDB Panache an optimistic lock feature, just like we have in JPA. Spring and other frameworks already have some similar.
I think it is not so complicated to implement, basically we need an annotation @Version
or some similar to identify the field used as “version”, and some adjusts in MongoOperations
the methods update
, and persistOrUpdate
.
Today when we call update
, in the MongoOperations.update
we build the query:
BsonValue id = document.get(ID);
BsonDocument query = new BsonDocument().append(ID, id);
We can change for some like:
BsonValue id = document.get(ID);
BsonValue version = document.get(VERSION);
return new BsonDocument().append(ID, id).append(VERSION, version);
In addition to that we add an OptimisticLockException
to inform users trying to update outdated documents.
Do you think it can work?
Best.
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (12 by maintainers)
@loicmathieu @diogocarleto
Hi, this change could be very useful, especially when the same collections on MongoDb are used simultaneously by Quarkus and SpringData. Do you plan to release it soon?
@loicmathieu do you think it makes sense?