DATACMNS-1106 - Removed deprecations in ProjectionFactory.

Removed the deprecated implementation of ResourceLoaderAware in favor of BeanClassLoaderAware. Removed deprecated ProjectionFactory.getInputProperties() in favor of ….getProjectionInformation(). Removed the Java conditional to add a MethodInterceptor for default methods. Adapted test cases.
This commit is contained in:
Oliver Gierke
2017-07-11 09:30:41 +02:00
parent 023a0b2a38
commit 8026e9ff72
6 changed files with 14 additions and 78 deletions

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.projection;
import java.util.List;
/**
* A factory to create projecting instances for other objects usually used to allow easy creation of representation
* projections to define which properties of a domain objects shall be exported in which way.
@@ -44,16 +42,6 @@ public interface ProjectionFactory {
*/
<T> T createProjection(Class<T> projectionType);
/**
* Returns the properties that will be consumed by the given projection type.
*
* @param projectionType must not be {@literal null}.
* @return
* @deprecated use {@link #getProjectionInformation(Class)}
*/
@Deprecated
List<String> getInputProperties(Class<?> projectionType);
/**
* Returns the {@link ProjectionInformation} for the given projection type.
*

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.projection;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
@@ -27,10 +26,8 @@ import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -45,10 +42,7 @@ import org.springframework.util.ClassUtils;
* @see SpelAwareProxyProjectionFactory
* @since 1.10
*/
class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware, BeanClassLoaderAware {
private static final boolean IS_JAVA_8 = org.springframework.util.ClassUtils.isPresent("java.util.Optional",
ProxyProjectionFactory.class.getClassLoader());
class ProxyProjectionFactory implements ProjectionFactory, BeanClassLoaderAware {
private final List<MethodInterceptorFactory> factories;
private final ConversionService conversionService;
@@ -66,16 +60,6 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware,
this.conversionService = new DefaultConversionService();
}
/**
* @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader)
* @deprecated rather set the {@link ClassLoader} directly via {@link #setBeanClassLoader(ClassLoader)}.
*/
@Override
@Deprecated
public void setResourceLoader(ResourceLoader resourceLoader) {
this.classLoader = resourceLoader.getClassLoader();
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader)
@@ -119,10 +103,7 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware,
factory.setOpaque(true);
factory.setInterfaces(projectionType, TargetAware.class);
if (IS_JAVA_8) {
factory.addAdvice(new DefaultMethodInvokingMethodInterceptor());
}
factory.addAdvice(new DefaultMethodInvokingMethodInterceptor());
factory.addAdvice(new TargetAwareMethodInterceptor(source.getClass()));
factory.addAdvice(getMethodInterceptor(source, projectionType));
@@ -141,24 +122,6 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware,
return createProjection(projectionType, new HashMap<String, Object>());
}
/*
* (non-Javadoc)
* @see org.springframework.data.projection.ProjectionFactory#getProperties(java.lang.Class)
*/
@Override
public List<String> getInputProperties(Class<?> projectionType) {
Assert.notNull(projectionType, "Projection type must not be null!");
List<String> result = new ArrayList<>();
for (PropertyDescriptor descriptor : getProjectionInformation(projectionType).getInputProperties()) {
result.add(descriptor.getName());
}
return result;
}
/*
* (non-Javadoc)
* @see org.springframework.data.projection.ProjectionFactory#getProjectionInformation(java.lang.Class)

View File

@@ -77,7 +77,8 @@ public class SpelAwareProxyProjectionFactory extends ProxyProjectionFactory impl
}
return typeCache.get(projectionType)
? new SpelEvaluatingMethodInterceptor(interceptor, source, beanFactory, parser, projectionType) : interceptor;
? new SpelEvaluatingMethodInterceptor(interceptor, source, beanFactory, parser, projectionType)
: interceptor;
}
/*

View File

@@ -23,11 +23,9 @@ import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.WebDataBinder;
@@ -43,7 +41,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
* @since 1.10
*/
public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodProcessor
implements BeanFactoryAware, ResourceLoaderAware, BeanClassLoaderAware {
implements BeanFactoryAware, BeanClassLoaderAware {
private static final List<String> IGNORED_PACKAGES = Arrays.asList("java", "org.springframework");
@@ -72,16 +70,6 @@ public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodP
this.proxyFactory.setBeanFactory(beanFactory);
}
/**
* @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader)
* @deprecated rather set the {@link ClassLoader} via {@link #setBeanClassLoader(ClassLoader)}.
*/
@Override
@Deprecated
public void setResourceLoader(ResourceLoader resourceLoader) {
this.proxyFactory.setResourceLoader(resourceLoader);
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader)
@@ -115,13 +103,9 @@ public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodP
}
// Fallback for only user defined interfaces
for (String prefix : IGNORED_PACKAGES) {
if (ClassUtils.getPackageName(type).startsWith(prefix)) {
return false;
}
}
String packageName = ClassUtils.getPackageName(type);
return true;
return !IGNORED_PACKAGES.stream().anyMatch(it -> packageName.startsWith(it));
}
/*