开发者

jdbctemplate and optimistic locking

In the project I'm in Hibernate and Spring jdbctemplate are mixed. I added optimistic locking. Hibernate works great with versioning but now I have to tansform all this jdbctemplate code to use versioning too.

Is there something like LockingJdbcTemplate (like SimpleJdbcTemplate)? I was thinking I could implement a generic update method


update(String tableName, String columnsSql, Str开发者_如何学Cing whereSql, Long version, Object... params)

Where I could:

  • append version=version+1 to columnSql
  • append version=? to whereSql
  • add version number to correct place within params (separate param is forcing to pass that value)
  • Check that exactly 1 item was updated and throw StaleObjectStateException otherwise

Is there any library that would wrap jdbctemplate and do something similar for me? Don't want to invent something that exists... :)


Nope, you'll have to add the optimistic locking behavior to your update queries manually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜