コード例 #1
0
ファイル: OptimisticLock.php プロジェクト: m6w6/pq-gateway
 /**
  * @param \pq\Gateway\Table $table
  * @param \pq\Gateway\Row $row
  * @param string $event create/update/delete
  * @param array $where reference to the criteria
  */
 function update(\SplSubject $table, Row $row = null, $event = null, array &$where = null)
 {
     if ($event === "update") {
         $where["{$this->column}="] = $row->getData()[$this->column];
         $row->{$this->column}->mod(+1);
     }
 }
コード例 #2
0
ファイル: PessimisticLock.php プロジェクト: m6w6/pq-gateway
 /**
  * @param \pq\Gateway\Table $table
  * @param \pq\Gateway\Row $row
  * @param string $event create/update/delete
  * @param array $where reference to the criteria
  * @throws \UnexpectedValueException if the row has already been modified
  */
 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");
         }
     }
 }