aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb43
1 files changed, 18 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index d5c7caad2e..3a8fbcf93f 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -5,6 +5,7 @@ require 'active_support/core_ext/benchmark'
require 'active_record/connection_adapters/schema_cache'
require 'active_record/connection_adapters/abstract/schema_dumper'
require 'monitor'
+require 'active_support/deprecation'
module ActiveRecord
module ConnectionAdapters # :nodoc:
@@ -34,6 +35,12 @@ module ActiveRecord
autoload :QueryCache
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
# related classes form the abstraction layer which makes this possible.
# An AbstractAdapter represents a connection to a database, and provides an
@@ -64,14 +71,11 @@ module ActiveRecord
def initialize(connection, logger = nil, pool = nil) #:nodoc:
super()
- @active = nil
@connection = connection
@in_use = false
@instrumenter = ActiveSupport::Notifications.instrumenter
@last_use = false
@logger = logger
- @open_transactions = 0
- @current_transaction = nil
@pool = pool
@query_cache = Hash.new { |h,sql| h[sql] = {} }
@query_cache_enabled = false
@@ -184,19 +188,21 @@ module ActiveRecord
# checking whether the database is actually capable of responding, i.e. whether
# the connection isn't stale.
def active?
- @active != false
end
# Disconnects from the database if already connected, and establishes a
- # new connection with the database.
+ # new connection with the database. Implementors should call super if they
+ # override the default implementation.
def reconnect!
- @active = true
+ clear_cache!
+ reset_transaction
end
# Disconnects from the database if already connected. Otherwise, this
# method does nothing.
def disconnect!
- @active = false
+ clear_cache!
+ reset_transaction
end
# Reset the state of this connection, directing the DBMS to clear
@@ -240,33 +246,20 @@ module ActiveRecord
end
def open_transactions
- count = 0
- txn = current_transaction
-
- while txn
- count += 1
- txn = txn.next
- end
-
- count
+ @transaction.number
end
- attr_reader :current_transaction
-
def increment_open_transactions
- @current_transaction = Transaction.new(current_transaction)
+ ActiveSupport::Deprecation.warn "#increment_open_transactions is deprecated and has no effect"
end
def decrement_open_transactions
- return unless current_transaction
-
- txn = current_transaction
- @current_transaction = txn.next
- txn
+ ActiveSupport::Deprecation.warn "#decrement_open_transactions is deprecated and has no effect"
end
def transaction_joinable=(joinable)
- @transaction_joinable = joinable
+ ActiveSupport::Deprecation.warn "#transaction_joinable= is deprecated. Please pass the :joinable option to #begin_transaction instead."
+ @transaction.joinable = joinable
end
def create_savepoint