Class: ActiveRecord::ConnectionAdapters::Transaction
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::Transaction
show all
- Defined in:
- lib/active_record/connection_adapters/abstract/transaction.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(connection, options) ⇒ Transaction
Returns a new instance of Transaction.
50
51
52
53
54
55
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 50
def initialize(connection, options)
@connection = connection
@state = TransactionState.new
@records = []
@joinable = options.fetch(:joinable, true)
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
47
48
49
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 47
def connection
@connection
end
|
#joinable=(value) ⇒ Object
Sets the attribute joinable
48
49
50
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 48
def joinable=(value)
@joinable = value
end
|
#records ⇒ Object
Returns the value of attribute records.
47
48
49
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 47
def records
@records
end
|
#savepoint_name ⇒ Object
Returns the value of attribute savepoint_name.
47
48
49
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 47
def savepoint_name
@savepoint_name
end
|
#state ⇒ Object
Returns the value of attribute state.
47
48
49
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 47
def state
@state
end
|
Instance Method Details
#add_record(record) ⇒ Object
57
58
59
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 57
def add_record(record)
records << record
end
|
#closed? ⇒ Boolean
103
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 103
def closed?; false; end
|
#commit ⇒ Object
81
82
83
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 81
def commit
@state.set_state(:committed)
end
|
#commit_records ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 85
def commit_records
ite = records.uniq
while record = ite.shift
begin
record.committed!
rescue => e
raise if ActiveRecord::Base.raise_in_transactional_callbacks
record.logger.error(e) if record.respond_to?(:logger) && record.logger
end
end
ensure
ite.each do |i|
i.committed!(false)
end
end
|
#full_rollback? ⇒ Boolean
101
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 101
def full_rollback?; true; end
|
#joinable? ⇒ Boolean
102
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 102
def joinable?; @joinable; end
|
#open? ⇒ Boolean
104
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 104
def open?; !closed?; end
|
#rollback ⇒ Object
61
62
63
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 61
def rollback
@state.set_state(:rolledback)
end
|
#rollback_records ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 65
def rollback_records
ite = records.uniq
while record = ite.shift
begin
record.rolledback! full_rollback?
rescue => e
raise if ActiveRecord::Base.raise_in_transactional_callbacks
record.logger.error(e) if record.respond_to?(:logger) && record.logger
end
end
ensure
ite.each do |i|
i.rolledback!(full_rollback?, false)
end
end
|