Class: ActiveRecord::ConnectionAdapters::PoolConfig

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/active_record/connection_adapters/pool_config.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_class, db_config, role, shard) ⇒ PoolConfig

Returns a new instance of PoolConfig.



28
29
30
31
32
33
34
35
36
37
# File 'lib/active_record/connection_adapters/pool_config.rb', line 28

def initialize(connection_class, db_config, role, shard)
  super()
  @server_version = nil
  self.connection_descriptor = connection_class
  @db_config = db_config
  @role = role
  @shard = shard
  @pool = nil
  INSTANCES[self] = self
end

Instance Attribute Details

#connection_descriptorObject

Returns the value of attribute connection_descriptor.



8
9
10
# File 'lib/active_record/connection_adapters/pool_config.rb', line 8

def connection_descriptor
  @connection_descriptor
end

#db_configObject (readonly)

Returns the value of attribute db_config.



8
9
10
# File 'lib/active_record/connection_adapters/pool_config.rb', line 8

def db_config
  @db_config
end

#roleObject (readonly)

Returns the value of attribute role.



8
9
10
# File 'lib/active_record/connection_adapters/pool_config.rb', line 8

def role
  @role
end

#schema_reflectionObject



11
12
13
# File 'lib/active_record/connection_adapters/pool_config.rb', line 11

def schema_reflection
  @schema_reflection ||= SchemaReflection.new(db_config.lazy_schema_cache_path)
end

#server_version(connection) ⇒ Object



39
40
41
# File 'lib/active_record/connection_adapters/pool_config.rb', line 39

def server_version(connection)
  @server_version || synchronize { @server_version ||= connection.get_database_version }
end

#shardObject (readonly)

Returns the value of attribute shard.



8
9
10
# File 'lib/active_record/connection_adapters/pool_config.rb', line 8

def shard
  @shard
end

Class Method Details

.discard_pools!Object



19
20
21
# File 'lib/active_record/connection_adapters/pool_config.rb', line 19

def discard_pools!
  INSTANCES.each_key(&:discard_pool!)
end

.disconnect_all!Object



23
24
25
# File 'lib/active_record/connection_adapters/pool_config.rb', line 23

def disconnect_all!
  INSTANCES.each_key { |c| c.disconnect!(automatic_reconnect: true) }
end

Instance Method Details

#discard_pool!Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/active_record/connection_adapters/pool_config.rb', line 69

def discard_pool!
  return unless @pool

  synchronize do
    return unless @pool

    @pool.discard!
    @pool = nil
  end
end

#disconnect!(automatic_reconnect: false) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/active_record/connection_adapters/pool_config.rb', line 52

def disconnect!(automatic_reconnect: false)
  return unless @pool

  synchronize do
    return unless @pool

    @pool.automatic_reconnect = automatic_reconnect
    @pool.disconnect!
  end

  nil
end

#poolObject



65
66
67
# File 'lib/active_record/connection_adapters/pool_config.rb', line 65

def pool
  @pool || synchronize { @pool ||= ConnectionAdapters::ConnectionPool.new(self) }
end