module Sequel::Plugins::MssqlOptimisticLocking::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/mssql_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/mssql_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/mssql_optimistic_locking.rb
68 def _refresh(ds)
69   clear_instance_filters
70   super
71 end
_save_update_all_columns_hash() click to toggle source

Remove the lock column from the columns to update. SQL Server automatically updates the lock column value, and does not like it to be assigned.

   # File lib/sequel/plugins/mssql_optimistic_locking.rb
76 def _save_update_all_columns_hash
77   v = @values.dup
78   cc = changed_columns
79   Array(primary_key).each{|x| v.delete(x) unless cc.include?(x)}
80   v.delete(model.lock_column)
81   v
82 end
_update_without_checking(columns) click to toggle source

Add an OUTPUT clause to fetch the updated timestamp when updating the row.

   # File lib/sequel/plugins/mssql_optimistic_locking.rb
85 def _update_without_checking(columns)
86   ds = _update_dataset
87   lc = model.lock_column
88   rows = ds.clone(ds.send(:default_server_opts, :sql=>ds.output(nil, [Sequel[:inserted][lc]]).update_sql(columns))).all
89   values[lc] = rows.first[lc] unless rows.empty?
90   rows.length
91 end
lock_column_instance_filter() click to toggle source

Add the lock column instance filter to the object.

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