public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Rename defined_connections to connection_pools

- Distinguis meaning of "active_connections" to always mean connections
  associated with the current thread
Nick (author)
Fri Apr 18 22:34:22 -0700 2008
commit  5879b15f23f080badedbbab7835eda8c2c748a52
tree    26d7a2ddcf4b9a844f0e7bf93427f6f0ff09c5a6
parent  6edaa267174dfedaf5b152b9eba25b4eb5e34c99
...
15
16
17
18
 
19
20
21
22
23
 
 
 
 
 
24
25
26
...
32
33
34
35
36
 
 
37
38
39
40
41
42
 
43
44
45
46
 
 
 
 
 
 
47
48
49
 
50
51
52
...
97
98
99
100
 
101
102
103
...
140
141
142
143
 
144
145
146
...
156
157
158
159
160
 
 
161
162
163
...
15
16
17
 
18
19
20
21
22
 
23
24
25
26
27
28
29
30
...
36
37
38
 
 
39
40
41
42
43
44
45
 
46
47
48
49
50
51
52
53
54
55
56
57
58
 
59
60
61
62
...
107
108
109
 
110
111
112
113
...
150
151
152
 
153
154
155
156
...
166
167
168
 
 
169
170
171
172
173
0
@@ -15,12 +15,16 @@ module ActiveRecord
0
     @@verification_timeout = 0
0
 
0
     # The class -> connection pool map
0
-    @@defined_connections = {}
0
+    @@connection_pools = {}
0
 
0
     class << self
0
       # for internal use only
0
       def active_connections
0
-        @@defined_connections.inject([]) {|arr,kv| arr << kv.last.active_connection}.compact.uniq
0
+        @@connection_pools.inject({}) do |hash,kv|
0
+          hash[kv.first] = kv.last.active_connection
0
+          hash.delete(kv.first) unless hash[kv.first]
0
+          hash
0
+        end
0
       end
0
 
0
       # Returns the connection currently associated with the class. This can
0
@@ -32,21 +36,27 @@ module ActiveRecord
0
 
0
       # Clears the cache which maps classes to connections.
0
       def clear_active_connections!
0
-        clear_cache!(@@defined_connections) do |name, pool|
0
-          pool.disconnect!
0
+        clear_cache!(@@connection_pools) do |name, pool|
0
+          pool.clear_active_connections!
0
         end
0
       end
0
       
0
       # Clears the cache which maps classes 
0
       def clear_reloadable_connections!
0
-        clear_cache!(@@defined_connections) do |name, pool|
0
+        clear_cache!(@@connection_pools) do |name, pool|
0
           pool.clear_reloadable_connections!
0
         end
0
       end
0
 
0
+      def clear_all_connections!
0
+        clear_cache!(@@connection_pools) do |name, pool|
0
+          pool.disconnect!
0
+        end
0
+      end
0
+
0
       # Verify active connections.
0
       def verify_active_connections! #:nodoc:
0
-        @@defined_connections.each_value {|pool| pool.verify_active_connections!}
0
+        @@connection_pools.each_value {|pool| pool.verify_active_connections!}
0
       end
0
 
0
       private
0
@@ -97,7 +107,7 @@ module ActiveRecord
0
           raise AdapterNotSpecified unless defined? RAILS_ENV
0
           establish_connection(RAILS_ENV)
0
         when ConnectionSpecification
0
-          @@defined_connections[name] = ConnectionAdapters::ConnectionPool.new(spec)
0
+          @@connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec)
0
         when Symbol, String
0
           if configuration = configurations[spec.to_s]
0
             establish_connection(configuration)
0
@@ -140,7 +150,7 @@ module ActiveRecord
0
     end
0
 
0
     def self.retrieve_connection_pool
0
-      pool = @@defined_connections[name]
0
+      pool = @@connection_pools[name]
0
       return pool if pool
0
       return nil if ActiveRecord::Base == self
0
       superclass.retrieve_connection_pool
0
@@ -156,8 +166,8 @@ module ActiveRecord
0
     # can be used as an argument for establish_connection, for easily
0
     # re-establishing the connection.
0
     def self.remove_connection(klass=self)
0
-      pool = @@defined_connections[klass.name]
0
-      @@defined_connections.delete_if { |key, value| value == pool }
0
+      pool = @@connection_pools[klass.name]
0
+      @@connection_pools.delete_if { |key, value| value == pool }
0
       pool.disconnect! if pool
0
       pool.spec.config if pool
0
     end
...
26
27
28
29
 
30
31
32
...
26
27
28
 
29
30
31
32
0
@@ -26,7 +26,7 @@ unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name
0
       5.times do
0
         Thread.new do
0
           Topic.find :first
0
-          @connections << ActiveRecord::Base.active_connections.first
0
+          @connections << ActiveRecord::Base.active_connections.values.first
0
         end.join
0
       end
0
     end

Comments