aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2016-05-05 15:25:08 -0500
committerArthur Neves <arthurnn@gmail.com>2016-05-05 15:39:27 -0500
commit598e7c9e2004b85146386571372423020ba7c52a (patch)
treed9749f43554c60008fe0fb3888c332356d0ef781 /activerecord
parent34856ba9fa893bd1483ca5b08b65562cd5c02c58 (diff)
downloadrails-598e7c9e2004b85146386571372423020ba7c52a.tar.gz
rails-598e7c9e2004b85146386571372423020ba7c52a.tar.bz2
rails-598e7c9e2004b85146386571372423020ba7c52a.zip
s/specification_id/specification_name
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb32
-rw-r--r--activerecord/lib/active_record/connection_adapters/connection_specification.rb12
-rw-r--r--activerecord/lib/active_record/connection_handling.rb22
-rw-r--r--activerecord/lib/active_record/core.rb2
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb2
-rw-r--r--activerecord/test/cases/connection_adapters/connection_handler_test.rb14
-rw-r--r--activerecord/test/cases/connection_specification/resolver_test.rb8
-rw-r--r--activerecord/test/cases/multiple_db_test.rb4
8 files changed, 48 insertions, 48 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 3968b59b8f..0498737b20 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -837,7 +837,7 @@ module ActiveRecord
alias :connection_pools :connection_pool_list
def establish_connection(spec)
- owner_to_pool[spec.id] = ConnectionAdapters::ConnectionPool.new(spec)
+ owner_to_pool[spec.name] = ConnectionAdapters::ConnectionPool.new(spec)
end
# Returns true if there are any active connections among the connection
@@ -868,18 +868,18 @@ module ActiveRecord
# active or defined connection: if it is the latter, it will be
# opened and set as the active connection for the class it was defined
# for (not necessarily the current class).
- def retrieve_connection(spec_id) #:nodoc:
- pool = retrieve_connection_pool(spec_id)
- raise ConnectionNotEstablished, "No connection pool with id #{spec_id} found." unless pool
+ def retrieve_connection(spec_name) #:nodoc:
+ pool = retrieve_connection_pool(spec_name)
+ raise ConnectionNotEstablished, "No connection pool with id #{spec_name} found." unless pool
conn = pool.connection
- raise ConnectionNotEstablished, "No connection for #{spec_id} in connection pool" unless conn
+ raise ConnectionNotEstablished, "No connection for #{spec_name} in connection pool" unless conn
conn
end
# Returns true if a connection that's accessible to this class has
# already been opened.
- def connected?(spec_id)
- conn = retrieve_connection_pool(spec_id)
+ def connected?(spec_name)
+ conn = retrieve_connection_pool(spec_name)
conn && conn.connected?
end
@@ -887,8 +887,8 @@ module ActiveRecord
# connection and the defined connection (if they exist). The result
# can be used as an argument for establish_connection, for easily
# re-establishing the connection.
- def remove_connection(spec_id)
- if pool = owner_to_pool.delete(spec_id)
+ def remove_connection(spec_name)
+ if pool = owner_to_pool.delete(spec_name)
pool.automatic_reconnect = false
pool.disconnect!
pool.spec.config
@@ -904,9 +904,9 @@ module ActiveRecord
# #fetch is significantly slower than #[]. So in the nil case, no caching will
# take place, but that's ok since the nil case is not the common one that we wish
# to optimise for.
- def retrieve_connection_pool(spec_id)
- owner_to_pool.fetch(spec_id) do
- if ancestor_pool = pool_from_any_process_for(spec_id)
+ def retrieve_connection_pool(spec_name)
+ owner_to_pool.fetch(spec_name) do
+ if ancestor_pool = pool_from_any_process_for(spec_name)
# A connection was established in an ancestor process that must have
# subsequently forked. We can't reuse the connection, but we can copy
# the specification and establish a new connection with it.
@@ -914,7 +914,7 @@ module ActiveRecord
pool.schema_cache = ancestor_pool.schema_cache if ancestor_pool.schema_cache
end
else
- owner_to_pool[spec_id] = nil
+ owner_to_pool[spec_name] = nil
end
end
end
@@ -925,9 +925,9 @@ module ActiveRecord
@owner_to_pool[Process.pid]
end
- def pool_from_any_process_for(spec_id)
- owner_to_pool = @owner_to_pool.values.find { |v| v[spec_id] }
- owner_to_pool && owner_to_pool[spec_id]
+ def pool_from_any_process_for(spec_name)
+ owner_to_pool = @owner_to_pool.values.find { |v| v[spec_name] }
+ owner_to_pool && owner_to_pool[spec_name]
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
index 430937ae65..901c98b22b 100644
--- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
@@ -3,10 +3,10 @@ require 'uri'
module ActiveRecord
module ConnectionAdapters
class ConnectionSpecification #:nodoc:
- attr_reader :config, :adapter_method, :id
+ attr_reader :name, :config, :adapter_method
- def initialize(id, config, adapter_method)
- @id, @config, @adapter_method = id, config, adapter_method
+ def initialize(name, config, adapter_method)
+ @name, @config, @adapter_method = name, config, adapter_method
end
def initialize_dup(original)
@@ -164,7 +164,7 @@ module ActiveRecord
# spec.config
# # => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" }
#
- def spec(config, id = nil)
+ def spec(config, name = nil)
spec = resolve(config).symbolize_keys
raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
@@ -180,13 +180,13 @@ module ActiveRecord
adapter_method = "#{spec[:adapter]}_connection"
- id ||=
+ name ||=
if config.is_a?(Symbol)
config.to_s
else
"primary"
end
- ConnectionSpecification.new(id, spec, adapter_method)
+ ConnectionSpecification.new(name, spec, adapter_method)
end
private
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb
index 7d01c4ea48..f363a2d21b 100644
--- a/activerecord/lib/active_record/connection_handling.rb
+++ b/activerecord/lib/active_record/connection_handling.rb
@@ -51,7 +51,7 @@ module ActiveRecord
resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new configurations
# TODO: uses name on establish_connection, for backwards compatibility
spec = resolver.spec(spec, self == Base ? "primary" : name)
- self.specification_id = spec.id
+ self.specification_name = spec.name
unless respond_to?(spec.adapter_method)
raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
@@ -91,15 +91,15 @@ module ActiveRecord
retrieve_connection
end
- attr_writer :specification_id
+ attr_writer :specification_name
# Return the specification id from this class otherwise look it up
# in the parent.
- def specification_id
- unless defined?(@specification_id)
- @specification_id = self == Base ? "primary" : superclass.specification_id
+ def specification_name
+ unless defined?(@specification_name)
+ @specification_name = self == Base ? "primary" : superclass.specification_name
end
- @specification_id
+ @specification_name
end
def connection_id
@@ -121,20 +121,20 @@ module ActiveRecord
end
def connection_pool
- connection_handler.retrieve_connection_pool(specification_id) or raise ConnectionNotEstablished
+ connection_handler.retrieve_connection_pool(specification_name) or raise ConnectionNotEstablished
end
def retrieve_connection
- connection_handler.retrieve_connection(specification_id)
+ connection_handler.retrieve_connection(specification_name)
end
# Returns +true+ if Active Record is connected.
def connected?
- connection_handler.connected?(specification_id)
+ connection_handler.connected?(specification_name)
end
- def remove_connection(id = specification_id)
- connection_handler.remove_connection(id)
+ def remove_connection(name = specification_name)
+ connection_handler.remove_connection(name)
end
def clear_cache! # :nodoc:
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 291cabb4bb..4abe25e5b7 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -257,7 +257,7 @@ module ActiveRecord
# Returns the Arel engine.
def arel_engine # :nodoc:
@arel_engine ||=
- if Base == self || connection_handler.retrieve_connection_pool(specification_id)
+ if Base == self || connection_handler.retrieve_connection_pool(specification_name)
self
else
superclass.arel_engine
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index 6f5bb88d35..4fbc93496a 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -117,7 +117,7 @@ module ActiveRecord
end
def create_all
- old_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool(ActiveRecord::Base.specification_id)
+ old_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool(ActiveRecord::Base.specification_name)
each_local_configuration { |configuration| create configuration }
if old_pool
ActiveRecord::Base.connection_handler.establish_connection(old_pool.spec)
diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
index 47e8486ded..fc5ca8865b 100644
--- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb
+++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
@@ -6,11 +6,11 @@ module ActiveRecord
def setup
@handler = ConnectionHandler.new
resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new Base.configurations
- @spec_id = "primary"
- @pool = @handler.establish_connection(resolver.spec(:arunit, @spec_id))
+ @spec_name = "primary"
+ @pool = @handler.establish_connection(resolver.spec(:arunit, @spec_name))
end
- def test_establish_connection_uses_spec_id
+ def test_establish_connection_uses_spec_name
config = {"readonly" => {"adapter" => 'sqlite3'}}
resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(config)
spec = resolver.spec(:readonly)
@@ -22,19 +22,19 @@ module ActiveRecord
end
def test_retrieve_connection
- assert @handler.retrieve_connection(@spec_id)
+ assert @handler.retrieve_connection(@spec_name)
end
def test_active_connections?
assert !@handler.active_connections?
- assert @handler.retrieve_connection(@spec_id)
+ assert @handler.retrieve_connection(@spec_name)
assert @handler.active_connections?
@handler.clear_active_connections!
assert !@handler.active_connections?
end
def test_retrieve_connection_pool
- assert_not_nil @handler.retrieve_connection_pool(@spec_id)
+ assert_not_nil @handler.retrieve_connection_pool(@spec_name)
end
def test_retrieve_connection_pool_with_invalid_id
@@ -77,7 +77,7 @@ module ActiveRecord
pid = fork {
rd.close
- pool = @handler.retrieve_connection_pool(@spec_id)
+ pool = @handler.retrieve_connection_pool(@spec_name)
wr.write Marshal.dump pool.schema_cache.size
wr.close
exit!
diff --git a/activerecord/test/cases/connection_specification/resolver_test.rb b/activerecord/test/cases/connection_specification/resolver_test.rb
index 36d1e059c7..3bddaf32ec 100644
--- a/activerecord/test/cases/connection_specification/resolver_test.rb
+++ b/activerecord/test/cases/connection_specification/resolver_test.rb
@@ -116,14 +116,14 @@ module ActiveRecord
"encoding" => "utf8" }, spec)
end
- def test_spec_id_on_key_lookup
+ def test_spec_name_on_key_lookup
spec = spec(:readonly, 'readonly' => {'adapter' => 'sqlite3'})
- assert_equal "readonly", spec.id
+ assert_equal "readonly", spec.name
end
- def test_spec_id_with_inline_config
+ def test_spec_name_with_inline_config
spec = spec({'adapter' => 'sqlite3'})
- assert_equal "primary", spec.id, "should default to primary id"
+ assert_equal "primary", spec.name, "should default to primary id"
end
end
end
diff --git a/activerecord/test/cases/multiple_db_test.rb b/activerecord/test/cases/multiple_db_test.rb
index b7fc8710ca..2838315bca 100644
--- a/activerecord/test/cases/multiple_db_test.rb
+++ b/activerecord/test/cases/multiple_db_test.rb
@@ -25,10 +25,10 @@ class MultipleDbTest < ActiveRecord::TestCase
end
def test_swapping_the_connection
- old_spec_id, Course.specification_id = Course.specification_id, "primary"
+ old_spec_name, Course.specification_name = Course.specification_name, "primary"
assert_equal(Entrant.connection, Course.connection)
ensure
- Course.specification_id = old_spec_id
+ Course.specification_name = old_spec_name
end
def test_find