Class: DBLock::Adapter::Sqlserver

Inherits:
Base
  • Object
show all
Defined in:
lib/db_lock/adapter/sqlserver.rb

Instance Method Summary collapse

Methods inherited from Base

#execute, #select_one, #select_value

Instance Method Details

#lock(name, timeout = 0) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/db_lock/adapter/sqlserver.rb', line 4

def lock(name, timeout = 0)
  connection.execute_procedure 'sp_getapplock', Resource: name,
                                                LockMode: 'Exclusive',
                                                LockOwner: 'Session',
                                                LockTimeout: (timeout * 1000).to_i,
                                                DbPrincipal: 'public'
  lock = connection.raw_connection.return_code
  lock.zero?
end

#release(name) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/db_lock/adapter/sqlserver.rb', line 14

def release(name)
  connection.execute_procedure 'sp_releaseapplock', Resource: name,
                                                    LockOwner: 'Session',
                                                    DbPrincipal: 'public'
  lock = connection.raw_connection.return_code
  lock.zero?
end