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.
|
||||
|
|
@ -24,49 +24,50 @@ package org.springframework.cache.interceptor;
|
|||
*/
|
||||
public class CacheEvictOperation extends CacheOperation {
|
||||
|
||||
private final boolean cacheWide;
|
||||
private final boolean cacheWide;
|
||||
|
||||
private final boolean beforeInvocation;
|
||||
private final boolean beforeInvocation;
|
||||
|
||||
public boolean isCacheWide() {
|
||||
return this.cacheWide;
|
||||
}
|
||||
public boolean isCacheWide() {
|
||||
return this.cacheWide;
|
||||
}
|
||||
|
||||
public boolean isBeforeInvocation() {
|
||||
return this.beforeInvocation;
|
||||
}
|
||||
public boolean isBeforeInvocation() {
|
||||
return this.beforeInvocation;
|
||||
}
|
||||
|
||||
public CacheEvictOperation(CacheEvictOperation.Builder b) {
|
||||
super(b);
|
||||
this.cacheWide = b.cacheWide;
|
||||
this.beforeInvocation = b.beforeInvocation;
|
||||
}
|
||||
public CacheEvictOperation(CacheEvictOperation.Builder b) {
|
||||
super(b);
|
||||
this.cacheWide = b.cacheWide;
|
||||
this.beforeInvocation = b.beforeInvocation;
|
||||
}
|
||||
|
||||
public static class Builder extends CacheOperation.Builder {
|
||||
private boolean cacheWide = false;
|
||||
public static class Builder extends CacheOperation.Builder {
|
||||
|
||||
private boolean beforeInvocation = false;
|
||||
private boolean cacheWide = false;
|
||||
|
||||
public void setCacheWide(boolean cacheWide) {
|
||||
this.cacheWide = cacheWide;
|
||||
}
|
||||
private boolean beforeInvocation = false;
|
||||
|
||||
public void setBeforeInvocation(boolean beforeInvocation) {
|
||||
this.beforeInvocation = beforeInvocation;
|
||||
}
|
||||
public void setCacheWide(boolean cacheWide) {
|
||||
this.cacheWide = cacheWide;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder sb = super.getOperationDescription();
|
||||
sb.append(",");
|
||||
sb.append(this.cacheWide);
|
||||
sb.append(",");
|
||||
sb.append(this.beforeInvocation);
|
||||
return sb;
|
||||
}
|
||||
public void setBeforeInvocation(boolean beforeInvocation) {
|
||||
this.beforeInvocation = beforeInvocation;
|
||||
}
|
||||
|
||||
public CacheEvictOperation build() {
|
||||
return new CacheEvictOperation(this);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder sb = super.getOperationDescription();
|
||||
sb.append(",");
|
||||
sb.append(this.cacheWide);
|
||||
sb.append(",");
|
||||
sb.append(this.beforeInvocation);
|
||||
return sb;
|
||||
}
|
||||
|
||||
public CacheEvictOperation build() {
|
||||
return new CacheEvictOperation(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,197 +31,196 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
public abstract class CacheOperation implements BasicOperation {
|
||||
|
||||
private final String name;
|
||||
private final String name;
|
||||
|
||||
private final Set<String> cacheNames;
|
||||
private final Set<String> cacheNames;
|
||||
|
||||
private final String key;
|
||||
private final String key;
|
||||
|
||||
private final String keyGenerator;
|
||||
private final String keyGenerator;
|
||||
|
||||
private final String cacheManager;
|
||||
private final String cacheManager;
|
||||
|
||||
private final String cacheResolver;
|
||||
private final String cacheResolver;
|
||||
|
||||
private final String condition;
|
||||
private final String condition;
|
||||
|
||||
private final String toString;
|
||||
private final String toString;
|
||||
|
||||
protected CacheOperation(Builder b) {
|
||||
this.name = b.name;
|
||||
this.cacheNames = b.cacheNames;
|
||||
this.key = b.key;
|
||||
this.keyGenerator = b.keyGenerator;
|
||||
this.cacheManager = b.cacheManager;
|
||||
this.cacheResolver = b.cacheResolver;
|
||||
this.condition = b.condition;
|
||||
this.toString = b.getOperationDescription().toString();
|
||||
}
|
||||
protected CacheOperation(Builder b) {
|
||||
this.name = b.name;
|
||||
this.cacheNames = b.cacheNames;
|
||||
this.key = b.key;
|
||||
this.keyGenerator = b.keyGenerator;
|
||||
this.cacheManager = b.cacheManager;
|
||||
this.cacheResolver = b.cacheResolver;
|
||||
this.condition = b.condition;
|
||||
this.toString = b.getOperationDescription().toString();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> getCacheNames() {
|
||||
return this.cacheNames;
|
||||
}
|
||||
@Override
|
||||
public Set<String> getCacheNames() {
|
||||
return this.cacheNames;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
public String getKeyGenerator() {
|
||||
return this.keyGenerator;
|
||||
}
|
||||
|
||||
|
||||
public String getKeyGenerator() {
|
||||
return this.keyGenerator;
|
||||
}
|
||||
public String getCacheManager() {
|
||||
return this.cacheManager;
|
||||
}
|
||||
|
||||
|
||||
public String getCacheManager() {
|
||||
return this.cacheManager;
|
||||
}
|
||||
public String getCacheResolver() {
|
||||
return this.cacheResolver;
|
||||
}
|
||||
|
||||
|
||||
public String getCacheResolver() {
|
||||
return this.cacheResolver;
|
||||
}
|
||||
public String getCondition() {
|
||||
return this.condition;
|
||||
}
|
||||
|
||||
|
||||
public String getCondition() {
|
||||
return this.condition;
|
||||
}
|
||||
/**
|
||||
* This implementation compares the {@code toString()} results.
|
||||
*
|
||||
* @see #toString()
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (other instanceof CacheOperation && toString().equals(other.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation returns {@code toString()}'s hash code.
|
||||
*
|
||||
* @see #toString()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation compares the {@code toString()} results.
|
||||
*
|
||||
* @see #toString()
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (other instanceof CacheOperation && toString().equals(other.toString()));
|
||||
}
|
||||
/**
|
||||
* Return an identifying description for this cache operation.
|
||||
* <p>Returned value is produced by calling {@link Builder#getOperationDescription()}
|
||||
* during object construction. This method is used in {#hashCode} and {#equals}.
|
||||
*
|
||||
* @see Builder#getOperationDescription()
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return this.toString;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation returns {@code toString()}'s hash code.
|
||||
*
|
||||
* @see #toString()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
public abstract static class Builder {
|
||||
|
||||
/**
|
||||
* Return an identifying description for this cache operation.
|
||||
* <p>Returned value is produced by calling {@link Builder#getOperationDescription()}
|
||||
* during object construction. This method is used in {#hashCode} and {#equals}.
|
||||
*
|
||||
* @see Builder#getOperationDescription()
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return toString;
|
||||
}
|
||||
private String name = "";
|
||||
|
||||
public abstract static class Builder {
|
||||
private Set<String> cacheNames = Collections.emptySet();
|
||||
|
||||
private String name = "";
|
||||
private String key = "";
|
||||
|
||||
private Set<String> cacheNames = Collections.emptySet();
|
||||
private String keyGenerator = "";
|
||||
|
||||
private String key = "";
|
||||
private String cacheManager = "";
|
||||
|
||||
private String keyGenerator = "";
|
||||
private String cacheResolver = "";
|
||||
|
||||
private String cacheManager = "";
|
||||
private String condition = "";
|
||||
|
||||
private String cacheResolver = "";
|
||||
public void setName(String name) {
|
||||
Assert.hasText(name);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private String condition = "";
|
||||
public void setCacheName(String cacheName) {
|
||||
Assert.hasText(cacheName);
|
||||
this.cacheNames = Collections.singleton(cacheName);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Assert.hasText(name);
|
||||
this.name = name;
|
||||
}
|
||||
public void setCacheNames(String... cacheNames) {
|
||||
this.cacheNames = new LinkedHashSet<String>(cacheNames.length);
|
||||
for (String cacheName : cacheNames) {
|
||||
Assert.hasText(cacheName, "Cache name must be non-null if specified");
|
||||
this.cacheNames.add(cacheName);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCacheName(String cacheName) {
|
||||
Assert.hasText(cacheName);
|
||||
this.cacheNames = Collections.singleton(cacheName);
|
||||
}
|
||||
public Set<String> getCacheNames() {
|
||||
return this.cacheNames;
|
||||
}
|
||||
|
||||
public void setCacheNames(String... cacheNames) {
|
||||
this.cacheNames = new LinkedHashSet<String>(cacheNames.length);
|
||||
for (String cacheName : cacheNames) {
|
||||
Assert.hasText(cacheName, "Cache name must be non-null if specified");
|
||||
this.cacheNames.add(cacheName);
|
||||
}
|
||||
}
|
||||
public void setKey(String key) {
|
||||
Assert.notNull(key);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public Set<String> getCacheNames() {
|
||||
return cacheNames;
|
||||
}
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
Assert.notNull(key);
|
||||
this.key = key;
|
||||
}
|
||||
public String getKeyGenerator() {
|
||||
return this.keyGenerator;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
public String getCacheManager() {
|
||||
return this.cacheManager;
|
||||
}
|
||||
|
||||
public String getKeyGenerator() {
|
||||
return keyGenerator;
|
||||
}
|
||||
public String getCacheResolver() {
|
||||
return this.cacheResolver;
|
||||
}
|
||||
|
||||
public String getCacheManager() {
|
||||
return cacheManager;
|
||||
}
|
||||
public void setKeyGenerator(String keyGenerator) {
|
||||
Assert.notNull(keyGenerator);
|
||||
this.keyGenerator = keyGenerator;
|
||||
}
|
||||
|
||||
public String getCacheResolver() {
|
||||
return cacheResolver;
|
||||
}
|
||||
public void setCacheManager(String cacheManager) {
|
||||
Assert.notNull(cacheManager);
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
public void setKeyGenerator(String keyGenerator) {
|
||||
Assert.notNull(keyGenerator);
|
||||
this.keyGenerator = keyGenerator;
|
||||
}
|
||||
public void setCacheResolver(String cacheResolver) {
|
||||
Assert.notNull(this.cacheManager);
|
||||
this.cacheResolver = cacheResolver;
|
||||
}
|
||||
|
||||
public void setCacheManager(String cacheManager) {
|
||||
Assert.notNull(cacheManager);
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
public void setCondition(String condition) {
|
||||
Assert.notNull(condition);
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public void setCacheResolver(String cacheResolver) {
|
||||
Assert.notNull(cacheManager);
|
||||
this.cacheResolver = cacheResolver;
|
||||
}
|
||||
/**
|
||||
* Return an identifying description for this caching operation.
|
||||
* <p>Available to subclasses, for inclusion in their {@code toString()} result.
|
||||
*/
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder result = new StringBuilder(getClass().getSimpleName());
|
||||
result.append("[").append(this.name);
|
||||
result.append("] caches=").append(this.cacheNames);
|
||||
result.append(" | key='").append(this.key);
|
||||
result.append("' | keyGenerator='").append(this.keyGenerator);
|
||||
result.append("' | cacheManager='").append(this.cacheManager);
|
||||
result.append("' | cacheResolver='").append(this.cacheResolver);
|
||||
result.append("' | condition='").append(this.condition).append("'");
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setCondition(String condition) {
|
||||
Assert.notNull(condition);
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an identifying description for this caching operation.
|
||||
* <p>Available to subclasses, for inclusion in their {@code toString()} result.
|
||||
*/
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder result = new StringBuilder(getClass().getSimpleName());
|
||||
result.append("[").append(this.name);
|
||||
result.append("] caches=").append(this.cacheNames);
|
||||
result.append(" | key='").append(this.key);
|
||||
result.append("' | keyGenerator='").append(this.keyGenerator);
|
||||
result.append("' | cacheManager='").append(this.cacheManager);
|
||||
result.append("' | cacheResolver='").append(this.cacheResolver);
|
||||
result.append("' | condition='").append(this.condition).append("'");
|
||||
return result;
|
||||
}
|
||||
|
||||
public abstract CacheOperation build();
|
||||
}
|
||||
public abstract CacheOperation build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,36 +25,36 @@ package org.springframework.cache.interceptor;
|
|||
*/
|
||||
public class CachePutOperation extends CacheOperation {
|
||||
|
||||
private final String unless;
|
||||
private final String unless;
|
||||
|
||||
public CachePutOperation(CachePutOperation.Builder b) {
|
||||
super(b);
|
||||
this.unless = b.unless;
|
||||
}
|
||||
public CachePutOperation(CachePutOperation.Builder b) {
|
||||
super(b);
|
||||
this.unless = b.unless;
|
||||
}
|
||||
|
||||
public String getUnless() {
|
||||
return this.unless;
|
||||
}
|
||||
|
||||
public static class Builder extends CacheOperation.Builder {
|
||||
public static class Builder extends CacheOperation.Builder {
|
||||
|
||||
private String unless;
|
||||
private String unless;
|
||||
|
||||
public void setUnless(String unless) {
|
||||
this.unless = unless;
|
||||
}
|
||||
public void setUnless(String unless) {
|
||||
this.unless = unless;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder sb = super.getOperationDescription();
|
||||
sb.append(" | unless='");
|
||||
sb.append(this.unless);
|
||||
sb.append("'");
|
||||
return sb;
|
||||
}
|
||||
@Override
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder sb = super.getOperationDescription();
|
||||
sb.append(" | unless='");
|
||||
sb.append(this.unless);
|
||||
sb.append("'");
|
||||
return sb;
|
||||
}
|
||||
|
||||
public CachePutOperation build() {
|
||||
return new CachePutOperation(this);
|
||||
}
|
||||
}
|
||||
public CachePutOperation build() {
|
||||
return new CachePutOperation(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,15 +25,15 @@ package org.springframework.cache.interceptor;
|
|||
*/
|
||||
public class CacheableOperation extends CacheOperation {
|
||||
|
||||
private final String unless;
|
||||
private final String unless;
|
||||
|
||||
private boolean sync;
|
||||
private boolean sync;
|
||||
|
||||
public CacheableOperation(CacheableOperation.Builder b) {
|
||||
super(b);
|
||||
this.unless = b.unless;
|
||||
this.sync = b.sync;
|
||||
}
|
||||
public CacheableOperation(CacheableOperation.Builder b) {
|
||||
super(b);
|
||||
this.unless = b.unless;
|
||||
this.sync = b.sync;
|
||||
}
|
||||
|
||||
public String getUnless() {
|
||||
return this.unless;
|
||||
|
|
@ -44,34 +44,35 @@ public class CacheableOperation extends CacheOperation {
|
|||
}
|
||||
|
||||
|
||||
public static class Builder extends CacheOperation.Builder {
|
||||
public static class Builder extends CacheOperation.Builder {
|
||||
|
||||
private String unless;
|
||||
private String unless;
|
||||
|
||||
private boolean sync;
|
||||
public void setUnless(String unless) {
|
||||
this.unless = unless;
|
||||
}
|
||||
private boolean sync;
|
||||
|
||||
public void setSync(boolean sync) {
|
||||
this.sync = sync;
|
||||
}
|
||||
public void setUnless(String unless) {
|
||||
this.unless = unless;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder sb = super.getOperationDescription();
|
||||
sb.append(" | unless='");
|
||||
sb.append(this.unless);
|
||||
sb.append("'");
|
||||
sb.append(" | sync='");
|
||||
sb.append(this.sync);
|
||||
sb.append("'");
|
||||
return sb;
|
||||
}
|
||||
public void setSync(boolean sync) {
|
||||
this.sync = sync;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheableOperation build() {
|
||||
return new CacheableOperation(this);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder sb = super.getOperationDescription();
|
||||
sb.append(" | unless='");
|
||||
sb.append(this.unless);
|
||||
sb.append("'");
|
||||
sb.append(" | sync='");
|
||||
sb.append(this.sync);
|
||||
sb.append("'");
|
||||
return sb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheableOperation build() {
|
||||
return new CacheableOperation(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue