Issue
I saw in the documentation the example of optimistic lock and it works:
// Properly configure the DSLContext
DSLContext optimistic = DSL.using(connection, SQLDialect.ORACLE,
new Settings().withExecuteWithOptimisticLocking(true));
// Fetch a book two times
BookRecord book1 = optimistic.fetchOne(BOOK, BOOK.ID.eq(5));
BookRecord book2 = optimistic.fetchOne(BOOK, BOOK.ID.eq(5));
// Change the title and store this book. The MODIFIED value has not been changed since the book was fetched.
// It can be safely updated
book1.setTitle("Animal Farm");
book1.store();
But i have a question about optimistic locking with operations. As i see optimistic locking works only with store() methods. Do I have a chance of optimistic locking this way:
dslContext.update(getIdField().getTable())
.set(getEntityField(), dto)
.where(getIdField().eq(dto.getId()))
dslContext.batch(updateOperations).execute();
Solution
As of jOOQ 3.16, jOOQ's optimistic locking is an UpdatableRecord
only feature, meaning it applies to jOOQ-generated SQL queries that arise from your insert()
, update()
, store()
, merge()
, delete()
calls on your record. It does not apply to any other queries.
In a future version of jOOQ, there might be a re-design of this functionality to use the new jOOQ 3.17 feature called "client side computed columns" (#9879). The re-design is tracked as #13339. It may or may not ship with jOOQ 3.17. Once implemented, your arbitrary DML statement will be transformed in order to implement optimistic locking semantics.
Answered By - Lukas Eder
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.