| 1 |
Index: C:/code_work/Edge Rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb===================================================================--- C:/code_work/Edge Rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb (revision 8167)+++ C:/code_work/Edge Rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb (working copy)@@ -124,6 +124,25 @@ end |
|---|
| 2 |
end |
|---|
| 3 |
|
|---|
| 4 |
+ # Used to track the number of transactions currently running |
|---|
| 5 |
+ # on a connection. |
|---|
| 6 |
+ def open_transactions |
|---|
| 7 |
+ @open_transactions ||= 0 |
|---|
| 8 |
+ end |
|---|
| 9 |
+ |
|---|
| 10 |
+ # Increment the number of database transactions running by one. |
|---|
| 11 |
+ def increment_open_transactions |
|---|
| 12 |
+ @open_transactions ||= 0 |
|---|
| 13 |
+ @open_transactions += 1 |
|---|
| 14 |
+ end |
|---|
| 15 |
+ |
|---|
| 16 |
+ # Decrement the number of database transactions running by one. |
|---|
| 17 |
+ def decrement_open_transactions |
|---|
| 18 |
+ @open_transactions -= 1 |
|---|
| 19 |
+ end |
|---|
| 20 |
+ |
|---|
| 21 |
+ |
|---|
| 22 |
+ |
|---|
| 23 |
protected |
|---|
| 24 |
def log(sql, name) |
|---|
| 25 |
if block_given? |
|---|
| 26 |
Index: C:/code_work/Edge Rails/activerecord/lib/active_record/transactions.rb===================================================================--- C:/code_work/Edge Rails/activerecord/lib/active_record/transactions.rb (revision 8167)+++ C:/code_work/Edge Rails/activerecord/lib/active_record/transactions.rb (working copy)@@ -84,12 +84,13 @@ module ClassMethods |
|---|
| 27 |
def transaction(&block) |
|---|
| 28 |
previous_handler = trap('TERM') { raise TransactionError, "Transaction aborted" } |
|---|
| 29 |
- increment_open_transactions |
|---|
| 30 |
+ trans_count = connection.increment_open_transactions |
|---|
| 31 |
+ start_db_trans = (trans_count == 1) |
|---|
| 32 |
|
|---|
| 33 |
begin |
|---|
| 34 |
- connection.transaction(Thread.current['start_db_transaction'], &block) |
|---|
| 35 |
+ connection.transaction(start_db_trans, &block) |
|---|
| 36 |
ensure |
|---|
| 37 |
- decrement_open_transactions |
|---|
| 38 |
+ connection.decrement_open_transactions |
|---|
| 39 |
trap('TERM', previous_handler) |
|---|
| 40 |
end |
|---|
| 41 |
end |
|---|