Polishing
This commit is contained in:
@@ -24,41 +24,40 @@ import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Strategy interface for parsing known caching annotation types.
|
||||
* {@link AnnotationCacheOperationSource} delegates to such
|
||||
* parsers for supporting specific annotation types such as Spring's own
|
||||
* {@link Cacheable}, {@link CachePut} or {@link CacheEvict}.
|
||||
* {@link AnnotationCacheOperationSource} delegates to such parsers
|
||||
* for supporting specific annotation types such as Spring's own
|
||||
* {@link Cacheable}, {@link CachePut} and{@link CacheEvict}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Stephane Nicoll
|
||||
* @since 3.1
|
||||
* @see AnnotationCacheOperationSource
|
||||
* @see SpringCacheAnnotationParser
|
||||
*/
|
||||
public interface CacheAnnotationParser {
|
||||
|
||||
/**
|
||||
* Parses the cache definition for the given class,
|
||||
* based on a known annotation type.
|
||||
* <p>This essentially parses a known cache annotation into Spring's
|
||||
* metadata attribute class. Returns {@code null} if the class
|
||||
* is not cacheable.
|
||||
* Parse the cache definition for the given class,
|
||||
* based on an annotation type understood by this parser.
|
||||
* <p>This essentially parses a known cache annotation into Spring's metadata
|
||||
* attribute class. Returns {@code null} if the class is not cacheable.
|
||||
* @param type the annotated class
|
||||
* @return the configured caching operation,
|
||||
* or {@code null} if none was found
|
||||
* @return the configured caching operation, or {@code null} if none found
|
||||
* @see AnnotationCacheOperationSource#findCacheOperations(Class)
|
||||
*/
|
||||
@Nullable
|
||||
Collection<CacheOperation> parseCacheAnnotations(Class<?> type);
|
||||
|
||||
/**
|
||||
* Parses the cache definition for the given method,
|
||||
* based on a known annotation type.
|
||||
* <p>This essentially parses a known cache annotation into Spring's
|
||||
* metadata attribute class. Returns {@code null} if the method
|
||||
* is not cacheable.
|
||||
* Parse the cache definition for the given method,
|
||||
* based on an annotation type understood by this parser.
|
||||
* <p>This essentially parses a known cache annotation into Spring's metadata
|
||||
* attribute class. Returns {@code null} if the method is not cacheable.
|
||||
* @param method the annotated method
|
||||
* @return the configured caching operation,
|
||||
* or {@code null} if none was found
|
||||
* @return the configured caching operation, or {@code null} if none found
|
||||
* @see AnnotationCacheOperationSource#findCacheOperations(Method)
|
||||
*/
|
||||
@Nullable
|
||||
Collection<CacheOperation> parseCacheAnnotations(Method method);
|
||||
|
||||
}
|
||||
|
||||
@@ -163,25 +163,23 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
|
||||
|
||||
|
||||
/**
|
||||
* Subclasses need to implement this to return the caching attribute
|
||||
* for the given method, if any.
|
||||
* @param method the method to retrieve the attribute for
|
||||
* @return all caching attribute associated with this method
|
||||
* (or {@code null} if none)
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract Collection<CacheOperation> findCacheOperations(Method method);
|
||||
|
||||
/**
|
||||
* Subclasses need to implement this to return the caching attribute
|
||||
* for the given class, if any.
|
||||
* Subclasses need to implement this to return the caching attribute for the
|
||||
* given class, if any.
|
||||
* @param clazz the class to retrieve the attribute for
|
||||
* @return all caching attribute associated with this class
|
||||
* (or {@code null} if none)
|
||||
* @return all caching attribute associated with this class, or {@code null} if none
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract Collection<CacheOperation> findCacheOperations(Class<?> clazz);
|
||||
|
||||
/**
|
||||
* Subclasses need to implement this to return the caching attribute for the
|
||||
* given method, if any.
|
||||
* @param method the method to retrieve the attribute for
|
||||
* @return all caching attribute associated with this method, or {@code null} if none
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract Collection<CacheOperation> findCacheOperations(Method method);
|
||||
|
||||
/**
|
||||
* Should only public methods be allowed to have caching semantics?
|
||||
* <p>The default implementation returns {@code false}.
|
||||
|
||||
@@ -99,7 +99,6 @@ public class EnableAsyncTests {
|
||||
fail("Should have thrown UnsatisfiedDependencyException");
|
||||
}
|
||||
catch (UnsatisfiedDependencyException ex) {
|
||||
ex.printStackTrace();
|
||||
assertTrue(ex.getCause() instanceof BeanNotOfRequiredTypeException);
|
||||
}
|
||||
}
|
||||
@@ -114,7 +113,6 @@ public class EnableAsyncTests {
|
||||
fail("Should have thrown UnsatisfiedDependencyException");
|
||||
}
|
||||
catch (UnsatisfiedDependencyException ex) {
|
||||
ex.printStackTrace();
|
||||
assertTrue(ex.getCause() instanceof BeanNotOfRequiredTypeException);
|
||||
}
|
||||
}
|
||||
@@ -244,8 +242,8 @@ public class EnableAsyncTests {
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr14949FindsOnInterfaceWithInterfaceProxy() throws InterruptedException {
|
||||
@Test // SPR-14949
|
||||
public void findOnInterfaceWithInterfaceProxy() throws InterruptedException {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14949ConfigA.class);
|
||||
|
||||
AsyncInterface asyncBean = ctx.getBean(AsyncInterface.class);
|
||||
@@ -256,8 +254,8 @@ public class EnableAsyncTests {
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr14949FindsOnInterfaceWithCglibProxy() throws InterruptedException {
|
||||
@Test // SPR-14949
|
||||
public void findOnInterfaceWithCglibProxy() throws InterruptedException {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14949ConfigB.class);
|
||||
|
||||
AsyncInterface asyncBean = ctx.getBean(AsyncInterface.class);
|
||||
|
||||
@@ -139,14 +139,14 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected TransactionAttribute findTransactionAttribute(Method method) {
|
||||
return determineTransactionAttribute(method);
|
||||
protected TransactionAttribute findTransactionAttribute(Class<?> clazz) {
|
||||
return determineTransactionAttribute(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected TransactionAttribute findTransactionAttribute(Class<?> clazz) {
|
||||
return determineTransactionAttribute(clazz);
|
||||
protected TransactionAttribute findTransactionAttribute(Method method) {
|
||||
return determineTransactionAttribute(method);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,7 +55,13 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
|
||||
* Canonical value held in cache to indicate no transaction attribute was
|
||||
* found for this method, and we don't need to look again.
|
||||
*/
|
||||
private static final TransactionAttribute NULL_TRANSACTION_ATTRIBUTE = new DefaultTransactionAttribute();
|
||||
@SuppressWarnings("serial")
|
||||
private static final TransactionAttribute NULL_TRANSACTION_ATTRIBUTE = new DefaultTransactionAttribute() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@@ -90,7 +96,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
|
||||
|
||||
// First, see if we have a cached value.
|
||||
Object cacheKey = getCacheKey(method, targetClass);
|
||||
Object cached = this.attributeCache.get(cacheKey);
|
||||
TransactionAttribute cached = this.attributeCache.get(cacheKey);
|
||||
if (cached != null) {
|
||||
// Value will either be canonical value indicating there is no transaction attribute,
|
||||
// or an actual transaction attribute.
|
||||
@@ -98,7 +104,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return (TransactionAttribute) cached;
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -182,25 +188,22 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
|
||||
|
||||
|
||||
/**
|
||||
* Subclasses need to implement this to return the transaction attribute
|
||||
* for the given method, if any.
|
||||
* @param method the method to retrieve the attribute for
|
||||
* @return all transaction attribute associated with this method
|
||||
* (or {@code null} if none)
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract TransactionAttribute findTransactionAttribute(Method method);
|
||||
|
||||
/**
|
||||
* Subclasses need to implement this to return the transaction attribute
|
||||
* for the given class, if any.
|
||||
* Subclasses need to implement this to return the transaction attribute for the
|
||||
* given class, if any.
|
||||
* @param clazz the class to retrieve the attribute for
|
||||
* @return all transaction attribute associated with this class
|
||||
* (or {@code null} if none)
|
||||
* @return all transaction attribute associated with this class, or {@code null} if none
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract TransactionAttribute findTransactionAttribute(Class<?> clazz);
|
||||
|
||||
/**
|
||||
* Subclasses need to implement this to return the transaction attribute for the
|
||||
* given method, if any.
|
||||
* @param method the method to retrieve the attribute for
|
||||
* @return all transaction attribute associated with this method, or {@code null} if none
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract TransactionAttribute findTransactionAttribute(Method method);
|
||||
|
||||
/**
|
||||
* Should only public methods be allowed to have transactional semantics?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -31,23 +31,23 @@ public class MapTransactionAttributeSource extends AbstractFallbackTransactionAt
|
||||
private final Map<Object, TransactionAttribute> attributeMap = new HashMap<>();
|
||||
|
||||
|
||||
public void register(Method method, TransactionAttribute txAttr) {
|
||||
this.attributeMap.put(method, txAttr);
|
||||
}
|
||||
|
||||
public void register(Class<?> clazz, TransactionAttribute txAttr) {
|
||||
this.attributeMap.put(clazz, txAttr);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TransactionAttribute findTransactionAttribute(Method method) {
|
||||
return this.attributeMap.get(method);
|
||||
public void register(Method method, TransactionAttribute txAttr) {
|
||||
this.attributeMap.put(method, txAttr);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TransactionAttribute findTransactionAttribute(Class<?> clazz) {
|
||||
return this.attributeMap.get(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TransactionAttribute findTransactionAttribute(Method method) {
|
||||
return this.attributeMap.get(method);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user