DATACMNS-1781 - Move off deprecated Spring Framework API.
Use KotlinDetector instead of ReflectionUtils.isKotlinClass(…). Use replacement MethodParameter(…).withContainingClass(…) instead of GenericTypeResolver.resolveParameterType(…). Use MergedAnnotations.from(…).isPresent(…) instead of AnnotationUtils.isAnnotationMetaPresent(…).
This commit is contained in:
@@ -19,7 +19,6 @@ import java.lang.annotation.Annotation;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.data.annotation.Immutable;
|
||||
import org.springframework.data.convert.EntityInstantiator;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -47,7 +46,8 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
|
||||
*
|
||||
* @return {@literal null} in case no suitable constructor for automatic construction can be found. This usually
|
||||
* indicates that the instantiation of the object of that persistent entity is done through either a customer
|
||||
* {@link EntityInstantiator} or handled by custom conversion mechanisms entirely.
|
||||
* {@link org.springframework.data.mapping.model.EntityInstantiator} or handled by custom conversion
|
||||
* mechanisms entirely.
|
||||
*/
|
||||
@Nullable
|
||||
PreferredConstructor<T, P> getPersistenceConstructor();
|
||||
|
||||
@@ -55,16 +55,6 @@ public interface PersistentPropertyPathAccessor<T> extends PersistentPropertyAcc
|
||||
@Nullable
|
||||
Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, GetOptions context);
|
||||
|
||||
/**
|
||||
* Sets the given value for the {@link PersistentProperty} pointed to by the given {@link PersistentPropertyPath}. The
|
||||
* lookup of intermediate values must not yield {@literal null}.
|
||||
*
|
||||
* @param path must not be {@literal null} or empty.
|
||||
* @param value can be {@literal null}.
|
||||
* @see AccessOptions#DEFAULT
|
||||
*/
|
||||
void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, @Nullable Object value);
|
||||
|
||||
/**
|
||||
* Sets the given value for the {@link PersistentProperty} pointed to by the given {@link PersistentPropertyPath}
|
||||
* considering the given {@link AccessOptions}.
|
||||
|
||||
@@ -17,13 +17,13 @@ package org.springframework.data.mapping.model;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -99,7 +99,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
|
||||
PersistentEntity<?, ?> owner = property.getOwner();
|
||||
PersistentPropertyAccessor<T> delegate = delegateFunction.apply(this.bean);
|
||||
|
||||
if (!property.isImmutable() || property.getWither() != null || ReflectionUtils.isKotlinClass(owner.getType())) {
|
||||
if (!property.isImmutable() || property.getWither() != null || KotlinDetector.isKotlinType(owner.getType())) {
|
||||
|
||||
delegate.setProperty(property, value);
|
||||
this.bean = delegate.getBean();
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.util.KotlinReflectionUtils;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -50,7 +51,7 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
|
||||
|
||||
PreferredConstructor<?, ?> constructor = entity.getPersistenceConstructor();
|
||||
|
||||
if (ReflectionUtils.isSupportedKotlinClass(entity.getType()) && constructor != null) {
|
||||
if (KotlinReflectionUtils.isSupportedKotlinClass(entity.getType()) && constructor != null) {
|
||||
|
||||
PreferredConstructor<?, ?> defaultConstructor = new DefaultingKotlinConstructorResolver(entity)
|
||||
.getDefaultConstructor();
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.Optional;
|
||||
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.data.util.KotlinReflectionUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -102,7 +102,7 @@ public class MappingInstantiationException extends RuntimeException {
|
||||
|
||||
Constructor<?> constructor = preferredConstructor.getConstructor();
|
||||
|
||||
if (ReflectionUtils.isSupportedKotlinClass(constructor.getDeclaringClass())) {
|
||||
if (KotlinReflectionUtils.isSupportedKotlinClass(constructor.getDeclaringClass())) {
|
||||
|
||||
KFunction<?> kotlinFunction = ReflectJvmMapping.getKotlinFunction(constructor);
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.KotlinReflectionUtils;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -182,7 +183,7 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
|
||||
* @return the appropriate discoverer for {@code type}.
|
||||
*/
|
||||
private static Discoverers findDiscoverer(Class<?> type) {
|
||||
return ReflectionUtils.isSupportedKotlinClass(type) ? KOTLIN : DEFAULT;
|
||||
return KotlinReflectionUtils.isSupportedKotlinClass(type) ? KOTLIN : DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.data.util.KotlinReflectionUtils;
|
||||
import org.springframework.data.util.NullableUtils;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -57,7 +58,7 @@ public class MethodInvocationValidator implements MethodInterceptor {
|
||||
*/
|
||||
public static boolean supports(Class<?> repositoryInterface) {
|
||||
|
||||
return ReflectionUtils.isSupportedKotlinClass(repositoryInterface)
|
||||
return KotlinReflectionUtils.isSupportedKotlinClass(repositoryInterface)
|
||||
|| NullableUtils.isNonNull(repositoryInterface, ElementType.METHOD)
|
||||
|| NullableUtils.isNonNull(repositoryInterface, ElementType.PARAMETER);
|
||||
}
|
||||
@@ -155,7 +156,7 @@ public class MethodInvocationValidator implements MethodInterceptor {
|
||||
private static boolean isNullableParameter(MethodParameter parameter) {
|
||||
|
||||
return requiresNoValue(parameter) || NullableUtils.isExplicitNullable(parameter)
|
||||
|| (ReflectionUtils.isSupportedKotlinClass(parameter.getDeclaringClass())
|
||||
|| (KotlinReflectionUtils.isSupportedKotlinClass(parameter.getDeclaringClass())
|
||||
&& ReflectionUtils.isNullable(parameter));
|
||||
}
|
||||
|
||||
|
||||
@@ -194,8 +194,8 @@ interface MethodLookups {
|
||||
|
||||
Type genericType = genericTypes[i];
|
||||
Class<?> type = types[i];
|
||||
MethodParameter parameter = new MethodParameter(invokedMethod, i);
|
||||
Class<?> parameterType = resolveParameterType(parameter, repositoryInterface);
|
||||
MethodParameter parameter = new MethodParameter(invokedMethod, i).withContainingClass(repositoryInterface);
|
||||
Class<?> parameterType = parameter.getParameterType();
|
||||
|
||||
if (genericType instanceof TypeVariable<?>) {
|
||||
|
||||
@@ -273,7 +273,8 @@ interface MethodLookups {
|
||||
|
||||
return (parameterCriteria) -> {
|
||||
|
||||
Class<?> parameterType = resolveParameterType(parameterCriteria.getDeclared(), repositoryInterface);
|
||||
Class<?> parameterType = parameterCriteria.getDeclared().withContainingClass(repositoryInterface)
|
||||
.getParameterType();
|
||||
Type genericType = parameterCriteria.getGenericBaseType();
|
||||
|
||||
if (genericType instanceof TypeVariable<?>) {
|
||||
|
||||
@@ -34,6 +34,7 @@ import javax.annotation.Nonnull;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -159,7 +160,7 @@ public abstract class NullableUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!AnnotationUtils.isAnnotationMetaPresent(annotation.annotationType(), annotationClass)
|
||||
if (!MergedAnnotations.from(annotation.annotationType()).isPresent(annotationClass)
|
||||
|| !isNonNull(annotation)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user