Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
52b029d7
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,发现更多精彩内容 >>
提交
52b029d7
编写于
10月 21, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DefaultTransactionAttribute stores descriptor (method identification)
Issue: SPR-14760
上级
67a5ff02
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
87 addition
and
32 deletion
+87
-32
spring-core/src/main/java/org/springframework/util/ClassUtils.java
...re/src/main/java/org/springframework/util/ClassUtils.java
+17
-4
spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java
...terceptor/AbstractFallbackTransactionAttributeSource.java
+21
-19
spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java
.../transaction/interceptor/DefaultTransactionAttribute.java
+26
-3
spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java
...ork/transaction/interceptor/TransactionAspectSupport.java
+19
-2
spring-tx/src/test/java/org/springframework/transaction/interceptor/MapTransactionAttributeSource.java
...ransaction/interceptor/MapTransactionAttributeSource.java
+4
-4
未找到文件。
spring-core/src/main/java/org/springframework/util/ClassUtils.java
浏览文件 @
52b029d7
...
...
@@ -511,8 +511,21 @@ public abstract class ClassUtils {
* @return the qualified name of the method
*/
public
static
String
getQualifiedMethodName
(
Method
method
)
{
return
getQualifiedMethodName
(
method
,
null
);
}
/**
* Return the qualified name of the given method, consisting of
* fully qualified interface/class name + "." + method name.
* @param method the method
* @param clazz the clazz that the method is being invoked on
* (may be {@code null} to indicate the method's declaring class)
* @return the qualified name of the method
* @since 4.3.4
*/
public
static
String
getQualifiedMethodName
(
Method
method
,
Class
<?>
clazz
)
{
Assert
.
notNull
(
method
,
"Method must not be null"
);
return
method
.
getDeclaringClass
().
getName
()
+
"."
+
method
.
getName
();
return
(
clazz
!=
null
?
clazz
:
method
.
getDeclaringClass
()).
getName
()
+
'.'
+
method
.
getName
();
}
/**
...
...
@@ -640,10 +653,10 @@ public abstract class ClassUtils {
return
candidates
.
iterator
().
next
();
}
else
if
(
candidates
.
isEmpty
())
{
throw
new
IllegalStateException
(
"Expected method not found: "
+
clazz
+
"."
+
methodName
);
throw
new
IllegalStateException
(
"Expected method not found: "
+
clazz
.
getName
()
+
'.'
+
methodName
);
}
else
{
throw
new
IllegalStateException
(
"No unique method found: "
+
clazz
+
"."
+
methodName
);
throw
new
IllegalStateException
(
"No unique method found: "
+
clazz
.
getName
()
+
'.'
+
methodName
);
}
}
}
...
...
@@ -980,7 +993,7 @@ public abstract class ClassUtils {
public
static
String
addResourcePathToPackagePath
(
Class
<?>
clazz
,
String
resourceName
)
{
Assert
.
notNull
(
resourceName
,
"Resource name must not be null"
);
if
(!
resourceName
.
startsWith
(
"/"
))
{
return
classPackageAsResourcePath
(
clazz
)
+
"/"
+
resourceName
;
return
classPackageAsResourcePath
(
clazz
)
+
'/'
+
resourceName
;
}
return
classPackageAsResourcePath
(
clazz
)
+
resourceName
;
}
...
...
spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java
浏览文件 @
52b029d7
...
...
@@ -97,20 +97,22 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
}
else
{
// We need to work it out.
TransactionAttribute
txAtt
=
computeTransactionAttribute
(
method
,
targetClass
);
TransactionAttribute
txAtt
r
=
computeTransactionAttribute
(
method
,
targetClass
);
// Put it in the cache.
if
(
txAtt
==
null
)
{
if
(
txAtt
r
==
null
)
{
this
.
attributeCache
.
put
(
cacheKey
,
NULL_TRANSACTION_ATTRIBUTE
);
}
else
{
String
methodIdentification
=
ClassUtils
.
getQualifiedMethodName
(
method
,
targetClass
);
if
(
txAttr
instanceof
DefaultTransactionAttribute
)
{
((
DefaultTransactionAttribute
)
txAttr
).
setDescriptor
(
methodIdentification
);
}
if
(
logger
.
isDebugEnabled
())
{
Class
<?>
classToLog
=
(
targetClass
!=
null
?
targetClass
:
method
.
getDeclaringClass
());
logger
.
debug
(
"Adding transactional method '"
+
classToLog
.
getSimpleName
()
+
"."
+
method
.
getName
()
+
"' with attribute: "
+
txAtt
);
logger
.
debug
(
"Adding transactional method '"
+
methodIdentification
+
"' with attribute: "
+
txAttr
);
}
this
.
attributeCache
.
put
(
cacheKey
,
txAtt
);
this
.
attributeCache
.
put
(
cacheKey
,
txAtt
r
);
}
return
txAtt
;
return
txAtt
r
;
}
}
...
...
@@ -148,27 +150,27 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
specificMethod
=
BridgeMethodResolver
.
findBridgedMethod
(
specificMethod
);
// First try is the method in the target class.
TransactionAttribute
txAtt
=
findTransactionAttribute
(
specificMethod
);
if
(
txAtt
!=
null
)
{
return
txAtt
;
TransactionAttribute
txAtt
r
=
findTransactionAttribute
(
specificMethod
);
if
(
txAtt
r
!=
null
)
{
return
txAtt
r
;
}
// Second try is the transaction attribute on the target class.
txAtt
=
findTransactionAttribute
(
specificMethod
.
getDeclaringClass
());
if
(
txAtt
!=
null
&&
ClassUtils
.
isUserLevelMethod
(
method
))
{
return
txAtt
;
txAtt
r
=
findTransactionAttribute
(
specificMethod
.
getDeclaringClass
());
if
(
txAtt
r
!=
null
&&
ClassUtils
.
isUserLevelMethod
(
method
))
{
return
txAtt
r
;
}
if
(
specificMethod
!=
method
)
{
// Fallback is to look at the original method.
txAtt
=
findTransactionAttribute
(
method
);
if
(
txAtt
!=
null
)
{
return
txAtt
;
txAtt
r
=
findTransactionAttribute
(
method
);
if
(
txAtt
r
!=
null
)
{
return
txAtt
r
;
}
// Last fallback is the class of the original method.
txAtt
=
findTransactionAttribute
(
method
.
getDeclaringClass
());
if
(
txAtt
!=
null
&&
ClassUtils
.
isUserLevelMethod
(
method
))
{
return
txAtt
;
txAtt
r
=
findTransactionAttribute
(
method
.
getDeclaringClass
());
if
(
txAtt
r
!=
null
&&
ClassUtils
.
isUserLevelMethod
(
method
))
{
return
txAtt
r
;
}
}
...
...
spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java
浏览文件 @
52b029d7
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -19,10 +19,11 @@ package org.springframework.transaction.interceptor;
import
org.springframework.transaction.support.DefaultTransactionDefinition
;
/**
*
Transaction attribute that takes the EJB approach to rolling
*
back on runtime, but not checked, exceptions
.
*
Spring's common transaction attribute implementation.
*
Rolls back on runtime, but not checked, exceptions by default
.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @since 16.03.2003
*/
@SuppressWarnings
(
"serial"
)
...
...
@@ -30,6 +31,8 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im
private
String
qualifier
;
private
String
descriptor
;
/**
* Create a new DefaultTransactionAttribute, with default settings.
...
...
@@ -74,6 +77,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im
* Associate a qualifier value with this transaction attribute.
* <p>This may be used for choosing a corresponding transaction manager
* to process this specific transaction.
* @since 3.0
*/
public
void
setQualifier
(
String
qualifier
)
{
this
.
qualifier
=
qualifier
;
...
...
@@ -81,12 +85,31 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im
/**
* Return a qualifier value associated with this transaction attribute.
* @since 3.0
*/
@Override
public
String
getQualifier
()
{
return
this
.
qualifier
;
}
/**
* Set a descriptor for this transaction attribute,
* e.g. indicating where the attribute is applying.
* @since 4.3.4
*/
public
void
setDescriptor
(
String
descriptor
)
{
this
.
descriptor
=
descriptor
;
}
/**
* Return a descriptor for this transaction attribute,
* or {@code null} if none.
* @since 4.3.4
*/
public
String
getDescriptor
()
{
return
this
.
descriptor
;
}
/**
* The default behavior is as with EJB: rollback on unchecked exception.
* Additionally attempt to rollback on Error.
...
...
spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java
浏览文件 @
52b029d7
...
...
@@ -34,6 +34,7 @@ import org.springframework.transaction.TransactionStatus;
import
org.springframework.transaction.TransactionSystemException
;
import
org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager
;
import
org.springframework.transaction.support.TransactionCallback
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ConcurrentReferenceHashMap
;
import
org.springframework.util.StringUtils
;
...
...
@@ -269,7 +270,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
// If the transaction attribute is null, the method is non-transactional.
final
TransactionAttribute
txAttr
=
getTransactionAttributeSource
().
getTransactionAttribute
(
method
,
targetClass
);
final
PlatformTransactionManager
tm
=
determineTransactionManager
(
txAttr
);
final
String
joinpointIdentification
=
methodIdentification
(
method
,
targetClass
);
final
String
joinpointIdentification
=
methodIdentification
(
method
,
targetClass
,
txAttr
);
if
(
txAttr
==
null
||
!(
tm
instanceof
CallbackPreferringPlatformTransactionManager
))
{
// Standard transaction demarcation with getTransaction and commit/rollback calls.
...
...
@@ -385,17 +386,33 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
return
txManager
;
}
private
String
methodIdentification
(
Method
method
,
Class
<?>
targetClass
,
TransactionAttribute
txAttr
)
{
String
methodIdentification
=
methodIdentification
(
method
,
targetClass
);
if
(
methodIdentification
==
null
)
{
if
(
txAttr
instanceof
DefaultTransactionAttribute
)
{
methodIdentification
=
((
DefaultTransactionAttribute
)
txAttr
).
getDescriptor
();
}
if
(
methodIdentification
==
null
)
{
methodIdentification
=
ClassUtils
.
getQualifiedMethodName
(
method
,
targetClass
);
}
}
return
methodIdentification
;
}
/**
* Convenience method to return a String representation of this Method
* for use in logging. Can be overridden in subclasses to provide a
* different identifier for the given method.
* <p>The default implementation returns {@code null}, indicating the
* use of {@link DefaultTransactionAttribute#getDescriptor()} instead,
* ending up as {@link ClassUtils#getQualifiedMethodName(Method, Class)}.
* @param method the method we're interested in
* @param targetClass the class that the method is being invoked on
* @return a String representation identifying this method
* @see org.springframework.util.ClassUtils#getQualifiedMethodName
*/
protected
String
methodIdentification
(
Method
method
,
Class
<?>
targetClass
)
{
return
(
targetClass
!=
null
?
targetClass
:
method
.
getDeclaringClass
()).
getName
()
+
"."
+
method
.
getName
()
;
return
null
;
}
/**
...
...
spring-tx/src/test/java/org/springframework/transaction/interceptor/MapTransactionAttributeSource.java
浏览文件 @
52b029d7
...
...
@@ -31,12 +31,12 @@ public class MapTransactionAttributeSource extends AbstractFallbackTransactionAt
private
final
Map
<
Object
,
TransactionAttribute
>
attributeMap
=
new
HashMap
<>();
public
void
register
(
Method
method
,
TransactionAttribute
txAtt
)
{
this
.
attributeMap
.
put
(
method
,
txAtt
);
public
void
register
(
Method
method
,
TransactionAttribute
txAtt
r
)
{
this
.
attributeMap
.
put
(
method
,
txAtt
r
);
}
public
void
register
(
Class
<?>
clazz
,
TransactionAttribute
txAtt
)
{
this
.
attributeMap
.
put
(
clazz
,
txAtt
);
public
void
register
(
Class
<?>
clazz
,
TransactionAttribute
txAtt
r
)
{
this
.
attributeMap
.
put
(
clazz
,
txAtt
r
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录