Module: Glue::Locking
- Defined in:
- lib/glue/optimistic_locking.rb
Overview
Include this module into entity classes to provide optimistic locking suport. For more information on optimistic locking please consult:
c2.com/cgi/wiki?OptimisticLocking en.wikipedia.org/wiki/Optimistic_concurrency_control
Instance Method Summary collapse
Instance Method Details
#save_with_lock ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/glue/optimistic_locking.rb', line 42 def save_with_lock lock = @lock_version @lock_version += 1 unless save_without_lock(:condition => "lock_version=#{lock}") == 1 raise(StaleObjectError, 'Attempted to update a stale object') end end |
#update_with_lock ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/glue/optimistic_locking.rb', line 33 def update_with_lock lock = @lock_version @lock_version += 1 unless update_without_lock(:condition => "lock_version=#{lock}") == 1 raise(StaleObjectError, 'Attempted to update a stale object') end end |