diff --git a/src/main/java/org/springframework/data/domain/Auditable.java b/src/main/java/org/springframework/data/domain/Auditable.java index 5d7bc9848..36985ca1f 100644 --- a/src/main/java/org/springframework/data/domain/Auditable.java +++ b/src/main/java/org/springframework/data/domain/Auditable.java @@ -15,7 +15,6 @@ */ package org.springframework.data.domain; -import java.io.Serializable; import java.time.temporal.TemporalAccessor; import java.util.Optional; @@ -27,7 +26,7 @@ import java.util.Optional; * @param the type of the audited type's identifier * @author Oliver Gierke */ -public interface Auditable extends Persistable { +public interface Auditable extends Persistable { /** * Returns the user who created this entity. diff --git a/src/main/java/org/springframework/data/domain/Persistable.java b/src/main/java/org/springframework/data/domain/Persistable.java index 09ab2c1b7..ca4d42172 100644 --- a/src/main/java/org/springframework/data/domain/Persistable.java +++ b/src/main/java/org/springframework/data/domain/Persistable.java @@ -15,15 +15,13 @@ */ package org.springframework.data.domain; -import java.io.Serializable; - /** * Simple interface for entities. * * @param the type of the identifier * @author Oliver Gierke */ -public interface Persistable extends Serializable { +public interface Persistable { /** * Returns the id of the entity. diff --git a/src/main/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapter.java b/src/main/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapter.java index 6281f1615..f6d2c800a 100644 --- a/src/main/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapter.java +++ b/src/main/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapter.java @@ -15,7 +15,6 @@ */ package org.springframework.data.querydsl; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Optional; @@ -112,22 +111,22 @@ public class QuerydslRepositoryInvokerAdapter implements RepositoryInvoker { return delegate.hasSaveMethod(); } - /* + /* * (non-Javadoc) - * @see org.springframework.data.repository.support.RepositoryInvoker#invokeDelete(java.io.Serializable) + * @see org.springframework.data.repository.support.RepositoryInvoker#invokeDeleteById(java.lang.Object) */ @Override - public void invokeDelete(Serializable id) { - delegate.invokeDelete(id); + public void invokeDeleteById(Object id) { + delegate.invokeDeleteById(id); } - /* + /* * (non-Javadoc) - * @see org.springframework.data.repository.support.RepositoryInvoker#invokeFindOne(java.io.Serializable) + * @see org.springframework.data.repository.support.RepositoryInvoker#invokeFindById(java.lang.Object) */ @Override - public Optional invokeFindOne(Serializable id) { - return delegate.invokeFindOne(id); + public Optional invokeFindById(Object id) { + return delegate.invokeFindById(id); } /* diff --git a/src/main/java/org/springframework/data/repository/CrudRepository.java b/src/main/java/org/springframework/data/repository/CrudRepository.java index 689520f5d..a7da1fa8c 100644 --- a/src/main/java/org/springframework/data/repository/CrudRepository.java +++ b/src/main/java/org/springframework/data/repository/CrudRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2011 the original author or authors. + * Copyright 2008-2017 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. @@ -15,7 +15,6 @@ */ package org.springframework.data.repository; -import java.io.Serializable; import java.util.Optional; /** @@ -25,43 +24,43 @@ import java.util.Optional; * @author Eberhard Wolff */ @NoRepositoryBean -public interface CrudRepository extends Repository { +public interface CrudRepository extends Repository { /** * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the * entity instance completely. * - * @param entity - * @return the saved entity + * @param entity must not be {@literal null}. + * @return the saved entity will never be {@literal null}. */ S save(S entity); /** * Saves all given entities. * - * @param entities - * @return the saved entities + * @param entities must not be {@literal null}. + * @return the saved entities will never be {@literal null}. * @throws IllegalArgumentException in case the given entity is {@literal null}. */ - Iterable save(Iterable entities); + Iterable saveAll(Iterable entities); /** * Retrieves an entity by its id. * * @param id must not be {@literal null}. - * @return the entity with the given id or {@literal null} if none found - * @throws IllegalArgumentException if {@code id} is {@literal null} + * @return the entity with the given id or {@literal Optional#empty()} if none found + * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Optional findOne(ID id); + Optional findById(ID id); /** * Returns whether an entity with the given id exists. * * @param id must not be {@literal null}. - * @return true if an entity with the given id exists, {@literal false} otherwise - * @throws IllegalArgumentException if {@code id} is {@literal null} + * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. + * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - boolean exists(ID id); + boolean existsById(ID id); /** * Returns all instances of the type. @@ -76,7 +75,7 @@ public interface CrudRepository extends Repository findAll(Iterable ids); + Iterable findAllById(Iterable ids); /** * Returns the number of entities available. @@ -91,7 +90,7 @@ public interface CrudRepository extends Repository extends Repository entities); + void deleteAll(Iterable entities); /** * Deletes all entities managed by the repository. diff --git a/src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java b/src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java index 74137baef..1fb175b90 100644 --- a/src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java +++ b/src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java @@ -15,8 +15,6 @@ */ package org.springframework.data.repository; -import java.io.Serializable; - import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -31,7 +29,7 @@ import org.springframework.data.domain.Sort; * @see Page */ @NoRepositoryBean -public interface PagingAndSortingRepository extends CrudRepository { +public interface PagingAndSortingRepository extends CrudRepository { /** * Returns all entities sorted by the given options. diff --git a/src/main/java/org/springframework/data/repository/Repository.java b/src/main/java/org/springframework/data/repository/Repository.java index 3c22ab937..7cdb39573 100644 --- a/src/main/java/org/springframework/data/repository/Repository.java +++ b/src/main/java/org/springframework/data/repository/Repository.java @@ -15,8 +15,6 @@ */ package org.springframework.data.repository; -import java.io.Serializable; - import org.springframework.stereotype.Indexed; /** @@ -33,6 +31,6 @@ import org.springframework.stereotype.Indexed; * @author Oliver Gierke */ @Indexed -public interface Repository { +public interface Repository { } diff --git a/src/main/java/org/springframework/data/repository/RepositoryDefinition.java b/src/main/java/org/springframework/data/repository/RepositoryDefinition.java index cc2b4c3c6..c5004b0fb 100644 --- a/src/main/java/org/springframework/data/repository/RepositoryDefinition.java +++ b/src/main/java/org/springframework/data/repository/RepositoryDefinition.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository; -import java.io.Serializable; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; @@ -53,5 +52,5 @@ public @interface RepositoryDefinition { * @see Repository * @return */ - Class idClass(); + Class idClass(); } diff --git a/src/main/java/org/springframework/data/repository/core/CrudMethods.java b/src/main/java/org/springframework/data/repository/core/CrudMethods.java index ee3392081..0626c7780 100644 --- a/src/main/java/org/springframework/data/repository/core/CrudMethods.java +++ b/src/main/java/org/springframework/data/repository/core/CrudMethods.java @@ -65,7 +65,7 @@ public interface CrudMethods { /** * Returns the find one method of the repository. Usually signature compatible to - * {@link CrudRepository#findOne(java.io.Serializable)} + * {@link CrudRepository#findById(Object)} * * @return the find one method of the repository or {@literal null} if not available. * @see #hasFindOneMethod() diff --git a/src/main/java/org/springframework/data/repository/core/EntityInformation.java b/src/main/java/org/springframework/data/repository/core/EntityInformation.java index 49acaf2b6..cea912d5f 100644 --- a/src/main/java/org/springframework/data/repository/core/EntityInformation.java +++ b/src/main/java/org/springframework/data/repository/core/EntityInformation.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.core; -import java.io.Serializable; import java.util.Optional; import org.springframework.util.Assert; @@ -25,7 +24,7 @@ import org.springframework.util.Assert; * * @author Oliver Gierke */ -public interface EntityInformation extends EntityMetadata { +public interface EntityInformation extends EntityMetadata { /** * Returns whether the given entity is considered to be new. @@ -49,6 +48,7 @@ public interface EntityInformation extends EntityMet * @param entity must not be {@literal null}. * @return the identifier of the given entity * @throws IllegalArgumentException in case no id could be obtained from the given entity + * @since 2.0 */ default ID getRequiredId(T entity) throws IllegalArgumentException { diff --git a/src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java b/src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java index b0e336d74..5785c7676 100644 --- a/src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java +++ b/src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.core; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Collection; import java.util.Set; @@ -34,7 +33,7 @@ public interface RepositoryMetadata { * * @return the id class of the entity managed by the repository for or {@code null} if none found. */ - Class getIdType(); + Class getIdType(); /** * Returns the domain class the repository is declared for. diff --git a/src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java b/src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java index bb072771f..4c3879054 100644 --- a/src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java +++ b/src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java @@ -15,11 +15,12 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import java.util.Optional; import org.springframework.data.repository.core.EntityInformation; -import org.springframework.util.Assert; /** * Base class for implementations of {@link EntityInformation}. Considers an entity to be new whenever @@ -28,20 +29,10 @@ import org.springframework.util.Assert; * @author Oliver Gierke * @author Nick Williams */ -public abstract class AbstractEntityInformation implements EntityInformation { - - private final Class domainClass; +@RequiredArgsConstructor +public abstract class AbstractEntityInformation implements EntityInformation { - /** - * Creates a new {@link AbstractEntityInformation} from the given domain class. - * - * @param domainClass must not be {@literal null}. - */ - public AbstractEntityInformation(Class domainClass) { - - Assert.notNull(domainClass, "DomainClass must not be null!"); - this.domainClass = domainClass; - } + private final @NonNull Class domainClass; /* * (non-Javadoc) diff --git a/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java b/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java index 7539bc3c6..1fb6fb9fe 100644 --- a/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java +++ b/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java @@ -15,8 +15,6 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; - import org.springframework.data.repository.RepositoryDefinition; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.util.Assert; @@ -33,7 +31,7 @@ public class AnnotationRepositoryMetadata extends AbstractRepositoryMetadata { private static final String NO_ANNOTATION_FOUND = String.format("Interface must be annotated with @%s!", RepositoryDefinition.class.getName()); - private final Class idType; + private final Class idType; private final Class domainType; /** @@ -56,7 +54,7 @@ public class AnnotationRepositoryMetadata extends AbstractRepositoryMetadata { * @see org.springframework.data.repository.core.RepositoryMetadata#getIdType() */ @Override - public Class getIdType() { + public Class getIdType() { return this.idType; } @@ -69,7 +67,7 @@ public class AnnotationRepositoryMetadata extends AbstractRepositoryMetadata { return this.domainType; } - private Class resolveIdType(Class repositoryInterface) { + private Class resolveIdType(Class repositoryInterface) { RepositoryDefinition annotation = repositoryInterface.getAnnotation(RepositoryDefinition.class); diff --git a/src/main/java/org/springframework/data/repository/core/support/DefaultCrudMethods.java b/src/main/java/org/springframework/data/repository/core/support/DefaultCrudMethods.java index f8c88d4d1..aad400365 100644 --- a/src/main/java/org/springframework/data/repository/core/support/DefaultCrudMethods.java +++ b/src/main/java/org/springframework/data/repository/core/support/DefaultCrudMethods.java @@ -16,19 +16,21 @@ package org.springframework.data.repository.core.support; import static java.util.Arrays.*; -import static org.springframework.util.ClassUtils.*; -import static org.springframework.util.ReflectionUtils.*; +import static org.springframework.data.util.Optionals.*; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Optional; +import java.util.function.Supplier; +import java.util.stream.Stream; +import org.springframework.core.BridgeMethodResolver; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.core.CrudMethods; import org.springframework.data.repository.core.RepositoryMetadata; +import org.springframework.data.util.Optionals; +import org.springframework.data.util.Pair; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -44,10 +46,12 @@ import org.springframework.util.ReflectionUtils; */ public class DefaultCrudMethods implements CrudMethods { - private static final String FIND_ONE = "findOne"; + private static final String FIND_ONE = "findById"; private static final String SAVE = "save"; private static final String FIND_ALL = "findAll"; + private static final String DELETE = "delete"; + private static final String DELETE_BY_ID = "deleteById"; private final Optional findAllMethod; private final Optional findOneMethod; @@ -79,18 +83,12 @@ public class DefaultCrudMethods implements CrudMethods { * @param metadata must not be {@literal null}. * @return the most suitable method or {@literal null} if no method could be found. */ - private Optional selectMostSuitableSaveMethod(RepositoryMetadata metadata) { - - for (Class type : asList(metadata.getDomainType(), Object.class)) { - - Method saveMethodCandidate = findMethod(metadata.getRepositoryInterface(), SAVE, type); + private static Optional selectMostSuitableSaveMethod(RepositoryMetadata metadata) { - if (saveMethodCandidate != null) { - return getMostSpecificMethod(saveMethodCandidate, metadata.getRepositoryInterface()); - } - } - - return Optional.empty(); + return asList(metadata.getDomainType(), Object.class).stream()// + .flatMap(it -> toStream(findMethod(metadata.getRepositoryInterface(), SAVE, it)))// + .flatMap(it -> toStream(getMostSpecificMethod(it, metadata.getRepositoryInterface())))// + .findFirst(); } /** @@ -98,25 +96,28 @@ public class DefaultCrudMethods implements CrudMethods { *
    *
  1. a {@link RepositoryMetadata#getDomainType()} as first parameter over
  2. *
  3. a {@link RepositoryMetadata#getIdType()} as first parameter over
  4. - *
  5. a {@link Serializable} as first parameter over
  6. + *
  7. a {@link Object} as first parameter over
  8. *
  9. an {@link Iterable} as first parameter.
  10. *
* * @param metadata must not be {@literal null}. * @return the most suitable method or {@literal null} if no method could be found. */ - private Optional selectMostSuitableDeleteMethod(RepositoryMetadata metadata) { - - for (Class type : asList(metadata.getDomainType(), metadata.getIdType(), Serializable.class, Iterable.class)) { + private static Optional selectMostSuitableDeleteMethod(RepositoryMetadata metadata) { - Method candidate = findMethod(metadata.getRepositoryInterface(), DELETE, type); + Stream>> source = Stream.of(// + Pair.of(DELETE, metadata.getDomainType()), // + Pair.of(DELETE_BY_ID, metadata.getIdType()), // + Pair.of(DELETE, Object.class), // + Pair.of(DELETE_BY_ID, Object.class), // + Pair.of(DELETE, Iterable.class)); - if (candidate != null) { - return getMostSpecificMethod(candidate, metadata.getRepositoryInterface()); - } - } + Class repositoryInterface = metadata.getRepositoryInterface(); - return Optional.empty(); + return source// + .flatMap(it -> toStream(findMethod(repositoryInterface, it.getFirst(), it.getSecond())))// + .flatMap(it -> toStream(getMostSpecificMethod(it, repositoryInterface)))// + .findFirst(); } /** @@ -130,49 +131,37 @@ public class DefaultCrudMethods implements CrudMethods { * @param metadata must not be {@literal null}. * @return the most suitable method or {@literal null} if no method could be found. */ - private Optional selectMostSuitableFindAllMethod(RepositoryMetadata metadata) { - - for (Class type : asList(Pageable.class, Sort.class)) { + private static Optional selectMostSuitableFindAllMethod(RepositoryMetadata metadata) { - if (hasMethod(metadata.getRepositoryInterface(), FIND_ALL, type)) { + Class repositoryInterface = metadata.getRepositoryInterface(); - Method candidate = findMethod(PagingAndSortingRepository.class, FIND_ALL, type); + Supplier> withPageableOrSort = () -> Stream.of(Pageable.class, Sort.class)// + .flatMap(it -> toStream(findMethod(repositoryInterface, FIND_ALL, it)))// + .flatMap(it -> toStream(getMostSpecificMethod(it, repositoryInterface)))// + .findFirst(); - if (candidate != null) { - return getMostSpecificMethod(candidate, metadata.getRepositoryInterface()); - } - } - } + Supplier> withoutParameter = () -> findMethod(repositoryInterface, FIND_ALL)// + .flatMap(it -> getMostSpecificMethod(it, repositoryInterface)); - if (hasMethod(metadata.getRepositoryInterface(), FIND_ALL)) { - return getMostSpecificMethod(findMethod(CrudRepository.class, FIND_ALL), metadata.getRepositoryInterface()); - } - - return Optional.empty(); + return firstNonEmpty(withPageableOrSort, withoutParameter); } /** - * The most suitable findOne method is selected as follows: We prefer + * The most suitable {@code findById} method is selected as follows: We prefer *
    *
  1. a {@link RepositoryMetadata#getIdType()} as first parameter over
  2. - *
  3. a {@link Serializable} as first parameter
  4. + *
  5. a {@link Object} as first parameter
  6. *
* * @param metadata must not be {@literal null}. * @return the most suitable method or {@literal null} if no method could be found. */ - private Optional selectMostSuitableFindOneMethod(RepositoryMetadata metadata) { - - for (Class type : asList(metadata.getIdType(), Serializable.class)) { - - Method candidate = findMethod(metadata.getRepositoryInterface(), FIND_ONE, type); + private static Optional selectMostSuitableFindOneMethod(RepositoryMetadata metadata) { - if (candidate != null) { - return getMostSpecificMethod(candidate, metadata.getRepositoryInterface()); - } - } - - return Optional.empty(); + return asList(metadata.getIdType(), Object.class).stream()// + .flatMap(it -> toStream(findMethod(metadata.getRepositoryInterface(), FIND_ONE, it)))// + .flatMap(it -> toStream(getMostSpecificMethod(it, metadata.getRepositoryInterface())))// + .findFirst(); } /** @@ -186,10 +175,10 @@ public class DefaultCrudMethods implements CrudMethods { */ private static Optional getMostSpecificMethod(Method method, Class type) { - return Optional.ofNullable(ClassUtils.getMostSpecificMethod(method, type)).map(it -> { - ReflectionUtils.makeAccessible(it); - return it; - }); + return Optionals.toStream(Optional.ofNullable(ClassUtils.getMostSpecificMethod(method, type)))// + .map(it -> BridgeMethodResolver.findBridgedMethod(it))// + .peek(it -> ReflectionUtils.makeAccessible(it))// + .findFirst(); } /* @@ -263,4 +252,8 @@ public class DefaultCrudMethods implements CrudMethods { public Optional getDeleteMethod() { return this.deleteMethod; } + + private static Optional findMethod(Class type, String name, Class... parameterTypes) { + return Optional.ofNullable(ReflectionUtils.findMethod(type, name, parameterTypes)); + } } diff --git a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java index ddbc51795..fd419ec63 100644 --- a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java +++ b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java @@ -19,7 +19,6 @@ import static org.springframework.core.GenericTypeResolver.*; import static org.springframework.data.repository.util.ClassUtils.*; import static org.springframework.util.ReflectionUtils.*; -import java.io.Serializable; import java.lang.reflect.GenericDeclaration; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -101,7 +100,7 @@ class DefaultRepositoryInformation implements RepositoryInformation { * @see org.springframework.data.repository.support.RepositoryMetadata#getIdClass() */ @Override - public Class getIdType() { + public Class getIdType() { return metadata.getIdType(); } diff --git a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java index db6fbe03a..6f3dbb0cb 100644 --- a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java +++ b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java @@ -17,7 +17,6 @@ package org.springframework.data.repository.core.support; import lombok.Getter; -import java.io.Serializable; import java.util.List; import org.springframework.data.repository.Repository; @@ -39,7 +38,7 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata { private static final String MUST_BE_A_REPOSITORY = String.format("Given type must be assignable to %s!", Repository.class); - private final Class idType; + private final Class idType; private final Class domainType; /** @@ -56,8 +55,7 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata { this.domainType = resolveDomainType(repositoryInterface); } - @SuppressWarnings("unchecked") - private Class resolveIdType(Class repositoryInterface) { + private static Class resolveIdType(Class repositoryInterface) { TypeInformation information = ClassTypeInformation.from(repositoryInterface); List> arguments = information.getSuperTypeInformation(Repository.class).getTypeArguments(); @@ -66,10 +64,10 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata { throw new IllegalArgumentException(String.format("Could not resolve id type of %s!", repositoryInterface)); } - return (Class) arguments.get(1).getType(); + return arguments.get(1).getType(); } - private Class resolveDomainType(Class repositoryInterface) { + private static Class resolveDomainType(Class repositoryInterface) { TypeInformation information = ClassTypeInformation.from(repositoryInterface); List> arguments = information.getSuperTypeInformation(Repository.class).getTypeArguments(); diff --git a/src/main/java/org/springframework/data/repository/core/support/DelegatingEntityInformation.java b/src/main/java/org/springframework/data/repository/core/support/DelegatingEntityInformation.java index 2986b3349..469d7e780 100644 --- a/src/main/java/org/springframework/data/repository/core/support/DelegatingEntityInformation.java +++ b/src/main/java/org/springframework/data/repository/core/support/DelegatingEntityInformation.java @@ -15,11 +15,12 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import java.util.Optional; import org.springframework.data.repository.core.EntityInformation; -import org.springframework.util.Assert; /** * Useful base class to implement custom {@link EntityInformation}s and delegate execution of standard methods from @@ -27,21 +28,10 @@ import org.springframework.util.Assert; * * @author Oliver Gierke */ -public class DelegatingEntityInformation implements EntityInformation { - - private final EntityInformation delegate; +@RequiredArgsConstructor +public class DelegatingEntityInformation implements EntityInformation { - /** - * Creates a new {@link DelegatingEntityInformation} delegating method invocations to the given - * {@link EntityInformation}. - * - * @param delegate - */ - public DelegatingEntityInformation(EntityInformation delegate) { - - Assert.notNull(delegate, "Delegate EnittyInformation must not be null!"); - this.delegate = delegate; - } + private final @NonNull EntityInformation delegate; /* * (non-Javadoc) diff --git a/src/main/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessor.java b/src/main/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessor.java index a74d50808..ea04ef8d2 100644 --- a/src/main/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessor.java +++ b/src/main/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessor.java @@ -18,10 +18,10 @@ package org.springframework.data.repository.core.support; import lombok.RequiredArgsConstructor; import java.lang.reflect.Method; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.stream.Stream; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; @@ -90,7 +90,7 @@ public class EventPublishingRepositoryProxyPostProcessor implements RepositoryPr Object result = invocation.proceed(); - if (!invocation.getMethod().getName().equals("save")) { + if (!Stream.of("save", "saveAll").anyMatch(it -> invocation.getMethod().getName().equals(it))) { return result; } 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 index c48b13f45..c9e77d605 100644 --- a/src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java +++ b/src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java @@ -15,10 +15,9 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; import java.util.Optional; -import org.springframework.core.GenericTypeResolver; +import org.springframework.core.ResolvableType; import org.springframework.data.domain.Persistable; import org.springframework.data.repository.core.EntityMetadata; @@ -28,8 +27,7 @@ import org.springframework.data.repository.core.EntityMetadata; * * @author Oliver Gierke */ -public class PersistableEntityInformation, ID extends Serializable> - extends AbstractEntityInformation { +public class PersistableEntityInformation, ID> extends AbstractEntityInformation { private Class idClass; @@ -42,7 +40,7 @@ public class PersistableEntityInformation, ID extends public PersistableEntityInformation(Class domainClass) { super(domainClass); - this.idClass = (Class) GenericTypeResolver.resolveTypeArgument(domainClass, Persistable.class); + this.idClass = (Class) ResolvableType.forClass(Persistable.class, domainClass).resolveGeneric(0); } /* diff --git a/src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java b/src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java index b8f094ed0..396e046f1 100644 --- a/src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java +++ b/src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; import java.util.Optional; import org.springframework.data.mapping.PersistentEntity; @@ -30,7 +29,7 @@ import org.springframework.data.repository.core.EntityInformation; * @author Christoph Strobl */ @SuppressWarnings("unchecked") -public class PersistentEntityInformation extends AbstractEntityInformation { +public class PersistentEntityInformation extends AbstractEntityInformation { private final PersistentEntity> persistentEntity; 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 index 2858f32a0..6ba7711b9 100644 --- a/src/main/java/org/springframework/data/repository/core/support/ReflectionEntityInformation.java +++ b/src/main/java/org/springframework/data/repository/core/support/ReflectionEntityInformation.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.util.Optional; @@ -32,7 +31,7 @@ import org.springframework.util.ReflectionUtils; * @author Oliver Gierke * @author Christoph Strobl */ -public class ReflectionEntityInformation extends AbstractEntityInformation { +public class ReflectionEntityInformation extends AbstractEntityInformation { private static final Class DEFAULT_ID_ANNOTATION = Id.class; diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java index 1366305e6..708d6d25d 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; import java.util.List; import java.util.Optional; @@ -50,7 +49,7 @@ import org.springframework.util.Assert; * @author Oliver Gierke * @author Thomas Darimont */ -public abstract class RepositoryFactoryBeanSupport, S, ID extends Serializable> +public abstract class RepositoryFactoryBeanSupport, S, ID> implements InitializingBean, RepositoryFactoryInformation, FactoryBean, BeanClassLoaderAware, BeanFactoryAware, ApplicationEventPublisherAware { diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java index 7f35190c4..9c583bb54 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; import java.util.List; import org.springframework.data.mapping.PersistentEntity; @@ -31,7 +30,7 @@ import org.springframework.data.repository.query.QueryMethod; * * @author Oliver Gierke */ -public interface RepositoryFactoryInformation { +public interface RepositoryFactoryInformation { /** * Returns {@link EntityInformation} the repository factory is using. 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 051b46ff0..3c12b5396 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 @@ -19,7 +19,6 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; -import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.ArrayList; @@ -291,7 +290,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, * @param domainClass * @return */ - public abstract EntityInformation getEntityInformation(Class domainClass); + public abstract EntityInformation getEntityInformation(Class domainClass); /** * Create a repository instance as backing for the query proxy. diff --git a/src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java b/src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java index 612002656..bc0f74db2 100644 --- a/src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java @@ -15,8 +15,6 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; - import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.ListableBeanFactory; @@ -32,7 +30,7 @@ import org.springframework.util.Assert; * * @author Oliver Gierke */ -public abstract class TransactionalRepositoryFactoryBeanSupport, S, ID extends Serializable> +public abstract class TransactionalRepositoryFactoryBeanSupport, S, ID> extends RepositoryFactoryBeanSupport implements BeanFactoryAware { private String transactionManagerName = TxUtils.DEFAULT_TRANSACTION_MANAGER; diff --git a/src/main/java/org/springframework/data/repository/history/RevisionRepository.java b/src/main/java/org/springframework/data/repository/history/RevisionRepository.java index 94b0bc376..942317688 100755 --- a/src/main/java/org/springframework/data/repository/history/RevisionRepository.java +++ b/src/main/java/org/springframework/data/repository/history/RevisionRepository.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.history; -import java.io.Serializable; import java.util.Optional; import org.springframework.data.domain.Page; @@ -33,8 +32,7 @@ import org.springframework.data.repository.Repository; * @author Philipp Huegelmeyer */ @NoRepositoryBean -public interface RevisionRepository> - extends Repository { +public interface RevisionRepository> extends Repository { /** * Returns the revision of the entity it was last changed in. diff --git a/src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java b/src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java index e122a16c9..b907eb9c0 100644 --- a/src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java +++ b/src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java @@ -15,15 +15,13 @@ */ package org.springframework.data.repository.reactive; -import java.io.Serializable; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; import org.reactivestreams.Publisher; import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.Repository; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - /** * Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms * and uses Project Reactor types which are built on top of Reactive Streams. @@ -34,7 +32,7 @@ import reactor.core.publisher.Mono; * @see Flux */ @NoRepositoryBean -public interface ReactiveCrudRepository extends Repository { +public interface ReactiveCrudRepository extends Repository { /** * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the @@ -52,7 +50,7 @@ public interface ReactiveCrudRepository extends Repo * @return the saved entities. * @throws IllegalArgumentException in case the given entity is {@literal null}. */ - Flux save(Iterable entities); + Flux saveAll(Iterable entities); /** * Saves all given entities. @@ -61,7 +59,7 @@ public interface ReactiveCrudRepository extends Repo * @return the saved entities. * @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}. */ - Flux save(Publisher entityStream); + Flux saveAll(Publisher entityStream); /** * Retrieves an entity by its id. @@ -70,7 +68,7 @@ public interface ReactiveCrudRepository extends Repo * @return the entity with the given id or {@link Mono#empty()} if none found. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Mono findOne(ID id); + Mono findById(ID id); /** * Retrieves an entity by its id supplied by a {@link Mono}. @@ -79,7 +77,7 @@ public interface ReactiveCrudRepository extends Repo * @return the entity with the given id or {@link Mono#empty()} if none found. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Mono findOne(Mono id); + Mono findById(Mono id); /** * Returns whether an entity with the given id exists. @@ -88,7 +86,7 @@ public interface ReactiveCrudRepository extends Repo * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Mono exists(ID id); + Mono existsById(ID id); /** * Returns whether an entity with the given id, supplied by a {@link Mono}, exists. @@ -97,7 +95,7 @@ public interface ReactiveCrudRepository extends Repo * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise * @throws IllegalArgumentException if {@code id} is {@literal null} */ - Mono exists(Mono id); + Mono existsById(Mono id); /** * Returns all instances of the type. @@ -112,7 +110,7 @@ public interface ReactiveCrudRepository extends Repo * @param ids must not be {@literal null}. * @return the found entities. */ - Flux findAll(Iterable ids); + Flux findAllById(Iterable ids); /** * Returns all instances of the type with the given IDs. @@ -120,7 +118,7 @@ public interface ReactiveCrudRepository extends Repo * @param idStream must not be {@literal null}. * @return the found entities. */ - Flux findAll(Publisher idStream); + Flux findAllById(Publisher idStream); /** * Returns the number of entities available. @@ -135,7 +133,7 @@ public interface ReactiveCrudRepository extends Repo * @param id must not be {@literal null}. * @throws IllegalArgumentException in case the given {@code id} is {@literal null}. */ - Mono delete(ID id); + Mono deleteById(ID id); /** * Deletes a given entity. @@ -151,7 +149,7 @@ public interface ReactiveCrudRepository extends Repo * @param entities must not be {@literal null}. * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}. */ - Mono delete(Iterable entities); + Mono deleteAll(Iterable entities); /** * Deletes the given entities. @@ -159,7 +157,7 @@ public interface ReactiveCrudRepository extends Repo * @param entityStream must not be {@literal null}. * @throws IllegalArgumentException in case the given {@link Publisher} is {@literal null}. */ - Mono delete(Publisher entityStream); + Mono deleteAll(Publisher entityStream); /** * Deletes all entities managed by the repository. diff --git a/src/main/java/org/springframework/data/repository/reactive/ReactiveSortingRepository.java b/src/main/java/org/springframework/data/repository/reactive/ReactiveSortingRepository.java index 0151e92e2..3a496c8d7 100644 --- a/src/main/java/org/springframework/data/repository/reactive/ReactiveSortingRepository.java +++ b/src/main/java/org/springframework/data/repository/reactive/ReactiveSortingRepository.java @@ -15,14 +15,12 @@ */ package org.springframework.data.repository.reactive; -import java.io.Serializable; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; import org.springframework.data.domain.Sort; import org.springframework.data.repository.NoRepositoryBean; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - /** * Extension of {@link ReactiveCrudRepository} to provide additional methods to retrieve entities using the sorting * abstraction. @@ -34,7 +32,7 @@ import reactor.core.publisher.Mono; * @see Flux */ @NoRepositoryBean -public interface ReactiveSortingRepository extends ReactiveCrudRepository { +public interface ReactiveSortingRepository extends ReactiveCrudRepository { /** * Returns all entities sorted by the given options. diff --git a/src/main/java/org/springframework/data/repository/reactive/RxJava1CrudRepository.java b/src/main/java/org/springframework/data/repository/reactive/RxJava1CrudRepository.java index d390295fe..3cf8d4a1f 100644 --- a/src/main/java/org/springframework/data/repository/reactive/RxJava1CrudRepository.java +++ b/src/main/java/org/springframework/data/repository/reactive/RxJava1CrudRepository.java @@ -15,15 +15,13 @@ */ package org.springframework.data.repository.reactive; -import java.io.Serializable; - -import org.springframework.data.repository.NoRepositoryBean; -import org.springframework.data.repository.Repository; - import rx.Completable; import rx.Observable; import rx.Single; +import org.springframework.data.repository.NoRepositoryBean; +import org.springframework.data.repository.Repository; + /** * Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms * and uses RxJava 1 types. @@ -34,7 +32,7 @@ import rx.Single; * @see Observable */ @NoRepositoryBean -public interface RxJava1CrudRepository extends Repository { +public interface RxJava1CrudRepository extends Repository { /** * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the @@ -52,7 +50,7 @@ public interface RxJava1CrudRepository extends Repos * @return the saved entities. * @throws IllegalArgumentException in case the given entity is {@literal null}. */ - Observable save(Iterable entities); + Observable saveAll(Iterable entities); /** * Saves all given entities. @@ -61,7 +59,7 @@ public interface RxJava1CrudRepository extends Repos * @return the saved entities. * @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}. */ - Observable save(Observable entityStream); + Observable saveAll(Observable entityStream); /** * Retrieves an entity by its id. @@ -70,7 +68,7 @@ public interface RxJava1CrudRepository extends Repos * @return the entity with the given id or {@link Observable#empty()} if none found. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Observable findOne(ID id); + Observable findById(ID id); /** * Retrieves an entity by its id supplied by a {@link Single}. @@ -79,7 +77,7 @@ public interface RxJava1CrudRepository extends Repos * @return the entity with the given id or {@link Observable#empty()} if none found. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Observable findOne(Single id); + Observable findById(Single id); /** * Returns whether an entity with the given id exists. @@ -88,7 +86,7 @@ public interface RxJava1CrudRepository extends Repos * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Single exists(ID id); + Single existsById(ID id); /** * Returns whether an entity with the given id, supplied by a {@link Single}, exists. @@ -97,7 +95,7 @@ public interface RxJava1CrudRepository extends Repos * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Single exists(Single id); + Single existsById(Single id); /** * Returns all instances of the type. @@ -112,7 +110,7 @@ public interface RxJava1CrudRepository extends Repos * @param ids must not be {@literal null}. * @return the found entities. */ - Observable findAll(Iterable ids); + Observable findAllById(Iterable ids); /** * Returns all instances of the type with the given IDs. @@ -120,7 +118,7 @@ public interface RxJava1CrudRepository extends Repos * @param idStream must not be {@literal null}. * @return the found entities. */ - Observable findAll(Observable idStream); + Observable findAllById(Observable idStream); /** * Returns the number of entities available. @@ -135,7 +133,7 @@ public interface RxJava1CrudRepository extends Repos * @param id must not be {@literal null}. * @throws IllegalArgumentException in case the given {@code id} is {@literal null}. */ - Completable delete(ID id); + Completable deleteById(ID id); /** * Deletes a given entity. @@ -151,7 +149,7 @@ public interface RxJava1CrudRepository extends Repos * @param entities must not be {@literal null}. * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}. */ - Completable delete(Iterable entities); + Completable deleteAll(Iterable entities); /** * Deletes the given entities. @@ -159,7 +157,7 @@ public interface RxJava1CrudRepository extends Repos * @param entityStream must not be {@literal null}. * @throws IllegalArgumentException in case the given {@link Observable} is {@literal null}. */ - Completable delete(Observable entityStream); + Completable deleteAll(Observable entityStream); /** * Deletes all entities managed by the repository. diff --git a/src/main/java/org/springframework/data/repository/reactive/RxJava1SortingRepository.java b/src/main/java/org/springframework/data/repository/reactive/RxJava1SortingRepository.java index 7f5ffaa96..2c7855f9e 100644 --- a/src/main/java/org/springframework/data/repository/reactive/RxJava1SortingRepository.java +++ b/src/main/java/org/springframework/data/repository/reactive/RxJava1SortingRepository.java @@ -15,14 +15,12 @@ */ package org.springframework.data.repository.reactive; -import java.io.Serializable; +import rx.Observable; +import rx.Single; import org.springframework.data.domain.Sort; import org.springframework.data.repository.NoRepositoryBean; -import rx.Observable; -import rx.Single; - /** * Extension of {@link RxJava1CrudRepository} to provide additional methods to retrieve entities using the sorting * abstraction. @@ -35,7 +33,7 @@ import rx.Single; * @see RxJava1CrudRepository */ @NoRepositoryBean -public interface RxJava1SortingRepository extends RxJava1CrudRepository { +public interface RxJava1SortingRepository extends RxJava1CrudRepository { /** * Returns all entities sorted by the given options. diff --git a/src/main/java/org/springframework/data/repository/reactive/RxJava2CrudRepository.java b/src/main/java/org/springframework/data/repository/reactive/RxJava2CrudRepository.java index a26704f1b..8c4458850 100644 --- a/src/main/java/org/springframework/data/repository/reactive/RxJava2CrudRepository.java +++ b/src/main/java/org/springframework/data/repository/reactive/RxJava2CrudRepository.java @@ -20,8 +20,6 @@ import io.reactivex.Flowable; import io.reactivex.Maybe; import io.reactivex.Single; -import java.io.Serializable; - import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.Repository; @@ -37,7 +35,7 @@ import org.springframework.data.repository.Repository; * @see Completable */ @NoRepositoryBean -public interface RxJava2CrudRepository extends Repository { +public interface RxJava2CrudRepository extends Repository { /** * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the @@ -55,7 +53,7 @@ public interface RxJava2CrudRepository extends Repos * @return the saved entities. * @throws IllegalArgumentException in case the given entity is {@literal null}. */ - Flowable save(Iterable entities); + Flowable saveAll(Iterable entities); /** * Saves all given entities. @@ -64,7 +62,7 @@ public interface RxJava2CrudRepository extends Repos * @return the saved entities. * @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}. */ - Flowable save(Flowable entityStream); + Flowable saveAll(Flowable entityStream); /** * Retrieves an entity by its id. @@ -73,7 +71,7 @@ public interface RxJava2CrudRepository extends Repos * @return the entity with the given id or {@link Maybe#empty()} if none found. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Maybe findOne(ID id); + Maybe findById(ID id); /** * Retrieves an entity by its id supplied by a {@link Single}. @@ -82,7 +80,7 @@ public interface RxJava2CrudRepository extends Repos * @return the entity with the given id or {@link Maybe#empty()} if none found. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Maybe findOne(Single id); + Maybe findById(Single id); /** * Returns whether an entity with the given id exists. @@ -91,7 +89,7 @@ public interface RxJava2CrudRepository extends Repos * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Single exists(ID id); + Single existsById(ID id); /** * Returns whether an entity with the given id, supplied by a {@link Single}, exists. @@ -100,7 +98,7 @@ public interface RxJava2CrudRepository extends Repos * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @throws IllegalArgumentException if {@code id} is {@literal null} */ - Single exists(Single id); + Single existsById(Single id); /** * Returns all instances of the type. @@ -115,7 +113,7 @@ public interface RxJava2CrudRepository extends Repos * @param ids must not be {@literal null}. * @return the found entities. */ - Flowable findAll(Iterable ids); + Flowable findAllById(Iterable ids); /** * Returns all instances of the type with the given IDs. @@ -123,7 +121,7 @@ public interface RxJava2CrudRepository extends Repos * @param idStream must not be {@literal null}. * @return the found entities. */ - Flowable findAll(Flowable idStream); + Flowable findAllById(Flowable idStream); /** * Returns the number of entities available. @@ -138,7 +136,7 @@ public interface RxJava2CrudRepository extends Repos * @param id must not be {@literal null}. * @throws IllegalArgumentException in case the given {@code id} is {@literal null}. */ - Completable delete(ID id); + Completable deleteById(ID id); /** * Deletes a given entity. @@ -154,7 +152,7 @@ public interface RxJava2CrudRepository extends Repos * @param entities must not be {@literal null}. * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}. */ - Completable delete(Iterable entities); + Completable deleteAll(Iterable entities); /** * Deletes the given entities. @@ -162,7 +160,7 @@ public interface RxJava2CrudRepository extends Repos * @param entityStream must not be {@literal null}. * @throws IllegalArgumentException in case the given {@link Flowable} is {@literal null}. */ - Completable delete(Flowable entityStream); + Completable deleteAll(Flowable entityStream); /** * Deletes all entities managed by the repository. diff --git a/src/main/java/org/springframework/data/repository/reactive/RxJava2SortingRepository.java b/src/main/java/org/springframework/data/repository/reactive/RxJava2SortingRepository.java index 7d027e51f..0973af65e 100644 --- a/src/main/java/org/springframework/data/repository/reactive/RxJava2SortingRepository.java +++ b/src/main/java/org/springframework/data/repository/reactive/RxJava2SortingRepository.java @@ -17,8 +17,6 @@ package org.springframework.data.repository.reactive; import io.reactivex.Flowable; -import java.io.Serializable; - import org.springframework.data.domain.Sort; import org.springframework.data.repository.NoRepositoryBean; @@ -33,7 +31,7 @@ import org.springframework.data.repository.NoRepositoryBean; * @see RxJava2CrudRepository */ @NoRepositoryBean -public interface RxJava2SortingRepository extends RxJava2CrudRepository { +public interface RxJava2SortingRepository extends RxJava2CrudRepository { /** * Returns all entities sorted by the given options. diff --git a/src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java b/src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java index 4b8767b7e..73c1d4821 100644 --- a/src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java +++ b/src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.support; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Optional; @@ -36,7 +35,7 @@ import org.springframework.data.repository.core.RepositoryMetadata; */ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker { - private final CrudRepository repository; + private final CrudRepository repository; private final boolean customSaveMethod; private final boolean customFindOneMethod; @@ -51,7 +50,7 @@ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker { * @param metadata must not be {@literal null}. * @param conversionService must not be {@literal null}. */ - public CrudRepositoryInvoker(CrudRepository repository, RepositoryMetadata metadata, + public CrudRepositoryInvoker(CrudRepository repository, RepositoryMetadata metadata, ConversionService conversionService) { super(repository, metadata, conversionService); @@ -85,12 +84,12 @@ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker { /* * (non-Javadoc) - * @see org.springframework.data.rest.core.invoke.RepositoryInvoker#invokeFindOne(java.io.Serializable) + * @see org.springframework.data.repository.support.ReflectionRepositoryInvoker#invokeFindById(java.lang.Object) */ @Override @SuppressWarnings("unchecked") - public Optional invokeFindOne(Serializable id) { - return customFindOneMethod ? super.invokeFindOne(id) : (Optional) repository.findOne(convertId(id)); + public Optional invokeFindById(Object id) { + return customFindOneMethod ? super.invokeFindById(id) : (Optional) repository.findById(convertId(id)); } /* @@ -104,15 +103,15 @@ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker { /* * (non-Javadoc) - * @see org.springframework.data.rest.core.invoke.RepositoryInvoker#invokeDelete(java.io.Serializable) + * @see org.springframework.data.repository.support.ReflectionRepositoryInvoker#invokeDeleteById(java.lang.Object) */ @Override - public void invokeDelete(Serializable id) { + public void invokeDeleteById(Object id) { if (customDeleteMethod) { - super.invokeDelete(id); + super.invokeDeleteById(id); } else { - repository.delete(convertId(id)); + repository.deleteById(convertId(id)); } } diff --git a/src/main/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactory.java b/src/main/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactory.java index f4a892ad2..13d802a60 100644 --- a/src/main/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactory.java +++ b/src/main/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactory.java @@ -17,7 +17,6 @@ package org.springframework.data.repository.support; import static org.springframework.data.util.Optionals.*; -import java.io.Serializable; import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -100,11 +99,10 @@ public class DefaultRepositoryInvokerFactory implements RepositoryInvokerFactory protected RepositoryInvoker createInvoker(RepositoryInformation information, Object repository) { if (repository instanceof PagingAndSortingRepository) { - return new PagingAndSortingRepositoryInvoker((PagingAndSortingRepository) repository, - information, conversionService); - } else if (repository instanceof CrudRepository) { - return new CrudRepositoryInvoker((CrudRepository) repository, information, + return new PagingAndSortingRepositoryInvoker((PagingAndSortingRepository) repository, information, conversionService); + } else if (repository instanceof CrudRepository) { + return new CrudRepositoryInvoker((CrudRepository) repository, information, conversionService); } else { return new ReflectionRepositoryInvoker(repository, information, conversionService); } diff --git a/src/main/java/org/springframework/data/repository/support/DomainClassConverter.java b/src/main/java/org/springframework/data/repository/support/DomainClassConverter.java index 5321b88b7..1a27730bc 100644 --- a/src/main/java/org/springframework/data/repository/support/DomainClassConverter.java +++ b/src/main/java/org/springframework/data/repository/support/DomainClassConverter.java @@ -154,7 +154,7 @@ public class DomainClassConverter repository; + private final PagingAndSortingRepository repository; private final boolean customFindAll; /** @@ -46,7 +45,7 @@ class PagingAndSortingRepositoryInvoker extends CrudRepositoryInvoker { * @param metadata must not be {@literal null}. * @param conversionService must not be {@literal null}. */ - public PagingAndSortingRepositoryInvoker(PagingAndSortingRepository repository, + public PagingAndSortingRepositoryInvoker(PagingAndSortingRepository repository, RepositoryMetadata metadata, ConversionService conversionService) { super(repository, metadata, conversionService); diff --git a/src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java b/src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java index 50d05b5e7..ad7956db3 100644 --- a/src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java +++ b/src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.support; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; @@ -50,7 +49,7 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker { private final Object repository; private final CrudMethods methods; - private final Class idType; + private final Class idType; private final ConversionService conversionService; /** @@ -131,12 +130,12 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker { return methods.hasFindOneMethod(); } - /* + /* * (non-Javadoc) - * @see org.springframework.data.rest.core.invoke.RepositoryInvoker#invokeFindOne(java.io.Serializable) + * @see org.springframework.data.repository.support.RepositoryInvoker#invokeFindById(java.lang.Object) */ @Override - public Optional invokeFindOne(Serializable id) { + public Optional invokeFindById(Object id) { Method method = methods.getFindOneMethod()// .orElseThrow(() -> new IllegalStateException("Repository doesn't have a find-one-method declared!")); @@ -153,24 +152,24 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker { return methods.hasDelete(); } - /* + /* * (non-Javadoc) - * @see org.springframework.data.rest.core.invoke.RepositoryInvoker#invokeDelete(java.io.Serializable) + * @see org.springframework.data.repository.support.RepositoryInvoker#invokeDeleteById(java.lang.Object) */ @Override - public void invokeDelete(Serializable id) { + public void invokeDeleteById(Object id) { Assert.notNull(id, "Identifier must not be null!"); Method method = methods.getDeleteMethod() .orElseThrow(() -> new IllegalStateException("Repository doesn't have a delete-method declared!")); Class parameterType = method.getParameterTypes()[0]; - List> idTypes = Arrays.asList(idType, Serializable.class); + List> idTypes = Arrays.asList(idType, Object.class); if (idTypes.contains(parameterType)) { invoke(method, convertId(id)); } else { - invoke(method, this. invokeFindOne(id).orElse(null)); + invoke(method, this. invokeFindById(id).orElse(null)); } } @@ -263,7 +262,7 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker { * @param id must not be {@literal null}. * @return */ - protected Serializable convertId(Serializable id) { + protected Object convertId(Object id) { Assert.notNull(id, "Id must not be null!"); return conversionService.convert(id, idType); diff --git a/src/main/java/org/springframework/data/repository/support/Repositories.java b/src/main/java/org/springframework/data/repository/support/Repositories.java index 7f75af323..66941b36a 100644 --- a/src/main/java/org/springframework/data/repository/support/Repositories.java +++ b/src/main/java/org/springframework/data/repository/support/Repositories.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.support; -import java.io.Serializable; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -49,12 +48,12 @@ public class Repositories implements Iterable> { static final Repositories NONE = new Repositories(); - private static final RepositoryFactoryInformation EMPTY_REPOSITORY_FACTORY_INFO = EmptyRepositoryFactoryInformation.INSTANCE; + private static final RepositoryFactoryInformation EMPTY_REPOSITORY_FACTORY_INFO = EmptyRepositoryFactoryInformation.INSTANCE; private static final String DOMAIN_TYPE_MUST_NOT_BE_NULL = "Domain type must not be null!"; private final Optional beanFactory; private final Map, String> repositoryBeanNames; - private final Map, RepositoryFactoryInformation> repositoryFactoryInfos; + private final Map, RepositoryFactoryInformation> repositoryFactoryInfos; /** * Constructor to create the {@link #NONE} instance. @@ -148,12 +147,12 @@ public class Repositories implements Iterable> { * @return the {@link RepositoryFactoryInformation} for the given domain class or {@literal null} if no repository * registered for this domain class. */ - private RepositoryFactoryInformation getRepositoryFactoryInfoFor(Class domainClass) { + private RepositoryFactoryInformation getRepositoryFactoryInfoFor(Class domainClass) { Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); Class userType = ClassUtils.getUserClass(domainClass); - RepositoryFactoryInformation repositoryInfo = repositoryFactoryInfos.get(userType); + RepositoryFactoryInformation repositoryInfo = repositoryFactoryInfos.get(userType); if (repositoryInfo != null) { return repositoryInfo; @@ -173,7 +172,7 @@ public class Repositories implements Iterable> { * @return */ @SuppressWarnings("unchecked") - public EntityInformation getEntityInformationFor(Class domainClass) { + public EntityInformation getEntityInformationFor(Class domainClass) { Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); @@ -191,7 +190,7 @@ public class Repositories implements Iterable> { Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); - RepositoryFactoryInformation information = getRepositoryFactoryInfoFor(domainClass); + RepositoryFactoryInformation information = getRepositoryFactoryInfoFor(domainClass); return information == EMPTY_REPOSITORY_FACTORY_INFO ? Optional.empty() : Optional.of(information.getRepositoryInformation()); } @@ -264,12 +263,12 @@ public class Repositories implements Iterable> { * * @author Thomas Darimont */ - private static enum EmptyRepositoryFactoryInformation implements RepositoryFactoryInformation { + private static enum EmptyRepositoryFactoryInformation implements RepositoryFactoryInformation { INSTANCE; @Override - public EntityInformation getEntityInformation() { + public EntityInformation getEntityInformation() { return null; } diff --git a/src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java b/src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java index 8a062a4b2..be25514c5 100644 --- a/src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java +++ b/src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.support; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Optional; @@ -44,13 +43,13 @@ public interface RepositoryInvoker extends RepositoryInvocationInformation { T invokeSave(T object); /** - * Invokes the method equivalent to {@link org.springframework.data.repository.CrudRepository#findOne(Serializable)}. + * Invokes the method equivalent to {@link org.springframework.data.repository.CrudRepository#findById(Object)}. * * @param id must not be {@literal null}. * @return the entity with the given id. * @throws IllegalStateException if the repository does not expose a find-one-method. */ - Optional invokeFindOne(Serializable id); + Optional invokeFindById(Object id); /** * Invokes the find-all method of the underlying repository using the method taking a {@link Pageable} as parameter if @@ -80,13 +79,13 @@ public interface RepositoryInvoker extends RepositoryInvocationInformation { Iterable invokeFindAll(Sort sort); /** - * Invokes the method equivalent to {@link org.springframework.data.repository.CrudRepository#delete(Serializable)}. - * The given id is assumed to be of a type convertable into the actual identifier type of the backing repository. + * Invokes the method equivalent to {@link org.springframework.data.repository.CrudRepository#deleteById(Object)}. The + * given id is assumed to be of a type convertible into the actual identifier type of the backing repository. * * @param id must not be {@literal null}. * @throws {@link IllegalStateException} if the repository does not expose a delete-method. */ - void invokeDelete(Serializable id); + void invokeDeleteById(Object id); /** * Invokes the query method backed by the given {@link Method} using the given parameters, {@link Pageable} and diff --git a/src/test/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapterUnitTests.java b/src/test/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapterUnitTests.java index a51e069e9..b61fd8e62 100755 --- a/src/test/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapterUnitTests.java +++ b/src/test/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapterUnitTests.java @@ -86,11 +86,11 @@ public class QuerydslRepositoryInvokerAdapterUnitTests { adapter.hasSaveMethod(); verify(delegate, times(1)).hasSaveMethod(); - adapter.invokeDelete(any(Serializable.class)); - verify(delegate, times(1)).invokeDelete(any()); + adapter.invokeDeleteById(any(Serializable.class)); + verify(delegate, times(1)).invokeDeleteById(any()); - adapter.invokeFindOne(any(Serializable.class)); - verify(delegate, times(1)).invokeFindOne(any()); + adapter.invokeFindById(any(Serializable.class)); + verify(delegate, times(1)).invokeFindById(any()); adapter.invokeQueryMethod(any(), any(), any(), any()); diff --git a/src/test/java/org/springframework/data/repository/core/support/AbstractEntityInformationUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/AbstractEntityInformationUnitTests.java index 40123aaa4..7ffd9257d 100755 --- a/src/test/java/org/springframework/data/repository/core/support/AbstractEntityInformationUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/AbstractEntityInformationUnitTests.java @@ -100,7 +100,7 @@ public class AbstractEntityInformationUnitTests { @Id boolean id; } - static class CustomEntityInformation extends AbstractEntityInformation { + static class CustomEntityInformation extends AbstractEntityInformation { private final Class type; diff --git a/src/test/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadataUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadataUnitTests.java index 5e6fdc8be..c1eb5b1a9 100755 --- a/src/test/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadataUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadataUnitTests.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import org.junit.Test; +import org.springframework.core.ResolvableType; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.querydsl.User; @@ -138,12 +139,14 @@ public class AbstractRepositoryMetadataUnitTests { super(repositoryInterface); } + @SuppressWarnings("unchecked") public Class getIdType() { - return null; + return (Class) ResolvableType// + .forClass(Repository.class, getRepositoryInterface()).getGeneric(1).resolve(); } public Class getDomainType() { - return null; + return ResolvableType.forClass(Repository.class, getRepositoryInterface()).getGeneric(0).resolve(); } } diff --git a/src/test/java/org/springframework/data/repository/core/support/DefaultCrudMethodsUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/DefaultCrudMethodsUnitTests.java index 06fe9072a..590b14a31 100755 --- a/src/test/java/org/springframework/data/repository/core/support/DefaultCrudMethodsUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/DefaultCrudMethodsUnitTests.java @@ -47,7 +47,7 @@ public class DefaultCrudMethodsUnitTests { Class type = DomainCrudRepository.class; assertFindAllMethodOn(type, type.getMethod("findAll")); - assertDeleteMethodOn(type, type.getMethod("delete", Serializable.class)); + assertDeleteMethodOn(type, type.getMethod("delete", Object.class)); assertSaveMethodPresent(type, true); } @@ -57,7 +57,7 @@ public class DefaultCrudMethodsUnitTests { Class type = DomainPagingAndSortingRepository.class; assertFindAllMethodOn(type, type.getMethod("findAll", Pageable.class)); - assertDeleteMethodOn(type, type.getMethod("delete", Serializable.class)); + assertDeleteMethodOn(type, type.getMethod("delete", Object.class)); assertSaveMethodPresent(type, true); } @@ -100,8 +100,8 @@ public class DefaultCrudMethodsUnitTests { public void detectsOverloadedMethodsCorrectly() throws Exception { Class type = RepositoryWithAllCrudMethodOverloaded.class; - assertFindOneMethodOn(type, type.getDeclaredMethod("findOne", Long.class)); - assertDeleteMethodOn(type, type.getDeclaredMethod("delete", Long.class)); + assertFindOneMethodOn(type, type.getDeclaredMethod("findById", Long.class)); + assertDeleteMethodOn(type, type.getDeclaredMethod("deleteById", Long.class)); assertSaveMethodOn(type, type.getDeclaredMethod("save", Domain.class)); assertFindAllMethodOn(type, type.getDeclaredMethod("findAll")); } @@ -110,8 +110,8 @@ public class DefaultCrudMethodsUnitTests { public void ignoresWrongOverloadedMethods() throws Exception { Class type = RepositoryWithAllCrudMethodOverloadedWrong.class; - assertFindOneMethodOn(type, CrudRepository.class.getDeclaredMethod("findOne", Serializable.class)); - assertDeleteMethodOn(type, CrudRepository.class.getDeclaredMethod("delete", Serializable.class)); + assertFindOneMethodOn(type, CrudRepository.class.getDeclaredMethod("findById", Object.class)); + assertDeleteMethodOn(type, CrudRepository.class.getDeclaredMethod("delete", Object.class)); assertSaveMethodOn(type, CrudRepository.class.getDeclaredMethod("save", Object.class)); assertFindAllMethodOn(type, CrudRepository.class.getDeclaredMethod("findAll")); } @@ -241,9 +241,9 @@ public class DefaultCrudMethodsUnitTests { S save(S entity); - void delete(Long id); + void deleteById(Long id); - Optional findOne(Long id); + Optional findById(Long id); } // DATACMNS-393 @@ -251,11 +251,11 @@ public class DefaultCrudMethodsUnitTests { List findAll(String s); - Domain save(Serializable entity); + Domain save(Long entity); void delete(String o); - Domain findOne(Domain o); + Domain findById(Domain o); } // DATACMNS-539 diff --git a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java index f68ad5056..fb4972899 100755 --- a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java @@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.*; import lombok.experimental.Delegate; -import java.io.Serializable; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -63,19 +62,19 @@ public class DefaultRepositoryInformationUnitTests { @Test public void discoversRepositoryBaseClassMethod() throws Exception { - Method method = FooRepository.class.getMethod("findOne", Integer.class); + Method method = FooRepository.class.getMethod("findById", Integer.class); RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class); DefaultRepositoryInformation information = new DefaultRepositoryInformation(metadata, REPOSITORY, Optional.empty()); Method reference = information.getTargetClassMethod(method); assertThat(reference.getDeclaringClass()).isEqualTo(REPOSITORY); - assertThat(reference.getName()).isEqualTo("findOne"); + assertThat(reference.getName()).isEqualTo("findById"); } @Test public void discoveresNonRepositoryBaseClassMethod() throws Exception { - Method method = FooRepository.class.getMethod("findOne", Long.class); + Method method = FooRepository.class.getMethod("findById", Long.class); RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class); DefaultRepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, @@ -117,7 +116,7 @@ public class DefaultRepositoryInformationUnitTests { Method method = CustomRepository.class.getMethod("findAll", Pageable.class); assertThat(information.isBaseClassMethod(method)).isTrue(); - method = getMethodFrom(CustomRepository.class, "exists"); + method = getMethodFrom(CustomRepository.class, "existsById"); assertThat(information.isBaseClassMethod(method)).isTrue(); assertThat(information.getQueryMethods()).isEmpty(); @@ -184,7 +183,7 @@ public class DefaultRepositoryInformationUnitTests { RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, Optional.empty()); - Method method = BaseRepository.class.getMethod("findOne", Serializable.class); + Method method = BaseRepository.class.getMethod("findById", Object.class); assertThat(information.getQueryMethods()).contains(method); } @@ -196,8 +195,8 @@ public class DefaultRepositoryInformationUnitTests { RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, Optional.empty()); - Method method = BossRepository.class.getMethod("save", Iterable.class); - Method reference = CrudRepository.class.getMethod("save", Iterable.class); + Method method = BossRepository.class.getMethod("saveAll", Iterable.class); + Method reference = CrudRepository.class.getMethod("saveAll", Iterable.class); assertThat(information.getTargetClassMethod(method)).isEqualTo(reference); } @@ -268,10 +267,10 @@ public class DefaultRepositoryInformationUnitTests { RepositoryInformation information = new DefaultRepositoryInformation(metadata, DummyRepositoryImpl.class, Optional.empty()); - Method method = DummyRepository.class.getMethod("save", Iterable.class); + Method method = DummyRepository.class.getMethod("saveAll", Iterable.class); assertThat(information.getTargetClassMethod(method)) - .isEqualTo(DummyRepositoryImpl.class.getMethod("save", Iterable.class)); + .isEqualTo(DummyRepositoryImpl.class.getMethod("saveAll", Iterable.class)); } @Test // DATACMNS-1008, DATACMNS-912, DATACMNS-854 @@ -291,7 +290,7 @@ public class DefaultRepositoryInformationUnitTests { return Arrays.stream(type.getMethods())// .filter(method -> method.getName().equals(name))// .findFirst()// - .orElseThrow(() -> new IllegalStateException("No method found wwith name ".concat(name).concat("!"))); + .orElseThrow(() -> new IllegalStateException("No method found with name ".concat(name).concat("!"))); } @Target(ElementType.METHOD) @@ -303,10 +302,10 @@ public class DefaultRepositoryInformationUnitTests { interface FooRepository extends CrudRepository, FooRepositoryCustom { // Redeclared method - Optional findOne(Integer primaryKey); + Optional findById(Integer primaryKey); // Not a redeclared method - User findOne(Long primaryKey); + User findById(Long primaryKey); static void staticMethod() {} @@ -340,7 +339,7 @@ public class DefaultRepositoryInformationUnitTests { } } - interface BaseRepository extends CrudRepository { + interface BaseRepository extends CrudRepository { S findBySomething(String something); @@ -351,7 +350,7 @@ public class DefaultRepositoryInformationUnitTests { void delete(S entity); @MyQuery - Optional findOne(ID id); + Optional findById(ID id); } interface ConcreteRepository extends BaseRepository { @@ -361,9 +360,9 @@ public class DefaultRepositoryInformationUnitTests { User genericMethodToOverride(String something); } - interface ReadOnlyRepository extends Repository { + interface ReadOnlyRepository extends Repository { - T findOne(ID id); + T findById(ID id); Iterable findAll(); @@ -371,7 +370,7 @@ public class DefaultRepositoryInformationUnitTests { List findAll(Sort sort); - boolean exists(ID id); + boolean existsById(ID id); long count(); } @@ -405,10 +404,10 @@ public class DefaultRepositoryInformationUnitTests { interface DummyRepository extends CrudRepository { @Override - List save(Iterable entites); + List saveAll(Iterable entites); } - static class DummyRepositoryImpl implements CrudRepository { + static class DummyRepositoryImpl implements CrudRepository { private @Delegate CrudRepository delegate; } diff --git a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java index e17f8204b..ff48ed73b 100755 --- a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java @@ -168,7 +168,7 @@ public class DefaultRepositoryMetadataUnitTests { static abstract class DummyGenericRepositorySupport implements CrudRepository { - public java.util.Optional findOne(ID id) { + public java.util.Optional findById(ID id) { return java.util.Optional.empty(); } } diff --git a/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java b/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java index 496c4ebe9..f6b0b90f6 100644 --- a/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java +++ b/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java @@ -17,7 +17,6 @@ package org.springframework.data.repository.core.support; import static org.mockito.Mockito.*; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Optional; @@ -61,7 +60,7 @@ public class DummyRepositoryFactory extends RepositoryFactorySupport { */ @Override @SuppressWarnings("unchecked") - public EntityInformation getEntityInformation(Class domainClass) { + public EntityInformation getEntityInformation(Class domainClass) { return mock(EntityInformation.class); } diff --git a/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryInformation.java b/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryInformation.java index 37b4d08c3..23b9755e9 100644 --- a/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryInformation.java +++ b/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryInformation.java @@ -15,7 +15,6 @@ */ package org.springframework.data.repository.core.support; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Set; @@ -36,7 +35,7 @@ public final class DummyRepositoryInformation implements RepositoryInformation { this.metadata = metadata; } - public Class getIdType() { + public Class getIdType() { return metadata.getIdType(); } diff --git a/src/test/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessorUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessorUnitTests.java index ba257ef9f..a5c8ec142 100644 --- a/src/test/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessorUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessorUnitTests.java @@ -16,12 +16,12 @@ package org.springframework.data.repository.core.support; import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import lombok.Getter; import lombok.Value; -import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -122,7 +122,7 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests { @Test // DATACMNS-928 public void doesNotInterceptNonSaveMethod() throws Throwable { - doReturn(SampleRepository.class.getMethod("findOne", Serializable.class)).when(invocation).getMethod(); + doReturn(SampleRepository.class.getMethod("findById", Object.class)).when(invocation).getMethod(); EventPublishingMethodInterceptor// .of(EventPublishingMethod.of(MultipleEvents.class), publisher)// @@ -162,9 +162,9 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests { SomeEvent event = new SomeEvent(); MultipleEvents sample = MultipleEvents.of(Collections.singletonList(event)); - doReturn(new Object[] {Collections.singletonList(sample)}).when(invocation).getArguments(); + doReturn(new Object[] { Collections.singletonList(sample) }).when(invocation).getArguments(); - doReturn(SampleRepository.class.getMethod("save", Iterable.class)).when(invocation).getMethod(); + doReturn(SampleRepository.class.getMethod("saveAll", Iterable.class)).when(invocation).getMethod(); EventPublishingMethodInterceptor// .of(EventPublishingMethod.of(MultipleEvents.class), publisher)// diff --git a/src/test/java/org/springframework/data/repository/core/support/ReactiveRepositoryInformationUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/ReactiveRepositoryInformationUnitTests.java index 215ab44d4..a2a755ec0 100644 --- a/src/test/java/org/springframework/data/repository/core/support/ReactiveRepositoryInformationUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/ReactiveRepositoryInformationUnitTests.java @@ -22,7 +22,6 @@ import io.reactivex.Flowable; import reactor.core.publisher.Flux; import rx.Observable; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Optional; @@ -60,10 +59,11 @@ public class ReactiveRepositoryInformationUnitTests { @Test // DATACMNS-836 public void discoversRxJava1MethodWithConvertibleArguments() throws Exception { - Method reference = extractTargetMethodFromRepository(RxJava1InterfaceWithGenerics.class, "save", Observable.class); + Method reference = extractTargetMethodFromRepository(RxJava1InterfaceWithGenerics.class, "saveAll", + Observable.class); assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass()); - assertThat(reference.getName(), is("save")); + assertThat(reference.getName(), is("saveAll")); assertThat(reference.getParameterTypes()[0], is(equalTo(Publisher.class))); } @@ -79,31 +79,31 @@ public class ReactiveRepositoryInformationUnitTests { @Test // DATACMNS-988 public void discoversRxJava2MethodWithConvertibleArguments() throws Exception { - Method reference = extractTargetMethodFromRepository(RxJava2InterfaceWithGenerics.class, "save", Flowable.class); + Method reference = extractTargetMethodFromRepository(RxJava2InterfaceWithGenerics.class, "saveAll", Flowable.class); assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass()); - assertThat(reference.getName(), is("save")); + assertThat(reference.getName(), is("saveAll")); assertThat(reference.getParameterTypes()[0], is(equalTo(Publisher.class))); } @Test // DATACMNS-836 public void discoversMethodAssignableArguments() throws Exception { - Method reference = extractTargetMethodFromRepository(ReactiveSortingRepository.class, "save", Publisher.class); + Method reference = extractTargetMethodFromRepository(ReactiveSortingRepository.class, "saveAll", Publisher.class); assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass()); - assertThat(reference.getName(), is("save")); + assertThat(reference.getName(), is("saveAll")); assertThat(reference.getParameterTypes()[0], is(equalTo(Publisher.class))); } @Test // DATACMNS-836 public void discoversMethodExactIterableArguments() throws Exception { - Method reference = extractTargetMethodFromRepository(ReactiveJavaInterfaceWithGenerics.class, "save", + Method reference = extractTargetMethodFromRepository(ReactiveJavaInterfaceWithGenerics.class, "saveAll", Iterable.class); assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass()); - assertThat(reference.getName(), is("save")); + assertThat(reference.getName(), is("saveAll")); assertThat(reference.getParameterTypes()[0], is(equalTo(Iterable.class))); } @@ -120,12 +120,12 @@ public class ReactiveRepositoryInformationUnitTests { @Test // DATACMNS-1023 public void usesCorrectSaveOverload() throws Exception { - Method reference = extractTargetMethodFromRepository(DummyRepository.class, "save", Iterable.class); + Method reference = extractTargetMethodFromRepository(DummyRepository.class, "saveAll", Iterable.class); - assertThat(reference, is(ReactiveCrudRepository.class.getMethod("save", Iterable.class))); + assertThat(reference, is(ReactiveCrudRepository.class.getMethod("saveAll", Iterable.class))); } - private Method extractTargetMethodFromRepository(Class repositoryType, String methodName, Class... args) + private Method extractTargetMethodFromRepository(Class repositoryType, String methodName, Class... args) throws NoSuchMethodException { RepositoryInformation information = new ReactiveRepositoryInformation(new DefaultRepositoryMetadata(repositoryType), @@ -139,15 +139,14 @@ public class ReactiveRepositoryInformationUnitTests { interface ReactiveJavaInterfaceWithGenerics extends ReactiveCrudRepository {} - static abstract class DummyGenericReactiveRepositorySupport - implements ReactiveCrudRepository { + static abstract class DummyGenericReactiveRepositorySupport implements ReactiveCrudRepository { } interface DummyRepository extends ReactiveCrudRepository { @Override - Flux save(Iterable entities); + Flux saveAll(Iterable entities); } static class User { diff --git a/src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java index c80e98bdb..710f2c94d 100644 --- a/src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java @@ -15,6 +15,7 @@ */ package org.springframework.data.repository.core.support; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import io.reactivex.Completable; @@ -59,10 +60,10 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests { public void invokesCustomMethodIfItRedeclaresACRUDOne() { ObjectRepository repository = factory.getRepository(ObjectRepository.class, customImplementation); - repository.findOne(1); + repository.findById(1); - verify(customImplementation, times(1)).findOne(1); - verify(backingRepo, times(0)).findOne(1); + verify(customImplementation, times(1)).findById(1); + verify(backingRepo, times(0)).findById(1); } @Test // DATACMNS-836 @@ -70,10 +71,10 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests { Serializable id = 1L; RxJava1ConvertingRepository repository = factory.getRepository(RxJava1ConvertingRepository.class); - repository.exists(id); - repository.exists((Long) id); + repository.existsById(id); + repository.existsById((Long) id); - verify(backingRepo, times(2)).exists(id); + verify(backingRepo, times(2)).existsById(id); } @Test // DATACMNS-836 @@ -83,9 +84,9 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests { Single ids = Single.just(1L); RxJava1ConvertingRepository repository = factory.getRepository(RxJava1ConvertingRepository.class); - repository.exists(ids); + repository.existsById(ids); - verify(backingRepo, times(1)).exists(any(Mono.class)); + verify(backingRepo, times(1)).existsById(any(Mono.class)); } @Test // DATACMNS-988 @@ -93,9 +94,9 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests { Long id = 1L; RxJava2ConvertingRepository repository = factory.getRepository(RxJava2ConvertingRepository.class); - repository.findOne(id); + repository.findById(id); - verify(backingRepo, times(1)).findOne(id); + verify(backingRepo, times(1)).findById(id); } @Test // DATACMNS-988 @@ -104,36 +105,36 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests { Serializable id = 1L; RxJava2ConvertingRepository repository = factory.getRepository(RxJava2ConvertingRepository.class); - repository.delete(id); + repository.deleteById(id); - verify(backingRepo, times(1)).delete(id); + verify(backingRepo, times(1)).deleteById(id); } interface RxJava1ConvertingRepository extends Repository { - Single exists(Single id); + Single existsById(Single id); - Single exists(Serializable id); + Single existsById(Serializable id); - Single exists(Long id); + Single existsById(Long id); } interface RxJava2ConvertingRepository extends Repository { - Maybe findOne(Serializable id); + Maybe findById(Serializable id); - Single exists(Long id); + Single existsById(Long id); - Completable delete(Serializable id); + Completable deleteById(Serializable id); } interface ObjectRepository - extends Repository, RepositoryFactorySupportUnitTests.ObjectRepositoryCustom { + extends Repository, RepositoryFactorySupportUnitTests.ObjectRepositoryCustom { } interface ObjectRepositoryCustom { - Object findOne(Serializable id); + Object findById(Object id); } } diff --git a/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java index cdcd73092..b07d0ed9d 100755 --- a/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java @@ -22,9 +22,9 @@ import static org.mockito.Mockito.*; import java.io.Serializable; import java.lang.reflect.Method; -import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; @@ -77,7 +77,7 @@ public class RepositoryFactorySupportUnitTests { DummyRepositoryFactory factory; - @Mock PagingAndSortingRepository backingRepo; + @Mock PagingAndSortingRepository backingRepo; @Mock ObjectRepositoryCustom customImplementation; @Mock MyQueryCreationListener listener; @@ -119,10 +119,10 @@ public class RepositoryFactorySupportUnitTests { public void invokesCustomMethodIfItRedeclaresACRUDOne() { ObjectRepository repository = factory.getRepository(ObjectRepository.class, customImplementation); - repository.findOne(1); + repository.findById(1); - verify(customImplementation, times(1)).findOne(1); - verify(backingRepo, times(0)).findOne(1); + verify(customImplementation, times(1)).findById(1); + verify(backingRepo, times(0)).findById(1); } @Test @@ -316,7 +316,7 @@ public class RepositoryFactorySupportUnitTests { interface SimpleRepository extends Repository {} - interface ObjectRepository extends Repository, ObjectRepositoryCustom { + interface ObjectRepository extends Repository, ObjectRepositoryCustom { Object findByClass(Class clazz); @@ -335,7 +335,7 @@ public class RepositoryFactorySupportUnitTests { interface ObjectRepositoryCustom { - Object findOne(Serializable id); + Object findById(Object id); } interface PlainQueryCreationListener extends QueryCreationListener { @@ -352,7 +352,7 @@ public class RepositoryFactorySupportUnitTests { interface ReadOnlyRepository extends Repository { - T findOne(ID id); + Optional findById(ID id); Iterable findAll(); @@ -360,7 +360,7 @@ public class RepositoryFactorySupportUnitTests { List findAll(Sort sort); - boolean exists(ID id); + boolean existsById(ID id); long count(); } diff --git a/src/test/java/org/springframework/data/repository/sample/ProductRepository.java b/src/test/java/org/springframework/data/repository/sample/ProductRepository.java index 3fa9c52cf..fe9ee4172 100644 --- a/src/test/java/org/springframework/data/repository/sample/ProductRepository.java +++ b/src/test/java/org/springframework/data/repository/sample/ProductRepository.java @@ -4,7 +4,7 @@ import org.springframework.data.repository.Repository; public interface ProductRepository extends Repository { - Product findOne(Long id); + Product findById(Long id); Product save(Product product); } diff --git a/src/test/java/org/springframework/data/repository/support/CrudRepositoryInvokerUnitTests.java b/src/test/java/org/springframework/data/repository/support/CrudRepositoryInvokerUnitTests.java index 54945358f..590aee774 100755 --- a/src/test/java/org/springframework/data/repository/support/CrudRepositoryInvokerUnitTests.java +++ b/src/test/java/org/springframework/data/repository/support/CrudRepositoryInvokerUnitTests.java @@ -18,7 +18,6 @@ package org.springframework.data.repository.support; import static org.mockito.Mockito.*; import static org.springframework.data.repository.support.RepositoryInvocationTestUtils.*; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Collection; import java.util.Date; @@ -62,12 +61,12 @@ public class CrudRepositoryInvokerUnitTests { @Test // DATACMNS-589, DATAREST-216 public void invokesRedeclaredFindOne() { - getInvokerFor(orderRepository, expectInvocationOnType(OrderRepository.class)).invokeFindOne(1L); + getInvokerFor(orderRepository, expectInvocationOnType(OrderRepository.class)).invokeFindById(1L); } @Test // DATACMNS-589 public void invokesRedeclaredDelete() throws Exception { - getInvokerFor(orderRepository, expectInvocationOnType(OrderRepository.class)).invokeDelete(1L); + getInvokerFor(orderRepository, expectInvocationOnType(OrderRepository.class)).invokeDeleteById(1L); } @Test // DATACMNS-589 @@ -80,15 +79,15 @@ public class CrudRepositoryInvokerUnitTests { @Test // DATACMNS-589 public void invokesFindOneOnCrudRepository() throws Exception { - Method method = CrudRepository.class.getMethod("findOne", Serializable.class); - getInvokerFor(personRepository, expectInvocationOf(method)).invokeFindOne(1L); + Method method = CrudRepository.class.getMethod("findById", Object.class); + getInvokerFor(personRepository, expectInvocationOf(method)).invokeFindById(1L); } @Test // DATACMNS-589, DATAREST-216 public void invokesDeleteOnCrudRepository() throws Exception { - Method method = CrudRepository.class.getMethod("delete", Serializable.class); - getInvokerFor(personRepository, expectInvocationOf(method)).invokeDelete(1L); + Method method = CrudRepository.class.getMethod("deleteById", Object.class); + getInvokerFor(personRepository, expectInvocationOf(method)).invokeDeleteById(1L); } @Test // DATACMNS-589 @@ -142,10 +141,10 @@ public class CrudRepositoryInvokerUnitTests { S save(S entity); @Override - Optional findOne(Long id); + Optional findById(Long id); @Override - void delete(Long id); + void deleteById(Long id); } static class Person {} @@ -172,6 +171,6 @@ public class CrudRepositoryInvokerUnitTests { interface CrudWithRedeclaredDelete extends CrudRepository { - void delete(Long id); + void deleteById(Long id); } } diff --git a/src/test/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactoryIntegrationTests.java b/src/test/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactoryIntegrationTests.java index 9c5a5883c..24440e397 100755 --- a/src/test/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactoryIntegrationTests.java @@ -59,9 +59,9 @@ public class DefaultRepositoryInvokerFactoryIntegrationTests { // Mockito.reset(productRepository); Product product = new Product(); - when(productRepository.findOne(4711L)).thenReturn(product); + when(productRepository.findById(4711L)).thenReturn(product); - Optional invokeFindOne = factory.getInvokerFor(Product.class).invokeFindOne(4711L); + Optional invokeFindOne = factory.getInvokerFor(Product.class).invokeFindById(4711L); assertThat(invokeFindOne).isEqualTo(Optional.of(product)); } diff --git a/src/test/java/org/springframework/data/repository/support/DomainClassConverterUnitTests.java b/src/test/java/org/springframework/data/repository/support/DomainClassConverterUnitTests.java index 08a104f13..74f099888 100755 --- a/src/test/java/org/springframework/data/repository/support/DomainClassConverterUnitTests.java +++ b/src/test/java/org/springframework/data/repository/support/DomainClassConverterUnitTests.java @@ -121,7 +121,7 @@ public class DomainClassConverterUnitTests { UserRepository bean = context.getBean(UserRepository.class); UserRepository repo = (UserRepository) ((Advised) bean).getTargetSource().getTarget(); - verify(repo, times(1)).findOne(1L); + verify(repo, times(1)).findById(1L); } @Test // DATACMNS-133 diff --git a/src/test/java/org/springframework/data/repository/support/ReflectionRepositoryInvokerUnitTests.java b/src/test/java/org/springframework/data/repository/support/ReflectionRepositoryInvokerUnitTests.java index f12877d3f..4a29b4376 100755 --- a/src/test/java/org/springframework/data/repository/support/ReflectionRepositoryInvokerUnitTests.java +++ b/src/test/java/org/springframework/data/repository/support/ReflectionRepositoryInvokerUnitTests.java @@ -82,22 +82,22 @@ public class ReflectionRepositoryInvokerUnitTests { public void invokesFindOneCorrectly() throws Exception { ManualCrudRepository repository = mock(ManualCrudRepository.class); - Method method = ManualCrudRepository.class.getMethod("findOne", Long.class); + Method method = ManualCrudRepository.class.getMethod("findById", Long.class); - getInvokerFor(repository, expectInvocationOf(method)).invokeFindOne("1"); - getInvokerFor(repository, expectInvocationOf(method)).invokeFindOne(1L); + getInvokerFor(repository, expectInvocationOf(method)).invokeFindById("1"); + getInvokerFor(repository, expectInvocationOf(method)).invokeFindById(1L); } @Test // DATACMNS-589 public void invokesDeleteWithDomainCorrectly() throws Exception { RepoWithDomainDeleteAndFindOne repository = mock(RepoWithDomainDeleteAndFindOne.class); - when(repository.findOne(1L)).thenReturn(new Domain()); + when(repository.findById(1L)).thenReturn(new Domain()); - Method findOneMethod = RepoWithDomainDeleteAndFindOne.class.getMethod("findOne", Long.class); + Method findOneMethod = RepoWithDomainDeleteAndFindOne.class.getMethod("findById", Long.class); Method deleteMethod = RepoWithDomainDeleteAndFindOne.class.getMethod("delete", Domain.class); - getInvokerFor(repository, expectInvocationOf(findOneMethod, deleteMethod)).invokeDelete(1L); + getInvokerFor(repository, expectInvocationOf(findOneMethod, deleteMethod)).invokeDeleteById(1L); } @Test // DATACMNS-589 @@ -164,9 +164,9 @@ public class ReflectionRepositoryInvokerUnitTests { public void invokesOverriddenDeleteMethodCorrectly() throws Exception { MyRepo repository = mock(MyRepo.class); - Method method = CustomRepo.class.getMethod("delete", Long.class); + Method method = CustomRepo.class.getMethod("deleteById", Long.class); - getInvokerFor(repository, expectInvocationOf(method)).invokeDelete("1"); + getInvokerFor(repository, expectInvocationOf(method)).invokeDeleteById("1"); } @Test(expected = IllegalStateException.class) // DATACMNS-589 @@ -175,7 +175,7 @@ public class ReflectionRepositoryInvokerUnitTests { RepositoryInvoker invoker = getInvokerFor(mock(EmptyRepository.class)); assertThat(invoker.hasDeleteMethod()).isFalse(); - invoker.invokeDelete(1L); + invoker.invokeDeleteById(1L); } @Test(expected = IllegalStateException.class) // DATACMNS-589 @@ -184,7 +184,7 @@ public class ReflectionRepositoryInvokerUnitTests { RepositoryInvoker invoker = getInvokerFor(mock(EmptyRepository.class)); assertThat(invoker.hasFindOneMethod()).isFalse(); - invoker.invokeFindOne(1L); + invoker.invokeFindById(1L); } @Test(expected = IllegalStateException.class) // DATACMNS-589 @@ -245,11 +245,11 @@ public class ReflectionRepositoryInvokerUnitTests { public void convertsWrapperTypeToJdkOptional() { GuavaRepository mock = mock(GuavaRepository.class); - when(mock.findOne(any())).thenReturn(com.google.common.base.Optional.of(new Domain())); + when(mock.findById(any())).thenReturn(com.google.common.base.Optional.of(new Domain())); RepositoryInvoker invoker = getInvokerFor(mock); - Optional invokeFindOne = invoker.invokeFindOne(1L); + Optional invokeFindOne = invoker.invokeFindById(1L); assertThat(invokeFindOne).isPresent(); } @@ -262,8 +262,8 @@ public class ReflectionRepositoryInvokerUnitTests { Method method = ManualCrudRepository.class.getMethod("findAll"); - Optional result = getInvokerFor(mock).invokeQueryMethod(method, new LinkedMultiValueMap<>(), Pageable.unpaged(), - Sort.unsorted()); + Optional result = getInvokerFor(mock).invokeQueryMethod(method, new LinkedMultiValueMap<>(), + Pageable.unpaged(), Sort.unsorted()); assertThat(result).hasValueSatisfying(it -> { assertThat(it).isInstanceOf(Collection.class); @@ -287,20 +287,20 @@ public class ReflectionRepositoryInvokerUnitTests { class Domain {} interface CustomRepo { - void delete(Long id); + void deleteById(Long id); } interface EmptyRepository extends Repository {} interface ManualCrudRepository extends Repository { - Domain findOne(Long id); + Domain findById(Long id); Iterable findAll(); T save(T entity); - void delete(Long id); + void deleteById(Long id); } interface RepoWithFindAllWithoutParameters extends Repository { @@ -320,7 +320,7 @@ public class ReflectionRepositoryInvokerUnitTests { interface RepoWithDomainDeleteAndFindOne extends Repository { - Domain findOne(Long id); + Domain findById(Long id); void delete(Domain entity); } @@ -332,6 +332,6 @@ public class ReflectionRepositoryInvokerUnitTests { interface GuavaRepository extends Repository { - com.google.common.base.Optional findOne(Long id); + com.google.common.base.Optional findById(Long id); } }