CakePHP中是否支持樂觀鎖定?

[英]Any support for optimistic locking in CakePHP?


I'm just starting out with CakePHP, and I can't find any support for implementing an optimistic locking scheme. The closest I could find was a comment on this CakePHP blog post saying that it wasn't supported in June 2008.

我剛剛開始使用CakePHP,我找不到任何支持來實現樂觀鎖定方案。我能找到的最接近的是對這篇CakePHP博客文章的評論,稱其在2008年6月沒有得到支持。

Does anyone know if that has changed, or if someone has published an extension or a tutorial on how to implement it yourself?

有沒有人知道這是否已經改變,或者是否有人發布了關於如何自己實現它的擴展或教程?

For a description of optimistic locking, see this answer.

有關樂觀鎖定的說明,請參閱此答案。

3 个解决方案

#1


Not in the Core, and after a quick google it doesn appear that anyone is sharing a behavior if they made one. That would be my suggested tactic.

不在核心,並且在快速谷歌之后,似乎任何人都沒有共享行為,如果他們做了一個。這將是我建議的策略。

#2


In the book "Practical CakePHP Projects" on chapter 10 is some code given to make your own "Magic Fields". One of them is a field for optimistic locking. I haven't tried it yet, but it looks quite good actually.

在第10章的“Practical CakePHP Projects”一書中,有一些代碼用於制作你自己的“Magic Fields”。其中一個是樂觀鎖定領域。我還沒試過,但實際上它看起來很不錯。

#3


Tadashi Nakamura has posted an OptimisticLock behaviour on GitHub. It's not quite perfect, because it does the query for the last modified date before writing the changed record. That leaves you open to either silently overwriting another user's changes or hitting a deadlock. When I tried to write a behaviour like this, I wanted to include the last modified date in the update's where clause and fail if the rows affected is zero. At that time, there was no support for adding an extra condition to an update query. I haven't used PHP lately, so I don't know if that has changed.

Tadashi Nakamura在GitHub上發布了一個OptimisticLock行為。它並不完美,因為它在寫入更改的記錄之前對最后修改日期進行查詢。這讓你可以默默地覆蓋其他用戶的更改或者遇到死鎖。當我嘗試編寫這樣的行為時,我想在update的where子句中包含最后修改日期,如果受影響的行為零則失敗。那時,不支持向更新查詢添加額外條件。我最近沒有使用PHP,所以我不知道這是否已經改變。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/03/30/72fb22df22723a5c4af9b8223f0028d4.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com