diff options
author | Nick <nick@nicksieger.com> | 2008-04-19 00:34:22 -0500 |
---|---|---|
committer | Nick Sieger <nick@nicksieger.com> | 2008-08-29 14:12:08 -0500 |
commit | 5879b15f23f080badedbbab7835eda8c2c748a52 (patch) | |
tree | 26d7a2ddcf4b9a844f0e7bf93427f6f0ff09c5a6 /activerecord/lib/active_record/connection_adapters | |
parent | 6edaa267174dfedaf5b152b9eba25b4eb5e34c99 (diff) | |
download | rails-5879b15f23f080badedbbab7835eda8c2c748a52.tar.gz rails-5879b15f23f080badedbbab7835eda8c2c748a52.tar.bz2 rails-5879b15f23f080badedbbab7835eda8c2c748a52.zip |
Rename defined_connections to connection_pools
- Distinguis meaning of "active_connections" to always mean connections
associated with the current thread
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb | 30 |
1 files changed, 20 insertions, 10 deletions
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 6eee1ac8c1..b2771c60e7 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb @@ -15,12 +15,16 @@ module ActiveRecord @@verification_timeout = 0 # The class -> connection pool map - @@defined_connections = {} + @@connection_pools = {} class << self # for internal use only def active_connections - @@defined_connections.inject([]) {|arr,kv| arr << kv.last.active_connection}.compact.uniq + @@connection_pools.inject({}) do |hash,kv| + hash[kv.first] = kv.last.active_connection + hash.delete(kv.first) unless hash[kv.first] + hash + end end # Returns the connection currently associated with the class. This can @@ -32,21 +36,27 @@ module ActiveRecord # Clears the cache which maps classes to connections. def clear_active_connections! - clear_cache!(@@defined_connections) do |name, pool| - pool.disconnect! + clear_cache!(@@connection_pools) do |name, pool| + pool.clear_active_connections! end end # Clears the cache which maps classes def clear_reloadable_connections! - clear_cache!(@@defined_connections) do |name, pool| + clear_cache!(@@connection_pools) do |name, pool| pool.clear_reloadable_connections! end end + def clear_all_connections! + clear_cache!(@@connection_pools) do |name, pool| + pool.disconnect! + end + end + # Verify active connections. def verify_active_connections! #:nodoc: - @@defined_connections.each_value {|pool| pool.verify_active_connections!} + @@connection_pools.each_value {|pool| pool.verify_active_connections!} end private @@ -97,7 +107,7 @@ module ActiveRecord raise AdapterNotSpecified unless defined? RAILS_ENV establish_connection(RAILS_ENV) when ConnectionSpecification - @@defined_connections[name] = ConnectionAdapters::ConnectionPool.new(spec) + @@connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec) when Symbol, String if configuration = configurations[spec.to_s] establish_connection(configuration) @@ -140,7 +150,7 @@ module ActiveRecord end def self.retrieve_connection_pool - pool = @@defined_connections[name] + pool = @@connection_pools[name] return pool if pool return nil if ActiveRecord::Base == self superclass.retrieve_connection_pool @@ -156,8 +166,8 @@ module ActiveRecord # can be used as an argument for establish_connection, for easily # re-establishing the connection. def self.remove_connection(klass=self) - pool = @@defined_connections[klass.name] - @@defined_connections.delete_if { |key, value| value == pool } + pool = @@connection_pools[klass.name] + @@connection_pools.delete_if { |key, value| value == pool } pool.disconnect! if pool pool.spec.config if pool end |