committed by
Jens Schauder
parent
aecdf5001a
commit
2618221115
@@ -19,11 +19,9 @@ import java.util.Optional;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -40,20 +38,6 @@ public class AuditingHandler extends AuditingHandlerSupport implements Initializ
|
||||
|
||||
private Optional<AuditorAware<?>> auditorAware;
|
||||
|
||||
/**
|
||||
* Creates a new {@link AuditableBeanWrapper} using the given {@link MappingContext} when looking up auditing metadata
|
||||
* via reflection.
|
||||
*
|
||||
* @param mappingContext must not be {@literal null}.
|
||||
* @since 1.8
|
||||
* @deprecated use {@link AuditingHandler(PersistentEntities)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public AuditingHandler(
|
||||
MappingContext<? extends PersistentEntity<?, ?>, ? extends PersistentProperty<?>> mappingContext) {
|
||||
this(PersistentEntities.of(mappingContext));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link AuditableBeanWrapper} using the given {@link PersistentEntities} when looking up auditing
|
||||
* metadata via reflection.
|
||||
|
||||
@@ -35,19 +35,6 @@ public class IsNewAwareAuditingHandler extends AuditingHandler {
|
||||
|
||||
private final PersistentEntities entities;
|
||||
|
||||
/**
|
||||
* Creates a new {@link IsNewAwareAuditingHandler} for the given {@link MappingContext}.
|
||||
*
|
||||
* @param mappingContext must not be {@literal null}.
|
||||
* @since 1.8
|
||||
* @deprecated use {@link IsNewAwareAuditingHandler(PersistentEntities)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public IsNewAwareAuditingHandler(
|
||||
MappingContext<? extends PersistentEntity<?, ?>, ? extends PersistentProperty<?>> mappingContext) {
|
||||
this(PersistentEntities.of(mappingContext));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link IsNewAwareAuditingHandler} for the given {@link MappingContext}.
|
||||
*
|
||||
|
||||
@@ -64,17 +64,6 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
|
||||
*/
|
||||
TypeInformation<?> getTypeInformation();
|
||||
|
||||
/**
|
||||
* Returns the {@link TypeInformation} if the property references a {@link PersistentEntity}. Will return
|
||||
* {@literal null} in case it refers to a simple type. Will return {@link Collection}'s component type or the
|
||||
* {@link Map}'s value type transparently.
|
||||
*
|
||||
* @return
|
||||
* @deprecated since 2.6 for removal in 3.0. Use {@link #getPersistentEntityTypeInformation()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
Iterable<? extends TypeInformation<?>> getPersistentEntityTypes();
|
||||
|
||||
/**
|
||||
* Returns the detected {@link TypeInformation TypeInformations} if the property references a {@link PersistentEntity}.
|
||||
* Will return an {@literal empty} {@link Iterable} in case it refers to a simple type. Will return the {@link Collection}'s
|
||||
|
||||
@@ -158,15 +158,6 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
return information;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.PersistentProperty#getPersistentEntityTypes()
|
||||
*/
|
||||
@Override
|
||||
public Iterable<? extends TypeInformation<?>> getPersistentEntityTypes() {
|
||||
return getPersistentEntityTypeInformation();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.PersistentProperty#getPersistentEntityTypeInformation()
|
||||
|
||||
@@ -46,26 +46,6 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
|
||||
|
||||
private T bean;
|
||||
|
||||
/**
|
||||
* Creates an {@link InstantiationAwarePropertyAccessor} using the given delegate {@link PersistentPropertyAccessor}
|
||||
* and {@link EntityInstantiators}.
|
||||
*
|
||||
* @param delegate must not be {@literal null}.
|
||||
* @param instantiators must not be {@literal null}.
|
||||
* @deprecated since 2.4. Using this constructor allows only setting a single property as
|
||||
* {@link PersistentPropertyAccessor} holds a reference to the initial bean state.
|
||||
*/
|
||||
@Deprecated
|
||||
public InstantiationAwarePropertyAccessor(PersistentPropertyAccessor<T> delegate, EntityInstantiators instantiators) {
|
||||
|
||||
Assert.notNull(delegate, "Delegate PersistentPropertyAccessor must not be null!");
|
||||
Assert.notNull(instantiators, "EntityInstantiators must not be null!");
|
||||
|
||||
this.instantiators = instantiators;
|
||||
this.delegateFunction = t -> delegate;
|
||||
this.bean = delegate.getBean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link InstantiationAwarePropertyAccessor} using the given delegate {@code accessorFunction} and
|
||||
* {@link EntityInstantiators}. {@code accessorFunction} is used to obtain a new {@link PersistentPropertyAccessor}
|
||||
|
||||
@@ -322,16 +322,7 @@ public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapabl
|
||||
* @param repositoryType will never be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType) {
|
||||
|
||||
CdiRepositoryConfiguration cdiRepositoryConfiguration = lookupConfiguration(beanManager, qualifiers);
|
||||
|
||||
Optional<Bean<?>> customImplementationBean = getCustomImplementationBean(repositoryType,
|
||||
cdiRepositoryConfiguration);
|
||||
Optional<Object> customImplementation = customImplementationBean.map(this::getDependencyInstance);
|
||||
|
||||
return create(creationalContext, repositoryType, customImplementation);
|
||||
}
|
||||
protected abstract T create(CreationalContext<T> creationalContext, Class<T> repositoryType);
|
||||
|
||||
/**
|
||||
* Creates the actual component instance given a {@link RepositoryFactorySupport repository factory supplier} and the
|
||||
@@ -417,24 +408,6 @@ public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapabl
|
||||
Arrays.asList(repositoryType.getInterfaces()))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the actual component instance.
|
||||
*
|
||||
* @param creationalContext will never be {@literal null}.
|
||||
* @param repositoryType will never be {@literal null}.
|
||||
* @param customImplementation can be {@literal null}.
|
||||
* @return
|
||||
* @deprecated since 2.1, override {@link #create(CreationalContext, Class)} in which you create a repository factory
|
||||
* and call {@link #create(RepositoryFactorySupport, Class, RepositoryFragments)}.
|
||||
*/
|
||||
@Deprecated
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType,
|
||||
Optional<Object> customImplementation) {
|
||||
throw new UnsupportedOperationException(
|
||||
"You have to implement create(CreationalContext<T>, Class<T>, Optional<Object>) "
|
||||
+ "in order to use custom repository implementations");
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up an instance of a {@link CdiRepositoryConfiguration}. In case the instance cannot be found within the CDI
|
||||
* scope, a default configuration is used.
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.repository.query;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -46,16 +45,6 @@ public interface ParameterAccessor extends Iterable<Object> {
|
||||
*/
|
||||
Sort getSort();
|
||||
|
||||
/**
|
||||
* Returns the dynamic projection type to be used when executing the query or {@literal null} if none is defined.
|
||||
*
|
||||
* @return
|
||||
* @since 1.12
|
||||
* @deprecated use {@link #findDynamicProjection()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
Optional<Class<?>> getDynamicProjection();
|
||||
|
||||
/**
|
||||
* Returns the dynamic projection type to be used when executing the query or {@literal null} if none is defined.
|
||||
*
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.repository.query;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -128,18 +127,6 @@ public class ParametersParameterAccessor implements ParameterAccessor {
|
||||
return Sort.unsorted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dynamic projection type if available, {@literal null} otherwise.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Optional<Class<?>> getDynamicProjection() {
|
||||
|
||||
return Optional.ofNullable(parameters.hasDynamicProjection() //
|
||||
? (Class<?>) values[parameters.getDynamicProjectionIndex()] //
|
||||
: null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dynamic projection type if available, {@literal null} otherwise.
|
||||
*
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2021 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.repository.support;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* Support for query execution using {@link Pageable}. Using {@link PageableExecutionUtils} assumes that data queries
|
||||
* are cheaper than {@code COUNT} queries and so some cases can take advantage of optimizations.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Jens Schauder
|
||||
* @since 1.13
|
||||
* @deprecated since 2.4. Use {@link org.springframework.data.support.PageableExecutionUtils} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class PageableExecutionUtils {
|
||||
|
||||
private PageableExecutionUtils() {}
|
||||
|
||||
/**
|
||||
* Constructs a {@link Page} based on the given {@code content}, {@link Pageable} and {@link LongSupplier} applying
|
||||
* optimizations. The construction of {@link Page} omits a count query if the total can be determined based on the
|
||||
* result size and {@link Pageable}.
|
||||
*
|
||||
* @param content result of a query with applied {@link Pageable}. The list must not be {@literal null} and must
|
||||
* contain up to {@link Pageable#getPageSize()} items.
|
||||
* @param pageable must not be {@literal null}.
|
||||
* @param totalSupplier must not be {@literal null}.
|
||||
* @return the {@link Page} for {@link List content} and a total size.
|
||||
*/
|
||||
public static <T> Page<T> getPage(List<T> content, Pageable pageable, LongSupplier totalSupplier) {
|
||||
return org.springframework.data.support.PageableExecutionUtils.getPage(content, pageable, totalSupplier);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-2021 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.repository.util;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Simple value object to wrap a nullable delegate. Used to be able to write {@link Converter} implementations that
|
||||
* convert {@literal null} into an object of some sort.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @since 1.8
|
||||
* @see QueryExecutionConverters
|
||||
* @deprecated since 2.4, use {@link org.springframework.data.util.NullableWrapper} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class NullableWrapper extends org.springframework.data.util.NullableWrapper {
|
||||
|
||||
/**
|
||||
* Creates a new {@link NullableWrapper} for the given value.
|
||||
*
|
||||
* @param value can be {@literal null}.
|
||||
*/
|
||||
public NullableWrapper(@Nullable Object value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,6 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.ReactiveAdapter;
|
||||
@@ -220,39 +218,6 @@ public abstract class ReactiveWrappers {
|
||||
: findDescriptor(type).map(ReactiveTypeDescriptor::isMultiValue).orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of no-value wrapper types.
|
||||
*
|
||||
* @return a collection of no-value wrapper types.
|
||||
* @deprecated not supported anymore.
|
||||
*/
|
||||
@Deprecated
|
||||
public static Collection<Class<?>> getNoValueTypes() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of single-value wrapper types.
|
||||
*
|
||||
* @return a collection of single-value wrapper types.
|
||||
* @deprecated not supported anymore.
|
||||
*/
|
||||
@Deprecated
|
||||
public static Collection<Class<?>> getSingleValueTypes() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of multi-value wrapper types.
|
||||
*
|
||||
* @return a collection of multi-value wrapper types.
|
||||
* @deprecated not supported anymore.
|
||||
*/
|
||||
@Deprecated
|
||||
public static Collection<Class<?>> getMultiValueTypes() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given type is a reactive wrapper type.
|
||||
*
|
||||
|
||||
@@ -46,10 +46,8 @@ public class Lazy<T> implements Supplier<T> {
|
||||
* Creates a new {@link Lazy} instance for the given supplier.
|
||||
*
|
||||
* @param supplier
|
||||
* @deprecated prefer {@link Lazy#of(Supplier)}, to be turned private in 2.5.
|
||||
*/
|
||||
@Deprecated
|
||||
public Lazy(Supplier<? extends T> supplier) {
|
||||
private Lazy(Supplier<? extends T> supplier) {
|
||||
this(supplier, null, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -386,31 +386,6 @@ public final class ReflectionUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@literal true} if the specified class is a Kotlin one.
|
||||
*
|
||||
* @return {@literal true} if {@code type} is a Kotlin class.
|
||||
* @since 2.0
|
||||
* @deprecated since 2.3, use {@link KotlinDetector#isKotlinType(Class)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isKotlinClass(Class<?> type) {
|
||||
return KotlinDetector.isKotlinType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@literal true} if the specified class is a supported Kotlin class. Currently supported are only regular
|
||||
* Kotlin classes. Other class types (synthetic, SAM, lambdas) are not supported via reflection.
|
||||
*
|
||||
* @return {@literal true} if {@code type} is a supported Kotlin class.
|
||||
* @since 2.0
|
||||
* @deprecated since 2.3, use {@link KotlinReflectionUtils#isSupportedKotlinClass(Class)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isSupportedKotlinClass(Class<?> type) {
|
||||
return KotlinReflectionUtils.isSupportedKotlinClass(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@literal} whether the given {@link MethodParameter} is nullable. Nullable parameters are reference types
|
||||
* and ones that are defined in Kotlin as such.
|
||||
@@ -424,7 +399,8 @@ public final class ReflectionUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isSupportedKotlinClass(parameter.getDeclaringClass())) {
|
||||
if (KotlinDetector.isKotlinPresent()
|
||||
&& KotlinReflectionUtils.isSupportedKotlinClass(parameter.getDeclaringClass())) {
|
||||
return KotlinReflectionUtils.isNullable(parameter);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.log.LogMessage;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.hateoas.server.MethodLinkBuilderFactory;
|
||||
import org.springframework.hateoas.server.core.MethodParameters;
|
||||
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilderFactory;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
@@ -53,21 +51,6 @@ public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArg
|
||||
|
||||
private final HateoasPageableHandlerMethodArgumentResolver resolver;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PagedResourcesAssemblerArgumentResolver} using the given
|
||||
* {@link PageableHandlerMethodArgumentResolver} and {@link MethodLinkBuilderFactory}.
|
||||
*
|
||||
* @param resolver can be {@literal null}.
|
||||
* @param linkBuilderFactory can be {@literal null}, will be defaulted to a {@link WebMvcLinkBuilderFactory}.
|
||||
* @deprecated since 2.5, 2.4.4, 2.3.7, to be removed in 3.0
|
||||
* @use {@link #PagedResourcesAssemblerArgumentResolver(HateoasPageableHandlerMethodArgumentResolver)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PagedResourcesAssemblerArgumentResolver(HateoasPageableHandlerMethodArgumentResolver resolver,
|
||||
@Nullable MethodLinkBuilderFactory<?> linkBuilderFactory) {
|
||||
this(resolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link PagedResourcesAssemblerArgumentResolver} using the given
|
||||
* {@link PageableHandlerMethodArgumentResolver}.
|
||||
|
||||
@@ -41,9 +41,10 @@ class InstantiationAwarePersistentPropertyAccessorUnitTests {
|
||||
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Sample.class);
|
||||
|
||||
PersistentPropertyAccessor<Sample> accessor = entity.getPropertyAccessor(new Sample("Dave", "Matthews", 42));
|
||||
Sample sample = new Sample("Dave", "Matthews", 42);
|
||||
|
||||
PersistentPropertyAccessor<Sample> wrapper = new InstantiationAwarePropertyAccessor<>(accessor,
|
||||
PersistentPropertyAccessor<Sample> wrapper = new InstantiationAwarePropertyAccessor<>(sample,
|
||||
entity::getPropertyAccessor,
|
||||
instantiators);
|
||||
|
||||
wrapper.setProperty(entity.getRequiredPersistentProperty("firstname"), "Oliver August");
|
||||
|
||||
@@ -37,12 +37,16 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.config.CustomRepositoryImplementationDetector;
|
||||
import org.springframework.data.repository.config.ImplementationLookupConfiguration;
|
||||
import org.springframework.data.repository.core.NamedQueries;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.support.DummyRepositoryFactory;
|
||||
import org.springframework.data.repository.core.support.PropertiesBasedNamedQueries;
|
||||
import org.springframework.data.repository.core.support.QueryCreationListener;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
@@ -60,6 +64,7 @@ import org.springframework.data.repository.query.RepositoryQuery;
|
||||
* @author Kyrylo Merzlikin
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class CdiRepositoryBeanUnitTests {
|
||||
|
||||
static final String PASSIVATION_ID = "javax.enterprise.inject.Default:org.springframework.data.repository.cdi.CdiRepositoryBeanUnitTests$SampleRepository";
|
||||
@@ -148,8 +153,8 @@ class CdiRepositoryBeanUnitTests {
|
||||
|
||||
@Override
|
||||
protected SampleRepository create(CreationalContext<SampleRepository> creationalContext,
|
||||
Class<SampleRepository> repositoryType, Optional<Object> customImplementation) {
|
||||
return null;
|
||||
Class<SampleRepository> repositoryType) {
|
||||
return create(() -> new DummyRepositoryFactory(new Object()), repositoryType);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -158,9 +163,9 @@ class CdiRepositoryBeanUnitTests {
|
||||
ArgumentCaptor<ImplementationLookupConfiguration> captor = ArgumentCaptor
|
||||
.forClass(ImplementationLookupConfiguration.class);
|
||||
|
||||
verify(detector).detectCustomImplementation(captor.capture());
|
||||
verify(detector, times(2)).detectCustomImplementation(captor.capture());
|
||||
|
||||
ImplementationLookupConfiguration configuration = captor.getValue();
|
||||
ImplementationLookupConfiguration configuration = captor.getAllValues().get(0);
|
||||
|
||||
assertThat(configuration.getImplementationBeanName()).isEqualTo("cdiRepositoryBeanUnitTests.SampleRepositoryImpl");
|
||||
assertThat(configuration.getImplementationClassName()).isEqualTo("SampleRepositoryImpl");
|
||||
@@ -194,8 +199,7 @@ class CdiRepositoryBeanUnitTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType,
|
||||
Optional<Object> customImplementation) {
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2021 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.repository.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PageableExecutionUtils}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PageableExecutionUtilsUnitTests {
|
||||
|
||||
@Mock LongSupplier totalSupplierMock;
|
||||
|
||||
@Test // DATAMCNS-884
|
||||
void firstPageRequestIsLessThanOneFullPageDoesNotRequireTotal() {
|
||||
|
||||
Page<Integer> page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), PageRequest.of(0, 10),
|
||||
totalSupplierMock);
|
||||
|
||||
assertThat(page).contains(1, 2, 3);
|
||||
assertThat(page.getTotalElements()).isEqualTo(3L);
|
||||
verifyNoInteractions(totalSupplierMock);
|
||||
}
|
||||
|
||||
@Test // DATAMCNS-884
|
||||
void noPageableRequestDoesNotRequireTotal() {
|
||||
|
||||
Page<Integer> page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), Pageable.unpaged(), totalSupplierMock);
|
||||
|
||||
assertThat(page).contains(1, 2, 3);
|
||||
assertThat(page.getTotalElements()).isEqualTo(3L);
|
||||
|
||||
verifyNoInteractions(totalSupplierMock);
|
||||
}
|
||||
|
||||
@Test // DATAMCNS-884
|
||||
void subsequentPageRequestIsLessThanOneFullPageDoesNotRequireTotal() {
|
||||
|
||||
Page<Integer> page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), PageRequest.of(5, 10),
|
||||
totalSupplierMock);
|
||||
|
||||
assertThat(page).contains(1, 2, 3);
|
||||
assertThat(page.getTotalElements()).isEqualTo(53L);
|
||||
|
||||
verifyNoInteractions(totalSupplierMock);
|
||||
}
|
||||
|
||||
@Test // DATAMCNS-884
|
||||
void firstPageRequestHitsUpperBoundRequiresTotal() {
|
||||
|
||||
doReturn(4L).when(totalSupplierMock).getAsLong();
|
||||
|
||||
Page<Integer> page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), PageRequest.of(0, 3),
|
||||
totalSupplierMock);
|
||||
|
||||
assertThat(page).contains(1, 2, 3);
|
||||
assertThat(page.getTotalElements()).isEqualTo(4L);
|
||||
|
||||
verify(totalSupplierMock).getAsLong();
|
||||
}
|
||||
|
||||
@Test // DATAMCNS-884
|
||||
void subsequentPageRequestHitsUpperBoundRequiresTotal() {
|
||||
|
||||
doReturn(7L).when(totalSupplierMock).getAsLong();
|
||||
|
||||
Page<Integer> page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), PageRequest.of(1, 3),
|
||||
totalSupplierMock);
|
||||
|
||||
assertThat(page).contains(1, 2, 3);
|
||||
assertThat(page.getTotalElements()).isEqualTo(7L);
|
||||
|
||||
verify(totalSupplierMock).getAsLong();
|
||||
}
|
||||
|
||||
@Test // DATAMCNS-884
|
||||
void subsequentPageRequestWithoutResultRequiresRequireTotal() {
|
||||
|
||||
doReturn(7L).when(totalSupplierMock).getAsLong();
|
||||
Page<Integer> page = PageableExecutionUtils.getPage(Collections.<Integer> emptyList(), PageRequest.of(5, 10),
|
||||
totalSupplierMock);
|
||||
|
||||
assertThat(page.getTotalElements()).isEqualTo(7L);
|
||||
|
||||
verify(totalSupplierMock).getAsLong();
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.NullableWrapper;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.data.mapping.model.TypeCreatingSyntheticClassKt;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -58,6 +59,21 @@ public class KotlinReflectionUtilsUnitTests {
|
||||
assertThat(KotlinReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClass.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1171
|
||||
public void discoversKotlinClass() {
|
||||
|
||||
assertThat(KotlinDetector.isKotlinType(TypeCreatingSyntheticClass.class)).isTrue();
|
||||
assertThat(KotlinReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClass.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1171
|
||||
public void discoversUnsupportedKotlinClass() {
|
||||
|
||||
assertThat(KotlinDetector.isKotlinType(org.springframework.data.mapping.model.TypeCreatingSyntheticClassKt.class))
|
||||
.isTrue();
|
||||
assertThat(KotlinReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClassKt.class)).isFalse();
|
||||
}
|
||||
|
||||
void runTest(String testName)
|
||||
throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException {
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.mapping.model.TypeCreatingSyntheticClassKt;
|
||||
import org.springframework.data.repository.sample.User;
|
||||
import org.springframework.data.util.ReflectionUtils.DescribedFieldFilter;
|
||||
import org.springframework.util.ReflectionUtils.FieldFilter;
|
||||
@@ -38,46 +37,46 @@ import org.springframework.util.ReflectionUtils.FieldFilter;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class ReflectionUtilsUnitTests {
|
||||
class ReflectionUtilsUnitTests {
|
||||
|
||||
@SuppressWarnings("rawtypes") Constructor constructor;
|
||||
Field reference;
|
||||
@SuppressWarnings("rawtypes") private Constructor constructor;
|
||||
private Field reference;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() throws Exception {
|
||||
this.reference = Sample.class.getField("field");
|
||||
this.constructor = ConstructorDetection.class.getConstructor(int.class, String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsFieldByFilter() {
|
||||
void findsFieldByFilter() {
|
||||
|
||||
Field field = ReflectionUtils.findField(Sample.class, (FieldFilter) new FieldNameFieldFilter("field"));
|
||||
assertThat(field).isEqualTo(reference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullIfNoFieldFound() {
|
||||
void returnsNullIfNoFieldFound() {
|
||||
|
||||
Field field = ReflectionUtils.findField(Sample.class, (FieldFilter) new FieldNameFieldFilter("foo"));
|
||||
assertThat(field).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNonUniqueField() {
|
||||
void rejectsNonUniqueField() {
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
() -> ReflectionUtils.findField(Sample.class, new ReflectionUtils.AnnotationFieldFilter(Autowired.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsUniqueField() {
|
||||
void findsUniqueField() {
|
||||
|
||||
Field field = ReflectionUtils.findField(Sample.class, new FieldNameFieldFilter("field"), false);
|
||||
assertThat(field).isEqualTo(reference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsFieldInSuperclass() {
|
||||
void findsFieldInSuperclass() {
|
||||
|
||||
class Subclass extends Sample {
|
||||
|
||||
@@ -88,7 +87,7 @@ public class ReflectionUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setsNonPublicField() {
|
||||
void setsNonPublicField() {
|
||||
|
||||
Sample sample = new Sample();
|
||||
Field field = ReflectionUtils.findField(Sample.class, new FieldNameFieldFilter("first"));
|
||||
@@ -97,48 +96,48 @@ public class ReflectionUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-542
|
||||
public void detectsConstructorForCompleteMatch() throws Exception {
|
||||
void detectsConstructorForCompleteMatch() throws Exception {
|
||||
assertThat(ReflectionUtils.findConstructor(ConstructorDetection.class, 2, "test")).hasValue(constructor);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-542
|
||||
public void detectsConstructorForMatchWithNulls() throws Exception {
|
||||
void detectsConstructorForMatchWithNulls() throws Exception {
|
||||
assertThat(ReflectionUtils.findConstructor(ConstructorDetection.class, 2, null)).hasValue(constructor);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-542
|
||||
public void rejectsConstructorIfNumberOfArgumentsDontMatch() throws Exception {
|
||||
void rejectsConstructorIfNumberOfArgumentsDontMatch() throws Exception {
|
||||
assertThat(ReflectionUtils.findConstructor(ConstructorDetection.class, 2, "test", "test")).isNotPresent();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-542
|
||||
public void rejectsConstructorForNullForPrimitiveArgument() throws Exception {
|
||||
void rejectsConstructorForNullForPrimitiveArgument() throws Exception {
|
||||
assertThat(ReflectionUtils.findConstructor(ConstructorDetection.class, null, "test")).isNotPresent();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1154
|
||||
public void discoversNoReturnType() throws Exception {
|
||||
void discoversNoReturnType() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(DummyInterface.class.getDeclaredMethod("noReturnValue"), -1);
|
||||
assertThat(ReflectionUtils.isNullable(parameter)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1154
|
||||
public void discoversNullableReturnType() throws Exception {
|
||||
void discoversNullableReturnType() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(DummyInterface.class.getDeclaredMethod("nullableReturnValue"), -1);
|
||||
assertThat(ReflectionUtils.isNullable(parameter)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1154
|
||||
public void discoversNonNullableReturnType() throws Exception {
|
||||
void discoversNonNullableReturnType() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(DummyInterface.class.getDeclaredMethod("mandatoryReturnValue"), -1);
|
||||
assertThat(ReflectionUtils.isNullable(parameter)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1154
|
||||
public void discoversNullableParameter() throws Exception {
|
||||
void discoversNullableParameter() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(
|
||||
DummyInterface.class.getDeclaredMethod("nullableParameter", User.class), 0);
|
||||
@@ -146,28 +145,14 @@ public class ReflectionUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1154
|
||||
public void discoversNonNullablePrimitiveParameter() throws Exception {
|
||||
void discoversNonNullablePrimitiveParameter() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(DummyInterface.class.getDeclaredMethod("primitive", int.class), 0);
|
||||
assertThat(ReflectionUtils.isNullable(parameter)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1171
|
||||
public void discoversKotlinClass() {
|
||||
|
||||
assertThat(ReflectionUtils.isKotlinClass(TypeCreatingSyntheticClass.class)).isTrue();
|
||||
assertThat(ReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClass.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1171
|
||||
public void discoversUnsupportedKotlinClass() {
|
||||
|
||||
assertThat(ReflectionUtils.isKotlinClass(TypeCreatingSyntheticClassKt.class)).isTrue();
|
||||
assertThat(ReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClassKt.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1779
|
||||
public void shouldReportIsVoid() {
|
||||
void shouldReportIsVoid() {
|
||||
|
||||
assertThat(ReflectionUtils.isVoid(Void.class)).isTrue();
|
||||
assertThat(ReflectionUtils.isVoid(Void.TYPE)).isTrue();
|
||||
@@ -186,7 +171,7 @@ public class ReflectionUtilsUnitTests {
|
||||
|
||||
private final String name;
|
||||
|
||||
public FieldNameFieldFilter(String name) {
|
||||
FieldNameFieldFilter(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user