3 namespace pq\Gateway\Table
;
8 * A pessimistic row lock implementation using an additional SELECT FOR UPDATE
10 class PessimisticLock
implements \SplObserver
13 * @param \pq\Gateway\Table $table
14 * @param \pq\Gateway\Row $row
15 * @param string $event create/update/delete
16 * @param array $where reference to the criteria
17 * @throws \UnexpectedValueException if the row has already been modified
19 function update(\SplSubject
$table, Row
$row = null, $event = null, array &$where = null) {
20 if ($event === "update") {
21 if (1 != count($rowset = $table->find($where, null, 0, 0, "update nowait"))) {
22 throw new \
UnexpectedValueException("Failed to select a single row");
24 if ($rowset->current()->getData() != $row->getData()) {
25 throw new \
UnexpectedValueException("Row has already been modified");