org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource Java Examples

The following examples show how to use org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JCacheJavaConfigTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void exceptionCacheResolverLazilyRequired() {
	ConfigurableApplicationContext context =
			new AnnotationConfigApplicationContext(NoExceptionCacheResolverConfig.class);

	try {
		DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
		assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());

		JCacheableService<?> service = context.getBean(JCacheableService.class);
		service.cache("id");

		// This call requires the cache manager to be set
		thrown.expect(IllegalStateException.class);
		service.cacheWithException("test", false);
	}
	finally {
		context.close();
	}
}
 
Example #2
Source File: JCacheJavaConfigTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void exceptionCacheResolverLazilyRequired() {
	ConfigurableApplicationContext context =
			new AnnotationConfigApplicationContext(NoExceptionCacheResolverConfig.class);

	try {
		DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
		assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());

		JCacheableService<?> service = context.getBean(JCacheableService.class);
		service.cache("id");

		// This call requires the cache manager to be set
		assertThatIllegalStateException().isThrownBy(() ->
				service.cacheWithException("test", false));
	}
	finally {
		context.close();
	}
}
 
Example #3
Source File: AbstractJCacheConfiguration.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Bean(name = "jCacheOperationSource")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public JCacheOperationSource cacheOperationSource() {
	DefaultJCacheOperationSource source = new DefaultJCacheOperationSource();
	if (this.cacheManager != null) {
		source.setCacheManager(this.cacheManager);
	}
	if (this.keyGenerator != null) {
		source.setKeyGenerator(this.keyGenerator);
	}
	if (this.cacheResolver != null) {
		source.setCacheResolver(this.cacheResolver);
	}
	if (this.exceptionCacheResolver != null) {
		source.setExceptionCacheResolver(this.exceptionCacheResolver);
	}
	return source;
}
 
Example #4
Source File: AbstractJCacheConfiguration.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Bean(name = "jCacheOperationSource")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public JCacheOperationSource cacheOperationSource() {
	DefaultJCacheOperationSource source = new DefaultJCacheOperationSource();
	if (this.cacheManager != null) {
		source.setCacheManager(this.cacheManager);
	}
	if (this.keyGenerator != null) {
		source.setKeyGenerator(this.keyGenerator);
	}
	if (this.cacheResolver != null) {
		source.setCacheResolver(this.cacheResolver);
	}
	if (this.exceptionCacheResolver != null) {
		source.setExceptionCacheResolver(this.exceptionCacheResolver);
	}
	return source;
}
 
Example #5
Source File: JCacheJavaConfigTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void exceptionCacheResolverLazilyRequired() {
	ConfigurableApplicationContext context =
			new AnnotationConfigApplicationContext(NoExceptionCacheResolverConfig.class);

	try {
		DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
		assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());

		JCacheableService<?> service = context.getBean(JCacheableService.class);
		service.cache("id");

		// This call requires the cache manager to be set
		thrown.expect(IllegalStateException.class);
		service.cacheWithException("test", false);
	}
	finally {
		context.close();
	}
}
 
Example #6
Source File: JCacheJavaConfigTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void bothSetOnlyResolverIsUsed() {
	ConfigurableApplicationContext context =
			new AnnotationConfigApplicationContext(FullCachingConfigSupport.class);

	DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
	assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());
	assertSame(context.getBean("keyGenerator"), cos.getKeyGenerator());
	assertSame(context.getBean("exceptionCacheResolver"), cos.getExceptionCacheResolver());
	context.close();
}
 
Example #7
Source File: JCacheNamespaceDrivenTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void cacheResolver() {
	ConfigurableApplicationContext context = new GenericXmlApplicationContext(
			"/org/springframework/cache/jcache/config/jCacheNamespaceDriven-resolver.xml");

	DefaultJCacheOperationSource ci = context.getBean(DefaultJCacheOperationSource.class);
	assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
	context.close();
}
 
Example #8
Source File: JCacheJavaConfigTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void bothSetOnlyResolverIsUsed() {
	ConfigurableApplicationContext context =
			new AnnotationConfigApplicationContext(FullCachingConfigSupport.class);

	DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
	assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());
	assertSame(context.getBean("keyGenerator"), cos.getKeyGenerator());
	assertSame(context.getBean("exceptionCacheResolver"), cos.getExceptionCacheResolver());
	context.close();
}
 
Example #9
Source File: JCacheJavaConfigTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyConfigSupport() {
	ConfigurableApplicationContext context =
			new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);

	DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
	assertNotNull(cos.getCacheResolver());
	assertEquals(SimpleCacheResolver.class, cos.getCacheResolver().getClass());
	assertSame(context.getBean(CacheManager.class),
			((SimpleCacheResolver) cos.getCacheResolver()).getCacheManager());
	assertNull(cos.getExceptionCacheResolver());
	context.close();
}
 
Example #10
Source File: JCacheJavaConfigTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void fullCachingConfig() throws Exception {
	AnnotationConfigApplicationContext context =
			new AnnotationConfigApplicationContext(FullCachingConfig.class);

	DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
	assertSame(context.getBean(KeyGenerator.class), cos.getKeyGenerator());
	assertSame(context.getBean("cacheResolver", CacheResolver.class),
			cos.getCacheResolver());
	assertSame(context.getBean("exceptionCacheResolver", CacheResolver.class),
			cos.getExceptionCacheResolver());
	JCacheInterceptor interceptor = context.getBean(JCacheInterceptor.class);
	assertSame(context.getBean("errorHandler", CacheErrorHandler.class), interceptor.getErrorHandler());
}
 
Example #11
Source File: JCacheNamespaceDrivenTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void cacheResolver() {
	ConfigurableApplicationContext context = new GenericXmlApplicationContext(
			"/org/springframework/cache/jcache/config/jCacheNamespaceDriven-resolver.xml");

	DefaultJCacheOperationSource ci = context.getBean(DefaultJCacheOperationSource.class);
	assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
	context.close();
}
 
Example #12
Source File: JCacheJavaConfigTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void emptyConfigSupport() {
	ConfigurableApplicationContext context =
			new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);

	DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
	assertNotNull(cos.getCacheResolver());
	assertEquals(SimpleCacheResolver.class, cos.getCacheResolver().getClass());
	assertSame(context.getBean(CacheManager.class),
			((SimpleCacheResolver) cos.getCacheResolver()).getCacheManager());
	assertNull(cos.getExceptionCacheResolver());
	context.close();
}
 
Example #13
Source File: JCacheJavaConfigTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void fullCachingConfig() throws Exception {
	AnnotationConfigApplicationContext context =
			new AnnotationConfigApplicationContext(FullCachingConfig.class);

	DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
	assertSame(context.getBean(KeyGenerator.class), cos.getKeyGenerator());
	assertSame(context.getBean("cacheResolver", CacheResolver.class),
			cos.getCacheResolver());
	assertSame(context.getBean("exceptionCacheResolver", CacheResolver.class),
			cos.getExceptionCacheResolver());
	JCacheInterceptor interceptor = context.getBean(JCacheInterceptor.class);
	assertSame(context.getBean("errorHandler", CacheErrorHandler.class), interceptor.getErrorHandler());
}
 
Example #14
Source File: JCacheNamespaceDrivenTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void cacheResolver() {
	ConfigurableApplicationContext context = new GenericXmlApplicationContext(
			"/org/springframework/cache/jcache/config/jCacheNamespaceDriven-resolver.xml");

	DefaultJCacheOperationSource ci = context.getBean(DefaultJCacheOperationSource.class);
	assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
	context.close();
}
 
Example #15
Source File: JCacheJavaConfigTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void bothSetOnlyResolverIsUsed() {
	ConfigurableApplicationContext context =
			new AnnotationConfigApplicationContext(FullCachingConfigSupport.class);

	DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
	assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());
	assertSame(context.getBean("keyGenerator"), cos.getKeyGenerator());
	assertSame(context.getBean("exceptionCacheResolver"), cos.getExceptionCacheResolver());
	context.close();
}
 
Example #16
Source File: JCacheJavaConfigTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void emptyConfigSupport() {
	ConfigurableApplicationContext context =
			new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);

	DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
	assertNotNull(cos.getCacheResolver());
	assertEquals(SimpleCacheResolver.class, cos.getCacheResolver().getClass());
	assertSame(context.getBean(CacheManager.class),
			((SimpleCacheResolver) cos.getCacheResolver()).getCacheManager());
	assertNull(cos.getExceptionCacheResolver());
	context.close();
}
 
Example #17
Source File: JCacheJavaConfigTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void fullCachingConfig() throws Exception {
	AnnotationConfigApplicationContext context =
			new AnnotationConfigApplicationContext(FullCachingConfig.class);

	DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
	assertSame(context.getBean(KeyGenerator.class), cos.getKeyGenerator());
	assertSame(context.getBean("cacheResolver", CacheResolver.class),
			cos.getCacheResolver());
	assertSame(context.getBean("exceptionCacheResolver", CacheResolver.class),
			cos.getExceptionCacheResolver());
	JCacheInterceptor interceptor = context.getBean(JCacheInterceptor.class);
	assertSame(context.getBean("errorHandler", CacheErrorHandler.class), interceptor.getErrorHandler());
}
 
Example #18
Source File: AbstractJCacheConfiguration.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Bean(name = "jCacheOperationSource")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public JCacheOperationSource cacheOperationSource() {
	return new DefaultJCacheOperationSource(
			this.cacheManager, this.cacheResolver, this.exceptionCacheResolver, this.keyGenerator);
}
 
Example #19
Source File: AbstractJCacheConfiguration.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Bean(name = "jCacheOperationSource")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public JCacheOperationSource cacheOperationSource() {
	return new DefaultJCacheOperationSource(
			this.cacheManager, this.cacheResolver, this.exceptionCacheResolver, this.keyGenerator);
}