parent
c73e52412a
commit
37b3b24578
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -98,59 +98,59 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
|
|||
}
|
||||
|
||||
CacheableOperation parseCacheableAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, Cacheable cacheable) {
|
||||
CacheableOperation.Builder opBuilder = new CacheableOperation.Builder();
|
||||
CacheableOperation.Builder builder = new CacheableOperation.Builder();
|
||||
|
||||
opBuilder.setCacheNames(cacheable.cacheNames());
|
||||
opBuilder.setCondition(cacheable.condition());
|
||||
opBuilder.setUnless(cacheable.unless());
|
||||
opBuilder.setKey(cacheable.key());
|
||||
opBuilder.setKeyGenerator(cacheable.keyGenerator());
|
||||
opBuilder.setCacheManager(cacheable.cacheManager());
|
||||
opBuilder.setCacheResolver(cacheable.cacheResolver());
|
||||
opBuilder.setSync(cacheable.sync());
|
||||
opBuilder.setName(ae.toString());
|
||||
builder.setCacheNames(cacheable.cacheNames());
|
||||
builder.setCondition(cacheable.condition());
|
||||
builder.setUnless(cacheable.unless());
|
||||
builder.setKey(cacheable.key());
|
||||
builder.setKeyGenerator(cacheable.keyGenerator());
|
||||
builder.setCacheManager(cacheable.cacheManager());
|
||||
builder.setCacheResolver(cacheable.cacheResolver());
|
||||
builder.setSync(cacheable.sync());
|
||||
builder.setName(ae.toString());
|
||||
|
||||
defaultConfig.applyDefault(opBuilder);
|
||||
CacheableOperation op = opBuilder.build();
|
||||
defaultConfig.applyDefault(builder);
|
||||
CacheableOperation op = builder.build();
|
||||
validateCacheOperation(ae, op);
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
CacheEvictOperation parseEvictAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CacheEvict cacheEvict) {
|
||||
CacheEvictOperation.Builder opBuilder = new CacheEvictOperation.Builder();
|
||||
CacheEvictOperation.Builder builder = new CacheEvictOperation.Builder();
|
||||
|
||||
opBuilder.setCacheNames(cacheEvict.cacheNames());
|
||||
opBuilder.setCondition(cacheEvict.condition());
|
||||
opBuilder.setKey(cacheEvict.key());
|
||||
opBuilder.setKeyGenerator(cacheEvict.keyGenerator());
|
||||
opBuilder.setCacheManager(cacheEvict.cacheManager());
|
||||
opBuilder.setCacheResolver(cacheEvict.cacheResolver());
|
||||
opBuilder.setCacheWide(cacheEvict.allEntries());
|
||||
opBuilder.setBeforeInvocation(cacheEvict.beforeInvocation());
|
||||
opBuilder.setName(ae.toString());
|
||||
builder.setCacheNames(cacheEvict.cacheNames());
|
||||
builder.setCondition(cacheEvict.condition());
|
||||
builder.setKey(cacheEvict.key());
|
||||
builder.setKeyGenerator(cacheEvict.keyGenerator());
|
||||
builder.setCacheManager(cacheEvict.cacheManager());
|
||||
builder.setCacheResolver(cacheEvict.cacheResolver());
|
||||
builder.setCacheWide(cacheEvict.allEntries());
|
||||
builder.setBeforeInvocation(cacheEvict.beforeInvocation());
|
||||
builder.setName(ae.toString());
|
||||
|
||||
defaultConfig.applyDefault(opBuilder);
|
||||
CacheEvictOperation op = opBuilder.build();
|
||||
defaultConfig.applyDefault(builder);
|
||||
CacheEvictOperation op = builder.build();
|
||||
validateCacheOperation(ae, op);
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
CacheOperation parsePutAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CachePut cachePut) {
|
||||
CachePutOperation.Builder opBuilder = new CachePutOperation.Builder();
|
||||
CachePutOperation.Builder builder = new CachePutOperation.Builder();
|
||||
|
||||
opBuilder.setCacheNames(cachePut.cacheNames());
|
||||
opBuilder.setCondition(cachePut.condition());
|
||||
opBuilder.setUnless(cachePut.unless());
|
||||
opBuilder.setKey(cachePut.key());
|
||||
opBuilder.setKeyGenerator(cachePut.keyGenerator());
|
||||
opBuilder.setCacheManager(cachePut.cacheManager());
|
||||
opBuilder.setCacheResolver(cachePut.cacheResolver());
|
||||
opBuilder.setName(ae.toString());
|
||||
builder.setCacheNames(cachePut.cacheNames());
|
||||
builder.setCondition(cachePut.condition());
|
||||
builder.setUnless(cachePut.unless());
|
||||
builder.setKey(cachePut.key());
|
||||
builder.setKeyGenerator(cachePut.keyGenerator());
|
||||
builder.setCacheManager(cachePut.cacheManager());
|
||||
builder.setCacheResolver(cachePut.cacheResolver());
|
||||
builder.setName(ae.toString());
|
||||
|
||||
defaultConfig.applyDefault(opBuilder);
|
||||
CachePutOperation op = opBuilder.build();
|
||||
defaultConfig.applyDefault(builder);
|
||||
CachePutOperation op = builder.build();
|
||||
validateCacheOperation(ae, op);
|
||||
|
||||
return op;
|
||||
|
|
@ -278,26 +278,26 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
|
|||
}
|
||||
|
||||
/**
|
||||
* Apply the defaults to the specified {@link CacheOperation}.
|
||||
* @param operation the operation to update
|
||||
* Apply the defaults to the specified {@link CacheOperation.Builder}.
|
||||
* @param builder the operation builder to update
|
||||
*/
|
||||
public void applyDefault(CacheOperation.Builder operation) {
|
||||
if (operation.getCacheNames().isEmpty() && this.cacheNames != null) {
|
||||
operation.setCacheNames(this.cacheNames);
|
||||
public void applyDefault(CacheOperation.Builder builder) {
|
||||
if (builder.getCacheNames().isEmpty() && this.cacheNames != null) {
|
||||
builder.setCacheNames(this.cacheNames);
|
||||
}
|
||||
if (!StringUtils.hasText(operation.getKey()) && !StringUtils.hasText(operation.getKeyGenerator()) &&
|
||||
if (!StringUtils.hasText(builder.getKey()) && !StringUtils.hasText(builder.getKeyGenerator()) &&
|
||||
StringUtils.hasText(this.keyGenerator)) {
|
||||
operation.setKeyGenerator(this.keyGenerator);
|
||||
builder.setKeyGenerator(this.keyGenerator);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(operation.getCacheManager()) || StringUtils.hasText(operation.getCacheResolver())) {
|
||||
if (StringUtils.hasText(builder.getCacheManager()) || StringUtils.hasText(builder.getCacheResolver())) {
|
||||
// One of these is set so we should not inherit anything
|
||||
}
|
||||
else if (StringUtils.hasText(this.cacheResolver)) {
|
||||
operation.setCacheResolver(this.cacheResolver);
|
||||
builder.setCacheResolver(this.cacheResolver);
|
||||
}
|
||||
else if (StringUtils.hasText(this.cacheManager)) {
|
||||
operation.setCacheManager(this.cacheManager);
|
||||
builder.setCacheManager(this.cacheManager);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -107,16 +107,17 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
|||
String name = prop.merge(opElement, parserContext.getReaderContext());
|
||||
TypedStringValue nameHolder = new TypedStringValue(name);
|
||||
nameHolder.setSource(parserContext.extractSource(opElement));
|
||||
CacheableOperation.Builder op = prop.merge(opElement, parserContext.getReaderContext(), new CacheableOperation.Builder());
|
||||
op.setUnless(getAttributeValue(opElement, "unless", ""));
|
||||
op.setSync(Boolean.valueOf(getAttributeValue(opElement, "sync", "false")));
|
||||
CacheableOperation.Builder builder = prop.merge(opElement,
|
||||
parserContext.getReaderContext(), new CacheableOperation.Builder());
|
||||
builder.setUnless(getAttributeValue(opElement, "unless", ""));
|
||||
builder.setSync(Boolean.valueOf(getAttributeValue(opElement, "sync", "false")));
|
||||
|
||||
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
||||
if (col == null) {
|
||||
col = new ArrayList<CacheOperation>(2);
|
||||
cacheOpMap.put(nameHolder, col);
|
||||
}
|
||||
col.add(op.build());
|
||||
col.add(builder.build());
|
||||
}
|
||||
|
||||
List<Element> evictCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_EVICT_ELEMENT);
|
||||
|
|
@ -125,16 +126,17 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
|||
String name = prop.merge(opElement, parserContext.getReaderContext());
|
||||
TypedStringValue nameHolder = new TypedStringValue(name);
|
||||
nameHolder.setSource(parserContext.extractSource(opElement));
|
||||
CacheEvictOperation.Builder op = prop.merge(opElement, parserContext.getReaderContext(), new CacheEvictOperation.Builder());
|
||||
CacheEvictOperation.Builder builder = prop.merge(opElement,
|
||||
parserContext.getReaderContext(), new CacheEvictOperation.Builder());
|
||||
|
||||
String wide = opElement.getAttribute("all-entries");
|
||||
if (StringUtils.hasText(wide)) {
|
||||
op.setCacheWide(Boolean.valueOf(wide.trim()));
|
||||
builder.setCacheWide(Boolean.valueOf(wide.trim()));
|
||||
}
|
||||
|
||||
String after = opElement.getAttribute("before-invocation");
|
||||
if (StringUtils.hasText(after)) {
|
||||
op.setBeforeInvocation(Boolean.valueOf(after.trim()));
|
||||
builder.setBeforeInvocation(Boolean.valueOf(after.trim()));
|
||||
}
|
||||
|
||||
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
||||
|
|
@ -142,7 +144,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
|||
col = new ArrayList<CacheOperation>(2);
|
||||
cacheOpMap.put(nameHolder, col);
|
||||
}
|
||||
col.add(op.build());
|
||||
col.add(builder.build());
|
||||
}
|
||||
|
||||
List<Element> putCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_PUT_ELEMENT);
|
||||
|
|
@ -151,15 +153,16 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
|||
String name = prop.merge(opElement, parserContext.getReaderContext());
|
||||
TypedStringValue nameHolder = new TypedStringValue(name);
|
||||
nameHolder.setSource(parserContext.extractSource(opElement));
|
||||
CachePutOperation.Builder op = prop.merge(opElement, parserContext.getReaderContext(), new CachePutOperation.Builder());
|
||||
op.setUnless(getAttributeValue(opElement, "unless", ""));
|
||||
CachePutOperation.Builder builder = prop.merge(opElement,
|
||||
parserContext.getReaderContext(), new CachePutOperation.Builder());
|
||||
builder.setUnless(getAttributeValue(opElement, "unless", ""));
|
||||
|
||||
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
||||
if (col == null) {
|
||||
col = new ArrayList<CacheOperation>(2);
|
||||
cacheOpMap.put(nameHolder, col);
|
||||
}
|
||||
col.add(op.build());
|
||||
col.add(builder.build());
|
||||
}
|
||||
|
||||
RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchCacheOperationSource.class);
|
||||
|
|
@ -208,7 +211,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
|||
}
|
||||
}
|
||||
|
||||
<T extends CacheOperation.Builder> T merge(Element element, ReaderContext readerCtx, T op) {
|
||||
<T extends CacheOperation.Builder> T merge(Element element, ReaderContext readerCtx, T builder) {
|
||||
String cache = element.getAttribute("cache");
|
||||
|
||||
// sanity check
|
||||
|
|
@ -221,21 +224,21 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
|||
readerCtx.error("No cache specified specified for " + element.getNodeName(), element);
|
||||
}
|
||||
}
|
||||
op.setCacheNames(localCaches);
|
||||
builder.setCacheNames(localCaches);
|
||||
|
||||
op.setKey(getAttributeValue(element, "key", this.key));
|
||||
op.setKeyGenerator(getAttributeValue(element, "key-generator", this.keyGenerator));
|
||||
op.setCacheManager(getAttributeValue(element, "cache-manager", this.cacheManager));
|
||||
op.setCondition(getAttributeValue(element, "condition", this.condition));
|
||||
builder.setKey(getAttributeValue(element, "key", this.key));
|
||||
builder.setKeyGenerator(getAttributeValue(element, "key-generator", this.keyGenerator));
|
||||
builder.setCacheManager(getAttributeValue(element, "cache-manager", this.cacheManager));
|
||||
builder.setCondition(getAttributeValue(element, "condition", this.condition));
|
||||
|
||||
if (StringUtils.hasText(op.getKey()) && StringUtils.hasText(op.getKeyGenerator())) {
|
||||
if (StringUtils.hasText(builder.getKey()) && StringUtils.hasText(builder.getKeyGenerator())) {
|
||||
throw new IllegalStateException("Invalid cache advice configuration on '"
|
||||
+ element.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " +
|
||||
"These attributes are mutually exclusive: either set the SpEL expression used to" +
|
||||
"compute the key at runtime or set the name of the KeyGenerator bean to use.");
|
||||
}
|
||||
|
||||
return op;
|
||||
return builder;
|
||||
}
|
||||
|
||||
String merge(Element element, ReaderContext readerCtx) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -43,6 +43,7 @@ public class CacheEvictOperation extends CacheOperation {
|
|||
}
|
||||
|
||||
public static class Builder extends CacheOperation.Builder {
|
||||
|
||||
private boolean cacheWide = false;
|
||||
|
||||
private boolean beforeInvocation = false;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ public abstract class CacheOperation implements BasicOperation {
|
|||
return this.cacheNames;
|
||||
}
|
||||
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
|
@ -123,7 +122,7 @@ public abstract class CacheOperation implements BasicOperation {
|
|||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return toString;
|
||||
return this.toString;
|
||||
}
|
||||
|
||||
public abstract static class Builder {
|
||||
|
|
@ -161,7 +160,7 @@ public abstract class CacheOperation implements BasicOperation {
|
|||
}
|
||||
|
||||
public Set<String> getCacheNames() {
|
||||
return cacheNames;
|
||||
return this.cacheNames;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
|
|
@ -170,19 +169,19 @@ public abstract class CacheOperation implements BasicOperation {
|
|||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getKeyGenerator() {
|
||||
return keyGenerator;
|
||||
return this.keyGenerator;
|
||||
}
|
||||
|
||||
public String getCacheManager() {
|
||||
return cacheManager;
|
||||
return this.cacheManager;
|
||||
}
|
||||
|
||||
public String getCacheResolver() {
|
||||
return cacheResolver;
|
||||
return this.cacheResolver;
|
||||
}
|
||||
|
||||
public void setKeyGenerator(String keyGenerator) {
|
||||
|
|
@ -196,7 +195,7 @@ public abstract class CacheOperation implements BasicOperation {
|
|||
}
|
||||
|
||||
public void setCacheResolver(String cacheResolver) {
|
||||
Assert.notNull(cacheManager);
|
||||
Assert.notNull(this.cacheManager);
|
||||
this.cacheResolver = cacheResolver;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public class CacheableOperation extends CacheOperation {
|
|||
private String unless;
|
||||
|
||||
private boolean sync;
|
||||
|
||||
public void setUnless(String unless) {
|
||||
this.unless = unless;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue