Hi Sergey,
Let's discuss this on the user group
> Regarding implementation of "Optimistic Locking" in jOOQ.
> It requires new additional select and even row locking.
>
> I thought that "Optimisting Locking" implementation should not do any locks
> and additional selects.
Your solution is better than the one I have currently implemented in
jOOQ *if* you have knowledge about the database schema - i.e. you know
that there is a version/timestamp column. In that case, you can avoid
the round-trip of another SELECT statement and the overhead of
comparing all values.
If jOOQ were to support this too, the version column and increment
algorithm would have to be specified. The API could look like this,
then:
---------------------------------------------
interface UpdatableRecord {
// Regular store
int store();
// Current "optimistic" locking store
int storeLocked();
// Your improved "optimistic" locking store (this could also be
"protected" API)
int storeLockedWithVersion(Field<? extends Number> version);
int storeLockedWithTimestamp(Field<Timestamp> timestamp);
// ... repeat the same API for delete()
}
---------------------------------------------
As you said, using code-generation configurations, the
version/timestamp columns could be designated (e.g. using regular
expressions) and additional utility methods could be generated in
records:
---------------------------------------------
class MyRecord extends UpdatableRecordImpl {
int storeLockedWithVersion();
int storeLockedWithTimestamp();
}
---------------------------------------------
Now those method names are a bit awkward. As the (unreleased)
storeLocked() method hasn't made it into the public API yet, I'm open
to suggestions...
Anyone?
Cheers
Lukas
2012/7/19 Sergey Epik <[email protected]>:
> Hello Lukas,
>
> Regarding implementation of "Optimistic Locking" in jOOQ.
> It requires new additional select and even row locking.
>
> I thought that "Optimisting Locking" implementation should not do any locks
> and additional selects.
>
> We just define one of the columns (in generator configuration) as "Version"
> or "Timestamp" and do update the following way:
>
> int rows = update some_table
> set some_table.col1 = <new value1>,
> set some_table.col2 = <new value2>,
> set some_table.version = some_table.version + 1
> where some_table.id = <primary> and some_table.version =
> <previous_version_value>
>
> if rows = 0 {
> throw new DataChangedException("...");
> }
>
> What do you think?
>
> --
> Best regards,
>