[Dbix-class] Optimistic locking

Zbigniew Lukasiak zzbbyy at gmail.com
Sat Aug 5 09:51:41 CEST 2006


Hi,

There will be race conditions - is that acceptable for you?  See following
scenario:

Person A wants to save new record values
Person B wants to save new record values
A fetches the record to compute the hash
B fetches the record to compute the hash
The record has not been changed yet so both A and B are ready to save their
new values
A saves her new values
B saves her new values

The result is that the values saved by A are overwritten by B without any
warning.

It would be safe if we could do a

UPDATE rec ... WHERE (id = our_id AND hash = the_old_hash_val)

This would be a real optimistic locking using the database mechanisms to
eliminate the race conditions.

--
Zbyszek


On 8/4/06, Dan Horne <dan.horne at redbone.co.nz> wrote:
>
>
> Hi
>
> I'd like to implement a form of optimistic locking in one of my apps.
> Rather
> than handle this manually in the app itself, I'm hoping to reduce the
> coding
> overhead by incorporating the logic in a DBIC component. The basic steps
> are:
>
> 1. Generate a pseudocolumn that contains a hash of the current row (or
> allrows if $rs->all).
> 2. At some point in the future, a user will try to save the record via a
> webform. The overridden update method will query the original row and
> recompute the hash. If the two hashes don't match, an exception will be
> thrown.
>
> So, my question is: Is there any way to create such a pseudocolumn that
> can
> be populated as a result of the values of the other columns?
>
> Regards
>
> Dan
>
>
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
> http://www.mail-archive.com/dbix-class@lists.rawmode.org/
>



-- 
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20060805/b76229bb/attachment-0001.htm 


More information about the Dbix-class mailing list