
$c = new Criteria();
$c->add(InspectionPeer::ID, $ie->getId());
$c->add(InspectionPeer::IN_PROCESS, 1);
if(InspectionPeer::doUpdate($c) === 0) {
//field was not modified therefore it was already 1 and
//is being handled by another process so skip
continue;
}
$ie->setInProcess(1);
Simple record-level locking is achieved by atomically updating a lock field to grab the lock. This is done by updating the field and checking if it was actually locked by return of doUpdate which indicates the number of rows modified If no rows were modified then it returns 0. If you were able to grab the lock, then it returns 1.
This is important because it avoid the race condition between checking if the lock is free and actually grabbing the lock, which much the same as a typical get-set race condition with regular memory values.
This form of locking is known as "pessimistic offline" due to the fact that:
it grabs the lock first instead of only checking afterwards if it has changed
it actually stores the lock in the database rather than in the DBMS
New Blog Post! Gherkin - It Ain't Just a Pickle! http://t.co/diBtFADy
November 7, 2012
You built or have a site and now what? Usability testing! http://t.co/Qt8IX3NY Experiment, improve, repeat. We <3 usability!
October 18, 2012
Google Throws Open Doors to Its Top-Secret Data Center | Wired Enterprise | http://t.co/UoCR4op0 http://t.co/mnHXix2C -- we love this stuff!
October 17, 2012