-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new adapter for ActiveRecord 4.2, fix #198
- Loading branch information
Showing
3 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'active_record' | ||
|
||
module EM::Synchrony | ||
module ActiveRecord | ||
module Adapter_4_2 | ||
def configure_connection | ||
nil | ||
end | ||
|
||
def transaction(*args) | ||
@connection.execute(false) do |conn| | ||
super | ||
end | ||
end | ||
|
||
def reset_transaction #:nodoc: | ||
@transaction_manager = TransactionManager.new(self) | ||
end | ||
end | ||
|
||
class TransactionManager < ::ActiveRecord::ConnectionAdapters::TransactionManager | ||
def initialize(*args) | ||
super | ||
@stack = Hash.new([]) | ||
end | ||
|
||
def current_transaction #:nodoc: | ||
_current_stack.last || NULL_TRANSACTION | ||
end | ||
|
||
def open_transactions | ||
_current_stack.size | ||
end | ||
|
||
def begin_transaction(options = {}) #:nodoc: | ||
transaction = | ||
if _current_stack.empty? | ||
::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, options) | ||
else | ||
::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", options) | ||
end | ||
_current_stack.push(transaction) | ||
transaction | ||
end | ||
|
||
def commit_transaction #:nodoc: | ||
_current_stack.pop.commit | ||
end | ||
|
||
def rollback_transaction #:nodoc: | ||
_current_stack.pop.rollback | ||
end | ||
|
||
private | ||
|
||
def _current_stack | ||
@stack[Fiber.current.object_id] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters