ConnectionHandler is a collection of ConnectionPool objects. It is used for keeping separate connection pools for Active Record models that connect to different databases.

For example, suppose that you have 5 models, with the following hierarchy:

 |
 +-- Book
 |    |
 |    +-- ScaryBook
 |    +-- GoodBook
 +-- Author
 +-- BankAccount

Suppose that Book is to connect to a separate database (i.e. one other than the default database). Then Book, ScaryBook and GoodBook will all use the same connection pool. Likewise, Author and BankAccount will use the same connection pool. However, the connection pool used by Author/BankAccount is not the same as the one used by Book/ScaryBook/GoodBook.

Normally there is only a single ConnectionHandler instance, accessible via ActiveRecord::Base.connection_handler. Active Record models use this to determine that connection pool that they should use.

Methods
A
C
E
N
R
Attributes
[R] connection_pools
Class Public methods
new(pools = {})
     # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 364
364:       def initialize(pools = {})
365:         @connection_pools = pools
366:         @class_to_pool    = {}
367:       end
Instance Public methods
active_connections?()

Returns true if there are any active connections among the connection pools that the ConnectionHandler is managing.

     # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 376
376:       def active_connections?
377:         connection_pools.values.any? { |pool| pool.active_connection? }
378:       end
clear_active_connections!()

Returns any connections in use by the current thread back to the pool.

     # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 381
381:       def clear_active_connections!
382:         @connection_pools.each_value {|pool| pool.release_connection }
383:       end
clear_all_connections!()
     # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 390
390:       def clear_all_connections!
391:         @connection_pools.each_value {|pool| pool.disconnect! }
392:       end
clear_reloadable_connections!()

Clears the cache which maps classes.

     # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 386
386:       def clear_reloadable_connections!
387:         @connection_pools.each_value {|pool| pool.clear_reloadable_connections! }
388:       end
connected?(klass)

Returns true if a connection that’s accessible to this class has already been opened.

     # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 410
410:       def connected?(klass)
411:         conn = retrieve_connection_pool(klass)
412:         conn && conn.connected?
413:       end
establish_connection(name, spec)
     # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 369
369:       def establish_connection(name, spec)
370:         @connection_pools[spec] ||= ConnectionAdapters::ConnectionPool.new(spec)
371:         @class_to_pool[name] = @connection_pools[spec]
372:       end
remove_connection(klass)

Remove the connection for this class. This will close the active connection and the defined connection (if they exist). The result can be used as an argument for establish_connection, for easily re-establishing the connection.

     # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 419
419:       def remove_connection(klass)
420:         pool = @class_to_pool.delete(klass.name)
421:         return nil unless pool
422: 
423:         @connection_pools.delete pool.spec
424:         pool.automatic_reconnect = false
425:         pool.disconnect!
426:         pool.spec.config
427:       end
retrieve_connection_pool(klass)
     # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 429
429:       def retrieve_connection_pool(klass)
430:         pool = @class_to_pool[klass.name]
431:         return pool if pool
432:         return nil if ActiveRecord::Base == klass
433:         retrieve_connection_pool klass.superclass
434:       end