DATACMNS-1496 - Removed deprecations at least introduced in Lovelace.

This commit is contained in:
Oliver Drotbohm
2019-03-13 16:21:31 +01:00
parent 78e635fba9
commit 0bf160eb97
39 changed files with 63 additions and 1901 deletions

View File

@@ -1,165 +0,0 @@
/*
* Copyright 2011-2019 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
*
* http://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.authentication;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* Class used to provide credentials for username/password authentication
*
* @author Thomas Risberg
* @author Oliver Gierke
* @deprecated since 2.1 without replacement as it was meant for internal use only anyway.
*/
@Deprecated
public class UserCredentials {
public static final UserCredentials NO_CREDENTIALS = new UserCredentials(null, null);
private final @Nullable String username, password;
/**
* Creates a new {@link UserCredentials} instance from the given username and password. Empty {@link String}s provided
* will be treated like no username or password set.
*
* @param username
* @param password
*/
public UserCredentials(@Nullable String username, @Nullable String password) {
this.username = StringUtils.hasText(username) ? username : null;
this.password = StringUtils.hasText(password) ? password : null;
}
/**
* Get the username to use for authentication.
*
* @return the username
*/
@Nullable
public String getUsername() {
return username;
}
/**
* Get the password to use for authentication.
*
* @return the password
*/
@Nullable
public String getPassword() {
return password;
}
/**
* Returns whether the credentials contain a username.
*
* @return
*/
public boolean hasUsername() {
return this.username != null;
}
/**
* Returns whether the credentials contain a password.
*
* @return
*/
public boolean hasPassword() {
return this.password != null;
}
/**
* Returns the password in obfuscated fashion which means everything except the first and last character replaced by
* stars. If the password is one or two characters long we'll obfuscate it entirely.
*
* @return the obfuscated password
*/
@Nullable
public String getObfuscatedPassword() {
String password = this.password;
if (password == null) {
return null;
}
StringBuilder builder = new StringBuilder();
if (password.length() < 3) {
for (int i = password.length(); i != 0; i--) {
builder.append("*");
}
return builder.toString();
}
builder.append(password.charAt(0));
for (int i = password.length() - 2; i != 0; i--) {
builder.append("*");
}
return builder.append(password.substring(password.length() - 1)).toString();
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return String.format("username = [%s], password = [%s]", username, getObfuscatedPassword());
}
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !getClass().equals(obj.getClass())) {
return false;
}
UserCredentials that = (UserCredentials) obj;
return ObjectUtils.nullSafeEquals(this.username, that.username)
&& ObjectUtils.nullSafeEquals(this.password, that.password);
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
int result = 17;
result += 31 * ObjectUtils.nullSafeHashCode(username);
result += 31 * ObjectUtils.nullSafeHashCode(password);
return result;
}
}

View File

@@ -1,5 +0,0 @@
/**
* Types to abstract authentication concepts.
*/
@org.springframework.lang.NonNullApi
package org.springframework.data.authentication;

View File

@@ -560,19 +560,7 @@ public interface ExampleMatcher {
/**
* Allows to transform the property value before it is used in the query.
*/
interface PropertyValueTransformer extends Function<Optional<Object>, Optional<Object>> {
/**
* For backwards compatibility of clients used to invoke Spring's Converter interface.
*
* @param source
* @return
*/
@Deprecated
default Object convert(Object source) {
return apply(Optional.ofNullable(source)).orElse(null);
}
}
interface PropertyValueTransformer extends Function<Optional<Object>, Optional<Object>> {}
/**
* @author Christoph Strobl
@@ -699,18 +687,6 @@ public interface ExampleMatcher {
return valueTransformer == null ? NoOpPropertyValueTransformer.INSTANCE : valueTransformer;
}
/**
* Transforms a given source using the {@link PropertyValueTransformer}.
*
* @param source
* @return
* @deprecated since 2.0, use {@link #transformValue(Optional)} instead.
*/
@Deprecated
public Object transformValue(Object source) {
return transformValue(Optional.ofNullable(source)).orElse(null);
}
/**
* Transforms a given source using the {@link PropertyValueTransformer}.
*

View File

@@ -30,43 +30,14 @@ public class PageRequest extends AbstractPageRequest {
private final Sort sort;
/**
* Creates a new {@link PageRequest}. Pages are zero indexed, thus providing 0 for {@code page} will return the first
* page.
*
* @param page zero-based page index.
* @param size the size of the page to be returned.
* @deprecated use {@link #of(int, int)} instead.
*/
@Deprecated
public PageRequest(int page, int size) {
this(page, size, Sort.unsorted());
}
/**
* Creates a new {@link PageRequest} with sort parameters applied.
*
* @param page zero-based page index.
* @param size the size of the page to be returned.
* @param direction the direction of the {@link Sort} to be specified, can be {@literal null}.
* @param properties the properties to sort by, must not be {@literal null} or empty.
* @deprecated use {@link #of(int, int, Direction, String...)} instead.
* @param sort must not be {@literal null}, use {@link Sort#unsorted()} instead.
*/
@Deprecated
public PageRequest(int page, int size, Direction direction, String... properties) {
this(page, size, Sort.by(direction, properties));
}
/**
* Creates a new {@link PageRequest} with sort parameters applied.
*
* @param page zero-based page index.
* @param size the size of the page to be returned.
* @param sort can be {@literal null}.
* @deprecated since 2.0, use {@link #of(int, int, Sort)} instead.
*/
@Deprecated
public PageRequest(int page, int size, Sort sort) {
protected PageRequest(int page, int size, Sort sort) {
super(page, size);
@@ -89,7 +60,7 @@ public class PageRequest extends AbstractPageRequest {
*
* @param page zero-based page index.
* @param size the size of the page to be returned.
* @param sort must not be {@literal null}.
* @param sort must not be {@literal null}, use {@link Sort#unsorted()} instead.
* @since 2.0
*/
public static PageRequest of(int page, int size, Sort sort) {
@@ -121,6 +92,7 @@ public class PageRequest extends AbstractPageRequest {
* (non-Javadoc)
* @see org.springframework.data.domain.Pageable#next()
*/
@Override
public Pageable next() {
return new PageRequest(getPageNumber() + 1, getPageSize(), getSort());
}
@@ -129,6 +101,7 @@ public class PageRequest extends AbstractPageRequest {
* (non-Javadoc)
* @see org.springframework.data.domain.AbstractPageRequest#previous()
*/
@Override
public PageRequest previous() {
return getPageNumber() == 0 ? this : new PageRequest(getPageNumber() - 1, getPageSize(), getSort());
}
@@ -137,6 +110,7 @@ public class PageRequest extends AbstractPageRequest {
* (non-Javadoc)
* @see org.springframework.data.domain.Pageable#first()
*/
@Override
public Pageable first() {
return new PageRequest(0, getPageSize(), getSort());
}

View File

@@ -47,41 +47,6 @@ public class Range<T extends Comparable<T>> {
*/
private final @NonNull Bound<T> upperBound;
/**
* Creates a new {@link Range} with the given lower and upper bound. Treats the given values as inclusive bounds. Use
* {@link #Range(Comparable, Comparable, boolean, boolean)} to configure different bound behavior.
*
* @see Range#of(Bound, Bound)
* @param lowerBound can be {@literal null} in case upperBound is not {@literal null}.
* @param upperBound can be {@literal null} in case lowerBound is not {@literal null}.
* @deprecated since 2.0 in favor of {@link Range#of(Bound, Bound)}.
*/
@Deprecated
public Range(T lowerBound, T upperBound) {
this(lowerBound, upperBound, true, true);
}
/**
* Creates a new {@link Range} with the given lower and upper bound as well as the given inclusive/exclusive
* semantics.
*
* @param lowerBound can be {@literal null}.
* @param upperBound can be {@literal null}.
* @param lowerInclusive
* @param upperInclusive
* @deprecated since 2.0. Use {@link Range#of(Bound, Bound)} and {@link Bound} factory methods:
* {@link Bound#inclusive(Comparable)}, {@link Bound#exclusive(Comparable)}/{@link Bound#unbounded()}.
*/
@Deprecated
public Range(T lowerBound, T upperBound, boolean lowerInclusive, boolean upperInclusive) {
this.lowerBound = lowerBound == null ? Bound.unbounded()
: lowerInclusive ? Bound.inclusive(lowerBound) : Bound.exclusive(lowerBound);
this.upperBound = upperBound == null ? Bound.unbounded()
: upperInclusive ? Bound.inclusive(upperBound) : Bound.exclusive(upperBound);
}
/**
* Returns an unbounded {@link Range}.
*
@@ -117,24 +82,6 @@ public class Range<T extends Comparable<T>> {
return new Range<>(lowerBound, upperBound);
}
/**
* @return
* @deprecated since 2.0, use {@link #getLowerBound()} and {@link Bound#isInclusive()}.
*/
@Deprecated
public boolean isLowerInclusive() {
return lowerBound.isInclusive();
}
/**
* @return
* @deprecated since 2.0, use {@link #getUpperBound()} and {@link Bound#isInclusive()}.
*/
@Deprecated
public boolean isUpperInclusive() {
return upperBound.isInclusive();
}
/**
* Returns whether the {@link Range} contains the given value.
*

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.data.domain;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
@@ -41,6 +44,7 @@ import org.springframework.util.StringUtils;
* @author Thomas Darimont
* @author Mark Paluch
*/
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class Sort implements Streamable<org.springframework.data.domain.Sort.Order>, Serializable {
private static final long serialVersionUID = 5737186511678863905L;
@@ -51,68 +55,21 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
private final List<Order> orders;
/**
* Creates a new {@link Sort} instance using the given {@link Order}s.
*
* @param orders must not be {@literal null}.
*/
@Deprecated
public Sort(Order... orders) {
this(Arrays.asList(orders));
}
/**
* Creates a new {@link Sort} instance.
*
* @param orders must not be {@literal null} or contain {@literal null}.
* @deprecated see {@link Sort#by(List)}
*/
@Deprecated
public Sort(List<Order> orders) {
Assert.notNull(orders, "Orders must not be null!");
this.orders = Collections.unmodifiableList(orders);
}
/**
* Creates a new {@link Sort} instance. Order defaults to {@value Direction#ASC}.
*
* @param properties must not be {@literal null} or contain {@literal null} or empty strings
* @deprecated use {@link Sort#by(String...)}
*/
@Deprecated
public Sort(String... properties) {
this(DEFAULT_DIRECTION, properties);
}
/**
* Creates a new {@link Sort} instance.
*
* @param direction defaults to {@link Sort#DEFAULT_DIRECTION} (for {@literal null} cases, too)
* @param properties must not be {@literal null}, empty or contain {@literal null} or empty strings.
*/
public Sort(Direction direction, String... properties) {
this(direction, properties == null ? new ArrayList<>() : Arrays.asList(properties));
}
/**
* Creates a new {@link Sort} instance.
*
* @param direction defaults to {@link Sort#DEFAULT_DIRECTION} (for {@literal null} cases, too)
* @param properties must not be {@literal null} or contain {@literal null} or empty strings.
*/
public Sort(Direction direction, List<String> properties) {
private Sort(Direction direction, List<String> properties) {
if (properties == null || properties.isEmpty()) {
throw new IllegalArgumentException("You have to provide at least one property to sort by!");
}
this.orders = new ArrayList<>(properties.size());
for (String property : properties) {
this.orders.add(new Order(direction, property));
}
this.orders = properties.stream() //
.map(it -> new Order(direction, it)) //
.collect(Collectors.toList());
}
/**
@@ -125,7 +82,9 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
Assert.notNull(properties, "Properties must not be null!");
return properties.length == 0 ? Sort.unsorted() : new Sort(properties);
return properties.length == 0 //
? Sort.unsorted() //
: new Sort(DEFAULT_DIRECTION, Arrays.asList(properties));
}
/**
@@ -151,7 +110,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
Assert.notNull(orders, "Orders must not be null!");
return new Sort(orders);
return new Sort(Arrays.asList(orders));
}
/**
@@ -174,7 +133,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
/**
* Creates a new {@link TypedSort} for the given type.
*
*
* @param type must not be {@literal null}.
* @return
* @since 2.2
@@ -444,18 +403,6 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
this(direction, property, DEFAULT_IGNORE_CASE, nullHandlingHint);
}
/**
* Creates a new {@link Order} instance. Takes a single property. Direction defaults to
* {@link Sort#DEFAULT_DIRECTION}.
*
* @param property must not be {@literal null} or empty.
* @deprecated since 2.0, use {@link Order#by(String)}.
*/
@Deprecated
public Order(String property) {
this(DEFAULT_DIRECTION, property);
}
/**
* Creates a new {@link Order} instance. Takes a single property. Direction defaults to
* {@link Sort#DEFAULT_DIRECTION}.
@@ -726,7 +673,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
private TypedSort(Recorded<T> recorded) {
super(new Order[0]);
super(Collections.emptyList());
this.recorded = recorded;
}
@@ -742,10 +689,12 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
return new TypedSort<>(recorded.record(mapProperty));
}
@Override
public Sort ascending() {
return withDirection(Sort::ascending);
}
@Override
public Sort descending() {
return withDirection(Sort::descending);
}
@@ -758,7 +707,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
.orElseGet(Sort::unsorted);
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.domain.Sort#iterator()
*/
@@ -772,7 +721,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.domain.Sort#toString()
*/

View File

@@ -69,16 +69,6 @@ public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implem
return revisionNumber.get();
}
/*
* (non-Javadoc)
* @see org.springframework.data.history.RevisionMetadata#getRevisionDate()
*/
@Deprecated
public Optional<LocalDateTime> getRevisionDate() {
return revisionDate.get().map(AnnotationRevisionMetadata::convertToLocalDateTime);
}
/*
* (non-Javadoc)
* @see org.springframework.data.history.RevisionMetadata#getRevisionDate()
@@ -106,15 +96,6 @@ public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implem
});
}
private static LocalDateTime convertToLocalDateTime(Object timestamp) {
if (timestamp instanceof LocalDateTime) {
return (LocalDateTime) timestamp;
}
return LocalDateTime.ofInstant(convertToInstant(timestamp), ZoneOffset.systemDefault());
}
private static Instant convertToInstant(Object timestamp) {
if (timestamp instanceof Instant) {

View File

@@ -23,7 +23,6 @@ import lombok.RequiredArgsConstructor;
import lombok.Value;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Optional;
import org.springframework.lang.Nullable;
@@ -79,17 +78,6 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp
return metadata.getRequiredRevisionNumber();
}
/**
* Returns the revision date of the revision.
*
* @return Guaranteed to be not {@literal null}.
* @deprecated Use {@link #getRevisionInstant()} instead.
*/
@Deprecated
public Optional<LocalDateTime> getRevisionDate() {
return metadata.getRevisionDate();
}
/**
* Returns the timestamp of the revision.
*
@@ -99,17 +87,6 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp
return metadata.getRevisionInstant();
}
/**
* Returns the revision date of the revision, immediately failing on absence.
*
* @return the revision date.
* @deprecated Use {@link #getRequiredRevisionInstant()} instead.
*/
@Deprecated
public LocalDateTime getRequiredRevisionDate() {
return metadata.getRequiredRevisionDate();
}
/**
* Returns the timestamp of the revision, immediately failing on absence.
*
@@ -130,7 +107,7 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp
}
return mapIfAllPresent(getRevisionNumber(), that.getRevisionNumber(), //
(left, right) -> left.compareTo(right)).orElse(-1);
Comparable::compareTo).orElse(-1);
}
/*

View File

@@ -16,7 +16,6 @@
package org.springframework.data.history;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Optional;
/**
@@ -42,18 +41,10 @@ public interface RevisionMetadata<N extends Number & Comparable<N>> {
* @throws IllegalStateException if no revision number is available.
*/
default N getRequiredRevisionNumber() {
return getRevisionNumber().orElseThrow(
() -> new IllegalStateException(String.format("No revision number found on %s!", (Object) getDelegate())));
}
/**
* Returns the date of the revision.
*
* @return will never be {@literal null}.
* @deprecated use {@link #getRevisionInstant()} instead.
*/
@Deprecated
Optional<LocalDateTime> getRevisionDate();
return getRevisionNumber().orElseThrow(
() -> new IllegalStateException(String.format("No revision number found on %s!", this.<Object> getDelegate())));
}
/**
* Returns the timestamp of the revision.
@@ -63,28 +54,15 @@ public interface RevisionMetadata<N extends Number & Comparable<N>> {
Optional<Instant> getRevisionInstant();
/**
* Returns the revision date of the revision, immediately failing on absence.
*
* @return will never be {@literal null}.
* @throws IllegalStateException if no revision date is available.
* @deprecated Use {@link #getRevisionInstant()} instead.
*/
@Deprecated
default LocalDateTime getRequiredRevisionDate() {
return getRevisionDate().orElseThrow(
() -> new IllegalStateException(String.format("No revision date found on %s!", (Object) getDelegate())));
}
/**
* Returns the timestamp of the revision, immediately failing on absence.
* Returns the time stamp of the revision, immediately failing on absence.
*
* @return will never be {@literal null}.
* @throws IllegalStateException if no revision date is available.
*/
default Instant getRequiredRevisionInstant() {
return getRevisionInstant().orElseThrow(
() -> new IllegalStateException(String.format("No revision date found on %s!", (Object) getDelegate())));
() -> new IllegalStateException(String.format("No revision date found on %s!", this.<Object> getDelegate())));
}
/**

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.history;
import java.util.Arrays;
import org.springframework.data.domain.Sort;
import org.springframework.util.Assert;
@@ -40,7 +42,7 @@ public class RevisionSort extends Sort {
* @param direction must not be {@literal null}.
*/
private RevisionSort(Direction direction) {
super(direction, PROPERTY);
super(Arrays.asList(new Order(direction, PROPERTY)));
}
/**

View File

@@ -114,7 +114,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
this.applicationEventPublisher = applicationEventPublisher;
}
/*
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@@ -285,15 +285,6 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.MappingContext#getPersistentPropertyPath(org.springframework.data.mapping.context.InvalidPersistentPropertyPath)
*/
@Override
public PersistentPropertyPath<P> getPersistentPropertyPath(InvalidPersistentPropertyPath invalidPath) {
return persistentPropertyPathFactory.from(invalidPath.getType(), invalidPath.getResolvedPath());
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.MappingContext#findPersistentPropertyPath(java.lang.Class, java.util.function.Predicate)
*/
@@ -310,7 +301,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
* Actually looks up the {@link PersistentPropertyPaths} for the given type, selection predicate and traversal guard.
* Primary purpose is to allow sub-types to alter the default traversal guard, e.g. used by
* {@link #findPersistentPropertyPaths(Class, Predicate)}.
*
*
* @param type will never be {@literal null}.
* @param predicate will never be {@literal null}.
* @param traversalGuard will never be {@literal null}.

View File

@@ -173,26 +173,12 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath, Class<?> type)
throws InvalidPersistentPropertyPath;
/**
* Returns the {@link PersistentPropertyPath} for the resolvable part of the given
* {@link InvalidPersistentPropertyPath}.
*
* @param invalidPath must not be {@literal null}.
* @return the {@link PersistentPropertyPath} for the resolvable part of the given
* {@link InvalidPersistentPropertyPath}.
* @since 1.11
* @deprecated since 2.0, use {@link #getPersistentPropertyPath(PropertyPath)} with
* {@link InvalidPersistentPropertyPath#getResolvedPath()} instead.
*/
@Deprecated
PersistentPropertyPath<P> getPersistentPropertyPath(InvalidPersistentPropertyPath invalidPath);
/**
* Returns all {@link PersistentPropertyPath}s pointing to properties on the given type that match the given
* {@link Predicate}. In case of circular references the detection will stop at the property that references a type
* that's already included in the path. Note, that is is a potentially expensive operation as results cannot be
* cached.
*
*
* @param type must not be {@literal null}.
* @param predicate must not be {@literal null}.
* @return

View File

@@ -1,77 +0,0 @@
/*
* Copyright 2012-2019 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
*
* http://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.mapping.context;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.support.IsNewStrategy;
import org.springframework.data.support.IsNewStrategyFactory;
import org.springframework.data.support.IsNewStrategyFactorySupport;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* An {@link IsNewStrategyFactory} using a {@link MappingContext} to determine the {@link IsNewStrategy} to be returned
* for a particular type. It will look for a version and id property on the {@link PersistentEntity} and return a
* strategy instance that will reflectively inspect the property for {@literal null} values or {@literal null} or a
* value of 0 in case of a version property.
*
* @author Oliver Gierke
* @author Mark Paluch
* @deprecated as of 2.1 in favor of looking up the {@link PersistentEntity} and calling
* {@link PersistentEntity#isNew(Object)} on it
*/
@Deprecated
public class MappingContextIsNewStrategyFactory extends IsNewStrategyFactorySupport {
private final PersistentEntities entities;
/**
* Creates a new {@link MappingContextIsNewStrategyFactory} using the given {@link MappingContext}.
*
* @param context must not be {@literal null}.
* @deprecated use {@link MappingContextIsNewStrategyFactory(PersistentEntities)} instead.
*/
@Deprecated
public MappingContextIsNewStrategyFactory(MappingContext<? extends PersistentEntity<?, ?>, ?> context) {
this(PersistentEntities.of(context));
}
/**
* Creates a new {@link MappingContextIsNewStrategyFactory} using the given {@link PersistentEntities}.
*
* @param entities must not be {@literal null}.
* @since 1.10
*/
public MappingContextIsNewStrategyFactory(PersistentEntities entities) {
Assert.notNull(entities, "PersistentEntities must not be null!");
this.entities = entities;
}
/*
* (non-Javadoc)
* @see org.springframework.data.support.IsNewStrategyFactorySupport#getFallBackStrategy(java.lang.Class)
*/
@Nullable
@Override
protected IsNewStrategy doGetIsNewStrategy(Class<?> type) {
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(type);
return bean -> entity.isNew(bean);
}
}

View File

@@ -37,19 +37,6 @@ public interface RepositoryConfigurationExtension {
*/
String getModuleName();
/**
* Returns all {@link RepositoryConfiguration}s obtained through the given {@link RepositoryConfigurationSource}.
*
* @param configSource must not be {@literal null}.
* @param loader must not be {@literal null}.
* @deprecated call or implement
* {@link #getRepositoryConfigurations(RepositoryConfigurationSource, ResourceLoader, boolean)} instead.
* @return
*/
@Deprecated
<T extends RepositoryConfigurationSource> Collection<RepositoryConfiguration<T>> getRepositoryConfigurations(
T configSource, ResourceLoader loader);
/**
* Returns all {@link RepositoryConfiguration}s obtained through the given {@link RepositoryConfigurationSource}.
*

View File

@@ -183,33 +183,6 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
return loader.getClassLoader();
}
/**
* Sets the given source on the given {@link AbstractBeanDefinition} and registers it inside the given
* {@link BeanDefinitionRegistry}. For {@link BeanDefinition}s to be registered once-and-only-once for all
* configuration elements (annotation or XML), prefer calling
* {@link #registerIfNotAlreadyRegistered(AbstractBeanDefinition, BeanDefinitionRegistry, String, Object)} with a
* dedicated bean name to avoid the bead definition being registered multiple times.
*
* @param registry must not be {@literal null}.
* @param bean must not be {@literal null}.
* @param source must not be {@literal null}.
* @return the bean name generated for the given {@link BeanDefinition}
* @deprecated since 2.1, use
* {@link #registerWithSourceAndGeneratedBeanName(AbstractBeanDefinition, BeanDefinitionRegistry, Object)}
* instead.
*/
@Deprecated
public static String registerWithSourceAndGeneratedBeanName(BeanDefinitionRegistry registry,
AbstractBeanDefinition bean, Object source) {
bean.setSource(source);
String beanName = generateBeanName(bean, registry);
registry.registerBeanDefinition(beanName, bean);
return beanName;
}
/**
* Sets the given source on the given {@link AbstractBeanDefinition} and registers it inside the given
* {@link BeanDefinitionRegistry}. For {@link BeanDefinition}s to be registered once-and-only-once for all
@@ -233,23 +206,6 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
return beanName;
}
/**
* Registers the given {@link AbstractBeanDefinition} with the given registry with the given bean name unless the
* registry already contains a bean with that name.
*
* @param bean must not be {@literal null}.
* @param registry must not be {@literal null}.
* @param beanName must not be {@literal null} or empty.
* @param source must not be {@literal null}.
* @deprecated since 2.1, prefer
* {@link #registerIfNotAlreadyRegistered(Supplier, BeanDefinitionRegistry, String, Object)}
*/
@Deprecated
public static void registerIfNotAlreadyRegistered(AbstractBeanDefinition bean, BeanDefinitionRegistry registry,
String beanName, Object source) {
registerIfNotAlreadyRegistered(() -> bean, registry, beanName, source);
}
/**
* Registers the {@link AbstractBeanDefinition} produced by the given {@link Supplier} with the given registry with
* the given bean name unless the registry already contains a bean with that name.

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2016-2019 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
*
* http://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.core.support;
import org.springframework.data.domain.ExampleMatcher;
/**
* Accessor for the {@link ExampleMatcher} to use in modules that support query by example (QBE) querying.
*
* @author Mark Paluch
* @author Oliver Gierke
* @author Christoph Strobl
* @author Jens Schauder
*
* @since 1.12
*
* @deprecated use {@link org.springframework.data.support.ExampleMatcherAccessor} instead.
*/
@Deprecated
public class ExampleMatcherAccessor extends org.springframework.data.support.ExampleMatcherAccessor {
/**
* Creates a new {@link ExampleMatcherAccessor} for the given {@link ExampleMatcher}.
*
* @param matcher must not be {@literal null}.
*/
public ExampleMatcherAccessor(ExampleMatcher matcher) {
super(matcher);
}
}

View File

@@ -1,81 +0,0 @@
/*
* Copyright 2008-2019 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
*
* http://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.core.support;
import org.springframework.core.ResolvableType;
import org.springframework.data.domain.Persistable;
import org.springframework.data.repository.core.EntityMetadata;
import org.springframework.lang.Nullable;
/**
* Implementation of {@link EntityMetadata} that assumes the entity handled implements {@link Persistable} and uses
* {@link Persistable#isNew()} for the {@link #isNew(Object)} check.
*
* @author Oliver Gierke
* @deprecated as of 2.1 in favor of {@link PersistentEntityInformation}.
*/
@Deprecated
public class PersistableEntityInformation<T extends Persistable<ID>, ID> extends AbstractEntityInformation<T, ID> {
private Class<ID> idClass;
/**
* Creates a new {@link PersistableEntityInformation}.
*
* @param domainClass
*/
@SuppressWarnings("unchecked")
public PersistableEntityInformation(Class<T> domainClass) {
super(domainClass);
Class<?> idClass = ResolvableType.forClass(Persistable.class, domainClass).resolveGeneric(0);
if (idClass == null) {
throw new IllegalArgumentException(String.format("Could not resolve identifier type for %s!", domainClass));
}
this.idClass = (Class<ID>) idClass;
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.support.AbstractEntityInformation#isNew(java.lang.Object)
*/
@Override
public boolean isNew(T entity) {
return entity.isNew();
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.EntityInformation#getId(java.lang.Object)
*/
@Nullable
@Override
public ID getId(T entity) {
return entity.getId();
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.EntityInformation#getIdType()
*/
@Override
public Class<ID> getIdType() {
return this.idClass;
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2016-2019 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
*
* http://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.core.support;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.repository.core.RepositoryMetadata;
/**
* This {@link RepositoryInformation} uses a {@link ConversionService} to check whether method arguments can be
* converted for invocation of implementation methods.
*
* @author Mark Paluch
* @author Oliver Gierke
* @since 2.0
* @deprecated as of 2.0, can be deleted...
*/
@Deprecated
public class ReactiveRepositoryInformation extends DefaultRepositoryInformation {
/**
* Creates a new {@link ReactiveRepositoryInformation} for the given {@link RepositoryMetadata}, repository base
* class, custom implementation and {@link ConversionService}.
*
* @param metadata must not be {@literal null}.
* @param repositoryBaseClass must not be {@literal null}.
* @param composition can be {@literal null}.
*/
public ReactiveRepositoryInformation(RepositoryMetadata metadata, Class<?> repositoryBaseClass,
RepositoryComposition composition) {
super(metadata, repositoryBaseClass, composition.withMethodLookup(MethodLookups.forReactiveTypes(metadata)));
}
}

View File

@@ -1,99 +0,0 @@
/*
* Copyright 2012-2019 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
*
* http://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.core.support;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import org.springframework.data.annotation.Id;
import org.springframework.data.repository.core.EntityInformation;
import org.springframework.data.util.AnnotationDetectionFieldCallback;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
* {@link EntityInformation} implementation that inspects fields for an annotation and looks up this field's value to
* retrieve the id.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @deprecated since 2.1 in favor of {@link PersistentEntityInformation}
*/
@Deprecated
public class ReflectionEntityInformation<T, ID> extends AbstractEntityInformation<T, ID> {
private static final Class<Id> DEFAULT_ID_ANNOTATION = Id.class;
private Field field;
/**
* Creates a new {@link ReflectionEntityInformation} inspecting the given domain class for a field carrying the
* {@link Id} annotation.
*
* @param domainClass must not be {@literal null}.
*/
public ReflectionEntityInformation(Class<T> domainClass) {
this(domainClass, DEFAULT_ID_ANNOTATION);
}
/**
* Creates a new {@link ReflectionEntityInformation} inspecting the given domain class for a field carrying the given
* annotation.
*
* @param domainClass must not be {@literal null}.
* @param annotation must not be {@literal null}.
*/
public ReflectionEntityInformation(Class<T> domainClass, final Class<? extends Annotation> annotation) {
super(domainClass);
Assert.notNull(annotation, "Annotation must not be null!");
AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback(annotation);
ReflectionUtils.doWithFields(domainClass, callback);
try {
this.field = callback.getRequiredField();
} catch (IllegalStateException o_O) {
throw new IllegalArgumentException(String.format("Couldn't find field with annotation %s!", annotation), o_O);
}
ReflectionUtils.makeAccessible(this.field);
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.EntityInformation#getId(java.lang.Object)
*/
@Nullable
@SuppressWarnings("unchecked")
public ID getId(Object entity) {
Assert.notNull(entity, "Entity must not be null!");
return (ID) ReflectionUtils.getField(field, entity);
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.EntityInformation#getIdType()
*/
@SuppressWarnings("unchecked")
public Class<ID> getIdType() {
return (Class<ID>) field.getType();
}
}

View File

@@ -263,16 +263,13 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
}
/**
* Returns a repository instance for the given interface backed by an instance providing implementation logic for
* custom logic.
* Returns a repository instance for the given interface backed by a single instance providing implementation logic
* for custom logic. For more advanced composition needs use {@link #getRepository(Class, RepositoryFragments)}.
*
* @param repositoryInterface must not be {@literal null}.
* @param customImplementation must not be {@literal null}.
* @return
* @deprecated since 2.0. Use {@link RepositoryFragments} with {@link #getRepository(Class, RepositoryFragments)} to
* compose repositories backed by custom implementations.
*/
@Deprecated
public <T> T getRepository(Class<T> repositoryInterface, Object customImplementation) {
return getRepository(repositoryInterface, RepositoryFragments.just(customImplementation));
}

View File

@@ -27,8 +27,8 @@ import java.util.stream.Stream;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.data.spel.ExtensionAwareEvaluationContextProvider;
import org.springframework.data.spel.spi.EvaluationContextExtension;
import org.springframework.data.util.Lazy;
import org.springframework.data.util.Streamable;
@@ -56,29 +56,21 @@ public class ExtensionAwareQueryMethodEvaluationContextProvider implements Query
/**
* Creates a new {@link ExtensionAwareQueryMethodEvaluationContextProvider}.
*
*
* @param beanFactory the {@link ListableBeanFactory} to lookup the {@link EvaluationContextExtension}s from, must not
* be {@literal null}.
*/
@SuppressWarnings("deprecation")
public ExtensionAwareQueryMethodEvaluationContextProvider(ListableBeanFactory beanFactory) {
Assert.notNull(beanFactory, "ListableBeanFactory must not be null!");
this.delegate = Lazy.of(() -> {
org.springframework.data.spel.ExtensionAwareEvaluationContextProvider delegate = new org.springframework.data.spel.ExtensionAwareEvaluationContextProvider(
() -> getExtensionsFrom(beanFactory));
delegate.setBeanFactory(beanFactory);
return delegate;
});
this.delegate = Lazy.of(() -> new ExtensionAwareEvaluationContextProvider(() -> getExtensionsFrom(beanFactory)));
}
/**
* Creates a new {@link ExtensionAwareQueryMethodEvaluationContextProvider} using the given
* {@link EvaluationContextExtension}s.
*
*
* @param extensions must not be {@literal null}.
*/
public ExtensionAwareQueryMethodEvaluationContextProvider(List<? extends EvaluationContextExtension> extensions) {
@@ -88,7 +80,7 @@ public class ExtensionAwareQueryMethodEvaluationContextProvider implements Query
this.delegate = Lazy.of(new org.springframework.data.spel.ExtensionAwareEvaluationContextProvider(extensions));
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.QueryMethodEvaluationContextProvider#getEvaluationContext(org.springframework.data.repository.query.Parameters, java.lang.Object[])
*/
@@ -137,37 +129,12 @@ public class ExtensionAwareQueryMethodEvaluationContextProvider implements Query
* @param beanFactory must not be {@literal null}.
* @return
*/
@SuppressWarnings("deprecation")
private static List<EvaluationContextExtension> getExtensionsFrom(ListableBeanFactory beanFactory) {
Stream<EvaluationContextExtension> legacyExtensions = beanFactory //
.getBeansOfType(org.springframework.data.repository.query.spi.EvaluationContextExtension.class, true, false)
.values().stream() //
.map(ExtensionAwareQueryMethodEvaluationContextProvider::adaptFromLegacyApi);
Stream<EvaluationContextExtension> extensions = beanFactory
.getBeansOfType(EvaluationContextExtension.class, true, false).values().stream();
return Stream.concat(extensions, legacyExtensions).collect(Collectors.toList());
}
@SuppressWarnings({ "deprecation", "unchecked" })
private static final EvaluationContextExtension adaptFromLegacyApi(
org.springframework.data.repository.query.spi.EvaluationContextExtension extension) {
DelegatingMethodInterceptor advice = new DelegatingMethodInterceptor(extension);
advice.registerResultMapping("getFunctions",
result -> ((Map<String, org.springframework.data.repository.query.spi.Function>) result).entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toNewFunction())));
ProxyFactory factory = new ProxyFactory();
factory.setInterfaces(EvaluationContextExtension.class);
factory.setTargetClass(extension.getClass());
factory.setProxyTargetClass(true);
factory.setTarget(extension);
factory.addAdvice(advice);
return (EvaluationContextExtension) factory.getProxy();
return extensions.collect(Collectors.toList());
}
/**
@@ -187,7 +154,7 @@ public class ExtensionAwareQueryMethodEvaluationContextProvider implements Query
/**
* Registers a result mapping for the method with the given name. Invocation results for matching methods will be
* piped through the mapping.
*
*
* @param methodName
* @param mapping
*/
@@ -195,7 +162,7 @@ public class ExtensionAwareQueryMethodEvaluationContextProvider implements Query
this.directMappings.put(methodName, mapping);
}
/*
/*
* (non-Javadoc)
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
*/

View File

@@ -1,74 +0,0 @@
/*
* Copyright 2014-2019 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
*
* http://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.query.spi;
import java.util.Collections;
import java.util.Map;
import org.springframework.data.repository.query.ExtensionAwareQueryMethodEvaluationContextProvider;
import org.springframework.expression.EvaluationContext;
import org.springframework.lang.Nullable;
/**
* SPI to allow adding a set of properties and function definitions accessible via the root of an
* {@link EvaluationContext} provided by a {@link ExtensionAwareQueryMethodEvaluationContextProvider}.
*
* @author Thomas Darimont
* @author Oliver Gierke
* @since 1.9
* @deprecated since 2.1. Switch to same types in {@code org.springframework.data.spel.spi}.
*/
@Deprecated
public interface EvaluationContextExtension {
/**
* Returns the identifier of the extension. The id can be leveraged by users to fully qualify property lookups and
* thus overcome ambiguities in case multiple extensions expose properties with the same name.
*
* @return the extension id, must not be {@literal null}.
*/
String getExtensionId();
/**
* Returns the properties exposed by the extension.
*
* @return the properties
*/
default Map<String, Object> getProperties() {
return Collections.emptyMap();
}
/**
* Returns the functions exposed by the extension.
*
* @return the functions
*/
default Map<String, Function> getFunctions() {
return Collections.emptyMap();
}
/**
* Returns the root object to be exposed by the extension. It's strongly recommended to declare the most concrete type
* possible as return type of the implementation method. This will allow us to obtain the necessary metadata once and
* not for every evaluation.
*
* @return
*/
@Nullable
default Object getRootObject() {
return null;
}
}

View File

@@ -1,61 +0,0 @@
/*
* Copyright 2014-2019 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
*
* http://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.query.spi;
import java.util.Collections;
import java.util.Map;
import org.springframework.lang.Nullable;
/**
* A base class for {@link EvaluationContextExtension}s.
*
* @author Thomas Darimont
* @author Oliver Gierke
* @see 1.9
* @deprecated since 2.1. Implement {@link EvaluationContextExtension} directly.
*/
@Deprecated
public abstract class EvaluationContextExtensionSupport implements EvaluationContextExtension {
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.EvaluationContextExtension#getProperties()
*/
@Override
public Map<String, Object> getProperties() {
return Collections.emptyMap();
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.EvaluationContextExtension#getFunctions()
*/
@Override
public Map<String, Function> getFunctions() {
return Collections.emptyMap();
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.spi.EvaluationContextExtension#getRootObject()
*/
@Nullable
@Override
public Object getRootObject() {
return null;
}
}

View File

@@ -1,176 +0,0 @@
/*
* Copyright 2014-2019 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
*
* http://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.query.spi;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.List;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.TypeUtils;
/**
* Value object to represent a function. Can either be backed by a static {@link Method} invocation (see
* {@link #Function(Method)}) or a method invocation on an instance (see {@link #Function(Method, Object)}.
*
* @author Thomas Darimont
* @author Oliver Gierke
* @author Jens Schauder
* @since 1.9
* @deprecated since 2.1. Switch to same types in {@code org.springframework.data.spel.spi}.
*/
@Deprecated
public class Function {
private final Method method;
private final @Nullable Object target;
/**
* Creates a new {@link Function} to statically invoke the given {@link Method}.
*
* @param method
*/
public Function(Method method) {
this(method, null);
Assert.isTrue(Modifier.isStatic(method.getModifiers()), "Method must be static!");
}
/**
* Creates a new {@link Function} for the given method on the given target instance.
*
* @param method must not be {@literal null}.
* @param target can be {@literal null}, if so, the method
*/
public Function(Method method, @Nullable Object target) {
Assert.notNull(method, "Method must not be null!");
Assert.isTrue(target != null || Modifier.isStatic(method.getModifiers()),
"Method must either be static or a non-static one with a target object!");
this.method = method;
this.target = target;
}
/**
* Helper method to create a {@link org.springframework.data.spel.spi.Function} from the legacy instance.
*
* @return will never be {@literal null}.
*/
public org.springframework.data.spel.spi.Function toNewFunction() {
return new org.springframework.data.spel.spi.Function(method, target);
}
/**
* Invokes the function with the given arguments.
*
* @param arguments must not be {@literal null}.
* @return
* @throws Exception
*/
public Object invoke(Object[] arguments) throws Exception {
return method.invoke(target, arguments);
}
/**
* Returns the name of the function.
*
* @return
*/
public String getName() {
return method.getName();
}
/**
* Returns the type declaring the {@link Function}.
*
* @return
*/
public Class<?> getDeclaringClass() {
return method.getDeclaringClass();
}
/**
* Returns {@literal true} if the function can be called with the given {@code argumentTypes}.
*
* @param argumentTypes
* @return
*/
public boolean supports(List<TypeDescriptor> argumentTypes) {
if (method.getParameterCount() != argumentTypes.size()) {
return false;
}
Class<?>[] parameterTypes = method.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
if (!TypeUtils.isAssignable(parameterTypes[i], argumentTypes.get(i).getType())) {
return false;
}
}
return true;
}
/**
* Returns the number of parameters required by the underlying method.
*
* @return
*/
public int getParameterCount() {
return method.getParameterCount();
}
/**
* Checks if the encapsulated method has exactly the argument types as those passed as an argument.
*
* @param argumentTypes a list of {@link TypeDescriptor}s to compare with the argument types of the method
* @return {@code true} if the types are equal, {@code false} otherwise.
*/
public boolean supportsExact(List<TypeDescriptor> argumentTypes) {
if (method.getParameterCount() != argumentTypes.size()) {
return false;
}
Class<?>[] parameterTypes = method.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
if (parameterTypes[i] != argumentTypes.get(i).getType()) {
return false;
}
}
return true;
}
/**
* Checks wether this {@code Function} has the same signature as another {@code Function}.
*
* @param other the {@code Function} to compare {@code this} with.
* @return {@code true} iff name and argument list are the same.
*/
public boolean isSignatureEqual(Function other) {
return getName().equals(other.getName()) //
&& Arrays.equals(method.getParameterTypes(), other.method.getParameterTypes());
}
}

View File

@@ -1,5 +0,0 @@
/**
* Service provider interfaces to extend the query execution mechanism.
*/
@org.springframework.lang.NonNullApi
package org.springframework.data.repository.query.spi;

View File

@@ -82,7 +82,8 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
public ExtensionAwareEvaluationContextProvider(ListableBeanFactory beanFactory) {
this(() -> getExtensionsFrom(beanFactory));
this.setBeanFactory(beanFactory);
this.beanFactory = beanFactory;
}
/**
@@ -94,40 +95,29 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
this(() -> extensions);
}
/**
* Sets the {@link ListableBeanFactory} to be used on the {@link EvaluationContext} to be created.
*
* @param beanFactory
* @deprecated only exists to temporarily mitigate from the old APIs. Do not use!
*/
@Deprecated
public void setBeanFactory(ListableBeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
/* (non-Javadoc)
* @see org.springframework.data.jpa.repository.support.EvaluationContextProvider#getEvaluationContext()
*/
@Override
public StandardEvaluationContext getEvaluationContext(Object rootObject) {
StandardEvaluationContext ec = new StandardEvaluationContext();
StandardEvaluationContext context = new StandardEvaluationContext();
if (beanFactory != null) {
ec.setBeanResolver(new BeanFactoryResolver(beanFactory));
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
}
ExtensionAwarePropertyAccessor accessor = new ExtensionAwarePropertyAccessor(extensions.get());
ec.addPropertyAccessor(accessor);
ec.addPropertyAccessor(new ReflectivePropertyAccessor());
ec.addMethodResolver(accessor);
context.addPropertyAccessor(accessor);
context.addPropertyAccessor(new ReflectivePropertyAccessor());
context.addMethodResolver(accessor);
if (rootObject != null) {
ec.setRootObject(rootObject);
context.setRootObject(rootObject);
}
return ec;
return context;
}
/**

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2012-2019 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
*
* http://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.support;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* {@link IsNewStrategyFactory} that caches resolved {@link IsNewStrategy} instances per type to avoid re-resolving them
* on each and every request.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @deprecated as of 2.1 in favor of {@link org.springframework.data.mapping.PersistentEntity#isNew(Object)}
*/
@Deprecated
@RequiredArgsConstructor
public class CachingIsNewStrategyFactory implements IsNewStrategyFactory {
private final @NonNull IsNewStrategyFactory delegate;
private final Map<Class<?>, IsNewStrategy> cache = new ConcurrentHashMap<>();
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.model.IsNewStrategyFactory#getIsNewStrategy(java.lang.Class)
*/
public IsNewStrategy getIsNewStrategy(Class<?> type) {
return cache.computeIfAbsent(type, delegate::getIsNewStrategy);
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2012-2019 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
*
* http://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.support;
/**
* Factory interface to create {@link IsNewStrategy} instances for a given class.
*
* @author Oliver Gierke
* @since 1.5
* @deprecated since 2.1 in favor of simply calling
* {@link org.springframework.data.mapping.PersistentEntity#isNew(Object)}
*/
@Deprecated
public interface IsNewStrategyFactory {
/**
* Returns the {@link IsNewStrategy} to be used for the given type.
*
* @param type must not be {@literal null}.
* @return the {@link IsNewStrategy} to be used for the given type, will never be {@literal null}.
* @throws IllegalArgumentException in case no {@link IsNewStrategy} could be determined.
*/
IsNewStrategy getIsNewStrategy(Class<?> type);
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright 2012-2019 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
*
* http://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.support;
import org.springframework.data.domain.Persistable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* {@link IsNewStrategyFactory} that handles {@link Persistable} implementations directly by returning a
* {@link PersistableIsNewStrategy} and delegating to {@link #doGetIsNewStrategy(Class)} for all other types.
*
* @author Oliver Gierke
* @since 1.5
* @deprecated since 2.1 in favor of {@link org.springframework.data.mapping.PersistentEntity#isNew(Object)}
*/
public abstract class IsNewStrategyFactorySupport implements IsNewStrategyFactory {
/*
* (non-Javadoc)
* @see org.springframework.data.support.IsNewStrategyFactory#getIsNewStrategy(java.lang.Class)
*/
public final IsNewStrategy getIsNewStrategy(Class<?> type) {
Assert.notNull(type, "Type must not be null!");
if (Persistable.class.isAssignableFrom(type)) {
return PersistableIsNewStrategy.INSTANCE;
}
IsNewStrategy strategy = doGetIsNewStrategy(type);
if (strategy != null) {
return strategy;
}
throw new IllegalArgumentException(
String.format("Unsupported entity %s! Could not determine IsNewStrategy.", type.getName()));
}
/**
* Determine the actual {@link IsNewStrategy} to be used for the given type.
*
* @param type will never be {@literal null}.
* @return the {@link IsNewStrategy} to be used for the given type or {@literal null} in case none can be resolved.
*/
@Nullable
protected abstract IsNewStrategy doGetIsNewStrategy(Class<?> type);
}

View File

@@ -30,7 +30,6 @@ import org.springframework.core.convert.ConversionService;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.annotation.ModelAttributeMethodProcessor;
@@ -50,18 +49,6 @@ public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodP
private final SpelAwareProxyProjectionFactory proxyFactory;
private final ObjectFactory<ConversionService> conversionService;
/**
* Creates a new {@link PageableHandlerMethodArgumentResolver} using the given {@link ConversionService} and the
* {@link ModelAttribute} annotation not required.
*
* @param conversionService must not be {@literal null}.
* @deprecated use {@link #ProxyingHandlerMethodArgumentResolver(ObjectFactory, boolean)} instead.
*/
@Deprecated
public ProxyingHandlerMethodArgumentResolver(final ConversionService conversionService) {
this(() -> conversionService, true);
}
/**
* Creates a new {@link PageableHandlerMethodArgumentResolver} using the given {@link ConversionService}.
*

View File

@@ -58,7 +58,7 @@ public class XmlBeamHttpMessageConverter extends AbstractHttpMessageConverter<Ob
private static final long serialVersionUID = -1324345769124477493L;
/*
/*
* (non-Javadoc)
* @see org.xmlbeam.config.DefaultXMLFactoriesConfig#createDocumentBuilderFactory()
*/
@@ -77,7 +77,7 @@ public class XmlBeamHttpMessageConverter extends AbstractHttpMessageConverter<Ob
/**
* Creates a new {@link XmlBeamHttpMessageConverter} using the given {@link XBProjector}.
*
*
* @param projector must not be {@literal null}.
*/
public XmlBeamHttpMessageConverter(XBProjector projector) {
@@ -136,7 +136,7 @@ public class XmlBeamHttpMessageConverter extends AbstractHttpMessageConverter<Ob
Throwable cause = o_O.getCause();
if (SAXParseException.class.isInstance(cause)) {
throw new HttpMessageNotReadableException("Cannot read input message!", cause);
throw new HttpMessageNotReadableException("Cannot read input message!", cause, inputMessage);
} else {
throw o_O;
}

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2011-2019 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
*
* http://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.authentication;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
/**
* Unit tests for {@link UserCredentials}.
*
* @author Oliver Gierke
*/
public class UserCredentialsUnitTests {
@Test
public void treatsEmptyStringAsNull() {
UserCredentials credentials = new UserCredentials("", "");
assertThat(credentials.getUsername()).isNull();
assertThat(credentials.hasUsername()).isFalse();
assertThat(credentials.getPassword()).isNull();
assertThat(credentials.hasPassword()).isFalse();
}
@Test // DATACMNS-142
public void noCredentialsNullsUsernameAndPassword() {
assertThat(UserCredentials.NO_CREDENTIALS.getUsername()).isNull();
assertThat(UserCredentials.NO_CREDENTIALS.getPassword()).isNull();
}
@Test // DATACMNS-142
public void configuresUsernameCorrectly() {
UserCredentials credentials = new UserCredentials("username", null);
assertThat(credentials.hasUsername()).isTrue();
assertThat(credentials.getUsername()).isEqualTo("username");
assertThat(credentials.hasPassword()).isFalse();
assertThat(credentials.getPassword()).isNull();
}
@Test // DATACMNS-142
public void configuresPasswordCorrectly() {
UserCredentials credentials = new UserCredentials(null, "password");
assertThat(credentials.hasUsername()).isFalse();
assertThat(credentials.getUsername()).isNull();
assertThat(credentials.hasPassword()).isTrue();
assertThat(credentials.getPassword()).isEqualTo("password");
}
@Test // DATACMNS-275
public void returnsNullForNotSetObfuscatedPassword() {
assertThat(new UserCredentials(null, null).getObfuscatedPassword()).isNull();
}
@Test // DATACMNS-275
public void obfuscatesShortPasswordsEntirely() {
assertThat(new UserCredentials(null, "sa").getObfuscatedPassword()).isEqualTo("**");
assertThat(new UserCredentials(null, "s").getObfuscatedPassword()).isEqualTo("*");
}
@Test // DATACMNS-275
public void returnsObfuscatedPasswordCorrectly() {
assertThat(new UserCredentials(null, "password").getObfuscatedPassword()).isEqualTo("p******d");
}
@Test // DATACMNS-275
public void toStringDoesNotExposePlainPassword() {
UserCredentials credentials = new UserCredentials(null, "mypassword");
assertThat(credentials.toString()).doesNotContain(credentials.getPassword());
assertThat(credentials.toString()).contains(credentials.getObfuscatedPassword());
}
}

View File

@@ -45,14 +45,10 @@ public class AnnotationRevisionMetadataUnitTests {
RevisionMetadata<Long> metadata = getMetadata(sample);
assertThat(metadata.getRevisionNumber()).isEmpty();
assertThat(metadata.getRevisionDate()).isEmpty();
assertThatExceptionOfType(IllegalStateException.class) //
.isThrownBy(metadata::getRequiredRevisionNumber);
assertThatExceptionOfType(IllegalStateException.class) //
.isThrownBy(metadata::getRequiredRevisionDate);
assertThatExceptionOfType(IllegalStateException.class) //
.isThrownBy(metadata::getRequiredRevisionInstant);
@@ -81,9 +77,6 @@ public class AnnotationRevisionMetadataUnitTests {
RevisionMetadata<Long> metadata = getMetadata(sample);
softly.assertThat(metadata.getRevisionDate()).hasValue(sample.revisionDate);
softly.assertThat(metadata.getRequiredRevisionDate()).isEqualTo(sample.revisionDate);
softly.assertThat(metadata.getRevisionInstant()).hasValue(expectedInstant);
softly.assertThat(metadata.getRequiredRevisionInstant()).isEqualTo(expectedInstant);
@@ -99,9 +92,6 @@ public class AnnotationRevisionMetadataUnitTests {
RevisionMetadata<Long> metadata = getMetadata(sample);
softly.assertThat(metadata.getRevisionDate()).hasValue(expectedLocalDateTime);
softly.assertThat(metadata.getRequiredRevisionDate()).isEqualTo(expectedLocalDateTime);
softly.assertThat(metadata.getRevisionInstant()).hasValue(sample.revisionInstant);
softly.assertThat(metadata.getRequiredRevisionInstant()).isEqualTo(sample.revisionInstant);
@@ -119,9 +109,6 @@ public class AnnotationRevisionMetadataUnitTests {
RevisionMetadata<Long> metadata = getMetadata(sample);
softly.assertThat(metadata.getRevisionDate()).hasValue(expectedLocalDateTime);
softly.assertThat(metadata.getRequiredRevisionDate()).isEqualTo(expectedLocalDateTime);
softly.assertThat(metadata.getRevisionInstant()).hasValue(expectedInstant);
softly.assertThat(metadata.getRequiredRevisionInstant()).isEqualTo(expectedInstant);

View File

@@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -65,15 +64,6 @@ public class RevisionUnitTests {
assertThat(Revision.of(firstMetadata, new Object()).getRevisionNumber()).isEqualTo(reference);
}
@Test // DATACMNS-187
public void returnsRevisionDate() {
Optional<LocalDateTime> reference = Optional.of(LocalDateTime.now());
when(firstMetadata.getRevisionDate()).thenReturn(reference);
assertThat(Revision.of(firstMetadata, new Object()).getRevisionDate()).isEqualTo(reference);
}
@Test // DATACMNS-1251
public void returnsRevisionInstant() {

View File

@@ -1,145 +0,0 @@
/*
* Copyright 2012-2019 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
*
* http://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.mapping.context;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.HashSet;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.domain.Persistable;
import org.springframework.data.support.IsNewStrategy;
import org.springframework.data.support.IsNewStrategyFactory;
/**
* Unit tests for {@link MappingContextIsNewStrategyFactory}.
*
* @author Oliver Gierke
*/
public class MappingContextIsNewStrategyFactoryUnitTests {
IsNewStrategyFactory factory;
@Before
public void setUp() {
SampleMappingContext context = new SampleMappingContext();
context.setInitialEntitySet(
new HashSet<>(Arrays.asList(Entity.class, VersionedEntity.class, PrimitiveIdEntity.class)));
context.afterPropertiesSet();
factory = new MappingContextIsNewStrategyFactory(PersistentEntities.of(context));
}
@Test
public void returnsPropertyIsNullOrZeroIsNewStrategyForVersionedEntity() {
IsNewStrategy strategy = factory.getIsNewStrategy(VersionedEntity.class);
VersionedEntity entity = new VersionedEntity();
assertThat(strategy.isNew(entity)).isTrue();
entity.id = 1L;
assertThat(strategy.isNew(entity)).isTrue();
entity.version = 1L;
assertThat(strategy.isNew(entity)).isFalse();
}
@Test
public void returnsPropertyIsNullOrZeroIsNewStrategyForPrimitiveVersionedEntity() {
IsNewStrategy strategy = factory.getIsNewStrategy(VersionedEntity.class);
VersionedEntity entity = new VersionedEntity();
assertThat(strategy.isNew(entity)).isTrue();
entity.id = 1L;
assertThat(strategy.isNew(entity)).isTrue();
entity.version = 1L;
assertThat(strategy.isNew(entity)).isFalse();
}
@Test
public void returnsPropertyIsNullIsNewStrategyForEntity() {
IsNewStrategy strategy = factory.getIsNewStrategy(Entity.class);
Entity entity = new Entity();
assertThat(strategy.isNew(entity)).isTrue();
entity.id = 1L;
assertThat(strategy.isNew(entity)).isFalse();
}
@Test // DATACMNS-1326
public void entityWithPrimitiveDefaultIsNotConsideredNew() {
IsNewStrategy strategy = factory.getIsNewStrategy(PrimitiveIdEntity.class);
PrimitiveIdEntity entity = new PrimitiveIdEntity();
assertThat(strategy.isNew(entity)).isTrue();
entity.id = 1L;
assertThat(strategy.isNew(entity)).isFalse();
}
@SuppressWarnings("serial")
static class PersistableEntity implements Persistable<Long> {
@Version Long version;
@Id Long id;
boolean isNew = true;
public Long getId() {
return id;
}
public boolean isNew() {
return isNew;
}
}
static class VersionedEntity {
@Version Long version;
@Id Long id;
}
static class PrimitiveVersionedEntity {
@Version long version = 0;
@Id Long id;
}
static class Entity {
@Id Long id;
}
static class PrimitiveIdEntity {
@Id long id;
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2011-2019 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
*
* http://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.core.support;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.Persistable;
/**
* Unit tests for {@link Persistable}.
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class PersistableEntityInformationUnitTests {
@SuppressWarnings({ "rawtypes", "unchecked" }) //
static final PersistableEntityInformation metadata = new PersistableEntityInformation(PersistableEntity.class);
@Mock Persistable<Long> persistable;
@Test
@SuppressWarnings("unchecked")
public void usesPersistablesGetId() throws Exception {
when(persistable.getId()).thenReturn(2L, 1L, 3L);
assertThat(metadata.getId(persistable)).isEqualTo(2L);
assertThat(metadata.getId(persistable)).isEqualTo(1L);
assertThat(metadata.getId(persistable)).isEqualTo(3L);
}
@Test
@SuppressWarnings("unchecked")
public void usesPersistablesIsNew() throws Exception {
when(persistable.isNew()).thenReturn(true, false);
assertThat(metadata.isNew(persistable)).isTrue();
assertThat(metadata.isNew(persistable)).isFalse();
}
@Test
public void returnsGivenClassAsEntityType() throws Exception {
PersistableEntityInformation<PersistableEntity, Long> info = new PersistableEntityInformation<>(
PersistableEntity.class);
assertThat(info.getJavaType()).isEqualTo(PersistableEntity.class);
}
static class PersistableEntity implements Persistable<Long> {
public Long getId() {
return null;
}
public boolean isNew() {
return false;
}
}
}

View File

@@ -1,83 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may
import java.io.Serializable;
not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://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.core.support;
import static org.assertj.core.api.Assertions.*;
import java.io.Serializable;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.repository.core.EntityInformation;
/**
* Unit tests for {@link ReflectionEntityInformation}.
*
* @author Oliver Gierke
*/
public class ReflectionEntityInformationUnitTests {
@Test
public void discoversAnnotationOnField() {
EntityInformation<Sample, Serializable> information = getEntityInformation(Sample.class);
assertThat(information.getIdType()).isEqualTo(String.class);
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-170
public void rejectsTypeWithoutAnnotatedField() {
getEntityInformation(Unannotated.class);
}
@Test // DATACMNS-357
public void detectsNewStateForEntitiesWithPrimitiveIds() {
PrimitiveId primitiveId = new PrimitiveId();
EntityInformation<PrimitiveId, Serializable> information = new ReflectionEntityInformation<>(
PrimitiveId.class);
assertThat(information.isNew(primitiveId)).isTrue();
primitiveId.id = 5L;
assertThat(information.isNew(primitiveId)).isFalse();
}
@Test // DATACMNS-867
public void detectsNewStateForEntityWithNullId() {
assertThat(new ReflectionEntityInformation<>(Sample.class).isNew(new Sample())).isTrue();
}
private static <T> EntityInformation<T, Serializable> getEntityInformation(Class<T> type) {
return new ReflectionEntityInformation<>(type, Id.class);
}
static class Sample {
@Id String id;
}
static class Unannotated {
String id;
}
static class PrimitiveId {
@Id long id;
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2012-2019 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
*
* http://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.support;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
/**
* Unit tests for {@link CachingIsNewStrategyFactory}.
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class CachingIsNewStrategyFactoryUnitTests {
static final IsNewStrategy REFERENCE = PersistableIsNewStrategy.INSTANCE;
@Mock
IsNewStrategyFactory delegate;
CachingIsNewStrategyFactory factory;
@Before
public void setUp() {
factory = new CachingIsNewStrategyFactory(delegate);
}
@Test
public void invokesDelegateForFirstInvocation() {
when(delegate.getIsNewStrategy(Object.class)).thenReturn(REFERENCE);
IsNewStrategy strategy = factory.getIsNewStrategy(Object.class);
assertThat(strategy).isEqualTo(REFERENCE);
verify(delegate, times(1)).getIsNewStrategy(Object.class);
}
@Test
public void usesCachedValueForSecondInvocation() {
when(delegate.getIsNewStrategy(Mockito.any(Class.class))).thenReturn(REFERENCE);
IsNewStrategy strategy = factory.getIsNewStrategy(Object.class);
assertThat(strategy).isEqualTo(REFERENCE);
verify(delegate, times(1)).getIsNewStrategy(Object.class);
verify(delegate, times(0)).getIsNewStrategy(String.class);
strategy = factory.getIsNewStrategy(Object.class);
assertThat(strategy).isEqualTo(REFERENCE);
verify(delegate, times(1)).getIsNewStrategy(Object.class);
verify(delegate, times(0)).getIsNewStrategy(String.class);
strategy = factory.getIsNewStrategy(String.class);
assertThat(strategy).isEqualTo(REFERENCE);
verify(delegate, times(1)).getIsNewStrategy(Object.class);
verify(delegate, times(1)).getIsNewStrategy(String.class);
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.data.web;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.domain.Sort.Direction.*;
import org.junit.Rule;
import org.junit.Test;
@@ -51,10 +50,9 @@ public abstract class SortDefaultUnitTests {
@Test
public void parsesSimpleSortStringCorrectly() {
assertSortStringParsedInto(Sort.by(new Order("username")), SORT_1);
assertSortStringParsedInto(Sort.by(new Order(ASC, "username")), SORT_1);
assertSortStringParsedInto(Sort.by(new Order(ASC, "username"), //
new Order(DESC, "lastname"), new Order(DESC, "firstname")), SORT_2);
assertSortStringParsedInto(Sort.by(Order.asc("username")), SORT_1);
assertSortStringParsedInto(Sort.by(Order.asc("username"), //
Order.desc("lastname"), Order.desc("firstname")), SORT_2);
assertSortStringParsedInto(Sort.by("firstname", "lastname"), SORT_3);
}