Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3222

Show
Ignore:
Timestamp:
12/05/05 21:48:23 (3 years ago)
Author:
bitsweat
Message:

Clear the connection cache entry when a new connection is established on the same class.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/base.rb

    r3218 r3222  
    244244    cattr_accessor :logger 
    245245 
    246     @@connection_cache = Hash.new { |h, k| h[k] = Hash.new } 
    247  
    248     # Returns the connection currently associated with the class. This can 
    249     # also be used to "borrow" the connection to do database work unrelated 
    250     # to any of the specific Active Records. 
    251     def self.connection 
    252       @@connection_cache[Thread.current.object_id][name] ||= retrieve_connection 
    253     end 
    254  
    255     def self.clear_connection_cache! 
    256       @@connection_cache.clear 
    257     end 
    258  
    259     # Returns the connection currently associated with the class. This can 
    260     # also be used to "borrow" the connection to do database work that isn't 
    261     # easily done without going straight to SQL. 
    262     def connection 
    263       self.class.connection 
    264     end 
    265  
    266246    def self.inherited(child) #:nodoc: 
    267247      @@subclasses[self] ||= [] 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb

    r3218 r3222  
    1111    # The class -> [adapter_method, config] map 
    1212    @@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 
    1335 
    1436    # Establishes the connection to the database. Accepts a hash as input where 
     
    112134      conn = @@defined_connections[klass.name] 
    113135      @@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) 
    115138      @connection = nil 
    116139      conn.config if conn