X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FGateway%2FTable%2FPessimisticLock.php;h=04781578bc242f2de70cbae4b55411ccb6155b2c;hp=2076dbd2b7dc05aa06b7124a7088de4d0eb843b0;hb=c236ef4b1efd3f5d3a03a390f9a3721b06fa1e72;hpb=3c8b32baaac62855e2c9f5bfdb5ede9685ce2b76 diff --git a/lib/pq/Gateway/Table/PessimisticLock.php b/lib/pq/Gateway/Table/PessimisticLock.php index 2076dbd..0478157 100644 --- a/lib/pq/Gateway/Table/PessimisticLock.php +++ b/lib/pq/Gateway/Table/PessimisticLock.php @@ -7,29 +7,23 @@ use \pq\Gateway\Row; /** * A pessimistic row lock implementation using an additional SELECT FOR UPDATE */ -class PessimisticLock implements LockInterface +class PessimisticLock implements \SplObserver { /** - * @inheritdoc + * @param \pq\Gateway\Table $table * @param \pq\Gateway\Row $row - * @param array $ignore + * @param string $event create/update/delete + * @param array $where reference to the criteria * @throws \UnexpectedValueException if the row has already been modified */ - function onUpdate(Row $row, array &$ignore) { - $where = array(); - foreach ($row->getIdentity() as $col => $val) { - if (isset($val)) { - $where["$col="] = $val; - } else { - $where["$col IS"] = new QueryExpr("NULL"); + function update(\SplSubject $table, Row $row = null, $event = null, array &$where = null) { + if ($event === "update") { + if (1 != count($rowset = $table->find($where, null, 0, 0, "update nowait"))) { + throw new \UnexpectedValueException("Failed to select a single row"); + } + if ($rowset->current()->getData() != $row->getData()) { + throw new \UnexpectedValueException("Row has already been modified"); } - } - - if (1 != count($rowset = $row->getTable()->find($where, null, 0, 0, "update nowait"))) { - throw new \UnexpectedValueException("Failed to select a single row"); - } - if ($rowset->current()->getData() != $row->getData()) { - throw new \UnexpectedValueException("Row has already been modified"); } } } \ No newline at end of file