diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-08-08 23:27:54 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-08-08 23:28:23 +0100 |
commit | 7db90aa7c7dfe5033ad012b8ee13e6f15d1c66f0 (patch) | |
tree | c878847de183caa1c3807e5253baf7d1fdfe0f65 /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | |
parent | ff9a2e66975e8a5c9cc361ec1fd61980cd14eb3e (diff) | |
download | rails-7db90aa7c7dfe5033ad012b8ee13e6f15d1c66f0.tar.gz rails-7db90aa7c7dfe5033ad012b8ee13e6f15d1c66f0.tar.bz2 rails-7db90aa7c7dfe5033ad012b8ee13e6f15d1c66f0.zip |
Make it the responsibility of the connection to hold onto an ARel visitor for generating SQL. This improves the code architecture generally, and solves some problems with marshalling. Adapter authors please take note: you now need to define an Adapter.visitor_for method, but it degrades gracefully with a deprecation warning for now.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index ddfdb05297..61994d4a47 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -82,10 +82,11 @@ module ActiveRecord # default max pool size to 5 @size = (spec.config[:pool] && spec.config[:pool].to_i) || 5 - @connections = [] - @checked_out = [] + @connections = [] + @checked_out = [] @automatic_reconnect = true - @tables = {} + @tables = {} + @visitor = nil @columns = Hash.new do |h, table_name| h[table_name] = with_connection do |conn| @@ -298,8 +299,18 @@ module ActiveRecord :connected?, :disconnect!, :with => :@connection_mutex private + def new_connection - ActiveRecord::Base.send(spec.adapter_method, spec.config) + connection = ActiveRecord::Base.send(spec.adapter_method, spec.config) + + # TODO: This is a bit icky, and in the long term we may want to change the method + # signature for connections. Also, if we switch to have one visitor per + # connection (and therefore per thread), we can get rid of the thread-local + # variable in Arel::Visitors::ToSql. + @visitor ||= connection.class.visitor_for(self) + connection.visitor = @visitor + + connection end def current_connection_id #:nodoc: |