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, line 44
def before_destroy
  lock_column_instance_filter
  super
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, line 50
def before_update
  lock_column_instance_filter
  super
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, line 66
def _refresh(ds)
  clear_instance_filters
  super
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, line 74
def _save_update_all_columns_hash
  v = @values.dup
  Array(primary_key).each{|x| v.delete(x) unless changed_columns.include?(x)}
  v.delete(model.lock_column)
  v
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, line 82
def _update_without_checking(columns)
  ds = _update_dataset
  lc = model.lock_column
  rows = ds.clone(ds.send(:default_server_opts, :sql=>ds.output(nil, [Sequel.qualify(:inserted, lc)]).update_sql(columns))).all
  values[lc] = rows.first[lc] unless rows.empty?
  rows.length
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, line 58
def lock_column_instance_filter
  lc = model.lock_column
  instance_filter(lc=>Sequel.blob(get_column_value(lc)))
end