Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b37399ab
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,体验更适合开发者的 AI 搜索 >>
提交
b37399ab
编写于
3月 27, 2013
作者:
S
Sam Saffron
提交者:
Sam
3月 27, 2013
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make connection_handler overridable per thread
上级
c56e6204
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
75 addition
and
3 deletion
+75
-3
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+7
-1
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+11
-2
activerecord/test/cases/base_test.rb
activerecord/test/cases/base_test.rb
+57
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
b37399ab
## Rails 4.0.0 (unreleased) ##
*
Allow ActiveRecord::Base.connection_handler to have thread affinity and be
settable, this effectively allows ActiveRecord to be used in a multi threaded
setup with multiple connections to multiple dbs.
*Sam Saffron*
*
`rename_column`
preserves auto_increment in mysql migrations.
Fixes #3493.
...
...
@@ -8,7 +14,7 @@
*
PostgreSQL geometric type point is supported by ActiveRecord. Fixes #7324.
*Martin Schuerrer*
*
Add suport for concurrent indexing in PostgreSQL adapter via the
`algorithm: :concurrently`
option
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
b37399ab
...
...
@@ -77,8 +77,17 @@ module Core
mattr_accessor
:disable_implicit_join_references
,
instance_writer:
false
self
.
disable_implicit_join_references
=
false
class_attribute
:connection_handler
,
instance_writer:
false
self
.
connection_handler
=
ConnectionAdapters
::
ConnectionHandler
.
new
class_attribute
:default_connection_handler
,
instance_writer:
false
def
self
.
connection_handler
Thread
.
current
[
:active_record_connection_handler
]
||
self
.
default_connection_handler
end
def
self
.
connection_handler
=
(
handler
)
Thread
.
current
[
:active_record_connection_handler
]
=
handler
end
self
.
default_connection_handler
=
ConnectionAdapters
::
ConnectionHandler
.
new
end
module
ClassMethods
...
...
activerecord/test/cases/base_test.rb
浏览文件 @
b37399ab
...
...
@@ -1578,4 +1578,61 @@ def test_default_values_are_deeply_dupped
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
assert_equal
[
'foo'
],
klass
.
all
.
merge!
(
select:
'foo'
).
select_values
end
test
"connection_handler can be overriden"
do
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
orig_handler
=
klass
.
connection_handler
new_handler
=
ActiveRecord
::
ConnectionAdapters
::
ConnectionHandler
.
new
thread_connection_handler
=
nil
t
=
Thread
.
new
do
klass
.
connection_handler
=
new_handler
thread_connection_handler
=
klass
.
connection_handler
end
t
.
join
assert_equal
klass
.
connection_handler
,
orig_handler
assert_equal
thread_connection_handler
,
new_handler
end
test
"new threads get default the default connection handler"
do
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
orig_handler
=
klass
.
connection_handler
handler
=
nil
t
=
Thread
.
new
do
handler
=
klass
.
connection_handler
end
t
.
join
assert_equal
handler
,
orig_handler
assert_equal
klass
.
connection_handler
,
orig_handler
assert_equal
klass
.
default_connection_handler
,
orig_handler
end
test
"changing a connection handler in a main thread does not poison the other threads"
do
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
orig_handler
=
klass
.
connection_handler
new_handler
=
ActiveRecord
::
ConnectionAdapters
::
ConnectionHandler
.
new
after_handler
=
nil
is_set
=
false
t
=
Thread
.
new
do
klass
.
connection_handler
=
new_handler
is_set
=
true
Thread
.
stop
after_handler
=
klass
.
connection_handler
end
while
(
!
is_set
)
Thread
.
pass
end
klass
.
connection_handler
=
orig_handler
t
.
wakeup
t
.
join
assert_equal
after_handler
,
new_handler
assert_equal
orig_handler
,
klass
.
connection_handler
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录