SimpleFlatMapper
SimpleFlatMapper copied to clipboard
JdbcTemplateCrud add support for optimistic locking
Hi,
First thanks a lot for this fantastic library, we are using it successfully for many projects with spring boot jdbc (it has replaced hibernate).
Would you consider adding optimistic locking to JdbcTemplateCrud update method ?
Optimistic locking queries look like this:
update table
set
column1=newValue1,
column2=newValue2
where
pk=pkValue
// optimistic locking condition below
and column2=previousValue2
column 2 can be an integer or date that is incremented upon successful update.
The idea would be to support this using JdbcTemplateCrud, not too sure about the method contract or technical challenge but this could look like :
- jdbcTemplateCrud.update(pojo, column name used for locking, column value used for locking) -> jdbcTemplateCrud.update(pojo, "version", 1) -> update set where id=123 and version=1
- or jdbcTemplateCrud.update(pojo).optimisiticLockingAndClause("AND column2=?", previousValue2")
the possible complexity might be related to the use of the same column twice in the sql statement with 2 different values.
Thanks!
Will have a look... no guarantees on timing:) but that should be doable
And thanks for the feedback. I only use a small portion of it and ideas are very welcomed
Great news thanks!
It's not urgent as it's easy to do with a manual update query, just a nice feature to have ;)