Class

ActiveRecord::ConnectionAdapters::ConnectionHandler

Inheritance
< Object

ConnectionHandler is a collection of ConnectionPool objects. It is used for keeping separate connection pools for ActiveRecord 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. ActiveRecord models use this to determine that connection pool that they should use.

Methods

Class

Visibility Signature
public new (pools = {})

Instance

Visibility Signature
public clear_active_connections! ()
public clear_all_connections! ()
public clear_reloadable_connections! ()
public connected? (klass)
public connection_pools ()
public establish_connection (name, spec)
public remove_connection (klass)
public retrieve_connection_pool (klass)

Class Method Detail

new(pools = {})

Instance Method Detail

clear_active_connections!()

Returns any connections in use by the current thread back to the pool, and also returns connections to the pool cached by threads that are no longer alive.

clear_all_connections!()

clear_reloadable_connections!()

Clears the cache which maps classes

connected?(klass)

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

connection_pools()

establish_connection(name, spec)

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.

retrieve_connection_pool(klass)