Class: ServicesTestServer::DbController

Inherits:
Object
  • Object
show all
Defined in:
lib/services_test_server/db_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDbController

Returns a new instance of DbController.



16
17
18
# File 'lib/services_test_server/db_controller.rb', line 16

def initialize
  @mutex = Mutex.new
end

Class Method Details

.only_one_connectionObject



6
7
8
9
10
11
12
13
14
# File 'lib/services_test_server/db_controller.rb', line 6

def self.only_one_connection
  ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
    alias_method :old_checkout, :checkout

    def checkout
      @cached_connection ||= old_checkout
    end
  end
end

Instance Method Details

#begin_transactionObject



20
21
22
23
24
# File 'lib/services_test_server/db_controller.rb', line 20

def begin_transaction
  @mutex.lock
  ServicesTestServer.logger.debug "Beginning remote transaction"
  ActiveRecord::Base.connection.begin_transaction(joinable: false)
end

#rollback_transactionObject



26
27
28
29
30
# File 'lib/services_test_server/db_controller.rb', line 26

def rollback_transaction
  ServicesTestServer.logger.debug "Rolling back remote transaction"
  ActiveRecord::Base.connection.rollback_transaction
  @mutex.unlock
end