Skip to content

Commit d9e0b29

Browse files
committed
polishing
1 parent 5be1ff2 commit d9e0b29

File tree

53 files changed

+433
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+433
-293
lines changed

spring-aspects/src/test/java/org/springframework/cache/config/AnnotatedJCacheableService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import javax.cache.annotation.CacheValue;
3030

3131
import org.springframework.cache.Cache;
32+
import org.springframework.cache.interceptor.SimpleKeyGenerator;
3233
import org.springframework.cache.jcache.config.JCacheableService;
33-
import org.springframework.cache.jcache.interceptor.SimpleGeneratedCacheKey;
3434
import org.springframework.cache.jcache.support.TestableCacheKeyGenerator;
3535
import org.springframework.cache.jcache.support.TestableCacheResolverFactory;
3636

@@ -111,7 +111,7 @@ public void putWithException(@CacheKey String id, @CacheValue Object value, bool
111111
@Override
112112
@CachePut(afterInvocation = false)
113113
public void earlyPut(String id, @CacheValue Object value) {
114-
SimpleGeneratedCacheKey key = new SimpleGeneratedCacheKey(id);
114+
Object key = SimpleKeyGenerator.generateKey(id);
115115
Cache.ValueWrapper valueWrapper = defaultCache.get(key);
116116
if (valueWrapper == null) {
117117
throw new AssertionError("Excepted value to be put in cache with key " + key);
@@ -143,7 +143,7 @@ public void removeWithException(@CacheKey String id, boolean matchFilter) {
143143
@Override
144144
@CacheRemove(afterInvocation = false)
145145
public void earlyRemove(String id) {
146-
SimpleGeneratedCacheKey key = new SimpleGeneratedCacheKey(id);
146+
Object key = SimpleKeyGenerator.generateKey(id);
147147
Cache.ValueWrapper valueWrapper = defaultCache.get(key);
148148
if (valueWrapper != null) {
149149
throw new AssertionError("Value with key " + key + " expected to be already remove from cache");

spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,17 @@ protected void useCachingConfigurer(JCacheConfigurer config) {
4949
public JCacheOperationSource cacheOperationSource() {
5050
DefaultJCacheOperationSource source = new DefaultJCacheOperationSource();
5151
if (this.cacheManager != null) {
52-
source.setCacheManager(cacheManager);
52+
source.setCacheManager(this.cacheManager);
5353
}
54-
if (keyGenerator != null) {
55-
source.setKeyGenerator(keyGenerator);
54+
if (this.keyGenerator != null) {
55+
source.setKeyGenerator(this.keyGenerator);
5656
}
5757
if (this.cacheResolver != null) {
58-
source.setCacheResolver(cacheResolver);
58+
source.setCacheResolver(this.cacheResolver);
5959
}
6060
if (this.exceptionCacheResolver != null) {
61-
source.setExceptionCacheResolver(exceptionCacheResolver);
61+
source.setExceptionCacheResolver(this.exceptionCacheResolver);
6262
}
63-
6463
return source;
6564
}
6665

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractCacheInterceptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.cache.interceptor.CacheErrorHandler;
2929
import org.springframework.cache.interceptor.CacheOperationInvocationContext;
3030
import org.springframework.cache.interceptor.CacheOperationInvoker;
31-
import org.springframework.cache.jcache.model.BaseCacheOperation;
3231

3332
/**
3433
* A base interceptor for JSR-107 cache annotations.
@@ -37,7 +36,7 @@
3736
* @since 4.1
3837
*/
3938
@SuppressWarnings("serial")
40-
public abstract class AbstractCacheInterceptor<O extends BaseCacheOperation<A>, A extends Annotation>
39+
abstract class AbstractCacheInterceptor<O extends AbstractJCacheOperation<A>, A extends Annotation>
4140
extends AbstractCacheInvoker implements Serializable {
4241

4342
protected final Log logger = LogFactory.getLog(getClass());

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractFallbackJCacheOperationSource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.commons.logging.LogFactory;
2626

2727
import org.springframework.cache.interceptor.MethodCacheKey;
28-
import org.springframework.cache.jcache.model.JCacheOperation;
2928
import org.springframework.core.BridgeMethodResolver;
3029
import org.springframework.util.ClassUtils;
3130

@@ -58,7 +57,7 @@ public JCacheOperation<?> getCacheOperation(Method method, Class<?> targetClass)
5857
return cached;
5958
}
6059
else {
61-
JCacheOperation<?> operation = computeCacheOperations(method, targetClass);
60+
JCacheOperation<?> operation = computeCacheOperation(method, targetClass);
6261
if (operation != null) {
6362
if (logger.isDebugEnabled()) {
6463
logger.debug("Adding cacheable method '" + method.getName()
@@ -70,7 +69,7 @@ public JCacheOperation<?> getCacheOperation(Method method, Class<?> targetClass)
7069
}
7170
}
7271

73-
private JCacheOperation<?> computeCacheOperations(Method method, Class<?> targetClass) {
72+
private JCacheOperation<?> computeCacheOperation(Method method, Class<?> targetClass) {
7473
// Don't allow no-public methods as required.
7574
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
7675
return null;
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.cache.jcache.model;
17+
package org.springframework.cache.jcache.interceptor;
1818

1919
import java.lang.annotation.Annotation;
2020
import java.util.ArrayList;
@@ -32,30 +32,33 @@
3232
* @author Stephane Nicoll
3333
* @since 4.1
3434
*/
35-
public abstract class BaseKeyCacheOperation<A extends Annotation> extends BaseCacheOperation<A> {
35+
abstract class AbstractJCacheKeyOperation<A extends Annotation> extends AbstractJCacheOperation<A> {
3636

3737
private final KeyGenerator keyGenerator;
3838

3939
private final List<CacheParameterDetail> keyParameterDetails;
4040

41+
4142
/**
4243
* Create a new instance.
4344
* @param methodDetails the {@link CacheMethodDetails} related to the cached method
4445
* @param cacheResolver the cache resolver to resolve regular caches
4546
* @param keyGenerator the key generator to compute cache keys
4647
*/
47-
protected BaseKeyCacheOperation(CacheMethodDetails<A> methodDetails,
48+
protected AbstractJCacheKeyOperation(CacheMethodDetails<A> methodDetails,
4849
CacheResolver cacheResolver, KeyGenerator keyGenerator) {
50+
4951
super(methodDetails, cacheResolver);
5052
this.keyGenerator = keyGenerator;
51-
this.keyParameterDetails = initializeKeyParameterDetails(allParameterDetails);
53+
this.keyParameterDetails = initializeKeyParameterDetails(this.allParameterDetails);
5254
}
5355

56+
5457
/**
5558
* Return the {@link KeyGenerator} to use to compute cache keys.
5659
*/
5760
public KeyGenerator getKeyGenerator() {
58-
return keyGenerator;
61+
return this.keyGenerator;
5962
}
6063

6164
/**
@@ -72,7 +75,7 @@ public KeyGenerator getKeyGenerator() {
7275
*/
7376
public CacheInvocationParameter[] getKeyParameters(Object... values) {
7477
List<CacheInvocationParameter> result = new ArrayList<CacheInvocationParameter>();
75-
for (CacheParameterDetail keyParameterDetail : keyParameterDetails) {
78+
for (CacheParameterDetail keyParameterDetail : this.keyParameterDetails) {
7679
int parameterPosition = keyParameterDetail.getParameterPosition();
7780
if (parameterPosition >= values.length) {
7881
throw new IllegalStateException("Values mismatch, key parameter at position "
@@ -95,7 +98,7 @@ private static List<CacheParameterDetail> initializeKeyParameterDetails(List<Cac
9598
annotated.add(allParameter);
9699
}
97100
}
98-
return annotated.size() == 0 ? all : annotated;
101+
return (annotated.isEmpty() ? all : annotated);
99102
}
100103

101104
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.cache.jcache.model;
17+
package org.springframework.cache.jcache.interceptor;
1818

1919
import java.lang.annotation.Annotation;
2020
import java.lang.reflect.Method;
@@ -40,7 +40,7 @@
4040
* @author Stephane Nicoll
4141
* @since 4.1
4242
*/
43-
public abstract class BaseCacheOperation<A extends Annotation> implements JCacheOperation<A> {
43+
abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOperation<A> {
4444

4545
private final CacheMethodDetails<A> methodDetails;
4646

@@ -54,7 +54,7 @@ public abstract class BaseCacheOperation<A extends Annotation> implements JCache
5454
* @param methodDetails the {@link CacheMethodDetails} related to the cached method
5555
* @param cacheResolver the cache resolver to resolve regular caches
5656
*/
57-
protected BaseCacheOperation(CacheMethodDetails<A> methodDetails, CacheResolver cacheResolver) {
57+
protected AbstractJCacheOperation(CacheMethodDetails<A> methodDetails, CacheResolver cacheResolver) {
5858
Assert.notNull(methodDetails, "method details must not be null.");
5959
Assert.notNull(cacheResolver, "cache resolver must not be null.");
6060
this.methodDetails = methodDetails;
@@ -159,13 +159,13 @@ protected static class CacheParameterDetail {
159159

160160
private final boolean isValue;
161161

162-
public CacheParameterDetail(Method m, int parameterPosition) {
163-
this.rawType = m.getParameterTypes()[parameterPosition];
162+
public CacheParameterDetail(Method method, int parameterPosition) {
163+
this.rawType = method.getParameterTypes()[parameterPosition];
164164
this.annotations = new LinkedHashSet<Annotation>();
165165
boolean foundKeyAnnotation = false;
166166
boolean foundValueAnnotation = false;
167-
for (Annotation annotation : m.getParameterAnnotations()[parameterPosition]) {
168-
annotations.add(annotation);
167+
for (Annotation annotation : method.getParameterAnnotations()[parameterPosition]) {
168+
this.annotations.add(annotation);
169169
if (CacheKey.class.isAssignableFrom(annotation.annotationType())) {
170170
foundKeyAnnotation = true;
171171
}

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractKeyCacheInterceptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.springframework.cache.interceptor.CacheErrorHandler;
2424
import org.springframework.cache.interceptor.CacheOperationInvocationContext;
2525
import org.springframework.cache.interceptor.KeyGenerator;
26-
import org.springframework.cache.jcache.model.BaseKeyCacheOperation;
2726

2827
/**
2928
* A base interceptor for JSR-107 key-based cache annotations.
@@ -32,7 +31,7 @@
3231
* @since 4.1
3332
*/
3433
@SuppressWarnings("serial")
35-
public abstract class AbstractKeyCacheInterceptor<O extends BaseKeyCacheOperation<A>, A extends Annotation>
34+
abstract class AbstractKeyCacheInterceptor<O extends AbstractJCacheKeyOperation<A>, A extends Annotation>
3635
extends AbstractCacheInterceptor<O, A> {
3736

3837
protected AbstractKeyCacheInterceptor(CacheErrorHandler errorHandler) {
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232

3333
import org.springframework.cache.interceptor.CacheResolver;
3434
import org.springframework.cache.interceptor.KeyGenerator;
35-
import org.springframework.cache.jcache.model.CachePutOperation;
36-
import org.springframework.cache.jcache.model.CacheRemoveAllOperation;
37-
import org.springframework.cache.jcache.model.CacheRemoveOperation;
38-
import org.springframework.cache.jcache.model.CacheResultOperation;
39-
import org.springframework.cache.jcache.model.DefaultCacheMethodDetails;
40-
import org.springframework.cache.jcache.model.JCacheOperation;
4135
import org.springframework.util.StringUtils;
4236

4337
/**
@@ -48,8 +42,7 @@
4842
* @author Stephane Nicoll
4943
* @since 4.1
5044
*/
51-
public abstract class AnnotationCacheOperationSource
52-
extends AbstractFallbackJCacheOperationSource {
45+
public abstract class AnnotationJCacheOperationSource extends AbstractFallbackJCacheOperationSource {
5346

5447
/**
5548
* Locate or create an instance of the specified {@code type}.
@@ -236,7 +229,6 @@ protected String determineCacheName(Method method, CacheDefaults defaults, Strin
236229

237230
/**
238231
* Generate a default cache name for the specified {@link Method}.
239-
*
240232
* @param method the annotated method
241233
* @return the default cache name, according to JSR-107
242234
*/

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CachePutInterceptor.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.springframework.cache.interceptor.CacheErrorHandler;
2424
import org.springframework.cache.interceptor.CacheOperationInvocationContext;
2525
import org.springframework.cache.interceptor.CacheOperationInvoker;
26-
import org.springframework.cache.jcache.model.CachePutOperation;
2726

2827
/**
2928
* Intercept methods annotated with {@link CachePut}.
@@ -32,7 +31,7 @@
3231
* @since 4.1
3332
*/
3433
@SuppressWarnings("serial")
35-
public class CachePutInterceptor extends AbstractKeyCacheInterceptor<CachePutOperation, CachePut> {
34+
class CachePutInterceptor extends AbstractKeyCacheInterceptor<CachePutOperation, CachePut> {
3635

3736
public CachePutInterceptor(CacheErrorHandler errorHandler) {
3837
super(errorHandler);
@@ -41,11 +40,12 @@ public CachePutInterceptor(CacheErrorHandler errorHandler) {
4140
@Override
4241
protected Object invoke(CacheOperationInvocationContext<CachePutOperation> context,
4342
CacheOperationInvoker invoker) {
43+
4444
CacheKeyInvocationContext<CachePut> invocationContext = createCacheKeyInvocationContext(context);
4545
CachePutOperation operation = context.getOperation();
4646

47-
final boolean earlyPut = operation.isEarlyPut();
48-
final Object value = invocationContext.getValueParameter().getValue();
47+
boolean earlyPut = operation.isEarlyPut();
48+
Object value = invocationContext.getValueParameter().getValue();
4949

5050
if (earlyPut) {
5151
cacheValue(context, value);
@@ -58,12 +58,12 @@ protected Object invoke(CacheOperationInvocationContext<CachePutOperation> conte
5858
}
5959
return result;
6060
}
61-
catch (CacheOperationInvoker.ThrowableWrapper t) {
62-
Throwable ex = t.getOriginal();
63-
if (!earlyPut && operation.getExceptionTypeFilter().match(ex.getClass())) {
61+
catch (CacheOperationInvoker.ThrowableWrapper ex) {
62+
Throwable original = ex.getOriginal();
63+
if (!earlyPut && operation.getExceptionTypeFilter().match(original.getClass())) {
6464
cacheValue(context, value);
6565
}
66-
throw t;
66+
throw ex;
6767
}
6868
}
6969

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.cache.jcache.model;
17+
package org.springframework.cache.jcache.interceptor;
1818

1919
import java.lang.reflect.Method;
2020
import java.util.List;
@@ -34,7 +34,7 @@
3434
* @since 4.1
3535
* @see CachePut
3636
*/
37-
public class CachePutOperation extends BaseKeyCacheOperation<CachePut> {
37+
class CachePutOperation extends AbstractJCacheKeyOperation<CachePut> {
3838

3939
private final ExceptionTypeFilter exceptionTypeFilter;
4040

@@ -47,8 +47,8 @@ public CachePutOperation(
4747
super(methodDetails, cacheResolver, keyGenerator);
4848
CachePut ann = methodDetails.getCacheAnnotation();
4949
this.exceptionTypeFilter = createExceptionTypeFilter(ann.cacheFor(), ann.noCacheFor());
50-
this.valueParameterDetail = initializeValueParameterDetail(methodDetails.getMethod(), allParameterDetails);
51-
if (valueParameterDetail == null) {
50+
this.valueParameterDetail = initializeValueParameterDetail(methodDetails.getMethod(), this.allParameterDetails);
51+
if (this.valueParameterDetail == null) {
5252
throw new IllegalArgumentException("No parameter annotated with @CacheValue was found for " +
5353
"" + methodDetails.getMethod());
5454
}

0 commit comments

Comments
 (0)