@@ -2,18 +2,35 @@ module AfterCommit
22 module ConnectionAdapters
33 def self . included ( base )
44 base . class_eval do
5- def transaction_with_callback ( *args , &block )
6- # @disable_rollback is set to false at the start of the
7- # outermost call to #transaction. After committing, it is
8- # set to true to prevent exceptions causing a spurious
9- # rollback.
10- outermost_call = @disable_rollback . nil?
11- @disable_rollback = false if outermost_call
12- transaction_without_callback ( *args , &block )
13- ensure
14- @disable_rollback = nil if outermost_call
15- end
16- alias_method_chain :transaction , :callback
5+
6+ if respond_to? ( :transaction )
7+ def transaction_with_callback ( *args , &block )
8+ # @disable_rollback is set to false at the start of the
9+ # outermost call to #transaction. After committing, it is
10+ # set to true to prevent exceptions causing a spurious
11+ # rollback.
12+ outermost_call = @disable_rollback . nil?
13+ @disable_rollback = false if outermost_call
14+ transaction_without_callback ( *args , &block )
15+ ensure
16+ @disable_rollback = nil if outermost_call
17+ end
18+ alias_method_chain :transaction , :callback
19+
20+ elsif respond_to? ( :begin_db_transaction )
21+ def begin_db_transaction_with_callback ( *args , &block )
22+ # @disable_rollback is set to false at the start of the
23+ # outermost call to #transaction. After committing, it is
24+ # set to true to prevent exceptions causing a spurious
25+ # rollback.
26+ outermost_call = @disable_rollback . nil?
27+ @disable_rollback = false if outermost_call
28+ begin_db_transaction_without_callback ( *args , &block )
29+ ensure
30+ @disable_rollback = nil if outermost_call
31+ end
32+ alias_method_chain :begin_db_transaction , :callback
33+ end
1734
1835 # The commit_db_transaction method gets called when the outermost
1936 # transaction finishes and everything inside commits. We want to
@@ -53,7 +70,7 @@ def commit_db_transaction_with_callback
5370 AfterCommit . cleanup ( self )
5471 decrement_transaction_pointer unless @already_decremented
5572 end
56- end
73+ end
5774 alias_method_chain :commit_db_transaction , :callback
5875
5976 # In the event the transaction fails and rolls back, nothing inside
0 commit comments