From 6bd8e351361a895e7ada7d7702bb099034103d62 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 26 Feb 2006 23:12:01 +0000 Subject: ActiveRecord::Base.remove_connection explicitly closes database connections and doesn't corrupt the connection cache. Introducing the disconnect! instance method for the PostgreSQL, MySQL, and SQL Server adapters; implementations for the others are welcome. References #3591. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3674 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../abstract/connection_specification.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract') 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 84dde1b14f..a73ce02104 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb @@ -130,12 +130,13 @@ module ActiveRecord # can be used as argument for establish_connection, for easy # re-establishing of the connection. def self.remove_connection(klass=self) - conn = @@defined_connections[klass.name] - @@defined_connections.delete(klass.name) - @@connection_cache[Thread.current.object_id].delete(klass.name) - active_connections.delete(klass.name) - @connection = nil - conn.config if conn + spec = @@defined_connections[klass.name] + konn = active_connections[klass.name] + @@defined_connections.delete_if { |key, value| value == spec } + @@connection_cache[Thread.current.object_id].delete_if { |key, value| value == konn } + active_connections.delete_if { |key, value| value == konn } + konn.disconnect! if konn + spec.config if spec end # Set the connection for the class. -- cgit v1.2.3