Changeset 3222
- Timestamp:
- 12/05/05 21:48:23 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/base.rb
r3218 r3222 244 244 cattr_accessor :logger 245 245 246 @@connection_cache = Hash.new { |h, k| h[k] = Hash.new }247 248 # Returns the connection currently associated with the class. This can249 # also be used to "borrow" the connection to do database work unrelated250 # to any of the specific Active Records.251 def self.connection252 @@connection_cache[Thread.current.object_id][name] ||= retrieve_connection253 end254 255 def self.clear_connection_cache!256 @@connection_cache.clear257 end258 259 # Returns the connection currently associated with the class. This can260 # also be used to "borrow" the connection to do database work that isn't261 # easily done without going straight to SQL.262 def connection263 self.class.connection264 end265 266 246 def self.inherited(child) #:nodoc: 267 247 @@subclasses[self] ||= [] trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
r3218 r3222 11 11 # The class -> [adapter_method, config] map 12 12 @@defined_connections = {} 13 14 # The class -> thread id -> adapter cache. 15 @@connection_cache = Hash.new { |h, k| h[k] = Hash.new } 16 17 # Returns the connection currently associated with the class. This can 18 # also be used to "borrow" the connection to do database work unrelated 19 # to any of the specific Active Records. 20 def self.connection 21 @@connection_cache[Thread.current.object_id][name] ||= retrieve_connection 22 end 23 24 # Clears the cache which maps classes to connections. 25 def self.clear_connection_cache! 26 @@connection_cache.clear 27 end 28 29 # Returns the connection currently associated with the class. This can 30 # also be used to "borrow" the connection to do database work that isn't 31 # easily done without going straight to SQL. 32 def connection 33 self.class.connection 34 end 13 35 14 36 # Establishes the connection to the database. Accepts a hash as input where … … 112 134 conn = @@defined_connections[klass.name] 113 135 @@defined_connections.delete(klass.name) 114 active_connections[klass.name] = nil 136 @@connection_cache[Thread.current.object_id].delete(klass.name) 137 active_connections.delete(klass.name) 115 138 @connection = nil 116 139 conn.config if conn