Polishing

(cherry picked from commit 6d6cf01)
This commit is contained in:
Juergen Hoeller
2017-02-28 13:13:23 +01:00
parent ce3cf3251d
commit b945e0f202
6 changed files with 46 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -322,7 +322,7 @@ class PostProcessorRegistrationDelegate {
if (bean != null && !(bean instanceof BeanPostProcessor) && !isInfrastructureBean(beanName) &&
this.beanFactory.getBeanPostProcessorCount() < this.beanPostProcessorTargetCount) {
if (logger.isInfoEnabled()) {
logger.info("Bean '" + beanName + "' of type [" + bean.getClass() +
logger.info("Bean '" + beanName + "' of type [" + bean.getClass().getName() +
"] is not eligible for getting processed by all BeanPostProcessors " +
"(for example: not eligible for auto-proxying)");
}
@@ -333,7 +333,7 @@ class PostProcessorRegistrationDelegate {
private boolean isInfrastructureBean(String beanName) {
if (beanName != null && this.beanFactory.containsBeanDefinition(beanName)) {
BeanDefinition bd = this.beanFactory.getBeanDefinition(beanName);
return RootBeanDefinition.ROLE_INFRASTRUCTURE == bd.getRole();
return (bd.getRole() == RootBeanDefinition.ROLE_INFRASTRUCTURE);
}
return false;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -159,11 +159,12 @@ public class AsyncAnnotationAdvisor extends AbstractPointcutAdvisor implements B
Pointcut cpc = new AnnotationMatchingPointcut(asyncAnnotationType, true);
Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(asyncAnnotationType);
if (result == null) {
result = new ComposablePointcut(cpc).union(mpc);
result = new ComposablePointcut(cpc);
}
else {
result.union(cpc).union(mpc);
result.union(cpc);
}
result = result.union(mpc);
}
return result;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@@ -17,7 +17,7 @@
package org.springframework.cache.config;
/**
* Basic service interface.
* Basic service interface for caching tests.
*
* @author Costin Leau
* @author Phillip Webb
@@ -83,7 +83,6 @@ public interface CacheableService<T> {
T throwUncheckedSync(Object arg1);
// multi annotations
T multiCache(Object arg1);
T multiEvict(Object arg1);
@@ -95,4 +94,5 @@ public interface CacheableService<T> {
T multiUpdate(Object arg1);
TestEntity putRefersToResult(TestEntity arg1);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@@ -25,7 +25,7 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
/**
* Simple cacheable service
* Simple cacheable service.
*
* @author Costin Leau
* @author Phillip Webb
@@ -34,12 +34,14 @@ import org.springframework.cache.annotation.Caching;
public class DefaultCacheableService implements CacheableService<Long> {
private final AtomicLong counter = new AtomicLong();
private final AtomicLong nullInvocations = new AtomicLong();
@Override
@Cacheable("testCache")
public Long cache(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@@ -51,7 +53,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Long cacheSync(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@@ -96,13 +98,13 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable(cacheNames = "testCache", condition = "#p0 == 3")
public Long conditional(int classField) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", sync = true, condition = "#p0 == 3")
public Long conditionalSync(int classField) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@@ -114,55 +116,55 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable(cacheNames = "testCache", key = "#p0")
public Long key(Object arg1, Object arg2) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache")
public Long varArgsKey(Object... args) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName")
public Long name(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
public Long rootVars(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "customKeyGenerator")
public Long customKeyGenerator(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "unknownBeanName")
public Long unknownCustomKeyGenerator(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "customCacheManager")
public Long customCacheManager(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "unknownBeanName")
public Long unknownCustomCacheManager(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@CachePut("testCache")
public Long update(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@@ -174,13 +176,13 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable("testCache")
public Long nullValue(Object arg1) {
nullInvocations.incrementAndGet();
this.nullInvocations.incrementAndGet();
return null;
}
@Override
public Number nullInvocations() {
return nullInvocations.get();
return this.nullInvocations.get();
}
@Override
@@ -212,25 +214,25 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Caching(cacheable = { @Cacheable("primary"), @Cacheable("secondary") })
public Long multiCache(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(cacheNames = "secondary", key = "#p0"), @CacheEvict(cacheNames = "primary", key = "#p0 + 'A'") })
public Long multiEvict(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", key = "#root.methodName") }, evict = { @CacheEvict("secondary") })
public Long multiCacheAndEvict(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", condition = "#p0 == 3") }, evict = { @CacheEvict("secondary") })
public Long multiConditionalCacheAndEvict(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -39,7 +39,8 @@ import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.*;
/**
* Integration tests for @EnableCaching and its related @Configuration classes.
* Integration tests for {@code @EnableCaching} and its related
* {@code @Configuration} classes.
*
* @author Chris Beams
* @author Stephane Nicoll
@@ -54,18 +55,16 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
@Test
public void testKeyStrategy() {
CacheInterceptor ci = ctx.getBean(CacheInterceptor.class);
assertSame(ctx.getBean("keyGenerator", KeyGenerator.class), ci.getKeyGenerator());
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
assertSame(this.ctx.getBean("keyGenerator", KeyGenerator.class), ci.getKeyGenerator());
}
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = ctx.getBean(CacheInterceptor.class);
assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
// --- local tests -------
@Test
public void singleCacheManagerBean() throws Throwable {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -91,7 +90,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
public void multipleCacheManagerBeans_implementsCachingConfigurer() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(MultiCacheManagerConfigurer.class);
ctx.refresh(); // does not throw
ctx.refresh(); // does not throw an exception
}
@Test(expected = IllegalStateException.class)
@@ -124,22 +123,17 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
@Test
public void emptyConfigSupport() {
ConfigurableApplicationContext context =
new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
assertNotNull(ci.getCacheResolver());
assertEquals(SimpleCacheResolver.class, ci.getCacheResolver().getClass());
assertSame(context.getBean(CacheManager.class),
((SimpleCacheResolver)ci.getCacheResolver()).getCacheManager());
assertSame(context.getBean(CacheManager.class), ((SimpleCacheResolver)ci.getCacheResolver()).getCacheManager());
context.close();
}
@Test
public void bothSetOnlyResolverIsUsed() {
ConfigurableApplicationContext context =
new AnnotationConfigApplicationContext(FullCachingConfig.class);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class);
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
assertSame(context.getBean("keyGenerator"), ci.getKeyGenerator());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -481,7 +481,7 @@ public abstract class JdbcUtils {
StringBuilder result = new StringBuilder();
boolean nextIsUpper = false;
if (name != null && name.length() > 0) {
if (name.length() > 1 && name.substring(1,2).equals("_")) {
if (name.length() > 1 && name.substring(1, 2).equals("_")) {
result.append(name.substring(0, 1).toUpperCase());
}
else {