Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
53d06739
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
53d06739
编写于
8月 02, 2019
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '5.1.x'
上级
9be32798
7c2e2d40
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
17 deletion
+19
-17
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java
...mework/jdbc/datasource/LazyConnectionDataSourceProxy.java
+4
-10
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java
...work/jdbc/datasource/TransactionAwareDataSourceProxy.java
+4
-4
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java
...rk/jdbc/datasource/DataSourceTransactionManagerTests.java
+11
-3
未找到文件。
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java
浏览文件 @
53d06739
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -354,18 +354,12 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
this
.
holdability
=
(
Integer
)
args
[
0
];
return
null
;
}
else
if
(
method
.
getName
().
equals
(
"commit"
))
{
else
if
(
method
.
getName
().
equals
(
"commit"
)
||
method
.
getName
().
equals
(
"rollback"
)
)
{
// Ignore: no statements created yet.
return
null
;
}
else
if
(
method
.
getName
().
equals
(
"rollback"
))
{
// Ignore: no statements created yet.
return
null
;
}
else
if
(
method
.
getName
().
equals
(
"getWarnings"
))
{
return
null
;
}
else
if
(
method
.
getName
().
equals
(
"clearWarnings"
))
{
else
if
(
method
.
getName
().
equals
(
"getWarnings"
)
||
method
.
getName
().
equals
(
"clearWarnings"
))
{
// Ignore: no warnings to expose yet.
return
null
;
}
else
if
(
method
.
getName
().
equals
(
"close"
))
{
...
...
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java
浏览文件 @
53d06739
...
...
@@ -203,10 +203,6 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
return
true
;
}
}
else
if
(
method
.
getName
().
equals
(
"getWarnings"
)
||
method
.
getName
().
equals
(
"clearWarnings"
))
{
// Avoid creation of target Connection on pre-close cleanup (e.g. in Hibernate Session)
return
null
;
}
else
if
(
method
.
getName
().
equals
(
"close"
))
{
// Handle close method: only close if not within a transaction.
DataSourceUtils
.
doReleaseConnection
(
this
.
target
,
this
.
targetDataSource
);
...
...
@@ -218,6 +214,10 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
}
if
(
this
.
target
==
null
)
{
if
(
method
.
getName
().
equals
(
"getWarnings"
)
||
method
.
getName
().
equals
(
"clearWarnings"
))
{
// Avoid creation of target Connection on pre-close cleanup (e.g. Hibernate Session)
return
null
;
}
if
(
this
.
closed
)
{
throw
new
SQLException
(
"Connection handle already closed"
);
}
...
...
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java
浏览文件 @
53d06739
...
...
@@ -125,6 +125,7 @@ public class DataSourceTransactionManagerTests {
if
(
lazyConnection
)
{
given
(
con
.
getAutoCommit
()).
willReturn
(
autoCommit
);
given
(
con
.
getTransactionIsolation
()).
willReturn
(
Connection
.
TRANSACTION_READ_COMMITTED
);
given
(
con
.
getWarnings
()).
willThrow
(
new
SQLException
());
}
if
(!
lazyConnection
||
createStatement
)
{
...
...
@@ -152,6 +153,10 @@ public class DataSourceTransactionManagerTests {
if
(
createStatement
)
{
tCon
.
createStatement
();
}
else
{
tCon
.
getWarnings
();
tCon
.
clearWarnings
();
}
}
catch
(
SQLException
ex
)
{
throw
new
UncategorizedSQLException
(
""
,
""
,
ex
);
...
...
@@ -703,7 +708,6 @@ public class DataSourceTransactionManagerTests {
SQLException
failure
=
new
SQLException
();
given
(
ds2
.
getConnection
()).
willThrow
(
failure
);
final
TransactionTemplate
tt
=
new
TransactionTemplate
(
tm
);
tt
.
setPropagationBehavior
(
TransactionDefinition
.
PROPAGATION_REQUIRES_NEW
);
...
...
@@ -1024,12 +1028,12 @@ public class DataSourceTransactionManagerTests {
ordered
.
verify
(
con
).
setAutoCommit
(
false
);
ordered
.
verify
(
con
).
setAutoCommit
(
true
);
verify
(
con
).
close
();
}
@Test
public
void
testTransactionAwareDataSourceProxy
()
throws
Exception
{
given
(
con
.
getAutoCommit
()).
willReturn
(
true
);
given
(
con
.
getWarnings
()).
willThrow
(
new
SQLException
());
TransactionTemplate
tt
=
new
TransactionTemplate
(
tm
);
boolean
condition1
=
!
TransactionSynchronizationManager
.
hasResource
(
ds
);
...
...
@@ -1041,6 +1045,9 @@ public class DataSourceTransactionManagerTests {
assertThat
(
DataSourceUtils
.
getConnection
(
ds
)).
isEqualTo
(
con
);
TransactionAwareDataSourceProxy
dsProxy
=
new
TransactionAwareDataSourceProxy
(
ds
);
try
{
Connection
tCon
=
dsProxy
.
getConnection
();
tCon
.
getWarnings
();
tCon
.
clearWarnings
();
assertThat
(((
ConnectionProxy
)
dsProxy
.
getConnection
()).
getTargetConnection
()).
isEqualTo
(
con
);
// should be ignored
dsProxy
.
getConnection
().
close
();
...
...
@@ -1286,7 +1293,8 @@ public class DataSourceTransactionManagerTests {
assertThat
(
condition
).
as
(
"Hasn't thread connection"
).
isTrue
();
}
@Test
public
void
testTransactionWithPropagationNotSupported
()
throws
Exception
{
@Test
public
void
testTransactionWithPropagationNotSupported
()
throws
Exception
{
TransactionTemplate
tt
=
new
TransactionTemplate
(
tm
);
tt
.
setPropagationBehavior
(
TransactionDefinition
.
PROPAGATION_NOT_SUPPORTED
);
boolean
condition1
=
!
TransactionSynchronizationManager
.
hasResource
(
ds
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录