Hello Ryan, > Is there any way for JOOQ to handle optimistic locking automatically?
There is currently no automatic way of dealing with optimistic locking. > Rather than adding a version column it could do a select on the record and > if the initial values are different then throw the exception. That sounds like a reasonable approach. I guess, in order to avoid race conditions, the select would have to be a SELECT ... FOR UPDATE. I'll register this as feature request #1547: https://sourceforge.net/apps/trac/jooq/ticket/1547 > Or is there another approach to achieve this? Right now, I could imagine that you'll be able to implement this on an ExecuteListener level. Prior to executing an UPDATE, you could manually issue the necessary select statement and throw your own custom RuntimeException. The relevant section in the manual and Javadocs are these: - http://www.jooq.org/manual/ADVANCED/ExecuteListener/ - http://www.jooq.org/javadoc/latest/org/jooq/ExecuteListener.html Cheers Lukas 2012/7/9 Ryan How <[email protected]>: > Hi, > > Is there any way for JOOQ to handle optimistic locking automatically? > > So given an updateable record something like the following: > > MyRecord r = .... // some query > r.setValue(.....) // do some stuff > r.storeWithCheck(); // throws an exception if has been updated by another > connection > > Rather than adding a version column it could do a select on the record and > if the initial values are different then throw the exception. > > Or is there another approach to achieve this? > > Thanks! Ryan >
