aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-09-14 18:01:00 +0100
committerJon Leighton <j@jonathanleighton.com>2012-09-15 00:00:50 +0100
commita6fbddb7be5095186e7d66aac0ef64e46b7284f9 (patch)
tree7157d4592f90c54cd2e13c0afaa15565084f0985 /activerecord
parent6d9e6b3a80ef1406c16aeb42ebb786c0a1e5b4b0 (diff)
downloadrails-a6fbddb7be5095186e7d66aac0ef64e46b7284f9.tar.gz
rails-a6fbddb7be5095186e7d66aac0ef64e46b7284f9.tar.bz2
rails-a6fbddb7be5095186e7d66aac0ef64e46b7284f9.zip
Alter the naming structure a bit
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/transaction.rb208
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb7
3 files changed, 111 insertions, 108 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index c7614b1e10..1ff46a57eb 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -4,7 +4,7 @@ module ActiveRecord
def initialize
super
@transaction_joinable = nil
- @transaction = Transaction::Closed.new(self)
+ @transaction = ClosedTransaction.new(self)
end
# Converts an arel AST to SQL
@@ -198,7 +198,7 @@ module ActiveRecord
@transaction_joinable = last_transaction_joinable
if outside_transaction?
- @transaction = Transactions::Closed.new(self)
+ @transaction = ClosedTransaction.new(self)
elsif @transaction.open? && transaction_open
begin
commit_transaction
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
index a305480d9e..f456ecae66 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
@@ -1,144 +1,142 @@
module ActiveRecord
module ConnectionAdapters
- module Transaction # :nodoc:
- class State
- attr_reader :connection
+ class Transaction #:nodoc:
+ attr_reader :connection
- def initialize(connection)
- @connection = connection
- end
+ def initialize(connection)
+ @connection = connection
end
+ end
- class Closed < State
- def number
- 0
- end
+ class ClosedTransaction < Transaction #:nodoc:
+ def number
+ 0
+ end
- def begin
- Real.new(connection, self)
- end
+ def begin
+ RealTransaction.new(connection, self)
+ end
- def closed?
- true
- end
+ def closed?
+ true
+ end
- def open?
- false
- end
+ def open?
+ false
+ end
- # This is a noop when there are no open transactions
- def add_record(record)
- end
+ # This is a noop when there are no open transactions
+ def add_record(record)
end
+ end
- class Open < State
- attr_reader :parent, :records
+ class OpenTransaction < Transaction #:nodoc:
+ attr_reader :parent, :records
- def initialize(connection, parent)
- super connection
+ def initialize(connection, parent)
+ super connection
- @parent = parent
- @records = []
- @finishing = false
- end
+ @parent = parent
+ @records = []
+ @finishing = false
+ end
- def number
- if finishing?
- parent.number
- else
- parent.number + 1
- end
+ def number
+ if finishing?
+ parent.number
+ else
+ parent.number + 1
end
+ end
- # Database adapters expect that #open_transactions will be decremented
- # before we've actually executed a COMMIT or ROLLBACK. This is kinda
- # annoying, but for now we use this @finishing flag to toggle what value
- # #number should return.
- def finishing?
- @finishing
- end
+ # Database adapters expect that #open_transactions will be decremented
+ # before we've actually executed a COMMIT or ROLLBACK. This is kinda
+ # annoying, but for now we use this @finishing flag to toggle what value
+ # #number should return.
+ def finishing?
+ @finishing
+ end
- def begin
- Savepoint.new(connection, self)
- end
+ def begin
+ SavepointTransaction.new(connection, self)
+ end
- def rollback
- @finishing = true
- perform_rollback
- parent
- end
+ def rollback
+ @finishing = true
+ perform_rollback
+ parent
+ end
- def commit
- @finishing = true
- perform_commit
- parent
- end
+ def commit
+ @finishing = true
+ perform_commit
+ parent
+ end
- def add_record(record)
- records << record
- end
+ def add_record(record)
+ records << record
+ end
- def rollback_records
- records.uniq.each do |record|
- begin
- record.rolledback!(parent.closed?)
- rescue => e
- record.logger.error(e) if record.respond_to?(:logger) && record.logger
- end
+ def rollback_records
+ records.uniq.each do |record|
+ begin
+ record.rolledback!(parent.closed?)
+ rescue => e
+ record.logger.error(e) if record.respond_to?(:logger) && record.logger
end
end
+ end
- def commit_records
- records.uniq.each do |record|
- begin
- record.committed!
- rescue => e
- record.logger.error(e) if record.respond_to?(:logger) && record.logger
- end
+ def commit_records
+ records.uniq.each do |record|
+ begin
+ record.committed!
+ rescue => e
+ record.logger.error(e) if record.respond_to?(:logger) && record.logger
end
end
+ end
- def closed?
- false
- end
+ def closed?
+ false
+ end
- def open?
- true
- end
+ def open?
+ true
end
+ end
- class Real < Open
- def initialize(connection, parent)
- super
- connection.begin_db_transaction
- end
+ class RealTransaction < OpenTransaction #:nodoc:
+ def initialize(connection, parent)
+ super
+ connection.begin_db_transaction
+ end
- def perform_rollback
- connection.rollback_db_transaction
- rollback_records
- end
+ def perform_rollback
+ connection.rollback_db_transaction
+ rollback_records
+ end
- def perform_commit
- connection.commit_db_transaction
- commit_records
- end
+ def perform_commit
+ connection.commit_db_transaction
+ commit_records
end
+ end
- class Savepoint < Open
- def initialize(connection, parent)
- super
- connection.create_savepoint
- end
+ class SavepointTransaction < OpenTransaction #:nodoc:
+ def initialize(connection, parent)
+ super
+ connection.create_savepoint
+ end
- def perform_rollback
- connection.rollback_to_savepoint
- rollback_records
- end
+ def perform_rollback
+ connection.rollback_to_savepoint
+ rollback_records
+ end
- def perform_commit
- connection.release_savepoint
- records.each { |r| parent.add_record(r) }
- end
+ def perform_commit
+ connection.release_savepoint
+ records.each { |r| parent.add_record(r) }
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index b7fcf0e512..11c6e76b0d 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -32,7 +32,12 @@ module ActiveRecord
autoload :Quoting
autoload :ConnectionPool
autoload :QueryCache
- autoload :Transaction
+ end
+
+ autoload_at 'active_record/connection_adapters/abstract/transaction' do
+ autoload :ClosedTransaction
+ autoload :RealTransaction
+ autoload :SavepointTransaction
end
# Active Record supports multiple database systems. AbstractAdapter and