diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-08-08 23:23:51 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-08-08 23:23:51 +0100 |
commit | 79411322ae225289e1c051f4f68ed84c6349e4a0 (patch) | |
tree | 424499366dc9c7ced8a271756b86a865ce17c977 /lib | |
parent | 03b6ca269ac8dfec8f70f2b98439d45b873f9e97 (diff) | |
download | rails-79411322ae225289e1c051f4f68ed84c6349e4a0.tar.gz rails-79411322ae225289e1c051f4f68ed84c6349e4a0.tar.bz2 rails-79411322ae225289e1c051f4f68ed84c6349e4a0.zip |
Make it the responsibility of the connection to hold on to a visitor for generating SQL, rather than the TreeManager. (There is a related commit coming in Active Record.)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/nodes/node.rb | 3 | ||||
-rw-r--r-- | lib/arel/select_manager.rb | 9 | ||||
-rw-r--r-- | lib/arel/tree_manager.rb | 12 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 6 |
4 files changed, 15 insertions, 15 deletions
diff --git a/lib/arel/nodes/node.rb b/lib/arel/nodes/node.rb index 1a5bc27856..4faace3782 100644 --- a/lib/arel/nodes/node.rb +++ b/lib/arel/nodes/node.rb @@ -32,8 +32,7 @@ module Arel # # Maybe we should just use `Table.engine`? :'( def to_sql engine = Table.engine - viz = Visitors.for engine - viz.accept self + engine.connection.visitor.accept self end # Iterate through AST, nodes will be yielded depth-first diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index d95a259177..dc80150957 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -149,13 +149,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, @ctx.wheres + Compatibility::Wheres.new @engine.connection_pool, @ctx.wheres end def where_sql return if @ctx.wheres.empty? - viz = Visitors::WhereSql.new @engine + viz = Visitors::WhereSql.new @engine.connection_pool Nodes::SqlLiteral.new viz.accept @ctx end @@ -205,12 +205,13 @@ module Arel def join_sql return nil if @ctx.source.right.empty? - sql = @visitor.dup.extend(Visitors::JoinSql).accept @ctx + sql = visitor.dup.extend(Visitors::JoinSql).accept @ctx Nodes::SqlLiteral.new sql end def order_clauses - Visitors::OrderClauses.new(@engine).accept(@ast).map { |x| + visitor = Visitors::OrderClauses.new(@engine.connection_pool) + visitor.accept(@ast).map { |x| Nodes::SqlLiteral.new x } end diff --git a/lib/arel/tree_manager.rb b/lib/arel/tree_manager.rb index 5722baca77..99a7164e2e 100644 --- a/lib/arel/tree_manager.rb +++ b/lib/arel/tree_manager.rb @@ -4,21 +4,23 @@ module Arel include Arel::Relation include Arel::FactoryMethods - attr_accessor :visitor attr_reader :ast, :engine def initialize engine - @engine = engine - @visitor = Visitors.visitor_for @engine - @ctx = nil + @engine = engine + @ctx = nil end def to_dot Visitors::Dot.new.accept @ast end + def visitor + engine.connection.visitor + end + def to_sql - @visitor.accept @ast + visitor.accept @ast end def initialize_copy other diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index ec62f4fb89..d424f8602e 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -4,17 +4,15 @@ require 'date' module Arel module Visitors class ToSql < Arel::Visitors::Visitor - def initialize engine - @engine = engine + def initialize pool + @pool = pool @connection = nil - @pool = nil @quoted_tables = {} @quoted_columns = {} end def accept object self.last_column = nil - @pool = @engine.connection_pool @pool.with_connection do |conn| @connection = conn super |