SimpleFlatMapper icon indicating copy to clipboard operation
SimpleFlatMapper copied to clipboard

JdbcTemplateCrud add support for optimistic locking

Open ltkn opened this issue 5 years ago • 3 comments

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!

ltkn avatar Nov 21 '19 09:11 ltkn

Will have a look... no guarantees on timing:) but that should be doable

arnaudroger avatar Nov 21 '19 10:11 arnaudroger

And thanks for the feedback. I only use a small portion of it and ideas are very welcomed

arnaudroger avatar Nov 21 '19 10:11 arnaudroger

Great news thanks!

It's not urgent as it's easy to do with a manual update query, just a nice feature to have ;)

ltkn avatar Nov 25 '19 10:11 ltkn