Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
02f56554
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,发现更多精彩内容 >>
提交
02f56554
编写于
9月 14, 2012
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure disconnecting or reconnecting resets the transaction state
上级
61951427
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
55 addition
and
9 deletion
+55
-9
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+6
-5
activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
...d/lib/active_record/connection_adapters/mysql2_adapter.rb
+2
-0
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
...rd/lib/active_record/connection_adapters/mysql_adapter.rb
+2
-1
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+2
-2
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
.../lib/active_record/connection_adapters/sqlite3_adapter.rb
+7
-1
activerecord/test/active_record/connection_adapters/fake_adapter.rb
...rd/test/active_record/connection_adapters/fake_adapter.rb
+4
-0
activerecord/test/cases/adapter_test.rb
activerecord/test/cases/adapter_test.rb
+32
-0
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
02f56554
...
...
@@ -69,7 +69,6 @@ class AbstractAdapter
def
initialize
(
connection
,
logger
=
nil
,
pool
=
nil
)
#:nodoc:
super
()
@active
=
nil
@connection
=
connection
@in_use
=
false
@instrumenter
=
ActiveSupport
::
Notifications
.
instrumenter
...
...
@@ -187,19 +186,21 @@ def disable_referential_integrity
# checking whether the database is actually capable of responding, i.e. whether
# the connection isn't stale.
def
active?
@active
!=
false
end
# Disconnects from the database if already connected, and establishes a
# new connection with the database.
# new connection with the database. Implementors should call super if they
# override the default implementation.
def
reconnect!
@active
=
true
clear_cache!
reset_transaction
end
# Disconnects from the database if already connected. Otherwise, this
# method does nothing.
def
disconnect!
@active
=
false
clear_cache!
reset_transaction
end
# Reset the state of this connection, directing the DBMS to clear
...
...
activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
浏览文件 @
02f56554
...
...
@@ -74,6 +74,7 @@ def active?
end
def
reconnect!
super
disconnect!
connect
end
...
...
@@ -82,6 +83,7 @@ def reconnect!
# Disconnects from the database if already connected.
# Otherwise, this method does nothing.
def
disconnect!
super
unless
@connection
.
nil?
@connection
.
close
@connection
=
nil
...
...
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
浏览文件 @
02f56554
...
...
@@ -189,14 +189,15 @@ def active?
end
def
reconnect!
super
disconnect!
clear_cache!
connect
end
# Disconnects from the database if already connected. Otherwise, this
# method does nothing.
def
disconnect!
super
@connection
.
close
rescue
nil
end
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
02f56554
...
...
@@ -431,7 +431,7 @@ def active?
# Close then reopen the connection.
def
reconnect!
clear_cache!
super
@connection
.
reset
configure_connection
end
...
...
@@ -444,7 +444,7 @@ def reset!
# Disconnects from the database if already connected. Otherwise, this
# method does nothing.
def
disconnect!
clear_cache!
super
@connection
.
close
rescue
nil
end
...
...
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
浏览文件 @
02f56554
...
...
@@ -104,6 +104,8 @@ class BindSubstitution < Arel::Visitors::SQLite # :nodoc:
def
initialize
(
connection
,
logger
,
config
)
super
(
connection
,
logger
)
@active
=
nil
@statements
=
StatementPool
.
new
(
@connection
,
config
.
fetch
(
:statement_limit
)
{
1000
})
@config
=
config
...
...
@@ -154,11 +156,15 @@ def supports_add_column?
true
end
def
active?
@active
!=
false
end
# Disconnects from the database if already connected. Otherwise, this
# method does nothing.
def
disconnect!
super
clear_cache!
@active
=
false
@connection
.
close
rescue
nil
end
...
...
activerecord/test/active_record/connection_adapters/fake_adapter.rb
浏览文件 @
02f56554
...
...
@@ -36,6 +36,10 @@ def merge_column(table_name, name, sql_type = nil, options = {})
def
columns
(
table_name
)
@columns
[
table_name
]
end
def
active?
true
end
end
end
end
activerecord/test/cases/adapter_test.rb
浏览文件 @
02f56554
...
...
@@ -160,4 +160,36 @@ def test_disable_referential_integrity
end
end
end
class
AdapterTestWithoutTransaction
<
ActiveRecord
::
TestCase
self
.
use_transactional_fixtures
=
false
def
setup
@klass
=
Class
.
new
(
ActiveRecord
::
Base
)
@klass
.
establish_connection
'arunit'
@connection
=
@klass
.
connection
end
def
teardown
@klass
.
remove_connection
end
test
"transaction state is reset after a reconnect"
do
skip
"in-memory db doesn't allow reconnect"
if
in_memory_db?
@connection
.
begin_transaction
assert
@connection
.
transaction_open?
@connection
.
reconnect!
assert
!
@connection
.
transaction_open?
end
test
"transaction state is reset after a disconnect"
do
skip
"in-memory db doesn't allow disconnect"
if
in_memory_db?
@connection
.
begin_transaction
assert
@connection
.
transaction_open?
@connection
.
disconnect!
assert
!
@connection
.
transaction_open?
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录