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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 parseCacheableAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, Cacheable cacheable) {
|
||||||
CacheableOperation.Builder opBuilder = new CacheableOperation.Builder();
|
CacheableOperation.Builder builder = new CacheableOperation.Builder();
|
||||||
|
|
||||||
opBuilder.setCacheNames(cacheable.cacheNames());
|
builder.setCacheNames(cacheable.cacheNames());
|
||||||
opBuilder.setCondition(cacheable.condition());
|
builder.setCondition(cacheable.condition());
|
||||||
opBuilder.setUnless(cacheable.unless());
|
builder.setUnless(cacheable.unless());
|
||||||
opBuilder.setKey(cacheable.key());
|
builder.setKey(cacheable.key());
|
||||||
opBuilder.setKeyGenerator(cacheable.keyGenerator());
|
builder.setKeyGenerator(cacheable.keyGenerator());
|
||||||
opBuilder.setCacheManager(cacheable.cacheManager());
|
builder.setCacheManager(cacheable.cacheManager());
|
||||||
opBuilder.setCacheResolver(cacheable.cacheResolver());
|
builder.setCacheResolver(cacheable.cacheResolver());
|
||||||
opBuilder.setSync(cacheable.sync());
|
builder.setSync(cacheable.sync());
|
||||||
opBuilder.setName(ae.toString());
|
builder.setName(ae.toString());
|
||||||
|
|
||||||
defaultConfig.applyDefault(opBuilder);
|
defaultConfig.applyDefault(builder);
|
||||||
CacheableOperation op = opBuilder.build();
|
CacheableOperation op = builder.build();
|
||||||
validateCacheOperation(ae, op);
|
validateCacheOperation(ae, op);
|
||||||
|
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheEvictOperation parseEvictAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CacheEvict cacheEvict) {
|
CacheEvictOperation parseEvictAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CacheEvict cacheEvict) {
|
||||||
CacheEvictOperation.Builder opBuilder = new CacheEvictOperation.Builder();
|
CacheEvictOperation.Builder builder = new CacheEvictOperation.Builder();
|
||||||
|
|
||||||
opBuilder.setCacheNames(cacheEvict.cacheNames());
|
builder.setCacheNames(cacheEvict.cacheNames());
|
||||||
opBuilder.setCondition(cacheEvict.condition());
|
builder.setCondition(cacheEvict.condition());
|
||||||
opBuilder.setKey(cacheEvict.key());
|
builder.setKey(cacheEvict.key());
|
||||||
opBuilder.setKeyGenerator(cacheEvict.keyGenerator());
|
builder.setKeyGenerator(cacheEvict.keyGenerator());
|
||||||
opBuilder.setCacheManager(cacheEvict.cacheManager());
|
builder.setCacheManager(cacheEvict.cacheManager());
|
||||||
opBuilder.setCacheResolver(cacheEvict.cacheResolver());
|
builder.setCacheResolver(cacheEvict.cacheResolver());
|
||||||
opBuilder.setCacheWide(cacheEvict.allEntries());
|
builder.setCacheWide(cacheEvict.allEntries());
|
||||||
opBuilder.setBeforeInvocation(cacheEvict.beforeInvocation());
|
builder.setBeforeInvocation(cacheEvict.beforeInvocation());
|
||||||
opBuilder.setName(ae.toString());
|
builder.setName(ae.toString());
|
||||||
|
|
||||||
defaultConfig.applyDefault(opBuilder);
|
defaultConfig.applyDefault(builder);
|
||||||
CacheEvictOperation op = opBuilder.build();
|
CacheEvictOperation op = builder.build();
|
||||||
validateCacheOperation(ae, op);
|
validateCacheOperation(ae, op);
|
||||||
|
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheOperation parsePutAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CachePut cachePut) {
|
CacheOperation parsePutAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CachePut cachePut) {
|
||||||
CachePutOperation.Builder opBuilder = new CachePutOperation.Builder();
|
CachePutOperation.Builder builder = new CachePutOperation.Builder();
|
||||||
|
|
||||||
opBuilder.setCacheNames(cachePut.cacheNames());
|
builder.setCacheNames(cachePut.cacheNames());
|
||||||
opBuilder.setCondition(cachePut.condition());
|
builder.setCondition(cachePut.condition());
|
||||||
opBuilder.setUnless(cachePut.unless());
|
builder.setUnless(cachePut.unless());
|
||||||
opBuilder.setKey(cachePut.key());
|
builder.setKey(cachePut.key());
|
||||||
opBuilder.setKeyGenerator(cachePut.keyGenerator());
|
builder.setKeyGenerator(cachePut.keyGenerator());
|
||||||
opBuilder.setCacheManager(cachePut.cacheManager());
|
builder.setCacheManager(cachePut.cacheManager());
|
||||||
opBuilder.setCacheResolver(cachePut.cacheResolver());
|
builder.setCacheResolver(cachePut.cacheResolver());
|
||||||
opBuilder.setName(ae.toString());
|
builder.setName(ae.toString());
|
||||||
|
|
||||||
defaultConfig.applyDefault(opBuilder);
|
defaultConfig.applyDefault(builder);
|
||||||
CachePutOperation op = opBuilder.build();
|
CachePutOperation op = builder.build();
|
||||||
validateCacheOperation(ae, op);
|
validateCacheOperation(ae, op);
|
||||||
|
|
||||||
return op;
|
return op;
|
||||||
|
|
@ -278,26 +278,26 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the defaults to the specified {@link CacheOperation}.
|
* Apply the defaults to the specified {@link CacheOperation.Builder}.
|
||||||
* @param operation the operation to update
|
* @param builder the operation builder to update
|
||||||
*/
|
*/
|
||||||
public void applyDefault(CacheOperation.Builder operation) {
|
public void applyDefault(CacheOperation.Builder builder) {
|
||||||
if (operation.getCacheNames().isEmpty() && this.cacheNames != null) {
|
if (builder.getCacheNames().isEmpty() && this.cacheNames != null) {
|
||||||
operation.setCacheNames(this.cacheNames);
|
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)) {
|
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
|
// One of these is set so we should not inherit anything
|
||||||
}
|
}
|
||||||
else if (StringUtils.hasText(this.cacheResolver)) {
|
else if (StringUtils.hasText(this.cacheResolver)) {
|
||||||
operation.setCacheResolver(this.cacheResolver);
|
builder.setCacheResolver(this.cacheResolver);
|
||||||
}
|
}
|
||||||
else if (StringUtils.hasText(this.cacheManager)) {
|
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());
|
String name = prop.merge(opElement, parserContext.getReaderContext());
|
||||||
TypedStringValue nameHolder = new TypedStringValue(name);
|
TypedStringValue nameHolder = new TypedStringValue(name);
|
||||||
nameHolder.setSource(parserContext.extractSource(opElement));
|
nameHolder.setSource(parserContext.extractSource(opElement));
|
||||||
CacheableOperation.Builder op = prop.merge(opElement, parserContext.getReaderContext(), new CacheableOperation.Builder());
|
CacheableOperation.Builder builder = prop.merge(opElement,
|
||||||
op.setUnless(getAttributeValue(opElement, "unless", ""));
|
parserContext.getReaderContext(), new CacheableOperation.Builder());
|
||||||
op.setSync(Boolean.valueOf(getAttributeValue(opElement, "sync", "false")));
|
builder.setUnless(getAttributeValue(opElement, "unless", ""));
|
||||||
|
builder.setSync(Boolean.valueOf(getAttributeValue(opElement, "sync", "false")));
|
||||||
|
|
||||||
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
||||||
if (col == null) {
|
if (col == null) {
|
||||||
col = new ArrayList<CacheOperation>(2);
|
col = new ArrayList<CacheOperation>(2);
|
||||||
cacheOpMap.put(nameHolder, col);
|
cacheOpMap.put(nameHolder, col);
|
||||||
}
|
}
|
||||||
col.add(op.build());
|
col.add(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Element> evictCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_EVICT_ELEMENT);
|
List<Element> evictCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_EVICT_ELEMENT);
|
||||||
|
|
@ -125,16 +126,17 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
||||||
String name = prop.merge(opElement, parserContext.getReaderContext());
|
String name = prop.merge(opElement, parserContext.getReaderContext());
|
||||||
TypedStringValue nameHolder = new TypedStringValue(name);
|
TypedStringValue nameHolder = new TypedStringValue(name);
|
||||||
nameHolder.setSource(parserContext.extractSource(opElement));
|
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");
|
String wide = opElement.getAttribute("all-entries");
|
||||||
if (StringUtils.hasText(wide)) {
|
if (StringUtils.hasText(wide)) {
|
||||||
op.setCacheWide(Boolean.valueOf(wide.trim()));
|
builder.setCacheWide(Boolean.valueOf(wide.trim()));
|
||||||
}
|
}
|
||||||
|
|
||||||
String after = opElement.getAttribute("before-invocation");
|
String after = opElement.getAttribute("before-invocation");
|
||||||
if (StringUtils.hasText(after)) {
|
if (StringUtils.hasText(after)) {
|
||||||
op.setBeforeInvocation(Boolean.valueOf(after.trim()));
|
builder.setBeforeInvocation(Boolean.valueOf(after.trim()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
||||||
|
|
@ -142,7 +144,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
||||||
col = new ArrayList<CacheOperation>(2);
|
col = new ArrayList<CacheOperation>(2);
|
||||||
cacheOpMap.put(nameHolder, col);
|
cacheOpMap.put(nameHolder, col);
|
||||||
}
|
}
|
||||||
col.add(op.build());
|
col.add(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Element> putCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_PUT_ELEMENT);
|
List<Element> putCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_PUT_ELEMENT);
|
||||||
|
|
@ -151,15 +153,16 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
||||||
String name = prop.merge(opElement, parserContext.getReaderContext());
|
String name = prop.merge(opElement, parserContext.getReaderContext());
|
||||||
TypedStringValue nameHolder = new TypedStringValue(name);
|
TypedStringValue nameHolder = new TypedStringValue(name);
|
||||||
nameHolder.setSource(parserContext.extractSource(opElement));
|
nameHolder.setSource(parserContext.extractSource(opElement));
|
||||||
CachePutOperation.Builder op = prop.merge(opElement, parserContext.getReaderContext(), new CachePutOperation.Builder());
|
CachePutOperation.Builder builder = prop.merge(opElement,
|
||||||
op.setUnless(getAttributeValue(opElement, "unless", ""));
|
parserContext.getReaderContext(), new CachePutOperation.Builder());
|
||||||
|
builder.setUnless(getAttributeValue(opElement, "unless", ""));
|
||||||
|
|
||||||
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
||||||
if (col == null) {
|
if (col == null) {
|
||||||
col = new ArrayList<CacheOperation>(2);
|
col = new ArrayList<CacheOperation>(2);
|
||||||
cacheOpMap.put(nameHolder, col);
|
cacheOpMap.put(nameHolder, col);
|
||||||
}
|
}
|
||||||
col.add(op.build());
|
col.add(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchCacheOperationSource.class);
|
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");
|
String cache = element.getAttribute("cache");
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
|
|
@ -221,21 +224,21 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
||||||
readerCtx.error("No cache specified specified for " + element.getNodeName(), element);
|
readerCtx.error("No cache specified specified for " + element.getNodeName(), element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
op.setCacheNames(localCaches);
|
builder.setCacheNames(localCaches);
|
||||||
|
|
||||||
op.setKey(getAttributeValue(element, "key", this.key));
|
builder.setKey(getAttributeValue(element, "key", this.key));
|
||||||
op.setKeyGenerator(getAttributeValue(element, "key-generator", this.keyGenerator));
|
builder.setKeyGenerator(getAttributeValue(element, "key-generator", this.keyGenerator));
|
||||||
op.setCacheManager(getAttributeValue(element, "cache-manager", this.cacheManager));
|
builder.setCacheManager(getAttributeValue(element, "cache-manager", this.cacheManager));
|
||||||
op.setCondition(getAttributeValue(element, "condition", this.condition));
|
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 '"
|
throw new IllegalStateException("Invalid cache advice configuration on '"
|
||||||
+ element.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " +
|
+ element.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " +
|
||||||
"These attributes are mutually exclusive: either set the SpEL expression used to" +
|
"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.");
|
"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) {
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 {
|
public class CacheEvictOperation extends CacheOperation {
|
||||||
|
|
||||||
private final boolean cacheWide;
|
private final boolean cacheWide;
|
||||||
|
|
||||||
private final boolean beforeInvocation;
|
private final boolean beforeInvocation;
|
||||||
|
|
||||||
public boolean isCacheWide() {
|
public boolean isCacheWide() {
|
||||||
return this.cacheWide;
|
return this.cacheWide;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBeforeInvocation() {
|
public boolean isBeforeInvocation() {
|
||||||
return this.beforeInvocation;
|
return this.beforeInvocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheEvictOperation(CacheEvictOperation.Builder b) {
|
public CacheEvictOperation(CacheEvictOperation.Builder b) {
|
||||||
super(b);
|
super(b);
|
||||||
this.cacheWide = b.cacheWide;
|
this.cacheWide = b.cacheWide;
|
||||||
this.beforeInvocation = b.beforeInvocation;
|
this.beforeInvocation = b.beforeInvocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder extends CacheOperation.Builder {
|
public static class Builder extends CacheOperation.Builder {
|
||||||
private boolean cacheWide = false;
|
|
||||||
|
|
||||||
private boolean beforeInvocation = false;
|
private boolean cacheWide = false;
|
||||||
|
|
||||||
public void setCacheWide(boolean cacheWide) {
|
private boolean beforeInvocation = false;
|
||||||
this.cacheWide = cacheWide;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBeforeInvocation(boolean beforeInvocation) {
|
public void setCacheWide(boolean cacheWide) {
|
||||||
this.beforeInvocation = beforeInvocation;
|
this.cacheWide = cacheWide;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setBeforeInvocation(boolean beforeInvocation) {
|
||||||
protected StringBuilder getOperationDescription() {
|
this.beforeInvocation = beforeInvocation;
|
||||||
StringBuilder sb = super.getOperationDescription();
|
}
|
||||||
sb.append(",");
|
|
||||||
sb.append(this.cacheWide);
|
|
||||||
sb.append(",");
|
|
||||||
sb.append(this.beforeInvocation);
|
|
||||||
return sb;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CacheEvictOperation build() {
|
@Override
|
||||||
return new CacheEvictOperation(this);
|
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 {
|
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) {
|
protected CacheOperation(Builder b) {
|
||||||
this.name = b.name;
|
this.name = b.name;
|
||||||
this.cacheNames = b.cacheNames;
|
this.cacheNames = b.cacheNames;
|
||||||
this.key = b.key;
|
this.key = b.key;
|
||||||
this.keyGenerator = b.keyGenerator;
|
this.keyGenerator = b.keyGenerator;
|
||||||
this.cacheManager = b.cacheManager;
|
this.cacheManager = b.cacheManager;
|
||||||
this.cacheResolver = b.cacheResolver;
|
this.cacheResolver = b.cacheResolver;
|
||||||
this.condition = b.condition;
|
this.condition = b.condition;
|
||||||
this.toString = b.getOperationDescription().toString();
|
this.toString = b.getOperationDescription().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getCacheNames() {
|
public Set<String> getCacheNames() {
|
||||||
return this.cacheNames;
|
return this.cacheNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return this.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getKey() {
|
public String getKeyGenerator() {
|
||||||
return this.key;
|
return this.keyGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getKeyGenerator() {
|
public String getCacheManager() {
|
||||||
return this.keyGenerator;
|
return this.cacheManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getCacheManager() {
|
public String getCacheResolver() {
|
||||||
return this.cacheManager;
|
return this.cacheResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getCacheResolver() {
|
public String getCondition() {
|
||||||
return this.cacheResolver;
|
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.
|
* Return an identifying description for this cache operation.
|
||||||
*
|
* <p>Returned value is produced by calling {@link Builder#getOperationDescription()}
|
||||||
* @see #toString()
|
* during object construction. This method is used in {#hashCode} and {#equals}.
|
||||||
*/
|
*
|
||||||
@Override
|
* @see Builder#getOperationDescription()
|
||||||
public boolean equals(Object other) {
|
*/
|
||||||
return (other instanceof CacheOperation && toString().equals(other.toString()));
|
@Override
|
||||||
}
|
public final String toString() {
|
||||||
|
return this.toString;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public abstract static class Builder {
|
||||||
* This implementation returns {@code toString()}'s hash code.
|
|
||||||
*
|
|
||||||
* @see #toString()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return toString().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
private String name = "";
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
public void setCacheNames(String... cacheNames) {
|
||||||
Assert.hasText(name);
|
this.cacheNames = new LinkedHashSet<String>(cacheNames.length);
|
||||||
this.name = name;
|
for (String cacheName : cacheNames) {
|
||||||
}
|
Assert.hasText(cacheName, "Cache name must be non-null if specified");
|
||||||
|
this.cacheNames.add(cacheName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setCacheName(String cacheName) {
|
public Set<String> getCacheNames() {
|
||||||
Assert.hasText(cacheName);
|
return this.cacheNames;
|
||||||
this.cacheNames = Collections.singleton(cacheName);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void setCacheNames(String... cacheNames) {
|
public void setKey(String key) {
|
||||||
this.cacheNames = new LinkedHashSet<String>(cacheNames.length);
|
Assert.notNull(key);
|
||||||
for (String cacheName : cacheNames) {
|
this.key = key;
|
||||||
Assert.hasText(cacheName, "Cache name must be non-null if specified");
|
}
|
||||||
this.cacheNames.add(cacheName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getCacheNames() {
|
public String getKey() {
|
||||||
return cacheNames;
|
return this.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(String key) {
|
public String getKeyGenerator() {
|
||||||
Assert.notNull(key);
|
return this.keyGenerator;
|
||||||
this.key = key;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public String getKey() {
|
public String getCacheManager() {
|
||||||
return key;
|
return this.cacheManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyGenerator() {
|
public String getCacheResolver() {
|
||||||
return keyGenerator;
|
return this.cacheResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCacheManager() {
|
public void setKeyGenerator(String keyGenerator) {
|
||||||
return cacheManager;
|
Assert.notNull(keyGenerator);
|
||||||
}
|
this.keyGenerator = keyGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCacheResolver() {
|
public void setCacheManager(String cacheManager) {
|
||||||
return cacheResolver;
|
Assert.notNull(cacheManager);
|
||||||
}
|
this.cacheManager = cacheManager;
|
||||||
|
}
|
||||||
|
|
||||||
public void setKeyGenerator(String keyGenerator) {
|
public void setCacheResolver(String cacheResolver) {
|
||||||
Assert.notNull(keyGenerator);
|
Assert.notNull(this.cacheManager);
|
||||||
this.keyGenerator = keyGenerator;
|
this.cacheResolver = cacheResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCacheManager(String cacheManager) {
|
public void setCondition(String condition) {
|
||||||
Assert.notNull(cacheManager);
|
Assert.notNull(condition);
|
||||||
this.cacheManager = cacheManager;
|
this.condition = condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCacheResolver(String cacheResolver) {
|
/**
|
||||||
Assert.notNull(cacheManager);
|
* Return an identifying description for this caching operation.
|
||||||
this.cacheResolver = cacheResolver;
|
* <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) {
|
public abstract CacheOperation build();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,36 +25,36 @@ package org.springframework.cache.interceptor;
|
||||||
*/
|
*/
|
||||||
public class CachePutOperation extends CacheOperation {
|
public class CachePutOperation extends CacheOperation {
|
||||||
|
|
||||||
private final String unless;
|
private final String unless;
|
||||||
|
|
||||||
public CachePutOperation(CachePutOperation.Builder b) {
|
public CachePutOperation(CachePutOperation.Builder b) {
|
||||||
super(b);
|
super(b);
|
||||||
this.unless = b.unless;
|
this.unless = b.unless;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUnless() {
|
public String getUnless() {
|
||||||
return this.unless;
|
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) {
|
public void setUnless(String unless) {
|
||||||
this.unless = unless;
|
this.unless = unless;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected StringBuilder getOperationDescription() {
|
protected StringBuilder getOperationDescription() {
|
||||||
StringBuilder sb = super.getOperationDescription();
|
StringBuilder sb = super.getOperationDescription();
|
||||||
sb.append(" | unless='");
|
sb.append(" | unless='");
|
||||||
sb.append(this.unless);
|
sb.append(this.unless);
|
||||||
sb.append("'");
|
sb.append("'");
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachePutOperation build() {
|
public CachePutOperation build() {
|
||||||
return new CachePutOperation(this);
|
return new CachePutOperation(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,15 @@ package org.springframework.cache.interceptor;
|
||||||
*/
|
*/
|
||||||
public class CacheableOperation extends CacheOperation {
|
public class CacheableOperation extends CacheOperation {
|
||||||
|
|
||||||
private final String unless;
|
private final String unless;
|
||||||
|
|
||||||
private boolean sync;
|
private boolean sync;
|
||||||
|
|
||||||
public CacheableOperation(CacheableOperation.Builder b) {
|
public CacheableOperation(CacheableOperation.Builder b) {
|
||||||
super(b);
|
super(b);
|
||||||
this.unless = b.unless;
|
this.unless = b.unless;
|
||||||
this.sync = b.sync;
|
this.sync = b.sync;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUnless() {
|
public String getUnless() {
|
||||||
return this.unless;
|
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;
|
private boolean sync;
|
||||||
public void setUnless(String unless) {
|
|
||||||
this.unless = unless;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSync(boolean sync) {
|
public void setUnless(String unless) {
|
||||||
this.sync = sync;
|
this.unless = unless;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setSync(boolean sync) {
|
||||||
protected StringBuilder getOperationDescription() {
|
this.sync = sync;
|
||||||
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
|
@Override
|
||||||
public CacheableOperation build() {
|
protected StringBuilder getOperationDescription() {
|
||||||
return new CacheableOperation(this);
|
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