Pessimistic lock
Shared lock
To acquire a shared lock on the queried rows, assign PESSIMISTIC_READ
to the lockMode
field of the PageQuery
class. This will generate an SQL statement with a FOR SHARE
clause, allowing other transactions to read the same rows but preventing them from updating or deleting them until the current transaction is complete.
Exclusive lock
To acquire an exclusive lock on queried rows, assign PESSIMISTIC_WRITE
to the lockMode
field of the PageQuery
class. This appends a FOR UPDATE
clause to the SQL query, locking the selected rows for the duration of the transaction and preventing concurrent access by other transactions.
Last updated
Was this helpful?