Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
598e7c9e
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
598e7c9e
编写于
5月 05, 2016
作者:
A
Arthur Neves
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
s/specification_id/specification_name
上级
34856ba9
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
48 addition
and
48 deletion
+48
-48
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
...ve_record/connection_adapters/abstract/connection_pool.rb
+16
-16
activerecord/lib/active_record/connection_adapters/connection_specification.rb
...ve_record/connection_adapters/connection_specification.rb
+6
-6
activerecord/lib/active_record/connection_handling.rb
activerecord/lib/active_record/connection_handling.rb
+11
-11
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+1
-1
activerecord/lib/active_record/tasks/database_tasks.rb
activerecord/lib/active_record/tasks/database_tasks.rb
+1
-1
activerecord/test/cases/connection_adapters/connection_handler_test.rb
...test/cases/connection_adapters/connection_handler_test.rb
+7
-7
activerecord/test/cases/connection_specification/resolver_test.rb
...cord/test/cases/connection_specification/resolver_test.rb
+4
-4
activerecord/test/cases/multiple_db_test.rb
activerecord/test/cases/multiple_db_test.rb
+2
-2
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
浏览文件 @
598e7c9e
...
...
@@ -837,7 +837,7 @@ def connection_pool_list
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 @@ def clear_all_connections!
# 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 @@ def connected?(spec_id)
# 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 @@ def remove_connection(spec_id)
# #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 @@ def retrieve_connection_pool(spec_id)
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 @@ def owner_to_pool
@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
...
...
activerecord/lib/active_record/connection_adapters/connection_specification.rb
浏览文件 @
598e7c9e
...
...
@@ -3,10 +3,10 @@
module
ActiveRecord
module
ConnectionAdapters
class
ConnectionSpecification
#:nodoc:
attr_reader
:
config
,
:adapter_method
,
:i
d
attr_reader
:
name
,
:config
,
:adapter_metho
d
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 @@ def resolve_all
# 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 @@ def spec(config, id = nil)
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
...
...
activerecord/lib/active_record/connection_handling.rb
浏览文件 @
598e7c9e
...
...
@@ -51,7 +51,7 @@ def establish_connection(spec = nil)
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 @@ def connection
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 @@ def connection_config
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:
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
598e7c9e
...
...
@@ -257,7 +257,7 @@ def arel_table # :nodoc:
# 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
...
...
activerecord/lib/active_record/tasks/database_tasks.rb
浏览文件 @
598e7c9e
...
...
@@ -117,7 +117,7 @@ def create(*arguments)
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
)
...
...
activerecord/test/cases/connection_adapters/connection_handler_test.rb
浏览文件 @
598e7c9e
...
...
@@ -6,11 +6,11 @@ class ConnectionHandlerTest < ActiveRecord::TestCase
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 @@ def test_establish_connection_uses_spec_id
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 @@ def test_retrieve_connection_pool_copies_schema_cache_from_ancestor_pool
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!
...
...
activerecord/test/cases/connection_specification/resolver_test.rb
浏览文件 @
598e7c9e
...
...
@@ -116,14 +116,14 @@ def test_url_sub_key_for_sqlite3
"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
...
...
activerecord/test/cases/multiple_db_test.rb
浏览文件 @
598e7c9e
...
...
@@ -25,10 +25,10 @@ def test_proper_connection
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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录