Class: Rooq::PooledConnectionProvider
- Inherits:
-
ConnectionProvider
- Object
- ConnectionProvider
- Rooq::PooledConnectionProvider
- Defined in:
- lib/rooq/connection.rb
Overview
A connection provider that acquires connections from a pool. Connections are returned to the pool after each query.
The pool must respond to #checkout (or #acquire) and optionally #checkin. If the pool doesn't respond to #checkin, the connection's #close method is called.
Instance Attribute Summary collapse
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
Instance Method Summary collapse
-
#acquire ⇒ Object
Acquire a connection from the pool.
-
#initialize(pool) ⇒ PooledConnectionProvider
constructor
A new instance of PooledConnectionProvider.
-
#release(connection) ⇒ Object
Release a connection back to the pool.
Methods inherited from ConnectionProvider
Constructor Details
#initialize(pool) ⇒ PooledConnectionProvider
Returns a new instance of PooledConnectionProvider.
73 74 75 76 |
# File 'lib/rooq/connection.rb', line 73 def initialize(pool) super() @pool = pool end |
Instance Attribute Details
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
70 71 72 |
# File 'lib/rooq/connection.rb', line 70 def pool @pool end |
Instance Method Details
#acquire ⇒ Object
Acquire a connection from the pool.
80 81 82 83 84 85 86 87 88 |
# File 'lib/rooq/connection.rb', line 80 def acquire if @pool.respond_to?(:checkout) @pool.checkout elsif @pool.respond_to?(:acquire) @pool.acquire else raise Error, "Pool must respond to #checkout or #acquire" end end |
#release(connection) ⇒ Object
Release a connection back to the pool.
92 93 94 95 96 97 98 |
# File 'lib/rooq/connection.rb', line 92 def release(connection) if @pool.respond_to?(:checkin) @pool.checkin(connection) elsif connection.respond_to?(:close) connection.close end end |