From 0bf160eb971819ea64bed92c5bc1fa323fd5f2b7 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Wed, 13 Mar 2019 16:21:31 +0100 Subject: [PATCH] DATACMNS-1496 - Removed deprecations at least introduced in Lovelace. --- .../data/authentication/UserCredentials.java | 165 ---------------- .../data/authentication/package-info.java | 5 - .../data/domain/ExampleMatcher.java | 26 +-- .../data/domain/PageRequest.java | 38 +--- .../springframework/data/domain/Range.java | 53 ------ .../org/springframework/data/domain/Sort.java | 87 ++------- .../history/AnnotationRevisionMetadata.java | 19 -- .../data/history/Revision.java | 25 +-- .../data/history/RevisionMetadata.java | 32 +--- .../data/history/RevisionSort.java | 4 +- .../context/AbstractMappingContext.java | 13 +- .../data/mapping/context/MappingContext.java | 16 +- .../MappingContextIsNewStrategyFactory.java | 77 -------- .../RepositoryConfigurationExtension.java | 13 -- ...positoryConfigurationExtensionSupport.java | 44 ----- .../core/support/ExampleMatcherAccessor.java | 44 ----- .../support/PersistableEntityInformation.java | 81 -------- .../ReactiveRepositoryInformation.java | 46 ----- .../support/ReflectionEntityInformation.java | 99 ---------- .../support/RepositoryFactorySupport.java | 7 +- ...eQueryMethodEvaluationContextProvider.java | 49 +---- .../query/spi/EvaluationContextExtension.java | 74 -------- .../EvaluationContextExtensionSupport.java | 61 ------ .../data/repository/query/spi/Function.java | 176 ------------------ .../repository/query/spi/package-info.java | 5 - ...tensionAwareEvaluationContextProvider.java | 28 +-- .../support/CachingIsNewStrategyFactory.java | 46 ----- .../data/support/IsNewStrategyFactory.java | 37 ---- .../support/IsNewStrategyFactorySupport.java | 62 ------ ...ProxyingHandlerMethodArgumentResolver.java | 13 -- .../data/web/XmlBeamHttpMessageConverter.java | 6 +- .../UserCredentialsUnitTests.java | 92 --------- .../AnnotationRevisionMetadataUnitTests.java | 13 -- .../data/history/RevisionUnitTests.java | 10 - ...gContextIsNewStrategyFactoryUnitTests.java | 145 --------------- ...PersistableEntityInformationUnitTests.java | 80 -------- .../ReflectionEntityInformationUnitTests.java | 83 --------- .../CachingIsNewStrategyFactoryUnitTests.java | 80 -------- .../data/web/SortDefaultUnitTests.java | 8 +- 39 files changed, 62 insertions(+), 1900 deletions(-) delete mode 100644 src/main/java/org/springframework/data/authentication/UserCredentials.java delete mode 100644 src/main/java/org/springframework/data/authentication/package-info.java delete mode 100644 src/main/java/org/springframework/data/mapping/context/MappingContextIsNewStrategyFactory.java delete mode 100644 src/main/java/org/springframework/data/repository/core/support/ExampleMatcherAccessor.java delete mode 100644 src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java delete mode 100644 src/main/java/org/springframework/data/repository/core/support/ReactiveRepositoryInformation.java delete mode 100644 src/main/java/org/springframework/data/repository/core/support/ReflectionEntityInformation.java delete mode 100644 src/main/java/org/springframework/data/repository/query/spi/EvaluationContextExtension.java delete mode 100644 src/main/java/org/springframework/data/repository/query/spi/EvaluationContextExtensionSupport.java delete mode 100644 src/main/java/org/springframework/data/repository/query/spi/Function.java delete mode 100644 src/main/java/org/springframework/data/repository/query/spi/package-info.java delete mode 100644 src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java delete mode 100644 src/main/java/org/springframework/data/support/IsNewStrategyFactory.java delete mode 100644 src/main/java/org/springframework/data/support/IsNewStrategyFactorySupport.java delete mode 100755 src/test/java/org/springframework/data/authentication/UserCredentialsUnitTests.java delete mode 100755 src/test/java/org/springframework/data/mapping/context/MappingContextIsNewStrategyFactoryUnitTests.java delete mode 100755 src/test/java/org/springframework/data/repository/core/support/PersistableEntityInformationUnitTests.java delete mode 100755 src/test/java/org/springframework/data/repository/core/support/ReflectionEntityInformationUnitTests.java delete mode 100755 src/test/java/org/springframework/data/support/CachingIsNewStrategyFactoryUnitTests.java diff --git a/src/main/java/org/springframework/data/authentication/UserCredentials.java b/src/main/java/org/springframework/data/authentication/UserCredentials.java deleted file mode 100644 index d4b871debf..0000000000 --- a/src/main/java/org/springframework/data/authentication/UserCredentials.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/org/springframework/data/authentication/package-info.java b/src/main/java/org/springframework/data/authentication/package-info.java deleted file mode 100644 index 32ec325ef5..0000000000 --- a/src/main/java/org/springframework/data/authentication/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Types to abstract authentication concepts. - */ -@org.springframework.lang.NonNullApi -package org.springframework.data.authentication; diff --git a/src/main/java/org/springframework/data/domain/ExampleMatcher.java b/src/main/java/org/springframework/data/domain/ExampleMatcher.java index 35bae50b6d..403062a9ae 100644 --- a/src/main/java/org/springframework/data/domain/ExampleMatcher.java +++ b/src/main/java/org/springframework/data/domain/ExampleMatcher.java @@ -560,19 +560,7 @@ enum StringMatcher { /** * Allows to transform the property value before it is used in the query. */ - interface PropertyValueTransformer extends Function, Optional> { - - /** - * 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> {} /** * @author Christoph Strobl @@ -699,18 +687,6 @@ public PropertyValueTransformer getPropertyValueTransformer() { 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}. * diff --git a/src/main/java/org/springframework/data/domain/PageRequest.java b/src/main/java/org/springframework/data/domain/PageRequest.java index fad4f6fd2d..eb8fad689f 100644 --- a/src/main/java/org/springframework/data/domain/PageRequest.java +++ b/src/main/java/org/springframework/data/domain/PageRequest.java @@ -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. - */ - @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. + * @param sort must not be {@literal null}, use {@link Sort#unsorted()} 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 static PageRequest of(int page, int size) { * * @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 Sort getSort() { * (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 Pageable next() { * (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 PageRequest previous() { * (non-Javadoc) * @see org.springframework.data.domain.Pageable#first() */ + @Override public Pageable first() { return new PageRequest(0, getPageSize(), getSort()); } diff --git a/src/main/java/org/springframework/data/domain/Range.java b/src/main/java/org/springframework/data/domain/Range.java index e0668d61ea..bf0acc3a74 100644 --- a/src/main/java/org/springframework/data/domain/Range.java +++ b/src/main/java/org/springframework/data/domain/Range.java @@ -47,41 +47,6 @@ public class Range> { */ private final @NonNull Bound 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 static > Range of(Bound lowerBound, Bound(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. * diff --git a/src/main/java/org/springframework/data/domain/Sort.java b/src/main/java/org/springframework/data/domain/Sort.java index 94f464a5a5..3dd59a327a 100644 --- a/src/main/java/org/springframework/data/domain/Sort.java +++ b/src/main/java/org/springframework/data/domain/Sort.java @@ -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 @@ * @author Thomas Darimont * @author Mark Paluch */ +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class Sort implements Streamable, Serializable { private static final long serialVersionUID = 5737186511678863905L; @@ -51,68 +55,21 @@ public class Sort implements Streamable 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 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 properties) { + private Sort(Direction direction, List 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 static Sort by(String... properties) { 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 static Sort by(Order... orders) { Assert.notNull(orders, "Orders must not be null!"); - return new Sort(orders); + return new Sort(Arrays.asList(orders)); } /** @@ -174,7 +133,7 @@ public static Sort by(Direction direction, String... properties) { /** * 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 Order(@Nullable Direction direction, String property, NullHandling nullHa 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 @@ private TypedSort(Class type) { private TypedSort(Recorded recorded) { - super(new Order[0]); + super(Collections.emptyList()); this.recorded = recorded; } @@ -742,10 +689,12 @@ public TypedSort by(Recorded.ToMapConverter mapProperty) { 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 @@ private Sort withDirection(Function direction) { .orElseGet(Sort::unsorted); } - /* + /* * (non-Javadoc) * @see org.springframework.data.domain.Sort#iterator() */ @@ -772,7 +721,7 @@ public Iterator iterator() { } - /* + /* * (non-Javadoc) * @see org.springframework.data.domain.Sort#toString() */ diff --git a/src/main/java/org/springframework/data/history/AnnotationRevisionMetadata.java b/src/main/java/org/springframework/data/history/AnnotationRevisionMetadata.java index 2718d43f09..fedda65c38 100755 --- a/src/main/java/org/springframework/data/history/AnnotationRevisionMetadata.java +++ b/src/main/java/org/springframework/data/history/AnnotationRevisionMetadata.java @@ -69,16 +69,6 @@ public Optional getRevisionNumber() { return revisionNumber.get(); } - /* - * (non-Javadoc) - * @see org.springframework.data.history.RevisionMetadata#getRevisionDate() - */ - @Deprecated - public Optional getRevisionDate() { - - return revisionDate.get().map(AnnotationRevisionMetadata::convertToLocalDateTime); - } - /* * (non-Javadoc) * @see org.springframework.data.history.RevisionMetadata#getRevisionDate() @@ -106,15 +96,6 @@ private static Lazy> detectAnnotation(Object entity, Class getRevisionDate() { - return metadata.getRevisionDate(); - } - /** * Returns the timestamp of the revision. * @@ -99,17 +87,6 @@ public Optional getRevisionInstant() { 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 int compareTo(@Nullable Revision that) { } return mapIfAllPresent(getRevisionNumber(), that.getRevisionNumber(), // - (left, right) -> left.compareTo(right)).orElse(-1); + Comparable::compareTo).orElse(-1); } /* diff --git a/src/main/java/org/springframework/data/history/RevisionMetadata.java b/src/main/java/org/springframework/data/history/RevisionMetadata.java index 5eee147e64..7fb4e1c019 100755 --- a/src/main/java/org/springframework/data/history/RevisionMetadata.java +++ b/src/main/java/org/springframework/data/history/RevisionMetadata.java @@ -16,7 +16,6 @@ package org.springframework.data.history; import java.time.Instant; -import java.time.LocalDateTime; import java.util.Optional; /** @@ -42,19 +41,11 @@ public interface RevisionMetadata> { * @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()))); + () -> new IllegalStateException(String.format("No revision number found on %s!", this. getDelegate()))); } - /** - * Returns the date of the revision. - * - * @return will never be {@literal null}. - * @deprecated use {@link #getRevisionInstant()} instead. - */ - @Deprecated - Optional getRevisionDate(); - /** * Returns the timestamp of the revision. * @@ -63,28 +54,15 @@ default N getRequiredRevisionNumber() { Optional 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. getDelegate()))); } /** diff --git a/src/main/java/org/springframework/data/history/RevisionSort.java b/src/main/java/org/springframework/data/history/RevisionSort.java index 7256010f62..13602b4482 100644 --- a/src/main/java/org/springframework/data/history/RevisionSort.java +++ b/src/main/java/org/springframework/data/history/RevisionSort.java @@ -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))); } /** diff --git a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index 9323e3ae5a..a7206f0c66 100644 --- a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -114,7 +114,7 @@ public void setApplicationEventPublisher(ApplicationEventPublisher applicationEv this.applicationEventPublisher = applicationEventPublisher; } - /* + /* * (non-Javadoc) * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) */ @@ -285,15 +285,6 @@ public PersistentPropertyPath

getPersistentPropertyPath(String propertyPath, } /* - * (non-Javadoc) - * @see org.springframework.data.mapping.context.MappingContext#getPersistentPropertyPath(org.springframework.data.mapping.context.InvalidPersistentPropertyPath) - */ - @Override - public PersistentPropertyPath

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 PersistentPropertyPaths findPersistentPropertyPaths(Class ty * 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}. diff --git a/src/main/java/org/springframework/data/mapping/context/MappingContext.java b/src/main/java/org/springframework/data/mapping/context/MappingContext.java index a1f6954552..5a533552f5 100644 --- a/src/main/java/org/springframework/data/mapping/context/MappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/MappingContext.java @@ -173,26 +173,12 @@ default E getRequiredPersistentEntity(P persistentProperty) throws MappingExcept PersistentPropertyPath

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

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 diff --git a/src/main/java/org/springframework/data/mapping/context/MappingContextIsNewStrategyFactory.java b/src/main/java/org/springframework/data/mapping/context/MappingContextIsNewStrategyFactory.java deleted file mode 100644 index d6abd88864..0000000000 --- a/src/main/java/org/springframework/data/mapping/context/MappingContextIsNewStrategyFactory.java +++ /dev/null @@ -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, ?> 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); - } -} diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtension.java b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtension.java index 1d01ce07c2..7ea62393d2 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtension.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtension.java @@ -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 - Collection> getRepositoryConfigurations( - T configSource, ResourceLoader loader); - /** * Returns all {@link RepositoryConfiguration}s obtained through the given {@link RepositoryConfigurationSource}. * diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java index 9175795435..e06196d361 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java @@ -183,33 +183,6 @@ protected ClassLoader getConfigurationInspectionClassLoader(ResourceLoader loade 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 static String registerWithSourceAndGeneratedBeanName(AbstractBeanDefiniti 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. diff --git a/src/main/java/org/springframework/data/repository/core/support/ExampleMatcherAccessor.java b/src/main/java/org/springframework/data/repository/core/support/ExampleMatcherAccessor.java deleted file mode 100644 index f716764319..0000000000 --- a/src/main/java/org/springframework/data/repository/core/support/ExampleMatcherAccessor.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java b/src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java deleted file mode 100644 index 74c807604b..0000000000 --- a/src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java +++ /dev/null @@ -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, ID> extends AbstractEntityInformation { - - private Class idClass; - - /** - * Creates a new {@link PersistableEntityInformation}. - * - * @param domainClass - */ - @SuppressWarnings("unchecked") - public PersistableEntityInformation(Class 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) 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 getIdType() { - return this.idClass; - } -} diff --git a/src/main/java/org/springframework/data/repository/core/support/ReactiveRepositoryInformation.java b/src/main/java/org/springframework/data/repository/core/support/ReactiveRepositoryInformation.java deleted file mode 100644 index 07626c39e8..0000000000 --- a/src/main/java/org/springframework/data/repository/core/support/ReactiveRepositoryInformation.java +++ /dev/null @@ -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))); - } -} diff --git a/src/main/java/org/springframework/data/repository/core/support/ReflectionEntityInformation.java b/src/main/java/org/springframework/data/repository/core/support/ReflectionEntityInformation.java deleted file mode 100644 index 343da8160f..0000000000 --- a/src/main/java/org/springframework/data/repository/core/support/ReflectionEntityInformation.java +++ /dev/null @@ -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 extends AbstractEntityInformation { - - private static final Class 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 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 domainClass, final Class 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 getIdType() { - return (Class) field.getType(); - } -} diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java index 63b658e6b6..76236b9a7e 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java @@ -263,16 +263,13 @@ public T getRepository(Class repositoryInterface) { } /** - * 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 getRepository(Class repositoryInterface, Object customImplementation) { return getRepository(repositoryInterface, RepositoryFragments.just(customImplementation)); } diff --git a/src/main/java/org/springframework/data/repository/query/ExtensionAwareQueryMethodEvaluationContextProvider.java b/src/main/java/org/springframework/data/repository/query/ExtensionAwareQueryMethodEvaluationContextProvider.java index ba899e6e2a..937e0a8a84 100644 --- a/src/main/java/org/springframework/data/repository/query/ExtensionAwareQueryMethodEvaluationContextProvider.java +++ b/src/main/java/org/springframework/data/repository/query/ExtensionAwareQueryMethodEvaluationContextProvider.java @@ -27,8 +27,8 @@ 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 extensions) { @@ -88,7 +80,7 @@ public ExtensionAwareQueryMethodEvaluationContextProvider(List collectVariables(Streamable getExtensionsFrom(ListableBeanFactory beanFactory) { - Stream legacyExtensions = beanFactory // - .getBeansOfType(org.springframework.data.repository.query.spi.EvaluationContextExtension.class, true, false) - .values().stream() // - .map(ExtensionAwareQueryMethodEvaluationContextProvider::adaptFromLegacyApi); - Stream 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) 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 @@ static class DelegatingMethodInterceptor implements MethodInterceptor { /** * 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 void registerResultMapping(String methodName, java.util.function.Function this.directMappings.put(methodName, mapping); } - /* + /* * (non-Javadoc) * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) */ diff --git a/src/main/java/org/springframework/data/repository/query/spi/EvaluationContextExtension.java b/src/main/java/org/springframework/data/repository/query/spi/EvaluationContextExtension.java deleted file mode 100644 index ae1bcac35e..0000000000 --- a/src/main/java/org/springframework/data/repository/query/spi/EvaluationContextExtension.java +++ /dev/null @@ -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 getProperties() { - return Collections.emptyMap(); - } - - /** - * Returns the functions exposed by the extension. - * - * @return the functions - */ - default Map 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; - } -} diff --git a/src/main/java/org/springframework/data/repository/query/spi/EvaluationContextExtensionSupport.java b/src/main/java/org/springframework/data/repository/query/spi/EvaluationContextExtensionSupport.java deleted file mode 100644 index 42e7969f31..0000000000 --- a/src/main/java/org/springframework/data/repository/query/spi/EvaluationContextExtensionSupport.java +++ /dev/null @@ -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 getProperties() { - return Collections.emptyMap(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.repository.query.EvaluationContextExtension#getFunctions() - */ - @Override - public Map getFunctions() { - return Collections.emptyMap(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.repository.query.spi.EvaluationContextExtension#getRootObject() - */ - @Nullable - @Override - public Object getRootObject() { - return null; - } -} diff --git a/src/main/java/org/springframework/data/repository/query/spi/Function.java b/src/main/java/org/springframework/data/repository/query/spi/Function.java deleted file mode 100644 index e5d66507d7..0000000000 --- a/src/main/java/org/springframework/data/repository/query/spi/Function.java +++ /dev/null @@ -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 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 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()); - } -} diff --git a/src/main/java/org/springframework/data/repository/query/spi/package-info.java b/src/main/java/org/springframework/data/repository/query/spi/package-info.java deleted file mode 100644 index 0550c1c2fb..0000000000 --- a/src/main/java/org/springframework/data/repository/query/spi/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Service provider interfaces to extend the query execution mechanism. - */ -@org.springframework.lang.NonNullApi -package org.springframework.data.repository.query.spi; diff --git a/src/main/java/org/springframework/data/spel/ExtensionAwareEvaluationContextProvider.java b/src/main/java/org/springframework/data/spel/ExtensionAwareEvaluationContextProvider.java index eab6c26d2c..94c9f64f28 100644 --- a/src/main/java/org/springframework/data/spel/ExtensionAwareEvaluationContextProvider.java +++ b/src/main/java/org/springframework/data/spel/ExtensionAwareEvaluationContextProvider.java @@ -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 ExtensionAwareEvaluationContextProvider(Collection 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; } /** diff --git a/src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java b/src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java deleted file mode 100644 index d95f225b2d..0000000000 --- a/src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java +++ /dev/null @@ -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, 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); - } -} diff --git a/src/main/java/org/springframework/data/support/IsNewStrategyFactory.java b/src/main/java/org/springframework/data/support/IsNewStrategyFactory.java deleted file mode 100644 index da6b779b9d..0000000000 --- a/src/main/java/org/springframework/data/support/IsNewStrategyFactory.java +++ /dev/null @@ -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); -} diff --git a/src/main/java/org/springframework/data/support/IsNewStrategyFactorySupport.java b/src/main/java/org/springframework/data/support/IsNewStrategyFactorySupport.java deleted file mode 100644 index b3f01adcee..0000000000 --- a/src/main/java/org/springframework/data/support/IsNewStrategyFactorySupport.java +++ /dev/null @@ -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); -} diff --git a/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java b/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java index 06defce85a..17217efee0 100644 --- a/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java +++ b/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java @@ -30,7 +30,6 @@ 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; - /** - * 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}. * diff --git a/src/main/java/org/springframework/data/web/XmlBeamHttpMessageConverter.java b/src/main/java/org/springframework/data/web/XmlBeamHttpMessageConverter.java index 2c5efd4d07..b4ec63d120 100644 --- a/src/main/java/org/springframework/data/web/XmlBeamHttpMessageConverter.java +++ b/src/main/java/org/springframework/data/web/XmlBeamHttpMessageConverter.java @@ -58,7 +58,7 @@ public XmlBeamHttpMessageConverter() { private static final long serialVersionUID = -1324345769124477493L; - /* + /* * (non-Javadoc) * @see org.xmlbeam.config.DefaultXMLFactoriesConfig#createDocumentBuilderFactory() */ @@ -77,7 +77,7 @@ public DocumentBuilderFactory createDocumentBuilderFactory() { /** * 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 @@ protected Object readInternal(Class clazz, HttpInputMessage in 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; } diff --git a/src/test/java/org/springframework/data/authentication/UserCredentialsUnitTests.java b/src/test/java/org/springframework/data/authentication/UserCredentialsUnitTests.java deleted file mode 100755 index c04f08c02d..0000000000 --- a/src/test/java/org/springframework/data/authentication/UserCredentialsUnitTests.java +++ /dev/null @@ -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()); - } -} diff --git a/src/test/java/org/springframework/data/history/AnnotationRevisionMetadataUnitTests.java b/src/test/java/org/springframework/data/history/AnnotationRevisionMetadataUnitTests.java index 7edbdd2449..693c18df77 100644 --- a/src/test/java/org/springframework/data/history/AnnotationRevisionMetadataUnitTests.java +++ b/src/test/java/org/springframework/data/history/AnnotationRevisionMetadataUnitTests.java @@ -45,14 +45,10 @@ public void exposesNoInformationOnEmptyProbe() { RevisionMetadata 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 void exposesRevisionDateAndInstantForLocalDateTime() { RevisionMetadata 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 void exposesRevisionDateAndInstantForInstant() { RevisionMetadata 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 void exposesRevisionDateAndInstantForLong() { RevisionMetadata 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); diff --git a/src/test/java/org/springframework/data/history/RevisionUnitTests.java b/src/test/java/org/springframework/data/history/RevisionUnitTests.java index bbecd51d4a..c24a782d1c 100755 --- a/src/test/java/org/springframework/data/history/RevisionUnitTests.java +++ b/src/test/java/org/springframework/data/history/RevisionUnitTests.java @@ -19,7 +19,6 @@ 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 void returnsRevisionNumber() { assertThat(Revision.of(firstMetadata, new Object()).getRevisionNumber()).isEqualTo(reference); } - @Test // DATACMNS-187 - public void returnsRevisionDate() { - - Optional 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() { diff --git a/src/test/java/org/springframework/data/mapping/context/MappingContextIsNewStrategyFactoryUnitTests.java b/src/test/java/org/springframework/data/mapping/context/MappingContextIsNewStrategyFactoryUnitTests.java deleted file mode 100755 index e97e288347..0000000000 --- a/src/test/java/org/springframework/data/mapping/context/MappingContextIsNewStrategyFactoryUnitTests.java +++ /dev/null @@ -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 { - - @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; - } -} diff --git a/src/test/java/org/springframework/data/repository/core/support/PersistableEntityInformationUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/PersistableEntityInformationUnitTests.java deleted file mode 100755 index a54b5d5b27..0000000000 --- a/src/test/java/org/springframework/data/repository/core/support/PersistableEntityInformationUnitTests.java +++ /dev/null @@ -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 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 info = new PersistableEntityInformation<>( - PersistableEntity.class); - - assertThat(info.getJavaType()).isEqualTo(PersistableEntity.class); - } - - static class PersistableEntity implements Persistable { - - public Long getId() { - return null; - } - - public boolean isNew() { - return false; - } - } -} diff --git a/src/test/java/org/springframework/data/repository/core/support/ReflectionEntityInformationUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/ReflectionEntityInformationUnitTests.java deleted file mode 100755 index 786562555a..0000000000 --- a/src/test/java/org/springframework/data/repository/core/support/ReflectionEntityInformationUnitTests.java +++ /dev/null @@ -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 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 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 EntityInformation getEntityInformation(Class type) { - return new ReflectionEntityInformation<>(type, Id.class); - } - - static class Sample { - - @Id String id; - } - - static class Unannotated { - - String id; - } - - static class PrimitiveId { - - @Id long id; - } -} diff --git a/src/test/java/org/springframework/data/support/CachingIsNewStrategyFactoryUnitTests.java b/src/test/java/org/springframework/data/support/CachingIsNewStrategyFactoryUnitTests.java deleted file mode 100755 index b0e996b539..0000000000 --- a/src/test/java/org/springframework/data/support/CachingIsNewStrategyFactoryUnitTests.java +++ /dev/null @@ -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); - } -} diff --git a/src/test/java/org/springframework/data/web/SortDefaultUnitTests.java b/src/test/java/org/springframework/data/web/SortDefaultUnitTests.java index 77a2386051..5f3f4e6182 100755 --- a/src/test/java/org/springframework/data/web/SortDefaultUnitTests.java +++ b/src/test/java/org/springframework/data/web/SortDefaultUnitTests.java @@ -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); }