method

with_raw_connection

Importance_2
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ActiveRecord::ConnectionAdapters::AbstractAdapter
  • 1.0.0
  • 1.1.6
  • 1.2.6
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.8
  • 3.0.0
  • 3.0.9
  • 3.1.0
  • 3.2.1
  • 3.2.8
  • 3.2.13
  • 4.0.2
  • 4.1.8
  • 4.2.1
  • 4.2.7
  • 4.2.9
  • 5.0.0.1
  • 5.1.7
  • 5.2.3
  • 6.0.0
  • 6.1.3.1
  • 6.1.7.7
  • 7.0.0
  • 7.1.3.2 (0)
  • 7.1.3.4 (0)
  • What's this?
with_raw_connection(allow_retry: false, materialize_transactions: true) private

Lock the monitor, ensure we’re properly connected and transactions are materialized, and then yield the underlying raw connection object.

If allow_retry is true, a connection-related exception will cause an automatic reconnect and re-run of the block, up to the connection’s configured connection_retries setting and the configured retry_deadline limit. (Note that when allow_retry is true, it’s possible to return without having marked the connection as verified. If the block is guaranteed to exercise the connection, consider calling `verified!` to avoid needless verification queries in subsequent calls.)

If materialize_transactions is false, the block will be run without ensuring virtual transactions have been materialized in the DB server’s state. The active transaction will also remain clean (if it is not already dirty), meaning it’s able to be restored by reconnecting and opening an equivalent-depth set of new transactions. This should only be used by transaction control methods, and internal transaction-agnostic queries.

It’s not the primary use case, so not something to optimize for, but note that this method does need to be re-entrant: materialize_transactions will re-enter if it has work to do, and the yield block can also do so under some circumstances.

In the latter case, we really ought to guarantee the inner call will not reconnect (which would interfere with the still-yielded connection in the outer block), but we currently provide no special enforcement there.

Show source
Register or log in to add new notes.