public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Fixed that each request with the WEBrick adapter would open a new database 
connection #1685 [Sam Stephenson]. Added 
ActiveRecord::Base.threaded_connections flag to turn off 1-connection per 
thread (required for thread safety). By default it's on, but WEBrick in 
Rails need it off #1685 [Sam Stephenson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1792 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Sat Jul 09 21:54:34 -0700 2005
commit  60499774c2a8ecd9d87b140ffbe24634559c3fcd
tree    e4e2a348e4dae4d107f020f9c21664a5e169b92c
parent  e008bfd2d8e8e19eb94ddb49121820effe93d7f4
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Added ActiveRecord::Base.threaded_connections flag to turn off 1-connection per thread (required for thread safety). By default it's on, but WEBrick in Rails need it off #1685 [Sam Stephenson]
0
+
0
 * Correct reflected table name for singular associations. #1688 [court3nay@gmail.com]
0
 
0
 * Fixed optimistic locking with SQL Server #1660 [tom@popdog.net]
...
289
290
291
 
 
 
 
 
292
293
294
...
289
290
291
292
293
294
295
296
297
298
299
0
@@ -289,6 +289,11 @@ module ActiveRecord #:nodoc:
0
     # This is set to :local by default.
0
     cattr_accessor :default_timezone
0
     @@default_timezone = :local
0
+
0
+ # Determines whether or not to use a connection for each thread, or a single shared connection for all threads.
0
+ # Defaults to true; Railties' WEBrick server sets this to false.
0
+ cattr_accessor :threaded_connections
0
+ @@threaded_connections = true
0
 
0
     class << self # Class methods
0
       # Find operates with three different retreval approaches:
...
86
87
88
 
 
 
 
 
 
 
 
89
90
91
...
94
95
96
97
 
98
99
100
...
109
110
111
112
 
113
114
115
...
125
126
127
128
129
 
130
131
132
...
134
135
136
137
138
 
139
140
141
...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
102
103
104
 
105
106
107
108
...
117
118
119
 
120
121
122
123
...
133
134
135
 
 
136
137
138
139
...
141
142
143
 
 
144
145
146
147
0
@@ -86,6 +86,14 @@ module ActiveRecord
0
       end
0
     end
0
 
0
+ def self.active_connections #:nodoc:
0
+ if threaded_connections
0
+ Thread.current['active_connections'] ||= {}
0
+ else
0
+ @@active_connections ||= {}
0
+ end
0
+ end
0
+
0
     # Locate the connection of the nearest super class. This can be an
0
     # active or defined connections: if it is the latter, it will be
0
     # opened and set as the active connection for the class it was defined
0
@@ -94,7 +102,7 @@ module ActiveRecord
0
       klass = self
0
       ar_super = ActiveRecord::Base.superclass
0
       until klass == ar_super
0
- if conn = (Thread.current['active_connections'] ||= {})[klass]
0
+ if conn = active_connections[klass]
0
           return conn
0
         elsif conn = @@defined_connections[klass]
0
           klass.connection = conn
0
@@ -109,7 +117,7 @@ module ActiveRecord
0
     def self.connected?
0
       klass = self
0
       until klass == ActiveRecord::Base.superclass
0
- if Thread.current['active_connections'].is_a?(Hash) && Thread.current['active_connections'][klass]
0
+ if active_connections[klass]
0
           return true
0
         else
0
           klass = klass.superclass
0
@@ -125,8 +133,7 @@ module ActiveRecord
0
     def self.remove_connection(klass=self)
0
       conn = @@defined_connections[klass]
0
       @@defined_connections.delete(klass)
0
- Thread.current['active_connections'] ||= {}
0
- Thread.current['active_connections'][klass] = nil
0
+ active_connections[klass] = nil
0
       conn.config if conn
0
     end
0
 
0
@@ -134,8 +141,7 @@ module ActiveRecord
0
     def self.connection=(spec)
0
       raise ConnectionNotEstablished unless spec
0
       conn = self.send(spec.adapter_method, spec.config)
0
- Thread.current['active_connections'] ||= {}
0
- Thread.current['active_connections'][self] = conn
0
+ active_connections[self] = conn
0
     end
0
 
0
     # Converts all strings in a hash to symbols.
...
51
52
53
54
55
 
56
57
58
...
51
52
53
 
 
54
55
56
57
0
@@ -51,8 +51,7 @@ module ActiveRecord
0
         QueryCache.new(self.send(spec.adapter_method, spec.config)) :
0
         self.send(spec.adapter_method, spec.config)
0
       
0
- Thread.current['active_connections'] ||= {}
0
- Thread.current['active_connections'][self] = conn
0
+ active_connections[self] = conn
0
     end
0
   end
0
   
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Fixed that each request with the WEBrick adapter would open a new database connection #1685 [Sam Stephenson]
0
+
0
 * Added support for SQL Server in the database rake tasks #1652 [ken.barker@gmail.com] Note: osql and scptxfr may need to be installed on your development environment. This involves getting the .exes and a .rll (scptxfr) from a production SQL Server (not developer level SQL Server). Add their location to your Environment PATH and you are all set.
0
 
0
 * Added a VERSION parameter to the migrate task that allows you to do "rake migrate VERSION=34" to migrate to the 34th version traveling up or down depending on the current version
...
8
9
10
 
 
11
12
13
...
8
9
10
11
12
13
14
15
0
@@ -8,6 +8,8 @@ include WEBrick
0
 
0
 ABSOLUTE_RAILS_ROOT = File.expand_path(RAILS_ROOT)
0
 
0
+ActiveRecord::Base.threaded_connections = false
0
+
0
 class CGI
0
   def stdinput
0
     @stdin || $stdin

Comments

    No one has commented yet.