Module: ActiveRecord::Bulkoperation::AbstractAdapter::InstanceMethods

Included in:
ConnectionAdapters::OracleEnhancedAdapter
Defined in:
lib/activerecord_bulkoperation/adapters/abstract_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/activerecord_bulkoperation/adapters/abstract_adapter.rb', line 6

def self.included(base)
  base.class_eval do
    alias_method :commit_db_transaction_without_callback, :commit_db_transaction
    alias_method :rollback_db_transaction_without_callback, :rollback_db_transaction
    alias_method :rollback_to_savepoint_without_callback, :rollback_to_savepoint
    alias_method :create_savepoint_without_callback, :create_savepoint

    def commit_db_transaction
      # AKu a copy of the listener array is required, because the listener can remove can modify the array
      connection_listeners.select{|l| l.respond_to?('before_commit') }.each{|l| l.before_commit}

      commit_db_transaction_without_callback

      # AKu a copy of the listener array is required, because the listener can remove can modify the array
      connection_listeners.select{|l| l.respond_to?('after_commit') }.each{|l| l.after_commit}

    end
    
    def rollback_db_transaction
      rollback_db_transaction_without_callback
      # AKu a copy of the listener array is required, because the listener can remove can modify the array
      connection_listeners.select{|l| l.respond_to?('after_rollback') }.each{|l| l.after_rollback}
    end
            
    def rollback_to_savepoint(name = current_savepoint_name)
      rollback_to_savepoint_without_callback(name)
      # AKu a copy of the listener array is required, because the listener can remove can modify the array
      connection_listeners.select{|l| l.respond_to?('after_rollback_to_savepoint') }.each{|l| l.after_rollback_to_savepoint}
    end
            
    def create_savepoint(name = current_savepoint_name)
      # AKu a copy of the listener array is required, because the listener can remove can modify the array
      connection_listeners.select{|l| l.respond_to?('before_create_savepoint') }.each{|l| l.before_create_savepoint}
      create_savepoint_without_callback(name)
    end
  end
end

Instance Method Details

#connection_listenersObject



44
45
46
# File 'lib/activerecord_bulkoperation/adapters/abstract_adapter.rb', line 44

def connection_listeners
  @connection_listeners ||= []
end