Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb
Class Method Summary collapse
Class Method Details
.establish_adapter(adapter) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb', line 42 def establish_adapter(adapter) raise AdapterNotSpecified.new("database configuration does not specify adapter") unless adapter raise AdapterNotFound.new("database pool must specify adapters") if adapter == 'MariaDB_Cluster_Pool' begin require 'rubygems' gem "activerecord-#{adapter}-adapter" require "active_record/connection_adapters/#{adapter}_adapter" rescue LoadError => e begin require "active_record/connection_adapters/#{adapter}_adapter" rescue LoadError => ee raise "Please install the #{adapter} adapter: `gem install activerecord-#{adapter}-adapter` (#{$!})" end end adapter_method = "#{adapter}_connection" if !respond_to?(adapter_method) raise AdapterNotFound, "database configuration specifies nonexistent #{adapter} adapter" end end |
.maria_db_cluster_pool_connection(config) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb', line 4 def maria_db_cluster_pool_connection(config) pool_weights = {} config = config.with_indifferent_access default_config = {:pool_weight => 1}.merge(config.merge(:adapter => config[:pool_adapter])).with_indifferent_access default_config.delete(:server_pool) default_config.delete(:pool_adapter) pool_connections = [] config[:server_pool].each do |server_config| server_config = default_config.merge(server_config).with_indifferent_access server_config[:pool_weight] = server_config[:pool_weight].to_i begin establish_adapter(server_config[:adapter]) conn = send("#{server_config[:adapter]}_connection".to_sym, server_config) # conn.class.send(:include, MariaDbClusterPool::ConnectTimeout) unless conn.class.include?(MariaDbClusterPool::ConnectTimeout) # conn.connect_timeout = server_config[:connect_timeout] pool_connections << conn pool_weights[conn] = server_config[:pool_weight] rescue Exception => e if logger logger.error("Error connecting to read connection #{server_config.inspect}") logger.error(e) end end end if config[:server_pool] @maria_db_cluster_pool_classes ||= {} klass = @maria_db_cluster_pool_classes[pool_connections[0].class] unless klass.present? klass = ActiveRecord::ConnectionAdapters::MariaDbClusterPoolAdapter.adapter_class(pool_connections[0]) @maria_db_cluster_pool_classes[pool_connections[0].class] = klass end return klass.new(pool_connections[0], logger, pool_connections, pool_weights) end |