Browse Source

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.
pull/231/head
Oliver Gierke 9 years ago
parent
commit
8026e9ff72
  1. 12
      src/main/java/org/springframework/data/projection/ProjectionFactory.java
  2. 41
      src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java
  3. 3
      src/main/java/org/springframework/data/projection/SpelAwareProxyProjectionFactory.java
  4. 22
      src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java
  5. 5
      src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java
  6. 9
      src/test/java/org/springframework/data/projection/SpelAwareProxyProjectionFactoryUnitTests.java

12
src/main/java/org/springframework/data/projection/ProjectionFactory.java

@ -15,8 +15,6 @@ @@ -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 { @@ -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.
*

41
src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java

@ -15,7 +15,6 @@ @@ -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; @@ -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; @@ -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, @@ -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, @@ -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, @@ -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)

3
src/main/java/org/springframework/data/projection/SpelAwareProxyProjectionFactory.java

@ -77,7 +77,8 @@ public class SpelAwareProxyProjectionFactory extends ProxyProjectionFactory impl @@ -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;
}
/*

22
src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java

@ -23,11 +23,9 @@ import org.springframework.beans.MutablePropertyValues; @@ -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; @@ -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 @@ -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 @@ -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));
}
/*

5
src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java

@ -49,11 +49,6 @@ public class ProxyProjectionFactoryUnitTests { @@ -49,11 +49,6 @@ public class ProxyProjectionFactoryUnitTests {
factory.createProjection(null, new Object());
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-630
public void rejectsNullProjectionTypeForInputProperties() {
factory.getInputProperties(null);
}
@Test // DATACMNS-630
public void returnsNullForNullSource() {
assertThat(factory.createProjection(CustomerExcerpt.class, null)).isNull();

9
src/test/java/org/springframework/data/projection/SpelAwareProxyProjectionFactoryUnitTests.java

@ -17,6 +17,7 @@ package org.springframework.data.projection; @@ -17,6 +17,7 @@ package org.springframework.data.projection;
import static org.assertj.core.api.Assertions.*;
import java.beans.PropertyDescriptor;
import java.util.List;
import org.junit.Before;
@ -58,9 +59,13 @@ public class SpelAwareProxyProjectionFactoryUnitTests { @@ -58,9 +59,13 @@ public class SpelAwareProxyProjectionFactoryUnitTests {
@Test // DATACMNS-630
public void excludesAtValueAnnotatedMethodsForInputProperties() {
List<String> properties = factory.getInputProperties(CustomerExcerpt.class);
List<PropertyDescriptor> properties = factory //
.getProjectionInformation(CustomerExcerpt.class) //
.getInputProperties();
assertThat(properties).containsExactly("firstname");
assertThat(properties) //
.extracting(PropertyDescriptor::getName) //
.containsExactly("firstname");
}
@Test // DATACMNS-89

Loading…
Cancel
Save