From c5f9fbf0d66ddeaf1fb2992e696ffe88244bda82 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 19 Nov 2011 18:57:36 -0800 Subject: calling cache methods against the connection --- lib/arel/select_manager.rb | 8 ++++---- lib/arel/visitors/to_sql.rb | 30 ++++++++++++------------------ 2 files changed, 16 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index ce8a9caf23..82b73cf3aa 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -51,7 +51,7 @@ module Arel if $VERBOSE warn "(#{caller.first}) where_clauses is deprecated and will be removed in arel 3.0.0 with no replacement" end - to_sql = Visitors::ToSql.new @engine.connection_pool + to_sql = Visitors::ToSql.new @engine.connection @ctx.wheres.map { |c| to_sql.accept c } end @@ -161,13 +161,13 @@ module Arel def wheres warn "#{caller[0]}: SelectManager#wheres is deprecated and will be removed in ARel 3.0.0 with no replacement" - Compatibility::Wheres.new @engine.connection_pool, @ctx.wheres + Compatibility::Wheres.new @engine.connection, @ctx.wheres end def where_sql return if @ctx.wheres.empty? - viz = Visitors::WhereSql.new @engine.connection_pool + viz = Visitors::WhereSql.new @engine.connection Nodes::SqlLiteral.new viz.accept @ctx end @@ -222,7 +222,7 @@ module Arel end def order_clauses - visitor = Visitors::OrderClauses.new(@engine.connection_pool) + visitor = Visitors::OrderClauses.new(@engine.connection) visitor.accept(@ast).map { |x| Nodes::SqlLiteral.new x } diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index b414234766..ab48ce8724 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -4,30 +4,22 @@ require 'date' module Arel module Visitors class ToSql < Arel::Visitors::Visitor - def initialize pool - @pool = pool - @connection = nil + attr_accessor :last_column + + def initialize connection + @connection = connection + @schema_cache = connection.schema_cache @quoted_tables = {} @quoted_columns = {} + @last_column = nil end def accept object self.last_column = nil - @pool.with_connection do |conn| - @connection = conn - super - end + super end private - def last_column= col - Thread.current[:arel_visitors_to_sql_last_column] = col - end - - def last_column - Thread.current[:arel_visitors_to_sql_last_column] - end - def visit_Arel_Nodes_DeleteStatement o [ "DELETE FROM #{visit o.relation}", @@ -97,7 +89,7 @@ key on UpdateManager using UpdateManager#key= end def table_exists? name - @pool.table_exists? name + @schema_cache.table_exists? name end def column_for attr @@ -110,7 +102,7 @@ key on UpdateManager using UpdateManager#key= end def column_cache - @pool.columns_hash + @schema_cache.columns_hash end def visit_Arel_Nodes_Values o @@ -387,7 +379,9 @@ key on UpdateManager using UpdateManager#key= alias :visit_Bignum :literal alias :visit_Fixnum :literal - def quoted o; quote(o, last_column) end + def quoted o + quote(o, last_column) + end alias :visit_ActiveSupport_Multibyte_Chars :quoted alias :visit_ActiveSupport_StringInquirer :quoted -- cgit v1.2.3