Polishing
This commit is contained in:
@@ -22,7 +22,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -93,7 +92,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* List of Advisors. If an Advice is added, it will be wrapped
|
||||
* in an Advisor before being added to this List.
|
||||
*/
|
||||
private List<Advisor> advisors = new LinkedList<Advisor>();
|
||||
private List<Advisor> advisors = new ArrayList<Advisor>();
|
||||
|
||||
/**
|
||||
* Array updated on changes to the advisors list, which is easier
|
||||
@@ -480,7 +479,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* for the given method, based on this configuration.
|
||||
* @param method the proxied method
|
||||
* @param targetClass the target class
|
||||
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
|
||||
* @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
|
||||
*/
|
||||
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, Class<?> targetClass) {
|
||||
MethodCacheKey cacheKey = new MethodCacheKey(method);
|
||||
@@ -534,7 +533,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
|
||||
/**
|
||||
* Build a configuration-only copy of this AdvisedSupport,
|
||||
* replacing the TargetSource
|
||||
* replacing the TargetSource.
|
||||
*/
|
||||
AdvisedSupport getConfigurationOnlyCopy() {
|
||||
AdvisedSupport copy = new AdvisedSupport();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -62,9 +62,9 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ
|
||||
// Add it conditionally.
|
||||
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor;
|
||||
if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) {
|
||||
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
|
||||
MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher();
|
||||
if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) {
|
||||
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
|
||||
if (mm.isRuntime()) {
|
||||
// Creating a new object instance in the getInterceptors() method
|
||||
// isn't a problem as we normally cache created chains.
|
||||
@@ -98,8 +98,7 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ
|
||||
* Determine whether the Advisors contain matching introductions.
|
||||
*/
|
||||
private static boolean hasMatchingIntroductions(Advised config, Class<?> actualClass) {
|
||||
for (int i = 0; i < config.getAdvisors().length; i++) {
|
||||
Advisor advisor = config.getAdvisors()[i];
|
||||
for (Advisor advisor : config.getAdvisors()) {
|
||||
if (advisor instanceof IntroductionAdvisor) {
|
||||
IntroductionAdvisor ia = (IntroductionAdvisor) advisor;
|
||||
if (ia.getClassFilter().matches(actualClass)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -31,15 +31,15 @@ import org.springframework.aop.Advisor;
|
||||
public interface AdvisorAdapterRegistry {
|
||||
|
||||
/**
|
||||
* Return an Advisor wrapping the given advice.
|
||||
* Return an {@link Advisor} wrapping the given advice.
|
||||
* <p>Should by default at least support
|
||||
* {@link org.aopalliance.intercept.MethodInterceptor},
|
||||
* {@link org.springframework.aop.MethodBeforeAdvice},
|
||||
* {@link org.springframework.aop.AfterReturningAdvice},
|
||||
* {@link org.springframework.aop.ThrowsAdvice}.
|
||||
* @param advice object that should be an advice
|
||||
* @return an Advisor wrapping the given advice. Never returns {@code null}.
|
||||
* If the advice parameter is an Advisor, return it.
|
||||
* @return an Advisor wrapping the given advice (never {@code null};
|
||||
* if the advice parameter is an Advisor, it is to be returned as-is)
|
||||
* @throws UnknownAdviceTypeException if no registered advisor adapter
|
||||
* can wrap the supposed advice
|
||||
*/
|
||||
@@ -48,21 +48,20 @@ public interface AdvisorAdapterRegistry {
|
||||
/**
|
||||
* Return an array of AOP Alliance MethodInterceptors to allow use of the
|
||||
* given Advisor in an interception-based framework.
|
||||
* <p>Don't worry about the pointcut associated with the Advisor,
|
||||
* if it's a PointcutAdvisor: just return an interceptor.
|
||||
* <p>Don't worry about the pointcut associated with the {@link Advisor}, if it is
|
||||
* a {@link org.springframework.aop.PointcutAdvisor}: just return an interceptor.
|
||||
* @param advisor Advisor to find an interceptor for
|
||||
* @return an array of MethodInterceptors to expose this Advisor's behavior
|
||||
* @throws UnknownAdviceTypeException if the Advisor type is
|
||||
* not understood by any registered AdvisorAdapter.
|
||||
* not understood by any registered AdvisorAdapter
|
||||
*/
|
||||
MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException;
|
||||
|
||||
/**
|
||||
* Register the given AdvisorAdapter. Note that it is not necessary to register
|
||||
* Register the given {@link AdvisorAdapter}. Note that it is not necessary to register
|
||||
* adapters for an AOP Alliance Interceptors or Spring Advices: these must be
|
||||
* automatically recognized by an AdvisorAdapterRegistry implementation.
|
||||
* @param adapter AdvisorAdapter that understands a particular Advisor
|
||||
* or Advice types
|
||||
* automatically recognized by an {@code AdvisorAdapterRegistry} implementation.
|
||||
* @param adapter AdvisorAdapter that understands particular Advisor or Advice types
|
||||
*/
|
||||
void registerAdvisorAdapter(AdvisorAdapter adapter);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -29,13 +29,13 @@ import org.apache.commons.logging.LogFactory;
|
||||
*/
|
||||
public class SimpleAsyncUncaughtExceptionHandler implements AsyncUncaughtExceptionHandler {
|
||||
|
||||
private final Log logger = LogFactory.getLog(SimpleAsyncUncaughtExceptionHandler.class);
|
||||
private static final Log logger = LogFactory.getLog(SimpleAsyncUncaughtExceptionHandler.class);
|
||||
|
||||
|
||||
@Override
|
||||
public void handleUncaughtException(Throwable ex, Method method, Object... params) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error(String.format("Unexpected error occurred invoking async " +
|
||||
"method '%s'.", method), ex);
|
||||
logger.error("Unexpected error occurred invoking async method: " + method, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -47,11 +47,11 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
|
||||
|
||||
private final DefaultJCacheOperationSource source = new DefaultJCacheOperationSource();
|
||||
|
||||
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
source.setCacheResolver(defaultCacheResolver);
|
||||
source.setExceptionCacheResolver(defaultExceptionCacheResolver);
|
||||
source.setKeyGenerator(defaultKeyGenerator);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -37,12 +37,12 @@ public class CachingConfigurerSupport implements CachingConfigurer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyGenerator keyGenerator() {
|
||||
public CacheResolver cacheResolver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheResolver cacheResolver() {
|
||||
public KeyGenerator keyGenerator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -110,21 +110,21 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
|
||||
*/
|
||||
private static void parseCacheResolution(Element element, BeanDefinition def, boolean setBoth) {
|
||||
String name = element.getAttribute("cache-resolver");
|
||||
if (StringUtils.hasText(name)) {
|
||||
boolean hasText = StringUtils.hasText(name);
|
||||
if (hasText) {
|
||||
def.getPropertyValues().add("cacheResolver", new RuntimeBeanReference(name.trim()));
|
||||
}
|
||||
if (!StringUtils.hasText(name) || setBoth) {
|
||||
if (!hasText || setBoth) {
|
||||
def.getPropertyValues().add("cacheManager",
|
||||
new RuntimeBeanReference(CacheNamespaceHandler.extractCacheManager(element)));
|
||||
}
|
||||
}
|
||||
|
||||
private static BeanDefinition parseErrorHandler(Element element, BeanDefinition def) {
|
||||
private static void parseErrorHandler(Element element, BeanDefinition def) {
|
||||
String name = element.getAttribute("error-handler");
|
||||
if (StringUtils.hasText(name)) {
|
||||
def.getPropertyValues().add("errorHandler", new RuntimeBeanReference(name.trim()));
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,12 +173,12 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a
|
||||
* Registers a cache aspect.
|
||||
* <pre class="code">
|
||||
* <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
|
||||
* <property name="cacheManager" ref="cacheManager"/>
|
||||
* <property name="keyGenerator" ref="keyGenerator"/>
|
||||
* </bean>
|
||||
* <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
|
||||
* <property name="cacheManager" ref="cacheManager"/>
|
||||
* <property name="keyGenerator" ref="keyGenerator"/>
|
||||
* </bean>
|
||||
* </pre>
|
||||
*/
|
||||
private static void registerCacheAspect(Element element, ParserContext parserContext) {
|
||||
|
||||
@@ -207,8 +207,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
}
|
||||
catch (NoUniqueBeanDefinitionException ex) {
|
||||
throw new IllegalStateException("No CacheResolver specified, and no unique bean of type " +
|
||||
"CacheManager found. Mark one as primary (or give it the name 'cacheManager') or " +
|
||||
"declare a specific CacheManager to use, that serves as the default one.");
|
||||
"CacheManager found. Mark one as primary or declare a specific CacheManager to use.");
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
throw new IllegalStateException("No CacheResolver specified, and no bean of type CacheManager found. " +
|
||||
@@ -651,6 +650,9 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A {@link CacheOperationInvocationContext} context for a {@link CacheOperation}.
|
||||
*/
|
||||
protected class CacheOperationContext implements CacheOperationInvocationContext<CacheOperation> {
|
||||
|
||||
private final CacheOperationMetadata metadata;
|
||||
|
||||
@@ -619,9 +619,9 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
private Reference<K, V>[] createReferenceArray(int size) {
|
||||
return (Reference<K, V>[]) Array.newInstance(Reference.class, size);
|
||||
return new Reference[size];
|
||||
}
|
||||
|
||||
private int getIndex(int hash, Reference<K, V>[] references) {
|
||||
@@ -756,8 +756,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||
|
||||
/**
|
||||
* Execute the task.
|
||||
* @param ref the found reference or {@code null}
|
||||
* @param entry the found entry or {@code null}
|
||||
* @param ref the found reference (or {@code null})
|
||||
* @param entry the found entry (or {@code null})
|
||||
* @param entries access to the underlying entries
|
||||
* @return the result of the task
|
||||
* @see #execute(Reference, Entry)
|
||||
@@ -768,8 +768,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||
|
||||
/**
|
||||
* Convenience method that can be used for tasks that do not need access to {@link Entries}.
|
||||
* @param ref the found reference or {@code null}
|
||||
* @param entry the found entry or {@code null}
|
||||
* @param ref the found reference (or {@code null})
|
||||
* @param entry the found entry (or {@code null})
|
||||
* @return the result of the task
|
||||
* @see #execute(Reference, Entry, Entries)
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -23,41 +23,48 @@ import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class OrderUtilsTests {
|
||||
|
||||
@Test
|
||||
public void getSimpleOrder() {
|
||||
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(SimpleOrder.class, null));
|
||||
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(SimpleOrder.class, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPriorityOrder() {
|
||||
assertEquals(Integer.valueOf(55), OrderUtils.getOrder(SimplePriority.class, null));
|
||||
assertEquals(Integer.valueOf(55), OrderUtils.getOrder(SimplePriority.class, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOrderWithBoth() {
|
||||
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(OrderAndPriority.class, null));
|
||||
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(OrderAndPriority.class, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultOrder() {
|
||||
assertEquals(Integer.valueOf(33), OrderUtils.getOrder(NoOrder.class, 33));
|
||||
assertEquals(Integer.valueOf(33), OrderUtils.getOrder(NoOrder.class, 33));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPriorityValueNoAnnotation() {
|
||||
assertNull(OrderUtils.getPriority(SimpleOrder.class));
|
||||
assertNull(OrderUtils.getPriority(SimpleOrder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPriorityValue() {
|
||||
assertEquals(Integer.valueOf(55), OrderUtils.getPriority(OrderAndPriority.class));
|
||||
assertEquals(Integer.valueOf(55), OrderUtils.getPriority(OrderAndPriority.class));
|
||||
}
|
||||
|
||||
|
||||
@Order(50)
|
||||
private static class SimpleOrder {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user