arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
438 stars 76 forks source link

JdbcTemplateCrud add support for optimistic locking #699

Open ltkn opened 4 years ago

ltkn commented 4 years ago

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 :

the possible complexity might be related to the use of the same column twice in the sql statement with 2 different values.

Thanks!

arnaudroger commented 4 years ago

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

arnaudroger commented 4 years ago

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

ltkn commented 4 years ago

Great news thanks!

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