3 namespace pq\Gateway\Table
;
8 * A pessimistic row lock implementation using an additional SELECT FOR UPDATE
10 class PessimisticLock
implements LockInterface
14 * @param \pq\Gateway\Row $row
15 * @param array $ignore
16 * @throws \UnexpectedValueException if the row has already been modified
18 function onUpdate(Row
$row, array &$ignore) {
20 foreach ($row->getIdentity() as $col => $val) {
22 $where["$col="] = $val;
24 $where["$col IS"] = new QueryExpr("NULL");
28 if (1 != count($rowset = $row->getTable()->find($where, null, 0, 0, "update nowait"))) {
29 throw new \
UnexpectedValueException("Failed to select a single row");
31 if ($rowset->current()->getData() != $row->getData()) {
32 throw new \
UnexpectedValueException("Row has already been modified");