aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb33
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb5
-rwxr-xr-xactiverecord/lib/active_record/fixtures.rb2
4 files changed, 12 insertions, 36 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 4232b18450..d8cdf225d6 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -243,11 +243,17 @@ module ActiveRecord #:nodoc:
# on to any new database connections made and which can be retrieved on both a class and instance level by calling +logger+.
cattr_accessor :logger
+ @@connection_cache = Hash.new { |h, k| h[k] = Hash.new }
+
# Returns the connection currently associated with the class. This can
# also be used to "borrow" the connection to do database work unrelated
# to any of the specific Active Records.
def self.connection
- retrieve_connection
+ @@connection_cache[Thread.current.object_id][name] ||= retrieve_connection
+ end
+
+ def self.clear_connection_cache!
+ @@connection_cache.clear
end
# Returns the connection currently associated with the class. This can
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
index 5ef200fd97..4ef31e8beb 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
@@ -1,28 +1,4 @@
module ActiveRecord
- module ConnectionAdapters
- module ConnectionManagement
- # Check whether the connection should be checked for activity before use.
- def needs_verification?
- @needs_verification == true
- end
-
- # Flag the connection for an activity check before use.
- def needs_verification!
- @needs_verification = true
- end
-
- # If the connection is flagged for an activity check, check whether
- # it is active and reconnect if not.
- def verify!
- if needs_verification?
- reconnect! unless active?
- @needs_verification = false
- end
- self
- end
- end
- end
-
# The root class of all active record objects.
class Base
class ConnectionSpecification #:nodoc:
@@ -102,8 +78,8 @@ module ActiveRecord
ar_super = ActiveRecord::Base.superclass
until klass == ar_super
if conn = active_connections[klass.name]
- # Validate the active connection before returning it.
- conn.verify!
+ # Reconnect if the connection is inactive.
+ conn.reconnect! unless conn.active?
return conn
elsif conn = @@defined_connections[klass.name]
# Activate this connection specification.
@@ -152,10 +128,5 @@ module ActiveRecord
establish_connection spec
end
end
-
- # Mark active connections for verification on next retrieve_connection.
- def self.mark_active_connections_for_verification! #:nodoc:
- active_connections.values.each { |conn| conn.needs_verification! }
- 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 bb6202666e..19812dda86 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -19,7 +19,7 @@ module ActiveRecord
# SchemaStatements#add_column, SchemaStatements#change_column and
# SchemaStatements#remove_column are very useful.
class AbstractAdapter
- include Quoting, DatabaseStatements, SchemaStatements, ConnectionManagement
+ include Quoting, DatabaseStatements, SchemaStatements
@@row_even = true
def initialize(connection, logger = nil) #:nodoc:
@@ -69,9 +69,6 @@ module ActiveRecord
nil
end
rescue Exception => e
- # Flag connection as possibly dirty; needs verification before use.
- self.needs_verification!
-
# Log message and raise exception.
message = "#{e.class.name}: #{e.message}: #{sql}"
log_info(message, name, 0)
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 8c2c0cdc3c..3adbd9b228 100755
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -503,6 +503,8 @@ module Test #:nodoc:
alias_method :setup, :setup_with_fixtures
def teardown_with_fixtures
+ ActiveRecord::Base.clear_connection_cache!
+ ensure
# Rollback changes.
if use_transactional_fixtures?
ActiveRecord::Base.connection.rollback_db_transaction