module Sequel::Plugins::OptimisticLocking::InstanceMethods

Public Instance Methods

before_destroy() click to toggle source

Add the lock column instance filter to the object before destroying it.

Calls superclass method
   # File lib/sequel/plugins/optimistic_locking.rb
46 def before_destroy
47   lock_column_instance_filter
48   super
49 end
before_update() click to toggle source

Add the lock column instance filter to the object before updating it.

Calls superclass method
   # File lib/sequel/plugins/optimistic_locking.rb
52 def before_update
53   lock_column_instance_filter
54   super
55 end

Private Instance Methods

_refresh(ds) click to toggle source

Clear the instance filters when refreshing, so that attempting to refresh after a failed save removes the previous lock column filter (the new one will be added before updating).

Calls superclass method
   # File lib/sequel/plugins/optimistic_locking.rb
68 def _refresh(ds)
69   clear_instance_filters
70   super
71 end
_update_columns(columns) click to toggle source

Only update the row if it has the same lock version, and increment the lock version.

Calls superclass method
   # File lib/sequel/plugins/optimistic_locking.rb
75 def _update_columns(columns)
76   lc = model.lock_column
77   lcv = get_column_value(lc)
78   columns[lc] = lcv + 1
79   super
80   set_column_value("#{lc}=", lcv + 1)
81 end
lock_column_instance_filter() click to toggle source

Add the lock column instance filter to the object.

   # File lib/sequel/plugins/optimistic_locking.rb
60 def lock_column_instance_filter
61   lc = model.lock_column
62   instance_filter(lc=>get_column_value(lc))
63 end