class Simple::Sharding::ConnectionHandler

Public Class Methods

connected?(shard_id) click to toggle source
# File lib/simple/sharding/connection_handler.rb, line 39
def self.connected?(shard_id)
  connection_handler.connected?(connection_pool_owner(shard_id))
end
connection_handler() click to toggle source
# File lib/simple/sharding/connection_handler.rb, line 26
def self.connection_handler
  raise 'Shards::ConnectionHandler was not setup' unless defined? @@connection_handler
  @@connection_handler
end
connection_pool(shard_id) click to toggle source
# File lib/simple/sharding/connection_handler.rb, line 31
def self.connection_pool(shard_id)
  connection_handler.retrieve_connection_pool(connection_pool_owner(shard_id))
end
connection_pool_owner(shard_id) click to toggle source
# File lib/simple/sharding/connection_handler.rb, line 47
def self.connection_pool_owner(shard_id)
  @@connection_pool_owners[shard_id] ||= ConnectionPoolOwner.new(shard_id)
end
remove_connection(shard_id) click to toggle source
# File lib/simple/sharding/connection_handler.rb, line 43
def self.remove_connection(shard_id)
  connection_handler.remove_connection(connection_pool_owner(shard_id))
end
retrie_connection(shard_id) click to toggle source
# File lib/simple/sharding/connection_handler.rb, line 35
def self.retrie_connection(shard_id)
  connection_handler.retrieve_connection(connection_pool_owner(shard_id))
end
setup() click to toggle source
# File lib/simple/sharding/connection_handler.rb, line 21
def self.setup
  @@connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
  @@connection_pool_owners = {}
end

Public Instance Methods

check(shard_id) click to toggle source

check

# File lib/simple/sharding/connection_handler.rb, line 4
def check(shard_id)
  shard_id.present?
end
connect(shard_id) click to toggle source
# File lib/simple/sharding/connection_handler.rb, line 15
def connect(shard_id)
  resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(Config.config(shard_id))
  connect_spec = resolver.spec(shard_id.to_sym)
  connect_spec
end
connect_all() click to toggle source

establish all connection

# File lib/simple/sharding/connection_handler.rb, line 9
def connect_all
  Core.config.keys.each do |shard_id|
    connect(shard_id)
  end
end