Class: Familia::Connection::ProviderConnectionHandler

Inherits:
Object
  • Object
show all
Includes:
Handler
Defined in:
lib/familia/connection/handlers.rb

Overview

Delegates to user-defined connection provider

Provider pattern = full flexibility. Use ad-hoc, operations, whatever you like. For each connection, choose one and then get another connection. Rapid-fire sub ms connection pool connection checkouts are all good and also expected how they are to be used. This is where connection pools live

Instance Method Summary collapse

Constructor Details

#initialize(familia_module = nil) ⇒ ProviderConnectionHandler

Returns a new instance of ProviderConnectionHandler.



131
132
133
# File 'lib/familia/connection/handlers.rb', line 131

def initialize(familia_module = nil)
  @familia_module = familia_module || Familia
end

Instance Method Details

#handle(uri) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/familia/connection/handlers.rb', line 135

def handle(uri)
  return nil unless @familia_module.connection_provider

  @familia_module.trace :DBCLIENT_PROVIDER, nil, 'Using connection provider'

  # Determine the correct URI including logical database if needed
  if uri.nil? && @familia_module.respond_to?(:logical_database) && @familia_module.logical_database
    uri = @familia_module.logical_database
  end

  # Always pass normalized URI with database to provider
  # Provider MUST return connection already on the correct database
  parsed_uri = @familia_module.normalize_uri(uri)
  @familia_module.connection_provider.call(parsed_uri.to_s)
end