diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 14:23:13 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 14:23:13 -0700 |
commit | d2092e7e0bb5260bd02d9eeea4decf7efa34e29c (patch) | |
tree | 58db6a0e38bbcaab67f1733aa200333d60bef0ac /lib | |
parent | 700cc8418800911aaab75e2ec1478ee958ef4df8 (diff) | |
download | rails-d2092e7e0bb5260bd02d9eeea4decf7efa34e29c.tar.gz rails-d2092e7e0bb5260bd02d9eeea4decf7efa34e29c.tar.bz2 rails-d2092e7e0bb5260bd02d9eeea4decf7efa34e29c.zip |
reorganizing classes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/algebra/relations/relation.rb | 70 | ||||
-rw-r--r-- | lib/arel/algebra/relations/utilities/externalization.rb | 10 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations.rb | 1 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/relation.rb | 65 |
4 files changed, 70 insertions, 76 deletions
diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 17a2cf3190..3f6151e27b 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -1,5 +1,7 @@ module Arel module Relation + @@connection_tables_primary_keys = {} + attr_reader :count def session @@ -18,6 +20,74 @@ module Arel self end + def externalize + @externalized ||= externalizable?? Externalization.new(self) : self + end + + def externalizable? + false + end + + def compiler + @compiler ||= begin + "Arel::SqlCompiler::#{engine.adapter_name}Compiler".constantize.new(self) + rescue + Arel::SqlCompiler::GenericCompiler.new(self) + end + end + + def to_sql(formatter = Sql::SelectStatement.new(self)) + formatter.select compiler.select_sql, self + end + + def christener + @christener ||= Sql::Christener.new + end + + def inclusion_predicate_sql + "IN" + end + + def exclusion_predicate_sql + "NOT IN" + end + + def primary_key + connection_id = engine.connection.object_id + if @@connection_tables_primary_keys[connection_id] && @@connection_tables_primary_keys[connection_id].has_key?(table.name) + @@connection_tables_primary_keys[connection_id][table.name] + else + @@connection_tables_primary_keys[connection_id] ||= {} + @@connection_tables_primary_keys[connection_id][table.name] = engine.connection.primary_key(table.name) + end + end + + protected + + def from_clauses + sources.blank? ? table_sql(Sql::TableReference.new(self)) : sources + end + + def select_clauses + attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) } + end + + def where_clauses + wheres.collect { |w| w.to_sql(Sql::WhereClause.new(self)) } + end + + def group_clauses + groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) } + end + + def having_clauses + havings.collect { |g| g.to_sql(Sql::HavingClause.new(self)) } + end + + def order_clauses + orders.collect { |o| o.to_sql(Sql::OrderClause.new(self)) } + end + module Enumerable include ::Enumerable diff --git a/lib/arel/algebra/relations/utilities/externalization.rb b/lib/arel/algebra/relations/utilities/externalization.rb index c7a7d9ca78..815e1e0aa7 100644 --- a/lib/arel/algebra/relations/utilities/externalization.rb +++ b/lib/arel/algebra/relations/utilities/externalization.rb @@ -12,14 +12,4 @@ module Arel @attributes ||= Header.new(relation.attributes.map { |a| a.to_attribute(self) }) end end - - module Relation - def externalize - @externalized ||= externalizable?? Externalization.new(self) : self - end - - def externalizable? - false - end - end end diff --git a/lib/arel/engines/sql/relations.rb b/lib/arel/engines/sql/relations.rb index 981455760f..1dea1423b8 100644 --- a/lib/arel/engines/sql/relations.rb +++ b/lib/arel/engines/sql/relations.rb @@ -3,7 +3,6 @@ require 'arel/engines/sql/relations/utilities/recursion' require 'arel/engines/sql/relations/utilities/externalization' require 'arel/engines/sql/relations/utilities/nil' require 'arel/engines/sql/relations/compiler' -require 'arel/engines/sql/relations/relation' require 'arel/engines/sql/relations/table' require 'arel/engines/sql/relations/operations/join' require 'arel/engines/sql/relations/writes' diff --git a/lib/arel/engines/sql/relations/relation.rb b/lib/arel/engines/sql/relations/relation.rb deleted file mode 100644 index 2136f85e5a..0000000000 --- a/lib/arel/engines/sql/relations/relation.rb +++ /dev/null @@ -1,65 +0,0 @@ -module Arel - module Relation - @@connection_tables_primary_keys = {} - - def compiler - @compiler ||= begin - "Arel::SqlCompiler::#{engine.adapter_name}Compiler".constantize.new(self) - rescue - Arel::SqlCompiler::GenericCompiler.new(self) - end - end - - def to_sql(formatter = Sql::SelectStatement.new(self)) - formatter.select compiler.select_sql, self - end - - def christener - @christener ||= Sql::Christener.new - end - - def inclusion_predicate_sql - "IN" - end - - def exclusion_predicate_sql - "NOT IN" - end - - def primary_key - connection_id = engine.connection.object_id - if @@connection_tables_primary_keys[connection_id] && @@connection_tables_primary_keys[connection_id].has_key?(table.name) - @@connection_tables_primary_keys[connection_id][table.name] - else - @@connection_tables_primary_keys[connection_id] ||= {} - @@connection_tables_primary_keys[connection_id][table.name] = engine.connection.primary_key(table.name) - end - end - - protected - - def from_clauses - sources.blank? ? table_sql(Sql::TableReference.new(self)) : sources - end - - def select_clauses - attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) } - end - - def where_clauses - wheres.collect { |w| w.to_sql(Sql::WhereClause.new(self)) } - end - - def group_clauses - groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) } - end - - def having_clauses - havings.collect { |g| g.to_sql(Sql::HavingClause.new(self)) } - end - - def order_clauses - orders.collect { |o| o.to_sql(Sql::OrderClause.new(self)) } - end - end -end |