Skip to content

Commit 8e571de

Browse files
committed
Polishing
1 parent 8f513f8 commit 8e571de

File tree

6 files changed

+62
-64
lines changed

6 files changed

+62
-64
lines changed

spring-context/src/main/java/org/springframework/cache/annotation/CacheAnnotationParser.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,40 @@
2424

2525
/**
2626
* Strategy interface for parsing known caching annotation types.
27-
* {@link AnnotationCacheOperationSource} delegates to such
28-
* parsers for supporting specific annotation types such as Spring's own
29-
* {@link Cacheable}, {@link CachePut} or {@link CacheEvict}.
27+
* {@link AnnotationCacheOperationSource} delegates to such parsers
28+
* for supporting specific annotation types such as Spring's own
29+
* {@link Cacheable}, {@link CachePut} and{@link CacheEvict}.
3030
*
3131
* @author Costin Leau
3232
* @author Stephane Nicoll
3333
* @since 3.1
34+
* @see AnnotationCacheOperationSource
35+
* @see SpringCacheAnnotationParser
3436
*/
3537
public interface CacheAnnotationParser {
3638

3739
/**
38-
* Parses the cache definition for the given class,
39-
* based on a known annotation type.
40-
* <p>This essentially parses a known cache annotation into Spring's
41-
* metadata attribute class. Returns {@code null} if the class
42-
* is not cacheable.
40+
* Parse the cache definition for the given class,
41+
* based on an annotation type understood by this parser.
42+
* <p>This essentially parses a known cache annotation into Spring's metadata
43+
* attribute class. Returns {@code null} if the class is not cacheable.
4344
* @param type the annotated class
44-
* @return the configured caching operation,
45-
* or {@code null} if none was found
45+
* @return the configured caching operation, or {@code null} if none found
4646
* @see AnnotationCacheOperationSource#findCacheOperations(Class)
4747
*/
4848
@Nullable
4949
Collection<CacheOperation> parseCacheAnnotations(Class<?> type);
5050

5151
/**
52-
* Parses the cache definition for the given method,
53-
* based on a known annotation type.
54-
* <p>This essentially parses a known cache annotation into Spring's
55-
* metadata attribute class. Returns {@code null} if the method
56-
* is not cacheable.
52+
* Parse the cache definition for the given method,
53+
* based on an annotation type understood by this parser.
54+
* <p>This essentially parses a known cache annotation into Spring's metadata
55+
* attribute class. Returns {@code null} if the method is not cacheable.
5756
* @param method the annotated method
58-
* @return the configured caching operation,
59-
* or {@code null} if none was found
57+
* @return the configured caching operation, or {@code null} if none found
6058
* @see AnnotationCacheOperationSource#findCacheOperations(Method)
6159
*/
6260
@Nullable
6361
Collection<CacheOperation> parseCacheAnnotations(Method method);
62+
6463
}

spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,22 @@ private Collection<CacheOperation> computeCacheOperations(Method method, @Nullab
163163

164164

165165
/**
166-
* Subclasses need to implement this to return the caching attribute
167-
* for the given method, if any.
168-
* @param method the method to retrieve the attribute for
169-
* @return all caching attribute associated with this method
170-
* (or {@code null} if none)
166+
* Subclasses need to implement this to return the caching attribute for the
167+
* given class, if any.
168+
* @param clazz the class to retrieve the attribute for
169+
* @return all caching attribute associated with this class, or {@code null} if none
171170
*/
172171
@Nullable
173-
protected abstract Collection<CacheOperation> findCacheOperations(Method method);
172+
protected abstract Collection<CacheOperation> findCacheOperations(Class<?> clazz);
174173

175174
/**
176-
* Subclasses need to implement this to return the caching attribute
177-
* for the given class, if any.
178-
* @param clazz the class to retrieve the attribute for
179-
* @return all caching attribute associated with this class
180-
* (or {@code null} if none)
175+
* Subclasses need to implement this to return the caching attribute for the
176+
* given method, if any.
177+
* @param method the method to retrieve the attribute for
178+
* @return all caching attribute associated with this method, or {@code null} if none
181179
*/
182180
@Nullable
183-
protected abstract Collection<CacheOperation> findCacheOperations(Class<?> clazz);
181+
protected abstract Collection<CacheOperation> findCacheOperations(Method method);
184182

185183
/**
186184
* Should only public methods be allowed to have caching semantics?

spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public void properExceptionForExistingProxyDependencyMismatch() {
9999
fail("Should have thrown UnsatisfiedDependencyException");
100100
}
101101
catch (UnsatisfiedDependencyException ex) {
102-
ex.printStackTrace();
103102
assertTrue(ex.getCause() instanceof BeanNotOfRequiredTypeException);
104103
}
105104
}
@@ -114,7 +113,6 @@ public void properExceptionForResolvedProxyDependencyMismatch() {
114113
fail("Should have thrown UnsatisfiedDependencyException");
115114
}
116115
catch (UnsatisfiedDependencyException ex) {
117-
ex.printStackTrace();
118116
assertTrue(ex.getCause() instanceof BeanNotOfRequiredTypeException);
119117
}
120118
}
@@ -244,8 +242,8 @@ public void customExecutorBeanConfig() throws InterruptedException {
244242
ctx.close();
245243
}
246244

247-
@Test
248-
public void spr14949FindsOnInterfaceWithInterfaceProxy() throws InterruptedException {
245+
@Test // SPR-14949
246+
public void findOnInterfaceWithInterfaceProxy() throws InterruptedException {
249247
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14949ConfigA.class);
250248

251249
AsyncInterface asyncBean = ctx.getBean(AsyncInterface.class);
@@ -256,8 +254,8 @@ public void spr14949FindsOnInterfaceWithInterfaceProxy() throws InterruptedExcep
256254
ctx.close();
257255
}
258256

259-
@Test
260-
public void spr14949FindsOnInterfaceWithCglibProxy() throws InterruptedException {
257+
@Test // SPR-14949
258+
public void findOnInterfaceWithCglibProxy() throws InterruptedException {
261259
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14949ConfigB.class);
262260

263261
AsyncInterface asyncBean = ctx.getBean(AsyncInterface.class);

spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ public AnnotationTransactionAttributeSource(Set<TransactionAnnotationParser> ann
139139

140140
@Override
141141
@Nullable
142-
protected TransactionAttribute findTransactionAttribute(Method method) {
143-
return determineTransactionAttribute(method);
142+
protected TransactionAttribute findTransactionAttribute(Class<?> clazz) {
143+
return determineTransactionAttribute(clazz);
144144
}
145145

146146
@Override
147147
@Nullable
148-
protected TransactionAttribute findTransactionAttribute(Class<?> clazz) {
149-
return determineTransactionAttribute(clazz);
148+
protected TransactionAttribute findTransactionAttribute(Method method) {
149+
return determineTransactionAttribute(method);
150150
}
151151

152152
/**

spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
5555
* Canonical value held in cache to indicate no transaction attribute was
5656
* found for this method, and we don't need to look again.
5757
*/
58-
private static final TransactionAttribute NULL_TRANSACTION_ATTRIBUTE = new DefaultTransactionAttribute();
58+
@SuppressWarnings("serial")
59+
private static final TransactionAttribute NULL_TRANSACTION_ATTRIBUTE = new DefaultTransactionAttribute() {
60+
@Override
61+
public String toString() {
62+
return "null";
63+
}
64+
};
5965

6066

6167
/**
@@ -90,15 +96,15 @@ public TransactionAttribute getTransactionAttribute(Method method, @Nullable Cla
9096

9197
// First, see if we have a cached value.
9298
Object cacheKey = getCacheKey(method, targetClass);
93-
Object cached = this.attributeCache.get(cacheKey);
99+
TransactionAttribute cached = this.attributeCache.get(cacheKey);
94100
if (cached != null) {
95101
// Value will either be canonical value indicating there is no transaction attribute,
96102
// or an actual transaction attribute.
97103
if (cached == NULL_TRANSACTION_ATTRIBUTE) {
98104
return null;
99105
}
100106
else {
101-
return (TransactionAttribute) cached;
107+
return cached;
102108
}
103109
}
104110
else {
@@ -182,25 +188,22 @@ protected TransactionAttribute computeTransactionAttribute(Method method, @Nulla
182188

183189

184190
/**
185-
* Subclasses need to implement this to return the transaction attribute
186-
* for the given method, if any.
187-
* @param method the method to retrieve the attribute for
188-
* @return all transaction attribute associated with this method
189-
* (or {@code null} if none)
191+
* Subclasses need to implement this to return the transaction attribute for the
192+
* given class, if any.
193+
* @param clazz the class to retrieve the attribute for
194+
* @return all transaction attribute associated with this class, or {@code null} if none
190195
*/
191196
@Nullable
192-
protected abstract TransactionAttribute findTransactionAttribute(Method method);
197+
protected abstract TransactionAttribute findTransactionAttribute(Class<?> clazz);
193198

194199
/**
195-
* Subclasses need to implement this to return the transaction attribute
196-
* for the given class, if any.
197-
* @param clazz the class to retrieve the attribute for
198-
* @return all transaction attribute associated with this class
199-
* (or {@code null} if none)
200+
* Subclasses need to implement this to return the transaction attribute for the
201+
* given method, if any.
202+
* @param method the method to retrieve the attribute for
203+
* @return all transaction attribute associated with this method, or {@code null} if none
200204
*/
201205
@Nullable
202-
protected abstract TransactionAttribute findTransactionAttribute(Class<?> clazz);
203-
206+
protected abstract TransactionAttribute findTransactionAttribute(Method method);
204207

205208
/**
206209
* Should only public methods be allowed to have transactional semantics?

spring-tx/src/test/java/org/springframework/transaction/interceptor/MapTransactionAttributeSource.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,23 +31,23 @@ public class MapTransactionAttributeSource extends AbstractFallbackTransactionAt
3131
private final Map<Object, TransactionAttribute> attributeMap = new HashMap<>();
3232

3333

34-
public void register(Method method, TransactionAttribute txAttr) {
35-
this.attributeMap.put(method, txAttr);
36-
}
37-
3834
public void register(Class<?> clazz, TransactionAttribute txAttr) {
3935
this.attributeMap.put(clazz, txAttr);
4036
}
4137

42-
43-
@Override
44-
protected TransactionAttribute findTransactionAttribute(Method method) {
45-
return this.attributeMap.get(method);
38+
public void register(Method method, TransactionAttribute txAttr) {
39+
this.attributeMap.put(method, txAttr);
4640
}
4741

42+
4843
@Override
4944
protected TransactionAttribute findTransactionAttribute(Class<?> clazz) {
5045
return this.attributeMap.get(clazz);
5146
}
5247

48+
@Override
49+
protected TransactionAttribute findTransactionAttribute(Method method) {
50+
return this.attributeMap.get(method);
51+
}
52+
5353
}

0 commit comments

Comments
 (0)