Chris Hartjes wrote: > > I've never heard of those terms before. "Optimistic/pesimistic > locking" sounds like a function of the database itself to me, and not > the responsibility of code. >
Databases can only perform transactions within a logical session - so a lock or a transaction start/end can only happen whilst the client holds onto the database connection. In a web environment the database connection is logically dropped for each http client connection, so a business 'transaction' can span multiple database connections (you don't want database connections hung up while the user pops out for a cup of coffee). You still want 'atomic' commits though, so all changes to data get stored in the session until the final 'commit/confirm' on the business transaction when all updates/inserts/deletes get applied as a single *database* transaction. The framework then has to check to see whether any of the records it is about to commit to the database have been updated/deleted by a different user since the first user fetched (and changed) them. An optimistic locking strategy assumes updates are infrequent and/or unlikely to clash so just performs the checks and raises an error if any of the records have been changed by someone else. If so, *all* changes are rolled back (this is where database transactions help) and the user has to re-query. Pessimistic locking 'flags' the record (remember, we cannot use database locks across database sessions) a bit like CVS files can be locked on checkout. This is a rarer form of locking, because the user has to explicitly commit or unlock the records or a timeout strategy has to be implemented. Either way, the framework controls all this, *not* the database (well, except for the atomic commit/rollback in the final commit of the business transaction). Hope this helps. ~GreyCells --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
