类org.springframework.cache.interceptor.CacheableOperation源码实例Demo

下面列出了怎么用org.springframework.cache.interceptor.CacheableOperation的API类实例代码及写法,或者点击链接到github查看源代码。

private CacheableOperation parseCacheableAnnotation(
		AnnotatedElement ae, DefaultCacheConfig defaultConfig, Cacheable cacheable) {

	CacheableOperation.Builder builder = new CacheableOperation.Builder();

	builder.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());

	defaultConfig.applyDefault(builder);
	CacheableOperation op = builder.build();
	validateCacheOperation(ae, op);

	return op;
}
 
@Test
public void multipleComposedAnnotations() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 4);
	Iterator<CacheOperation> it = ops.iterator();

	CacheOperation cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared")));
	assertThat(cacheOperation.getKey(), equalTo(""));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
	assertThat(cacheOperation.getKey(), equalTo("composedKey"));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("foo")));
	assertThat(cacheOperation.getKey(), equalTo(""));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheEvictOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCacheEvict")));
	assertThat(cacheOperation.getKey(), equalTo("composedEvictionKey"));
}
 
private CacheableOperation parseCacheableAnnotation(
		AnnotatedElement ae, DefaultCacheConfig defaultConfig, Cacheable cacheable) {

	CacheableOperation.Builder builder = new CacheableOperation.Builder();

	builder.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());

	defaultConfig.applyDefault(builder);
	CacheableOperation op = builder.build();
	validateCacheOperation(ae, op);

	return op;
}
 
@Test
public void multipleComposedAnnotations() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 4);
	Iterator<CacheOperation> it = ops.iterator();

	CacheOperation cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared")));
	assertThat(cacheOperation.getKey(), equalTo(""));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
	assertThat(cacheOperation.getKey(), equalTo("composedKey"));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("foo")));
	assertThat(cacheOperation.getKey(), equalTo(""));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheEvictOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCacheEvict")));
	assertThat(cacheOperation.getKey(), equalTo("composedEvictionKey"));
}
 
源代码5 项目: lams   文件: SpringCacheAnnotationParser.java
CacheableOperation parseCacheableAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, Cacheable cacheable) {
	CacheableOperation.Builder builder = new CacheableOperation.Builder();

	builder.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());

	defaultConfig.applyDefault(builder);
	CacheableOperation op = builder.build();
	validateCacheOperation(ae, op);

	return op;
}
 
CacheableOperation parseCacheableAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, Cacheable cacheable) {
    CacheableOperation.Builder builder = new CacheableOperation.Builder();

    builder.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());

    defaultConfig.applyDefault(builder);
    CacheableOperation op = builder.build();
    validateCacheOperation(ae, op);

    return op;
}
 
CacheableOperation parseCacheableAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, Cacheable cacheable) {
	CacheableOperation op = new CacheableOperation();

	op.setCacheNames(cacheable.cacheNames());
	op.setCondition(cacheable.condition());
	op.setUnless(cacheable.unless());
	op.setKey(cacheable.key());
	op.setKeyGenerator(cacheable.keyGenerator());
	op.setCacheManager(cacheable.cacheManager());
	op.setCacheResolver(cacheable.cacheResolver());
	op.setName(ae.toString());

	defaultConfig.applyDefault(op);
	validateCacheOperation(ae, op);

	return op;
}
 
@Ignore("Disabled until SPR-13475 is resolved")
@Test
public void multipleComposedAnnotations() throws Exception {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 3);
	Iterator<CacheOperation> it = ops.iterator();

	CacheOperation cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("foo")));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheEvictOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
}
 
@Test
public void multipleAnnotation() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multiple", 2);
	Iterator<CacheOperation> it = ops.iterator();
	assertTrue(it.next() instanceof CacheableOperation);
	assertTrue(it.next() instanceof CacheEvictOperation);
}
 
@Test
public void caching() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "caching", 2);
	Iterator<CacheOperation> it = ops.iterator();
	assertTrue(it.next() instanceof CacheableOperation);
	assertTrue(it.next() instanceof CacheEvictOperation);
}
 
@Test
public void singleComposedAnnotation() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 2);
	Iterator<CacheOperation> it = ops.iterator();

	CacheOperation cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared")));
	assertThat(cacheOperation.getKey(), equalTo(""));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
	assertThat(cacheOperation.getKey(), equalTo("composedKey"));
}
 
@Test
public void cacheAnnotationOverride() {
	Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheableOverride");
	assertSame(1, ops.size());
	CacheOperation cacheOperation = ops.iterator().next();
	assertTrue(cacheOperation instanceof CacheableOperation);
}
 
@Test
public void multipleAnnotation() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multiple", 2);
	Iterator<CacheOperation> it = ops.iterator();
	assertTrue(it.next() instanceof CacheableOperation);
	assertTrue(it.next() instanceof CacheEvictOperation);
}
 
@Test
public void caching() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "caching", 2);
	Iterator<CacheOperation> it = ops.iterator();
	assertTrue(it.next() instanceof CacheableOperation);
	assertTrue(it.next() instanceof CacheEvictOperation);
}
 
@Test
public void singleComposedAnnotation() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 2);
	Iterator<CacheOperation> it = ops.iterator();

	CacheOperation cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared")));
	assertThat(cacheOperation.getKey(), equalTo(""));

	cacheOperation = it.next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
	assertThat(cacheOperation.getKey(), equalTo("composedKey"));
}
 
@Test
public void cacheAnnotationOverride() {
	Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheableOverride");
	assertSame(1, ops.size());
	CacheOperation cacheOperation = ops.iterator().next();
	assertTrue(cacheOperation instanceof CacheableOperation);
}
 
@Test
public void multipleAnnotation() throws Exception {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multiple", 2);
	Iterator<CacheOperation> it = ops.iterator();
	assertTrue(it.next() instanceof CacheableOperation);
	assertTrue(it.next() instanceof CacheEvictOperation);
}
 
@Test
public void caching() throws Exception {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "caching", 2);
	Iterator<CacheOperation> it = ops.iterator();
	assertTrue(it.next() instanceof CacheableOperation);
	assertTrue(it.next() instanceof CacheEvictOperation);
}
 
@Ignore("Disabled until SPR-13475 is resolved")
@Test
public void singleComposedAnnotation() throws Exception {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 1);
	CacheOperation cacheOperation = ops.iterator().next();
	assertThat(cacheOperation, instanceOf(CacheableOperation.class));
	assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composed")));
}
 
@Test
public void singularAnnotation() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1);
	assertTrue(ops.iterator().next() instanceof CacheableOperation);
}
 
@Test
public void singularAnnotation() {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1);
	assertTrue(ops.iterator().next() instanceof CacheableOperation);
}
 
@Test
public void singularAnnotation() throws Exception {
	Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1);
	assertTrue(ops.iterator().next() instanceof CacheableOperation);
}
 
 类方法
 同包方法