Browse Source

DATACMNS-944 - Moved to more consistent naming scheme for CrudRepository methods.

We now follow a more consistent naming scheme for the methods in repository that are driven by the following guidelines:

* Methods referring to an identifier now all end on …ById(…).
* Methods taking or returning a collection are named …All(…)

That results in the following renames:

* findOne(…) -> findById(…)
* save(Iterable) -> saveAll(Iterable)
* findAll(Iterable<ID>) -> findAllById(…)
* delete(ID) -> deleteById(ID)
* delete(Iterable<T>) -> deleteAll(Iterable<T>)
* exists() -> existsById(…)

As a side-effect of that, we can now drop the Serializable requirement for identifiers.

Updated CRUD method detection to use the new naming scheme and moved the code to Java 8 streams and Optional. Adapted RepositoryInvoker API to reflect method name changes as well.
pull/214/head
Oliver Gierke 9 years ago
parent
commit
727ab8384c
  1. 3
      src/main/java/org/springframework/data/domain/Auditable.java
  2. 4
      src/main/java/org/springframework/data/domain/Persistable.java
  3. 13
      src/main/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapter.java
  4. 33
      src/main/java/org/springframework/data/repository/CrudRepository.java
  5. 4
      src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java
  6. 4
      src/main/java/org/springframework/data/repository/Repository.java
  7. 3
      src/main/java/org/springframework/data/repository/RepositoryDefinition.java
  8. 2
      src/main/java/org/springframework/data/repository/core/CrudMethods.java
  9. 4
      src/main/java/org/springframework/data/repository/core/EntityInformation.java
  10. 3
      src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java
  11. 21
      src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java
  12. 8
      src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java
  13. 109
      src/main/java/org/springframework/data/repository/core/support/DefaultCrudMethods.java
  14. 3
      src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java
  15. 10
      src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java
  16. 22
      src/main/java/org/springframework/data/repository/core/support/DelegatingEntityInformation.java
  17. 4
      src/main/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessor.java
  18. 8
      src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java
  19. 3
      src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java
  20. 3
      src/main/java/org/springframework/data/repository/core/support/ReflectionEntityInformation.java
  21. 3
      src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java
  22. 3
      src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java
  23. 3
      src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java
  24. 4
      src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java
  25. 4
      src/main/java/org/springframework/data/repository/history/RevisionRepository.java
  26. 30
      src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java
  27. 8
      src/main/java/org/springframework/data/repository/reactive/ReactiveSortingRepository.java
  28. 32
      src/main/java/org/springframework/data/repository/reactive/RxJava1CrudRepository.java
  29. 8
      src/main/java/org/springframework/data/repository/reactive/RxJava1SortingRepository.java
  30. 26
      src/main/java/org/springframework/data/repository/reactive/RxJava2CrudRepository.java
  31. 4
      src/main/java/org/springframework/data/repository/reactive/RxJava2SortingRepository.java
  32. 19
      src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java
  33. 8
      src/main/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactory.java
  34. 2
      src/main/java/org/springframework/data/repository/support/DomainClassConverter.java
  35. 5
      src/main/java/org/springframework/data/repository/support/PagingAndSortingRepositoryInvoker.java
  36. 17
      src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java
  37. 17
      src/main/java/org/springframework/data/repository/support/Repositories.java
  38. 11
      src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java
  39. 8
      src/test/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapterUnitTests.java
  40. 2
      src/test/java/org/springframework/data/repository/core/support/AbstractEntityInformationUnitTests.java
  41. 7
      src/test/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadataUnitTests.java
  42. 20
      src/test/java/org/springframework/data/repository/core/support/DefaultCrudMethodsUnitTests.java
  43. 39
      src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java
  44. 2
      src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java
  45. 3
      src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java
  46. 3
      src/test/java/org/springframework/data/repository/core/support/DummyRepositoryInformation.java
  47. 8
      src/test/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessorUnitTests.java
  48. 29
      src/test/java/org/springframework/data/repository/core/support/ReactiveRepositoryInformationUnitTests.java
  49. 41
      src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java
  50. 18
      src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java
  51. 2
      src/test/java/org/springframework/data/repository/sample/ProductRepository.java
  52. 19
      src/test/java/org/springframework/data/repository/support/CrudRepositoryInvokerUnitTests.java
  53. 4
      src/test/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactoryIntegrationTests.java
  54. 2
      src/test/java/org/springframework/data/repository/support/DomainClassConverterUnitTests.java
  55. 38
      src/test/java/org/springframework/data/repository/support/ReflectionRepositoryInvokerUnitTests.java

3
src/main/java/org/springframework/data/domain/Auditable.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.domain; package org.springframework.data.domain;
import java.io.Serializable;
import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAccessor;
import java.util.Optional; import java.util.Optional;
@ -27,7 +26,7 @@ import java.util.Optional;
* @param <ID> the type of the audited type's identifier * @param <ID> the type of the audited type's identifier
* @author Oliver Gierke * @author Oliver Gierke
*/ */
public interface Auditable<U, ID extends Serializable, T extends TemporalAccessor> extends Persistable<ID> { public interface Auditable<U, ID, T extends TemporalAccessor> extends Persistable<ID> {
/** /**
* Returns the user who created this entity. * Returns the user who created this entity.

4
src/main/java/org/springframework/data/domain/Persistable.java

@ -15,15 +15,13 @@
*/ */
package org.springframework.data.domain; package org.springframework.data.domain;
import java.io.Serializable;
/** /**
* Simple interface for entities. * Simple interface for entities.
* *
* @param <ID> the type of the identifier * @param <ID> the type of the identifier
* @author Oliver Gierke * @author Oliver Gierke
*/ */
public interface Persistable<ID extends Serializable> extends Serializable { public interface Persistable<ID> {
/** /**
* Returns the id of the entity. * Returns the id of the entity.

13
src/main/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapter.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.querydsl; package org.springframework.data.querydsl;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Optional; import java.util.Optional;
@ -114,20 +113,20 @@ public class QuerydslRepositoryInvokerAdapter implements RepositoryInvoker {
/* /*
* (non-Javadoc) * (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 @Override
public void invokeDelete(Serializable id) { public void invokeDeleteById(Object id) {
delegate.invokeDelete(id); delegate.invokeDeleteById(id);
} }
/* /*
* (non-Javadoc) * (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 @Override
public <T> Optional<T> invokeFindOne(Serializable id) { public <T> Optional<T> invokeFindById(Object id) {
return delegate.invokeFindOne(id); return delegate.invokeFindById(id);
} }
/* /*

33
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository; package org.springframework.data.repository;
import java.io.Serializable;
import java.util.Optional; import java.util.Optional;
/** /**
@ -25,43 +24,43 @@ import java.util.Optional;
* @author Eberhard Wolff * @author Eberhard Wolff
*/ */
@NoRepositoryBean @NoRepositoryBean
public interface CrudRepository<T, ID extends Serializable> extends Repository<T, ID> { public interface CrudRepository<T, ID> extends Repository<T, ID> {
/** /**
* Saves a given entity. Use the returned instance for further operations as the save operation might have changed the * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the
* entity instance completely. * entity instance completely.
* *
* @param entity * @param entity must not be {@literal null}.
* @return the saved entity * @return the saved entity will never be {@literal null}.
*/ */
<S extends T> S save(S entity); <S extends T> S save(S entity);
/** /**
* Saves all given entities. * Saves all given entities.
* *
* @param entities * @param entities must not be {@literal null}.
* @return the saved entities * @return the saved entities will never be {@literal null}.
* @throws IllegalArgumentException in case the given entity is {@literal null}. * @throws IllegalArgumentException in case the given entity is {@literal null}.
*/ */
<S extends T> Iterable<S> save(Iterable<S> entities); <S extends T> Iterable<S> saveAll(Iterable<S> entities);
/** /**
* Retrieves an entity by its id. * Retrieves an entity by its id.
* *
* @param id must not be {@literal null}. * @param id must not be {@literal null}.
* @return the entity with the given id or {@literal null} if none found * @return the entity with the given id or {@literal Optional#empty()} if none found
* @throws IllegalArgumentException if {@code id} is {@literal null} * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Optional<T> findOne(ID id); Optional<T> findById(ID id);
/** /**
* Returns whether an entity with the given id exists. * Returns whether an entity with the given id exists.
* *
* @param id must not be {@literal null}. * @param id must not be {@literal null}.
* @return true if an entity with the given id exists, {@literal false} otherwise * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
* @throws IllegalArgumentException if {@code id} is {@literal null} * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
boolean exists(ID id); boolean existsById(ID id);
/** /**
* Returns all instances of the type. * Returns all instances of the type.
@ -76,7 +75,7 @@ public interface CrudRepository<T, ID extends Serializable> extends Repository<T
* @param ids * @param ids
* @return * @return
*/ */
Iterable<T> findAll(Iterable<ID> ids); Iterable<T> findAllById(Iterable<ID> ids);
/** /**
* Returns the number of entities available. * Returns the number of entities available.
@ -91,7 +90,7 @@ public interface CrudRepository<T, ID extends Serializable> extends Repository<T
* @param id must not be {@literal null}. * @param id must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@code id} is {@literal null} * @throws IllegalArgumentException in case the given {@code id} is {@literal null}
*/ */
void delete(ID id); void deleteById(ID id);
/** /**
* Deletes a given entity. * Deletes a given entity.
@ -107,7 +106,7 @@ public interface CrudRepository<T, ID extends Serializable> extends Repository<T
* @param entities * @param entities
* @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}. * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
*/ */
void delete(Iterable<? extends T> entities); void deleteAll(Iterable<? extends T> entities);
/** /**
* Deletes all entities managed by the repository. * Deletes all entities managed by the repository.

4
src/main/java/org/springframework/data/repository/PagingAndSortingRepository.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.repository; package org.springframework.data.repository;
import java.io.Serializable;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
@ -31,7 +29,7 @@ import org.springframework.data.domain.Sort;
* @see Page * @see Page
*/ */
@NoRepositoryBean @NoRepositoryBean
public interface PagingAndSortingRepository<T, ID extends Serializable> extends CrudRepository<T, ID> { public interface PagingAndSortingRepository<T, ID> extends CrudRepository<T, ID> {
/** /**
* Returns all entities sorted by the given options. * Returns all entities sorted by the given options.

4
src/main/java/org/springframework/data/repository/Repository.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.repository; package org.springframework.data.repository;
import java.io.Serializable;
import org.springframework.stereotype.Indexed; import org.springframework.stereotype.Indexed;
/** /**
@ -33,6 +31,6 @@ import org.springframework.stereotype.Indexed;
* @author Oliver Gierke * @author Oliver Gierke
*/ */
@Indexed @Indexed
public interface Repository<T, ID extends Serializable> { public interface Repository<T, ID> {
} }

3
src/main/java/org/springframework/data/repository/RepositoryDefinition.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository; package org.springframework.data.repository;
import java.io.Serializable;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited; import java.lang.annotation.Inherited;
@ -53,5 +52,5 @@ public @interface RepositoryDefinition {
* @see Repository * @see Repository
* @return * @return
*/ */
Class<? extends Serializable> idClass(); Class<?> idClass();
} }

2
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 * 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. * @return the find one method of the repository or {@literal null} if not available.
* @see #hasFindOneMethod() * @see #hasFindOneMethod()

4
src/main/java/org/springframework/data/repository/core/EntityInformation.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.core; package org.springframework.data.repository.core;
import java.io.Serializable;
import java.util.Optional; import java.util.Optional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -25,7 +24,7 @@ import org.springframework.util.Assert;
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
public interface EntityInformation<T, ID extends Serializable> extends EntityMetadata<T> { public interface EntityInformation<T, ID> extends EntityMetadata<T> {
/** /**
* Returns whether the given entity is considered to be new. * Returns whether the given entity is considered to be new.
@ -49,6 +48,7 @@ public interface EntityInformation<T, ID extends Serializable> extends EntityMet
* @param entity must not be {@literal null}. * @param entity must not be {@literal null}.
* @return the identifier of the given entity * @return the identifier of the given entity
* @throws IllegalArgumentException in case no id could be obtained from 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 { default ID getRequiredId(T entity) throws IllegalArgumentException {

3
src/main/java/org/springframework/data/repository/core/RepositoryMetadata.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.core; package org.springframework.data.repository.core;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collection; import java.util.Collection;
import java.util.Set; 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. * @return the id class of the entity managed by the repository for or {@code null} if none found.
*/ */
Class<? extends Serializable> getIdType(); Class<?> getIdType();
/** /**
* Returns the domain class the repository is declared for. * Returns the domain class the repository is declared for.

21
src/main/java/org/springframework/data/repository/core/support/AbstractEntityInformation.java

@ -15,11 +15,12 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.Optional; import java.util.Optional;
import org.springframework.data.repository.core.EntityInformation; 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 * 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 Oliver Gierke
* @author Nick Williams * @author Nick Williams
*/ */
public abstract class AbstractEntityInformation<T, ID extends Serializable> implements EntityInformation<T, ID> { @RequiredArgsConstructor
public abstract class AbstractEntityInformation<T, ID> implements EntityInformation<T, ID> {
private final Class<T> domainClass;
/**
* Creates a new {@link AbstractEntityInformation} from the given domain class.
*
* @param domainClass must not be {@literal null}.
*/
public AbstractEntityInformation(Class<T> domainClass) {
Assert.notNull(domainClass, "DomainClass must not be null!"); private final @NonNull Class<T> domainClass;
this.domainClass = domainClass;
}
/* /*
* (non-Javadoc) * (non-Javadoc)

8
src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable;
import org.springframework.data.repository.RepositoryDefinition; import org.springframework.data.repository.RepositoryDefinition;
import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.util.Assert; 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!", private static final String NO_ANNOTATION_FOUND = String.format("Interface must be annotated with @%s!",
RepositoryDefinition.class.getName()); RepositoryDefinition.class.getName());
private final Class<? extends Serializable> idType; private final Class<?> idType;
private final Class<?> domainType; private final Class<?> domainType;
/** /**
@ -56,7 +54,7 @@ public class AnnotationRepositoryMetadata extends AbstractRepositoryMetadata {
* @see org.springframework.data.repository.core.RepositoryMetadata#getIdType() * @see org.springframework.data.repository.core.RepositoryMetadata#getIdType()
*/ */
@Override @Override
public Class<? extends Serializable> getIdType() { public Class<?> getIdType() {
return this.idType; return this.idType;
} }
@ -69,7 +67,7 @@ public class AnnotationRepositoryMetadata extends AbstractRepositoryMetadata {
return this.domainType; return this.domainType;
} }
private Class<? extends Serializable> resolveIdType(Class<?> repositoryInterface) { private Class<?> resolveIdType(Class<?> repositoryInterface) {
RepositoryDefinition annotation = repositoryInterface.getAnnotation(RepositoryDefinition.class); RepositoryDefinition annotation = repositoryInterface.getAnnotation(RepositoryDefinition.class);

109
src/main/java/org/springframework/data/repository/core/support/DefaultCrudMethods.java

@ -16,19 +16,21 @@
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static org.springframework.util.ClassUtils.*; import static org.springframework.data.util.Optionals.*;
import static org.springframework.util.ReflectionUtils.*;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Optional; 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.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.repository.CrudRepository; 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.CrudMethods;
import org.springframework.data.repository.core.RepositoryMetadata; 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.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
@ -44,10 +46,12 @@ import org.springframework.util.ReflectionUtils;
*/ */
public class DefaultCrudMethods implements CrudMethods { 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 SAVE = "save";
private static final String FIND_ALL = "findAll"; private static final String FIND_ALL = "findAll";
private static final String DELETE = "delete"; private static final String DELETE = "delete";
private static final String DELETE_BY_ID = "deleteById";
private final Optional<Method> findAllMethod; private final Optional<Method> findAllMethod;
private final Optional<Method> findOneMethod; private final Optional<Method> findOneMethod;
@ -79,18 +83,12 @@ public class DefaultCrudMethods implements CrudMethods {
* @param metadata must not be {@literal null}. * @param metadata must not be {@literal null}.
* @return the most suitable method or {@literal null} if no method could be found. * @return the most suitable method or {@literal null} if no method could be found.
*/ */
private Optional<Method> selectMostSuitableSaveMethod(RepositoryMetadata metadata) { private static Optional<Method> selectMostSuitableSaveMethod(RepositoryMetadata metadata) {
for (Class<?> type : asList(metadata.getDomainType(), Object.class)) {
Method saveMethodCandidate = findMethod(metadata.getRepositoryInterface(), SAVE, type);
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 {
* <ol> * <ol>
* <li>a {@link RepositoryMetadata#getDomainType()} as first parameter over</li> * <li>a {@link RepositoryMetadata#getDomainType()} as first parameter over</li>
* <li>a {@link RepositoryMetadata#getIdType()} as first parameter over</li> * <li>a {@link RepositoryMetadata#getIdType()} as first parameter over</li>
* <li>a {@link Serializable} as first parameter over</li> * <li>a {@link Object} as first parameter over</li>
* <li>an {@link Iterable} as first parameter.</li> * <li>an {@link Iterable} as first parameter.</li>
* </ol> * </ol>
* *
* @param metadata must not be {@literal null}. * @param metadata must not be {@literal null}.
* @return the most suitable method or {@literal null} if no method could be found. * @return the most suitable method or {@literal null} if no method could be found.
*/ */
private Optional<Method> selectMostSuitableDeleteMethod(RepositoryMetadata metadata) { private static Optional<Method> selectMostSuitableDeleteMethod(RepositoryMetadata metadata) {
for (Class<?> type : asList(metadata.getDomainType(), metadata.getIdType(), Serializable.class, Iterable.class)) { Stream<Pair<String, Class<?>>> 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));
Method candidate = findMethod(metadata.getRepositoryInterface(), DELETE, type); Class<?> repositoryInterface = metadata.getRepositoryInterface();
if (candidate != null) { return source//
return getMostSpecificMethod(candidate, metadata.getRepositoryInterface()); .flatMap(it -> toStream(findMethod(repositoryInterface, it.getFirst(), it.getSecond())))//
} .flatMap(it -> toStream(getMostSpecificMethod(it, repositoryInterface)))//
} .findFirst();
return Optional.empty();
} }
/** /**
@ -130,49 +131,37 @@ public class DefaultCrudMethods implements CrudMethods {
* @param metadata must not be {@literal null}. * @param metadata must not be {@literal null}.
* @return the most suitable method or {@literal null} if no method could be found. * @return the most suitable method or {@literal null} if no method could be found.
*/ */
private Optional<Method> selectMostSuitableFindAllMethod(RepositoryMetadata metadata) { private static Optional<Method> selectMostSuitableFindAllMethod(RepositoryMetadata metadata) {
for (Class<?> type : asList(Pageable.class, Sort.class)) {
if (hasMethod(metadata.getRepositoryInterface(), FIND_ALL, type)) {
Method candidate = findMethod(PagingAndSortingRepository.class, FIND_ALL, type); Class<?> repositoryInterface = metadata.getRepositoryInterface();
if (candidate != null) { Supplier<Optional<Method>> withPageableOrSort = () -> Stream.of(Pageable.class, Sort.class)//
return getMostSpecificMethod(candidate, metadata.getRepositoryInterface()); .flatMap(it -> toStream(findMethod(repositoryInterface, FIND_ALL, it)))//
} .flatMap(it -> toStream(getMostSpecificMethod(it, repositoryInterface)))//
} .findFirst();
}
if (hasMethod(metadata.getRepositoryInterface(), FIND_ALL)) { Supplier<Optional<Method>> withoutParameter = () -> findMethod(repositoryInterface, FIND_ALL)//
return getMostSpecificMethod(findMethod(CrudRepository.class, FIND_ALL), metadata.getRepositoryInterface()); .flatMap(it -> getMostSpecificMethod(it, repositoryInterface));
}
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
* <ol> * <ol>
* <li>a {@link RepositoryMetadata#getIdType()} as first parameter over</li> * <li>a {@link RepositoryMetadata#getIdType()} as first parameter over</li>
* <li>a {@link Serializable} as first parameter</li> * <li>a {@link Object} as first parameter</li>
* </ol> * </ol>
* *
* @param metadata must not be {@literal null}. * @param metadata must not be {@literal null}.
* @return the most suitable method or {@literal null} if no method could be found. * @return the most suitable method or {@literal null} if no method could be found.
*/ */
private Optional<Method> selectMostSuitableFindOneMethod(RepositoryMetadata metadata) { private static Optional<Method> selectMostSuitableFindOneMethod(RepositoryMetadata metadata) {
for (Class<?> type : asList(metadata.getIdType(), Serializable.class)) {
Method candidate = findMethod(metadata.getRepositoryInterface(), FIND_ONE, type);
if (candidate != null) { return asList(metadata.getIdType(), Object.class).stream()//
return getMostSpecificMethod(candidate, metadata.getRepositoryInterface()); .flatMap(it -> toStream(findMethod(metadata.getRepositoryInterface(), FIND_ONE, it)))//
} .flatMap(it -> toStream(getMostSpecificMethod(it, metadata.getRepositoryInterface())))//
} .findFirst();
return Optional.empty();
} }
/** /**
@ -186,10 +175,10 @@ public class DefaultCrudMethods implements CrudMethods {
*/ */
private static Optional<Method> getMostSpecificMethod(Method method, Class<?> type) { private static Optional<Method> getMostSpecificMethod(Method method, Class<?> type) {
return Optional.ofNullable(ClassUtils.getMostSpecificMethod(method, type)).map(it -> { return Optionals.toStream(Optional.ofNullable(ClassUtils.getMostSpecificMethod(method, type)))//
ReflectionUtils.makeAccessible(it); .map(it -> BridgeMethodResolver.findBridgedMethod(it))//
return it; .peek(it -> ReflectionUtils.makeAccessible(it))//
}); .findFirst();
} }
/* /*
@ -263,4 +252,8 @@ public class DefaultCrudMethods implements CrudMethods {
public Optional<Method> getDeleteMethod() { public Optional<Method> getDeleteMethod() {
return this.deleteMethod; return this.deleteMethod;
} }
private static Optional<Method> findMethod(Class<?> type, String name, Class<?>... parameterTypes) {
return Optional.ofNullable(ReflectionUtils.findMethod(type, name, parameterTypes));
}
} }

3
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.data.repository.util.ClassUtils.*;
import static org.springframework.util.ReflectionUtils.*; import static org.springframework.util.ReflectionUtils.*;
import java.io.Serializable;
import java.lang.reflect.GenericDeclaration; import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@ -101,7 +100,7 @@ class DefaultRepositoryInformation implements RepositoryInformation {
* @see org.springframework.data.repository.support.RepositoryMetadata#getIdClass() * @see org.springframework.data.repository.support.RepositoryMetadata#getIdClass()
*/ */
@Override @Override
public Class<? extends Serializable> getIdType() { public Class<?> getIdType() {
return metadata.getIdType(); return metadata.getIdType();
} }

10
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 lombok.Getter;
import java.io.Serializable;
import java.util.List; import java.util.List;
import org.springframework.data.repository.Repository; 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!", private static final String MUST_BE_A_REPOSITORY = String.format("Given type must be assignable to %s!",
Repository.class); Repository.class);
private final Class<? extends Serializable> idType; private final Class<?> idType;
private final Class<?> domainType; private final Class<?> domainType;
/** /**
@ -56,8 +55,7 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata {
this.domainType = resolveDomainType(repositoryInterface); this.domainType = resolveDomainType(repositoryInterface);
} }
@SuppressWarnings("unchecked") private static Class<?> resolveIdType(Class<?> repositoryInterface) {
private Class<? extends Serializable> resolveIdType(Class<?> repositoryInterface) {
TypeInformation<?> information = ClassTypeInformation.from(repositoryInterface); TypeInformation<?> information = ClassTypeInformation.from(repositoryInterface);
List<TypeInformation<?>> arguments = information.getSuperTypeInformation(Repository.class).getTypeArguments(); List<TypeInformation<?>> 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)); throw new IllegalArgumentException(String.format("Could not resolve id type of %s!", repositoryInterface));
} }
return (Class<? extends Serializable>) 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); TypeInformation<?> information = ClassTypeInformation.from(repositoryInterface);
List<TypeInformation<?>> arguments = information.getSuperTypeInformation(Repository.class).getTypeArguments(); List<TypeInformation<?>> arguments = information.getSuperTypeInformation(Repository.class).getTypeArguments();

22
src/main/java/org/springframework/data/repository/core/support/DelegatingEntityInformation.java

@ -15,11 +15,12 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.Optional; import java.util.Optional;
import org.springframework.data.repository.core.EntityInformation; 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 * 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 * @author Oliver Gierke
*/ */
public class DelegatingEntityInformation<T, ID extends Serializable> implements EntityInformation<T, ID> { @RequiredArgsConstructor
public class DelegatingEntityInformation<T, ID> implements EntityInformation<T, ID> {
private final EntityInformation<T, ID> delegate;
/**
* Creates a new {@link DelegatingEntityInformation} delegating method invocations to the given
* {@link EntityInformation}.
*
* @param delegate
*/
public DelegatingEntityInformation(EntityInformation<T, ID> delegate) {
Assert.notNull(delegate, "Delegate EnittyInformation must not be null!"); private final @NonNull EntityInformation<T, ID> delegate;
this.delegate = delegate;
}
/* /*
* (non-Javadoc) * (non-Javadoc)

4
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 lombok.RequiredArgsConstructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.stream.Stream;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
@ -90,7 +90,7 @@ public class EventPublishingRepositoryProxyPostProcessor implements RepositoryPr
Object result = invocation.proceed(); Object result = invocation.proceed();
if (!invocation.getMethod().getName().equals("save")) { if (!Stream.of("save", "saveAll").anyMatch(it -> invocation.getMethod().getName().equals(it))) {
return result; return result;
} }

8
src/main/java/org/springframework/data/repository/core/support/PersistableEntityInformation.java

@ -15,10 +15,9 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable;
import java.util.Optional; import java.util.Optional;
import org.springframework.core.GenericTypeResolver; import org.springframework.core.ResolvableType;
import org.springframework.data.domain.Persistable; import org.springframework.data.domain.Persistable;
import org.springframework.data.repository.core.EntityMetadata; import org.springframework.data.repository.core.EntityMetadata;
@ -28,8 +27,7 @@ import org.springframework.data.repository.core.EntityMetadata;
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
public class PersistableEntityInformation<T extends Persistable<ID>, ID extends Serializable> public class PersistableEntityInformation<T extends Persistable<ID>, ID> extends AbstractEntityInformation<T, ID> {
extends AbstractEntityInformation<T, ID> {
private Class<ID> idClass; private Class<ID> idClass;
@ -42,7 +40,7 @@ public class PersistableEntityInformation<T extends Persistable<ID>, ID extends
public PersistableEntityInformation(Class<T> domainClass) { public PersistableEntityInformation(Class<T> domainClass) {
super(domainClass); super(domainClass);
this.idClass = (Class<ID>) GenericTypeResolver.resolveTypeArgument(domainClass, Persistable.class); this.idClass = (Class<ID>) ResolvableType.forClass(Persistable.class, domainClass).resolveGeneric(0);
} }
/* /*

3
src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable;
import java.util.Optional; import java.util.Optional;
import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentEntity;
@ -30,7 +29,7 @@ import org.springframework.data.repository.core.EntityInformation;
* @author Christoph Strobl * @author Christoph Strobl
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class PersistentEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID> { public class PersistentEntityInformation<T, ID> extends AbstractEntityInformation<T, ID> {
private final PersistentEntity<T, ? extends PersistentProperty<?>> persistentEntity; private final PersistentEntity<T, ? extends PersistentProperty<?>> persistentEntity;

3
src/main/java/org/springframework/data/repository/core/support/ReflectionEntityInformation.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Optional; import java.util.Optional;
@ -32,7 +31,7 @@ import org.springframework.util.ReflectionUtils;
* @author Oliver Gierke * @author Oliver Gierke
* @author Christoph Strobl * @author Christoph Strobl
*/ */
public class ReflectionEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID> { public class ReflectionEntityInformation<T, ID> extends AbstractEntityInformation<T, ID> {
private static final Class<Id> DEFAULT_ID_ANNOTATION = Id.class; private static final Class<Id> DEFAULT_ID_ANNOTATION = Id.class;

3
src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -50,7 +49,7 @@ import org.springframework.util.Assert;
* @author Oliver Gierke * @author Oliver Gierke
* @author Thomas Darimont * @author Thomas Darimont
*/ */
public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>, S, ID extends Serializable> public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>, S, ID>
implements InitializingBean, RepositoryFactoryInformation<S, ID>, FactoryBean<T>, BeanClassLoaderAware, implements InitializingBean, RepositoryFactoryInformation<S, ID>, FactoryBean<T>, BeanClassLoaderAware,
BeanFactoryAware, ApplicationEventPublisherAware { BeanFactoryAware, ApplicationEventPublisherAware {

3
src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryInformation.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable;
import java.util.List; import java.util.List;
import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentEntity;
@ -31,7 +30,7 @@ import org.springframework.data.repository.query.QueryMethod;
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
public interface RepositoryFactoryInformation<T, ID extends Serializable> { public interface RepositoryFactoryInformation<T, ID> {
/** /**
* Returns {@link EntityInformation} the repository factory is using. * Returns {@link EntityInformation} the repository factory is using.

3
src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java

@ -19,7 +19,6 @@ import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
@ -291,7 +290,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
* @param domainClass * @param domainClass
* @return * @return
*/ */
public abstract <T, ID extends Serializable> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass); public abstract <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass);
/** /**
* Create a repository instance as backing for the query proxy. * Create a repository instance as backing for the query proxy.

4
src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java

@ -15,8 +15,6 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
@ -32,7 +30,7 @@ import org.springframework.util.Assert;
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
public abstract class TransactionalRepositoryFactoryBeanSupport<T extends Repository<S, ID>, S, ID extends Serializable> public abstract class TransactionalRepositoryFactoryBeanSupport<T extends Repository<S, ID>, S, ID>
extends RepositoryFactoryBeanSupport<T, S, ID> implements BeanFactoryAware { extends RepositoryFactoryBeanSupport<T, S, ID> implements BeanFactoryAware {
private String transactionManagerName = TxUtils.DEFAULT_TRANSACTION_MANAGER; private String transactionManagerName = TxUtils.DEFAULT_TRANSACTION_MANAGER;

4
src/main/java/org/springframework/data/repository/history/RevisionRepository.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.history; package org.springframework.data.repository.history;
import java.io.Serializable;
import java.util.Optional; import java.util.Optional;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -33,8 +32,7 @@ import org.springframework.data.repository.Repository;
* @author Philipp Huegelmeyer * @author Philipp Huegelmeyer
*/ */
@NoRepositoryBean @NoRepositoryBean
public interface RevisionRepository<T, ID extends Serializable, N extends Number & Comparable<N>> public interface RevisionRepository<T, ID, N extends Number & Comparable<N>> extends Repository<T, ID> {
extends Repository<T, ID> {
/** /**
* Returns the revision of the entity it was last changed in. * Returns the revision of the entity it was last changed in.

30
src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java

@ -15,15 +15,13 @@
*/ */
package org.springframework.data.repository.reactive; 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.reactivestreams.Publisher;
import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository; 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 * 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. * and uses Project Reactor types which are built on top of Reactive Streams.
@ -34,7 +32,7 @@ import reactor.core.publisher.Mono;
* @see Flux * @see Flux
*/ */
@NoRepositoryBean @NoRepositoryBean
public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repository<T, ID> { public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
/** /**
* Saves a given entity. Use the returned instance for further operations as the save operation might have changed the * 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<T, ID extends Serializable> extends Repo
* @return the saved entities. * @return the saved entities.
* @throws IllegalArgumentException in case the given entity is {@literal null}. * @throws IllegalArgumentException in case the given entity is {@literal null}.
*/ */
<S extends T> Flux<S> save(Iterable<S> entities); <S extends T> Flux<S> saveAll(Iterable<S> entities);
/** /**
* Saves all given entities. * Saves all given entities.
@ -61,7 +59,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @return the saved entities. * @return the saved entities.
* @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}. * @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}.
*/ */
<S extends T> Flux<S> save(Publisher<S> entityStream); <S extends T> Flux<S> saveAll(Publisher<S> entityStream);
/** /**
* Retrieves an entity by its id. * Retrieves an entity by its id.
@ -70,7 +68,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @return the entity with the given id or {@link Mono#empty()} if none found. * @return the entity with the given id or {@link Mono#empty()} if none found.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Mono<T> findOne(ID id); Mono<T> findById(ID id);
/** /**
* Retrieves an entity by its id supplied by a {@link Mono}. * Retrieves an entity by its id supplied by a {@link Mono}.
@ -79,7 +77,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @return the entity with the given id or {@link Mono#empty()} if none found. * @return the entity with the given id or {@link Mono#empty()} if none found.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Mono<T> findOne(Mono<ID> id); Mono<T> findById(Mono<ID> id);
/** /**
* Returns whether an entity with the given id exists. * Returns whether an entity with the given id exists.
@ -88,7 +86,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Mono<Boolean> exists(ID id); Mono<Boolean> existsById(ID id);
/** /**
* Returns whether an entity with the given id, supplied by a {@link Mono}, exists. * Returns whether an entity with the given id, supplied by a {@link Mono}, exists.
@ -97,7 +95,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise
* @throws IllegalArgumentException if {@code id} is {@literal null} * @throws IllegalArgumentException if {@code id} is {@literal null}
*/ */
Mono<Boolean> exists(Mono<ID> id); Mono<Boolean> existsById(Mono<ID> id);
/** /**
* Returns all instances of the type. * Returns all instances of the type.
@ -112,7 +110,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @param ids must not be {@literal null}. * @param ids must not be {@literal null}.
* @return the found entities. * @return the found entities.
*/ */
Flux<T> findAll(Iterable<ID> ids); Flux<T> findAllById(Iterable<ID> ids);
/** /**
* Returns all instances of the type with the given IDs. * Returns all instances of the type with the given IDs.
@ -120,7 +118,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @param idStream must not be {@literal null}. * @param idStream must not be {@literal null}.
* @return the found entities. * @return the found entities.
*/ */
Flux<T> findAll(Publisher<ID> idStream); Flux<T> findAllById(Publisher<ID> idStream);
/** /**
* Returns the number of entities available. * Returns the number of entities available.
@ -135,7 +133,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @param id must not be {@literal null}. * @param id must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}. * @throws IllegalArgumentException in case the given {@code id} is {@literal null}.
*/ */
Mono<Void> delete(ID id); Mono<Void> deleteById(ID id);
/** /**
* Deletes a given entity. * Deletes a given entity.
@ -151,7 +149,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @param entities must not be {@literal null}. * @param entities must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}. * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
*/ */
Mono<Void> delete(Iterable<? extends T> entities); Mono<Void> deleteAll(Iterable<? extends T> entities);
/** /**
* Deletes the given entities. * Deletes the given entities.
@ -159,7 +157,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @param entityStream must not be {@literal null}. * @param entityStream must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@link Publisher} is {@literal null}. * @throws IllegalArgumentException in case the given {@link Publisher} is {@literal null}.
*/ */
Mono<Void> delete(Publisher<? extends T> entityStream); Mono<Void> deleteAll(Publisher<? extends T> entityStream);
/** /**
* Deletes all entities managed by the repository. * Deletes all entities managed by the repository.

8
src/main/java/org/springframework/data/repository/reactive/ReactiveSortingRepository.java

@ -15,14 +15,12 @@
*/ */
package org.springframework.data.repository.reactive; 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.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean; 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 * Extension of {@link ReactiveCrudRepository} to provide additional methods to retrieve entities using the sorting
* abstraction. * abstraction.
@ -34,7 +32,7 @@ import reactor.core.publisher.Mono;
* @see Flux * @see Flux
*/ */
@NoRepositoryBean @NoRepositoryBean
public interface ReactiveSortingRepository<T, ID extends Serializable> extends ReactiveCrudRepository<T, ID> { public interface ReactiveSortingRepository<T, ID> extends ReactiveCrudRepository<T, ID> {
/** /**
* Returns all entities sorted by the given options. * Returns all entities sorted by the given options.

32
src/main/java/org/springframework/data/repository/reactive/RxJava1CrudRepository.java

@ -15,15 +15,13 @@
*/ */
package org.springframework.data.repository.reactive; 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.Completable;
import rx.Observable; import rx.Observable;
import rx.Single; 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 * Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms
* and uses RxJava 1 types. * and uses RxJava 1 types.
@ -34,7 +32,7 @@ import rx.Single;
* @see Observable * @see Observable
*/ */
@NoRepositoryBean @NoRepositoryBean
public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repository<T, ID> { public interface RxJava1CrudRepository<T, ID> extends Repository<T, ID> {
/** /**
* Saves a given entity. Use the returned instance for further operations as the save operation might have changed the * 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<T, ID extends Serializable> extends Repos
* @return the saved entities. * @return the saved entities.
* @throws IllegalArgumentException in case the given entity is {@literal null}. * @throws IllegalArgumentException in case the given entity is {@literal null}.
*/ */
<S extends T> Observable<S> save(Iterable<S> entities); <S extends T> Observable<S> saveAll(Iterable<S> entities);
/** /**
* Saves all given entities. * Saves all given entities.
@ -61,7 +59,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @return the saved entities. * @return the saved entities.
* @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}. * @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}.
*/ */
<S extends T> Observable<S> save(Observable<S> entityStream); <S extends T> Observable<S> saveAll(Observable<S> entityStream);
/** /**
* Retrieves an entity by its id. * Retrieves an entity by its id.
@ -70,7 +68,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @return the entity with the given id or {@link Observable#empty()} if none found. * @return the entity with the given id or {@link Observable#empty()} if none found.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Observable<T> findOne(ID id); Observable<T> findById(ID id);
/** /**
* Retrieves an entity by its id supplied by a {@link Single}. * Retrieves an entity by its id supplied by a {@link Single}.
@ -79,7 +77,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @return the entity with the given id or {@link Observable#empty()} if none found. * @return the entity with the given id or {@link Observable#empty()} if none found.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Observable<T> findOne(Single<ID> id); Observable<T> findById(Single<ID> id);
/** /**
* Returns whether an entity with the given id exists. * Returns whether an entity with the given id exists.
@ -88,7 +86,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Single<Boolean> exists(ID id); Single<Boolean> existsById(ID id);
/** /**
* Returns whether an entity with the given id, supplied by a {@link Single}, exists. * Returns whether an entity with the given id, supplied by a {@link Single}, exists.
@ -97,7 +95,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Single<Boolean> exists(Single<ID> id); Single<Boolean> existsById(Single<ID> id);
/** /**
* Returns all instances of the type. * Returns all instances of the type.
@ -112,7 +110,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @param ids must not be {@literal null}. * @param ids must not be {@literal null}.
* @return the found entities. * @return the found entities.
*/ */
Observable<T> findAll(Iterable<ID> ids); Observable<T> findAllById(Iterable<ID> ids);
/** /**
* Returns all instances of the type with the given IDs. * Returns all instances of the type with the given IDs.
@ -120,7 +118,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @param idStream must not be {@literal null}. * @param idStream must not be {@literal null}.
* @return the found entities. * @return the found entities.
*/ */
Observable<T> findAll(Observable<ID> idStream); Observable<T> findAllById(Observable<ID> idStream);
/** /**
* Returns the number of entities available. * Returns the number of entities available.
@ -135,7 +133,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @param id must not be {@literal null}. * @param id must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@code id} is {@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. * Deletes a given entity.
@ -151,7 +149,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @param entities must not be {@literal null}. * @param entities must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}. * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
*/ */
Completable delete(Iterable<? extends T> entities); Completable deleteAll(Iterable<? extends T> entities);
/** /**
* Deletes the given entities. * Deletes the given entities.
@ -159,7 +157,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @param entityStream must not be {@literal null}. * @param entityStream must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@link Observable} is {@literal null}. * @throws IllegalArgumentException in case the given {@link Observable} is {@literal null}.
*/ */
Completable delete(Observable<? extends T> entityStream); Completable deleteAll(Observable<? extends T> entityStream);
/** /**
* Deletes all entities managed by the repository. * Deletes all entities managed by the repository.

8
src/main/java/org/springframework/data/repository/reactive/RxJava1SortingRepository.java

@ -15,14 +15,12 @@
*/ */
package org.springframework.data.repository.reactive; 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.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean; 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 * Extension of {@link RxJava1CrudRepository} to provide additional methods to retrieve entities using the sorting
* abstraction. * abstraction.
@ -35,7 +33,7 @@ import rx.Single;
* @see RxJava1CrudRepository * @see RxJava1CrudRepository
*/ */
@NoRepositoryBean @NoRepositoryBean
public interface RxJava1SortingRepository<T, ID extends Serializable> extends RxJava1CrudRepository<T, ID> { public interface RxJava1SortingRepository<T, ID> extends RxJava1CrudRepository<T, ID> {
/** /**
* Returns all entities sorted by the given options. * Returns all entities sorted by the given options.

26
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.Maybe;
import io.reactivex.Single; import io.reactivex.Single;
import java.io.Serializable;
import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
@ -37,7 +35,7 @@ import org.springframework.data.repository.Repository;
* @see Completable * @see Completable
*/ */
@NoRepositoryBean @NoRepositoryBean
public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repository<T, ID> { public interface RxJava2CrudRepository<T, ID> extends Repository<T, ID> {
/** /**
* Saves a given entity. Use the returned instance for further operations as the save operation might have changed the * 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<T, ID extends Serializable> extends Repos
* @return the saved entities. * @return the saved entities.
* @throws IllegalArgumentException in case the given entity is {@literal null}. * @throws IllegalArgumentException in case the given entity is {@literal null}.
*/ */
<S extends T> Flowable<S> save(Iterable<S> entities); <S extends T> Flowable<S> saveAll(Iterable<S> entities);
/** /**
* Saves all given entities. * Saves all given entities.
@ -64,7 +62,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @return the saved entities. * @return the saved entities.
* @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}. * @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}.
*/ */
<S extends T> Flowable<S> save(Flowable<S> entityStream); <S extends T> Flowable<S> saveAll(Flowable<S> entityStream);
/** /**
* Retrieves an entity by its id. * Retrieves an entity by its id.
@ -73,7 +71,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @return the entity with the given id or {@link Maybe#empty()} if none found. * @return the entity with the given id or {@link Maybe#empty()} if none found.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Maybe<T> findOne(ID id); Maybe<T> findById(ID id);
/** /**
* Retrieves an entity by its id supplied by a {@link Single}. * Retrieves an entity by its id supplied by a {@link Single}.
@ -82,7 +80,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @return the entity with the given id or {@link Maybe#empty()} if none found. * @return the entity with the given id or {@link Maybe#empty()} if none found.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Maybe<T> findOne(Single<ID> id); Maybe<T> findById(Single<ID> id);
/** /**
* Returns whether an entity with the given id exists. * Returns whether an entity with the given id exists.
@ -91,7 +89,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
* @throws IllegalArgumentException if {@code id} is {@literal null}. * @throws IllegalArgumentException if {@code id} is {@literal null}.
*/ */
Single<Boolean> exists(ID id); Single<Boolean> existsById(ID id);
/** /**
* Returns whether an entity with the given id, supplied by a {@link Single}, exists. * Returns whether an entity with the given id, supplied by a {@link Single}, exists.
@ -100,7 +98,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
* @throws IllegalArgumentException if {@code id} is {@literal null} * @throws IllegalArgumentException if {@code id} is {@literal null}
*/ */
Single<Boolean> exists(Single<ID> id); Single<Boolean> existsById(Single<ID> id);
/** /**
* Returns all instances of the type. * Returns all instances of the type.
@ -115,7 +113,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @param ids must not be {@literal null}. * @param ids must not be {@literal null}.
* @return the found entities. * @return the found entities.
*/ */
Flowable<T> findAll(Iterable<ID> ids); Flowable<T> findAllById(Iterable<ID> ids);
/** /**
* Returns all instances of the type with the given IDs. * Returns all instances of the type with the given IDs.
@ -123,7 +121,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @param idStream must not be {@literal null}. * @param idStream must not be {@literal null}.
* @return the found entities. * @return the found entities.
*/ */
Flowable<T> findAll(Flowable<ID> idStream); Flowable<T> findAllById(Flowable<ID> idStream);
/** /**
* Returns the number of entities available. * Returns the number of entities available.
@ -138,7 +136,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @param id must not be {@literal null}. * @param id must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@code id} is {@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. * Deletes a given entity.
@ -154,7 +152,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @param entities must not be {@literal null}. * @param entities must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}. * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
*/ */
Completable delete(Iterable<? extends T> entities); Completable deleteAll(Iterable<? extends T> entities);
/** /**
* Deletes the given entities. * Deletes the given entities.
@ -162,7 +160,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @param entityStream must not be {@literal null}. * @param entityStream must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@link Flowable} is {@literal null}. * @throws IllegalArgumentException in case the given {@link Flowable} is {@literal null}.
*/ */
Completable delete(Flowable<? extends T> entityStream); Completable deleteAll(Flowable<? extends T> entityStream);
/** /**
* Deletes all entities managed by the repository. * Deletes all entities managed by the repository.

4
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 io.reactivex.Flowable;
import java.io.Serializable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.NoRepositoryBean;
@ -33,7 +31,7 @@ import org.springframework.data.repository.NoRepositoryBean;
* @see RxJava2CrudRepository * @see RxJava2CrudRepository
*/ */
@NoRepositoryBean @NoRepositoryBean
public interface RxJava2SortingRepository<T, ID extends Serializable> extends RxJava2CrudRepository<T, ID> { public interface RxJava2SortingRepository<T, ID> extends RxJava2CrudRepository<T, ID> {
/** /**
* Returns all entities sorted by the given options. * Returns all entities sorted by the given options.

19
src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.support; package org.springframework.data.repository.support;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Optional; import java.util.Optional;
@ -36,7 +35,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
*/ */
class CrudRepositoryInvoker extends ReflectionRepositoryInvoker { class CrudRepositoryInvoker extends ReflectionRepositoryInvoker {
private final CrudRepository<Object, Serializable> repository; private final CrudRepository<Object, Object> repository;
private final boolean customSaveMethod; private final boolean customSaveMethod;
private final boolean customFindOneMethod; private final boolean customFindOneMethod;
@ -51,7 +50,7 @@ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker {
* @param metadata must not be {@literal null}. * @param metadata must not be {@literal null}.
* @param conversionService must not be {@literal null}. * @param conversionService must not be {@literal null}.
*/ */
public CrudRepositoryInvoker(CrudRepository<Object, Serializable> repository, RepositoryMetadata metadata, public CrudRepositoryInvoker(CrudRepository<Object, Object> repository, RepositoryMetadata metadata,
ConversionService conversionService) { ConversionService conversionService) {
super(repository, metadata, conversionService); super(repository, metadata, conversionService);
@ -85,12 +84,12 @@ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker {
/* /*
* (non-Javadoc) * (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 @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> Optional<T> invokeFindOne(Serializable id) { public <T> Optional<T> invokeFindById(Object id) {
return customFindOneMethod ? super.invokeFindOne(id) : (Optional<T>) repository.findOne(convertId(id)); return customFindOneMethod ? super.invokeFindById(id) : (Optional<T>) repository.findById(convertId(id));
} }
/* /*
@ -104,15 +103,15 @@ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker {
/* /*
* (non-Javadoc) * (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 @Override
public void invokeDelete(Serializable id) { public void invokeDeleteById(Object id) {
if (customDeleteMethod) { if (customDeleteMethod) {
super.invokeDelete(id); super.invokeDeleteById(id);
} else { } else {
repository.delete(convertId(id)); repository.deleteById(convertId(id));
} }
} }

8
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 static org.springframework.data.util.Optionals.*;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -100,11 +99,10 @@ public class DefaultRepositoryInvokerFactory implements RepositoryInvokerFactory
protected RepositoryInvoker createInvoker(RepositoryInformation information, Object repository) { protected RepositoryInvoker createInvoker(RepositoryInformation information, Object repository) {
if (repository instanceof PagingAndSortingRepository) { if (repository instanceof PagingAndSortingRepository) {
return new PagingAndSortingRepositoryInvoker((PagingAndSortingRepository<Object, Serializable>) repository, return new PagingAndSortingRepositoryInvoker((PagingAndSortingRepository<Object, Object>) repository, information,
information, conversionService);
} else if (repository instanceof CrudRepository) {
return new CrudRepositoryInvoker((CrudRepository<Object, Serializable>) repository, information,
conversionService); conversionService);
} else if (repository instanceof CrudRepository) {
return new CrudRepositoryInvoker((CrudRepository<Object, Object>) repository, information, conversionService);
} else { } else {
return new ReflectionRepositoryInvoker(repository, information, conversionService); return new ReflectionRepositoryInvoker(repository, information, conversionService);
} }

2
src/main/java/org/springframework/data/repository/support/DomainClassConverter.java

@ -154,7 +154,7 @@ public class DomainClassConverter<T extends ConversionService & ConverterRegistr
RepositoryInvoker invoker = repositoryInvokerFactory.getInvokerFor(domainType); RepositoryInvoker invoker = repositoryInvokerFactory.getInvokerFor(domainType);
RepositoryInformation information = repositories.getRequiredRepositoryInformation(domainType); RepositoryInformation information = repositories.getRequiredRepositoryInformation(domainType);
return invoker.invokeFindOne(conversionService.convert(source, information.getIdType())).orElse(null); return invoker.invokeFindById(conversionService.convert(source, information.getIdType())).orElse(null);
} }
/* /*

5
src/main/java/org/springframework/data/repository/support/PagingAndSortingRepositoryInvoker.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.support; package org.springframework.data.repository.support;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Optional; import java.util.Optional;
@ -35,7 +34,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
*/ */
class PagingAndSortingRepositoryInvoker extends CrudRepositoryInvoker { class PagingAndSortingRepositoryInvoker extends CrudRepositoryInvoker {
private final PagingAndSortingRepository<Object, Serializable> repository; private final PagingAndSortingRepository<Object, Object> repository;
private final boolean customFindAll; private final boolean customFindAll;
/** /**
@ -46,7 +45,7 @@ class PagingAndSortingRepositoryInvoker extends CrudRepositoryInvoker {
* @param metadata must not be {@literal null}. * @param metadata must not be {@literal null}.
* @param conversionService must not be {@literal null}. * @param conversionService must not be {@literal null}.
*/ */
public PagingAndSortingRepositoryInvoker(PagingAndSortingRepository<Object, Serializable> repository, public PagingAndSortingRepositoryInvoker(PagingAndSortingRepository<Object, Object> repository,
RepositoryMetadata metadata, ConversionService conversionService) { RepositoryMetadata metadata, ConversionService conversionService) {
super(repository, metadata, conversionService); super(repository, metadata, conversionService);

17
src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.support; package org.springframework.data.repository.support;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -50,7 +49,7 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
private final Object repository; private final Object repository;
private final CrudMethods methods; private final CrudMethods methods;
private final Class<? extends Serializable> idType; private final Class<?> idType;
private final ConversionService conversionService; private final ConversionService conversionService;
/** /**
@ -133,10 +132,10 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
/* /*
* (non-Javadoc) * (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 @Override
public <T> Optional<T> invokeFindOne(Serializable id) { public <T> Optional<T> invokeFindById(Object id) {
Method method = methods.getFindOneMethod()// Method method = methods.getFindOneMethod()//
.orElseThrow(() -> new IllegalStateException("Repository doesn't have a find-one-method declared!")); .orElseThrow(() -> new IllegalStateException("Repository doesn't have a find-one-method declared!"));
@ -155,22 +154,22 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
/* /*
* (non-Javadoc) * (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 @Override
public void invokeDelete(Serializable id) { public void invokeDeleteById(Object id) {
Assert.notNull(id, "Identifier must not be null!"); Assert.notNull(id, "Identifier must not be null!");
Method method = methods.getDeleteMethod() Method method = methods.getDeleteMethod()
.orElseThrow(() -> new IllegalStateException("Repository doesn't have a delete-method declared!")); .orElseThrow(() -> new IllegalStateException("Repository doesn't have a delete-method declared!"));
Class<?> parameterType = method.getParameterTypes()[0]; Class<?> parameterType = method.getParameterTypes()[0];
List<Class<? extends Serializable>> idTypes = Arrays.asList(idType, Serializable.class); List<Class<?>> idTypes = Arrays.asList(idType, Object.class);
if (idTypes.contains(parameterType)) { if (idTypes.contains(parameterType)) {
invoke(method, convertId(id)); invoke(method, convertId(id));
} else { } else {
invoke(method, this.<Object> invokeFindOne(id).orElse(null)); invoke(method, this.<Object> invokeFindById(id).orElse(null));
} }
} }
@ -263,7 +262,7 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
* @param id must not be {@literal null}. * @param id must not be {@literal null}.
* @return * @return
*/ */
protected Serializable convertId(Serializable id) { protected Object convertId(Object id) {
Assert.notNull(id, "Id must not be null!"); Assert.notNull(id, "Id must not be null!");
return conversionService.convert(id, idType); return conversionService.convert(id, idType);

17
src/main/java/org/springframework/data/repository/support/Repositories.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.support; package org.springframework.data.repository.support;
import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -49,12 +48,12 @@ public class Repositories implements Iterable<Class<?>> {
static final Repositories NONE = new Repositories(); static final Repositories NONE = new Repositories();
private static final RepositoryFactoryInformation<Object, Serializable> EMPTY_REPOSITORY_FACTORY_INFO = EmptyRepositoryFactoryInformation.INSTANCE; private static final RepositoryFactoryInformation<Object, Object> EMPTY_REPOSITORY_FACTORY_INFO = EmptyRepositoryFactoryInformation.INSTANCE;
private static final String DOMAIN_TYPE_MUST_NOT_BE_NULL = "Domain type must not be null!"; private static final String DOMAIN_TYPE_MUST_NOT_BE_NULL = "Domain type must not be null!";
private final Optional<BeanFactory> beanFactory; private final Optional<BeanFactory> beanFactory;
private final Map<Class<?>, String> repositoryBeanNames; private final Map<Class<?>, String> repositoryBeanNames;
private final Map<Class<?>, RepositoryFactoryInformation<Object, Serializable>> repositoryFactoryInfos; private final Map<Class<?>, RepositoryFactoryInformation<Object, Object>> repositoryFactoryInfos;
/** /**
* Constructor to create the {@link #NONE} instance. * Constructor to create the {@link #NONE} instance.
@ -148,12 +147,12 @@ public class Repositories implements Iterable<Class<?>> {
* @return the {@link RepositoryFactoryInformation} for the given domain class or {@literal null} if no repository * @return the {@link RepositoryFactoryInformation} for the given domain class or {@literal null} if no repository
* registered for this domain class. * registered for this domain class.
*/ */
private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryInfoFor(Class<?> domainClass) { private RepositoryFactoryInformation<Object, Object> getRepositoryFactoryInfoFor(Class<?> domainClass) {
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
Class<?> userType = ClassUtils.getUserClass(domainClass); Class<?> userType = ClassUtils.getUserClass(domainClass);
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(userType); RepositoryFactoryInformation<Object, Object> repositoryInfo = repositoryFactoryInfos.get(userType);
if (repositoryInfo != null) { if (repositoryInfo != null) {
return repositoryInfo; return repositoryInfo;
@ -173,7 +172,7 @@ public class Repositories implements Iterable<Class<?>> {
* @return * @return
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T, S extends Serializable> EntityInformation<T, S> getEntityInformationFor(Class<?> domainClass) { public <T, S> EntityInformation<T, S> getEntityInformationFor(Class<?> domainClass) {
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
@ -191,7 +190,7 @@ public class Repositories implements Iterable<Class<?>> {
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
RepositoryFactoryInformation<Object, Serializable> information = getRepositoryFactoryInfoFor(domainClass); RepositoryFactoryInformation<Object, Object> information = getRepositoryFactoryInfoFor(domainClass);
return information == EMPTY_REPOSITORY_FACTORY_INFO ? Optional.empty() return information == EMPTY_REPOSITORY_FACTORY_INFO ? Optional.empty()
: Optional.of(information.getRepositoryInformation()); : Optional.of(information.getRepositoryInformation());
} }
@ -264,12 +263,12 @@ public class Repositories implements Iterable<Class<?>> {
* *
* @author Thomas Darimont * @author Thomas Darimont
*/ */
private static enum EmptyRepositoryFactoryInformation implements RepositoryFactoryInformation<Object, Serializable> { private static enum EmptyRepositoryFactoryInformation implements RepositoryFactoryInformation<Object, Object> {
INSTANCE; INSTANCE;
@Override @Override
public EntityInformation<Object, Serializable> getEntityInformation() { public EntityInformation<Object, Object> getEntityInformation() {
return null; return null;
} }

11
src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.support; package org.springframework.data.repository.support;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Optional; import java.util.Optional;
@ -44,13 +43,13 @@ public interface RepositoryInvoker extends RepositoryInvocationInformation {
<T> T invokeSave(T object); <T> 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}. * @param id must not be {@literal null}.
* @return the entity with the given id. * @return the entity with the given id.
* @throws IllegalStateException if the repository does not expose a find-one-method. * @throws IllegalStateException if the repository does not expose a find-one-method.
*/ */
<T> Optional<T> invokeFindOne(Serializable id); <T> Optional<T> invokeFindById(Object id);
/** /**
* Invokes the find-all method of the underlying repository using the method taking a {@link Pageable} as parameter if * 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<Object> invokeFindAll(Sort sort); Iterable<Object> invokeFindAll(Sort sort);
/** /**
* Invokes the method equivalent to {@link org.springframework.data.repository.CrudRepository#delete(Serializable)}. * Invokes the method equivalent to {@link org.springframework.data.repository.CrudRepository#deleteById(Object)}. The
* The given id is assumed to be of a type convertable into the actual identifier type of the backing repository. * 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}. * @param id must not be {@literal null}.
* @throws {@link IllegalStateException} if the repository does not expose a delete-method. * @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 * Invokes the query method backed by the given {@link Method} using the given parameters, {@link Pageable} and

8
src/test/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapterUnitTests.java

@ -86,11 +86,11 @@ public class QuerydslRepositoryInvokerAdapterUnitTests {
adapter.hasSaveMethod(); adapter.hasSaveMethod();
verify(delegate, times(1)).hasSaveMethod(); verify(delegate, times(1)).hasSaveMethod();
adapter.invokeDelete(any(Serializable.class)); adapter.invokeDeleteById(any(Serializable.class));
verify(delegate, times(1)).invokeDelete(any()); verify(delegate, times(1)).invokeDeleteById(any());
adapter.invokeFindOne(any(Serializable.class)); adapter.invokeFindById(any(Serializable.class));
verify(delegate, times(1)).invokeFindOne(any()); verify(delegate, times(1)).invokeFindById(any());
adapter.invokeQueryMethod(any(), any(), any(), any()); adapter.invokeQueryMethod(any(), any(), any(), any());

2
src/test/java/org/springframework/data/repository/core/support/AbstractEntityInformationUnitTests.java

@ -100,7 +100,7 @@ public class AbstractEntityInformationUnitTests {
@Id boolean id; @Id boolean id;
} }
static class CustomEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID> { static class CustomEntityInformation<T, ID> extends AbstractEntityInformation<T, ID> {
private final Class<T> type; private final Class<T> type;

7
src/test/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadataUnitTests.java

@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.ResolvableType;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.User; import org.springframework.data.querydsl.User;
@ -138,12 +139,14 @@ public class AbstractRepositoryMetadataUnitTests {
super(repositoryInterface); super(repositoryInterface);
} }
@SuppressWarnings("unchecked")
public Class<? extends Serializable> getIdType() { public Class<? extends Serializable> getIdType() {
return null; return (Class<? extends Serializable>) ResolvableType//
.forClass(Repository.class, getRepositoryInterface()).getGeneric(1).resolve();
} }
public Class<?> getDomainType() { public Class<?> getDomainType() {
return null; return ResolvableType.forClass(Repository.class, getRepositoryInterface()).getGeneric(0).resolve();
} }
} }

20
src/test/java/org/springframework/data/repository/core/support/DefaultCrudMethodsUnitTests.java

@ -47,7 +47,7 @@ public class DefaultCrudMethodsUnitTests {
Class<DomainCrudRepository> type = DomainCrudRepository.class; Class<DomainCrudRepository> type = DomainCrudRepository.class;
assertFindAllMethodOn(type, type.getMethod("findAll")); assertFindAllMethodOn(type, type.getMethod("findAll"));
assertDeleteMethodOn(type, type.getMethod("delete", Serializable.class)); assertDeleteMethodOn(type, type.getMethod("delete", Object.class));
assertSaveMethodPresent(type, true); assertSaveMethodPresent(type, true);
} }
@ -57,7 +57,7 @@ public class DefaultCrudMethodsUnitTests {
Class<DomainPagingAndSortingRepository> type = DomainPagingAndSortingRepository.class; Class<DomainPagingAndSortingRepository> type = DomainPagingAndSortingRepository.class;
assertFindAllMethodOn(type, type.getMethod("findAll", Pageable.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); assertSaveMethodPresent(type, true);
} }
@ -100,8 +100,8 @@ public class DefaultCrudMethodsUnitTests {
public void detectsOverloadedMethodsCorrectly() throws Exception { public void detectsOverloadedMethodsCorrectly() throws Exception {
Class<RepositoryWithAllCrudMethodOverloaded> type = RepositoryWithAllCrudMethodOverloaded.class; Class<RepositoryWithAllCrudMethodOverloaded> type = RepositoryWithAllCrudMethodOverloaded.class;
assertFindOneMethodOn(type, type.getDeclaredMethod("findOne", Long.class)); assertFindOneMethodOn(type, type.getDeclaredMethod("findById", Long.class));
assertDeleteMethodOn(type, type.getDeclaredMethod("delete", Long.class)); assertDeleteMethodOn(type, type.getDeclaredMethod("deleteById", Long.class));
assertSaveMethodOn(type, type.getDeclaredMethod("save", Domain.class)); assertSaveMethodOn(type, type.getDeclaredMethod("save", Domain.class));
assertFindAllMethodOn(type, type.getDeclaredMethod("findAll")); assertFindAllMethodOn(type, type.getDeclaredMethod("findAll"));
} }
@ -110,8 +110,8 @@ public class DefaultCrudMethodsUnitTests {
public void ignoresWrongOverloadedMethods() throws Exception { public void ignoresWrongOverloadedMethods() throws Exception {
Class<RepositoryWithAllCrudMethodOverloadedWrong> type = RepositoryWithAllCrudMethodOverloadedWrong.class; Class<RepositoryWithAllCrudMethodOverloadedWrong> type = RepositoryWithAllCrudMethodOverloadedWrong.class;
assertFindOneMethodOn(type, CrudRepository.class.getDeclaredMethod("findOne", Serializable.class)); assertFindOneMethodOn(type, CrudRepository.class.getDeclaredMethod("findById", Object.class));
assertDeleteMethodOn(type, CrudRepository.class.getDeclaredMethod("delete", Serializable.class)); assertDeleteMethodOn(type, CrudRepository.class.getDeclaredMethod("delete", Object.class));
assertSaveMethodOn(type, CrudRepository.class.getDeclaredMethod("save", Object.class)); assertSaveMethodOn(type, CrudRepository.class.getDeclaredMethod("save", Object.class));
assertFindAllMethodOn(type, CrudRepository.class.getDeclaredMethod("findAll")); assertFindAllMethodOn(type, CrudRepository.class.getDeclaredMethod("findAll"));
} }
@ -241,9 +241,9 @@ public class DefaultCrudMethodsUnitTests {
<S extends Domain> S save(S entity); <S extends Domain> S save(S entity);
void delete(Long id); void deleteById(Long id);
Optional<Domain> findOne(Long id); Optional<Domain> findById(Long id);
} }
// DATACMNS-393 // DATACMNS-393
@ -251,11 +251,11 @@ public class DefaultCrudMethodsUnitTests {
List<Domain> findAll(String s); List<Domain> findAll(String s);
Domain save(Serializable entity); Domain save(Long entity);
void delete(String o); void delete(String o);
Domain findOne(Domain o); Domain findById(Domain o);
} }
// DATACMNS-539 // DATACMNS-539

39
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 lombok.experimental.Delegate;
import java.io.Serializable;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@ -63,19 +62,19 @@ public class DefaultRepositoryInformationUnitTests {
@Test @Test
public void discoversRepositoryBaseClassMethod() throws Exception { 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); RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class);
DefaultRepositoryInformation information = new DefaultRepositoryInformation(metadata, REPOSITORY, Optional.empty()); DefaultRepositoryInformation information = new DefaultRepositoryInformation(metadata, REPOSITORY, Optional.empty());
Method reference = information.getTargetClassMethod(method); Method reference = information.getTargetClassMethod(method);
assertThat(reference.getDeclaringClass()).isEqualTo(REPOSITORY); assertThat(reference.getDeclaringClass()).isEqualTo(REPOSITORY);
assertThat(reference.getName()).isEqualTo("findOne"); assertThat(reference.getName()).isEqualTo("findById");
} }
@Test @Test
public void discoveresNonRepositoryBaseClassMethod() throws Exception { 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); RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class);
DefaultRepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, DefaultRepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class,
@ -117,7 +116,7 @@ public class DefaultRepositoryInformationUnitTests {
Method method = CustomRepository.class.getMethod("findAll", Pageable.class); Method method = CustomRepository.class.getMethod("findAll", Pageable.class);
assertThat(information.isBaseClassMethod(method)).isTrue(); assertThat(information.isBaseClassMethod(method)).isTrue();
method = getMethodFrom(CustomRepository.class, "exists"); method = getMethodFrom(CustomRepository.class, "existsById");
assertThat(information.isBaseClassMethod(method)).isTrue(); assertThat(information.isBaseClassMethod(method)).isTrue();
assertThat(information.getQueryMethods()).isEmpty(); assertThat(information.getQueryMethods()).isEmpty();
@ -184,7 +183,7 @@ public class DefaultRepositoryInformationUnitTests {
RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class,
Optional.empty()); Optional.empty());
Method method = BaseRepository.class.getMethod("findOne", Serializable.class); Method method = BaseRepository.class.getMethod("findById", Object.class);
assertThat(information.getQueryMethods()).contains(method); assertThat(information.getQueryMethods()).contains(method);
} }
@ -196,8 +195,8 @@ public class DefaultRepositoryInformationUnitTests {
RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class,
Optional.empty()); Optional.empty());
Method method = BossRepository.class.getMethod("save", Iterable.class); Method method = BossRepository.class.getMethod("saveAll", Iterable.class);
Method reference = CrudRepository.class.getMethod("save", Iterable.class); Method reference = CrudRepository.class.getMethod("saveAll", Iterable.class);
assertThat(information.getTargetClassMethod(method)).isEqualTo(reference); assertThat(information.getTargetClassMethod(method)).isEqualTo(reference);
} }
@ -268,10 +267,10 @@ public class DefaultRepositoryInformationUnitTests {
RepositoryInformation information = new DefaultRepositoryInformation(metadata, DummyRepositoryImpl.class, RepositoryInformation information = new DefaultRepositoryInformation(metadata, DummyRepositoryImpl.class,
Optional.empty()); Optional.empty());
Method method = DummyRepository.class.getMethod("save", Iterable.class); Method method = DummyRepository.class.getMethod("saveAll", Iterable.class);
assertThat(information.getTargetClassMethod(method)) 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 @Test // DATACMNS-1008, DATACMNS-912, DATACMNS-854
@ -291,7 +290,7 @@ public class DefaultRepositoryInformationUnitTests {
return Arrays.stream(type.getMethods())// return Arrays.stream(type.getMethods())//
.filter(method -> method.getName().equals(name))// .filter(method -> method.getName().equals(name))//
.findFirst()// .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) @Target(ElementType.METHOD)
@ -303,10 +302,10 @@ public class DefaultRepositoryInformationUnitTests {
interface FooRepository extends CrudRepository<User, Integer>, FooRepositoryCustom { interface FooRepository extends CrudRepository<User, Integer>, FooRepositoryCustom {
// Redeclared method // Redeclared method
Optional<User> findOne(Integer primaryKey); Optional<User> findById(Integer primaryKey);
// Not a redeclared method // Not a redeclared method
User findOne(Long primaryKey); User findById(Long primaryKey);
static void staticMethod() {} static void staticMethod() {}
@ -340,7 +339,7 @@ public class DefaultRepositoryInformationUnitTests {
} }
} }
interface BaseRepository<S, ID extends Serializable> extends CrudRepository<S, ID> { interface BaseRepository<S, ID> extends CrudRepository<S, ID> {
S findBySomething(String something); S findBySomething(String something);
@ -351,7 +350,7 @@ public class DefaultRepositoryInformationUnitTests {
void delete(S entity); void delete(S entity);
@MyQuery @MyQuery
Optional<S> findOne(ID id); Optional<S> findById(ID id);
} }
interface ConcreteRepository extends BaseRepository<User, Integer> { interface ConcreteRepository extends BaseRepository<User, Integer> {
@ -361,9 +360,9 @@ public class DefaultRepositoryInformationUnitTests {
User genericMethodToOverride(String something); User genericMethodToOverride(String something);
} }
interface ReadOnlyRepository<T, ID extends Serializable> extends Repository<T, ID> { interface ReadOnlyRepository<T, ID> extends Repository<T, ID> {
T findOne(ID id); T findById(ID id);
Iterable<T> findAll(); Iterable<T> findAll();
@ -371,7 +370,7 @@ public class DefaultRepositoryInformationUnitTests {
List<T> findAll(Sort sort); List<T> findAll(Sort sort);
boolean exists(ID id); boolean existsById(ID id);
long count(); long count();
} }
@ -405,10 +404,10 @@ public class DefaultRepositoryInformationUnitTests {
interface DummyRepository extends CrudRepository<User, Integer> { interface DummyRepository extends CrudRepository<User, Integer> {
@Override @Override
<S extends User> List<S> save(Iterable<S> entites); <S extends User> List<S> saveAll(Iterable<S> entites);
} }
static class DummyRepositoryImpl<T, ID extends Serializable> implements CrudRepository<T, ID> { static class DummyRepositoryImpl<T, ID> implements CrudRepository<T, ID> {
private @Delegate CrudRepository<T, ID> delegate; private @Delegate CrudRepository<T, ID> delegate;
} }

2
src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java

@ -168,7 +168,7 @@ public class DefaultRepositoryMetadataUnitTests {
static abstract class DummyGenericRepositorySupport<T, ID extends Serializable> implements CrudRepository<T, ID> { static abstract class DummyGenericRepositorySupport<T, ID extends Serializable> implements CrudRepository<T, ID> {
public java.util.Optional<T> findOne(ID id) { public java.util.Optional<T> findById(ID id) {
return java.util.Optional.empty(); return java.util.Optional.empty();
} }
} }

3
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 static org.mockito.Mockito.*;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Optional; import java.util.Optional;
@ -61,7 +60,7 @@ public class DummyRepositoryFactory extends RepositoryFactorySupport {
*/ */
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T, ID extends Serializable> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) { public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
return mock(EntityInformation.class); return mock(EntityInformation.class);
} }

3
src/test/java/org/springframework/data/repository/core/support/DummyRepositoryInformation.java

@ -15,7 +15,6 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Set; import java.util.Set;
@ -36,7 +35,7 @@ public final class DummyRepositoryInformation implements RepositoryInformation {
this.metadata = metadata; this.metadata = metadata;
} }
public Class<? extends Serializable> getIdType() { public Class<?> getIdType() {
return metadata.getIdType(); return metadata.getIdType();
} }

8
src/test/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessorUnitTests.java

@ -16,12 +16,12 @@
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import lombok.Getter; import lombok.Getter;
import lombok.Value; import lombok.Value;
import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -122,7 +122,7 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests {
@Test // DATACMNS-928 @Test // DATACMNS-928
public void doesNotInterceptNonSaveMethod() throws Throwable { 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// EventPublishingMethodInterceptor//
.of(EventPublishingMethod.of(MultipleEvents.class), publisher)// .of(EventPublishingMethod.of(MultipleEvents.class), publisher)//
@ -162,9 +162,9 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests {
SomeEvent event = new SomeEvent(); SomeEvent event = new SomeEvent();
MultipleEvents sample = MultipleEvents.of(Collections.singletonList(event)); 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// EventPublishingMethodInterceptor//
.of(EventPublishingMethod.of(MultipleEvents.class), publisher)// .of(EventPublishingMethod.of(MultipleEvents.class), publisher)//

29
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 reactor.core.publisher.Flux;
import rx.Observable; import rx.Observable;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Optional; import java.util.Optional;
@ -60,10 +59,11 @@ public class ReactiveRepositoryInformationUnitTests {
@Test // DATACMNS-836 @Test // DATACMNS-836
public void discoversRxJava1MethodWithConvertibleArguments() throws Exception { 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()); assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass());
assertThat(reference.getName(), is("save")); assertThat(reference.getName(), is("saveAll"));
assertThat(reference.getParameterTypes()[0], is(equalTo(Publisher.class))); assertThat(reference.getParameterTypes()[0], is(equalTo(Publisher.class)));
} }
@ -79,31 +79,31 @@ public class ReactiveRepositoryInformationUnitTests {
@Test // DATACMNS-988 @Test // DATACMNS-988
public void discoversRxJava2MethodWithConvertibleArguments() throws Exception { 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()); assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass());
assertThat(reference.getName(), is("save")); assertThat(reference.getName(), is("saveAll"));
assertThat(reference.getParameterTypes()[0], is(equalTo(Publisher.class))); assertThat(reference.getParameterTypes()[0], is(equalTo(Publisher.class)));
} }
@Test // DATACMNS-836 @Test // DATACMNS-836
public void discoversMethodAssignableArguments() throws Exception { 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()); assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass());
assertThat(reference.getName(), is("save")); assertThat(reference.getName(), is("saveAll"));
assertThat(reference.getParameterTypes()[0], is(equalTo(Publisher.class))); assertThat(reference.getParameterTypes()[0], is(equalTo(Publisher.class)));
} }
@Test // DATACMNS-836 @Test // DATACMNS-836
public void discoversMethodExactIterableArguments() throws Exception { public void discoversMethodExactIterableArguments() throws Exception {
Method reference = extractTargetMethodFromRepository(ReactiveJavaInterfaceWithGenerics.class, "save", Method reference = extractTargetMethodFromRepository(ReactiveJavaInterfaceWithGenerics.class, "saveAll",
Iterable.class); Iterable.class);
assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass()); assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass());
assertThat(reference.getName(), is("save")); assertThat(reference.getName(), is("saveAll"));
assertThat(reference.getParameterTypes()[0], is(equalTo(Iterable.class))); assertThat(reference.getParameterTypes()[0], is(equalTo(Iterable.class)));
} }
@ -120,12 +120,12 @@ public class ReactiveRepositoryInformationUnitTests {
@Test // DATACMNS-1023 @Test // DATACMNS-1023
public void usesCorrectSaveOverload() throws Exception { 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 { throws NoSuchMethodException {
RepositoryInformation information = new ReactiveRepositoryInformation(new DefaultRepositoryMetadata(repositoryType), RepositoryInformation information = new ReactiveRepositoryInformation(new DefaultRepositoryMetadata(repositoryType),
@ -139,15 +139,14 @@ public class ReactiveRepositoryInformationUnitTests {
interface ReactiveJavaInterfaceWithGenerics extends ReactiveCrudRepository<User, String> {} interface ReactiveJavaInterfaceWithGenerics extends ReactiveCrudRepository<User, String> {}
static abstract class DummyGenericReactiveRepositorySupport<T, ID extends Serializable> static abstract class DummyGenericReactiveRepositorySupport<T, ID> implements ReactiveCrudRepository<T, ID> {
implements ReactiveCrudRepository<T, ID> {
} }
interface DummyRepository extends ReactiveCrudRepository<User, Integer> { interface DummyRepository extends ReactiveCrudRepository<User, Integer> {
@Override @Override
<S extends User> Flux<S> save(Iterable<S> entities); <S extends User> Flux<S> saveAll(Iterable<S> entities);
} }
static class User { static class User {

41
src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java

@ -15,6 +15,7 @@
*/ */
package org.springframework.data.repository.core.support; package org.springframework.data.repository.core.support;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import io.reactivex.Completable; import io.reactivex.Completable;
@ -59,10 +60,10 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests {
public void invokesCustomMethodIfItRedeclaresACRUDOne() { public void invokesCustomMethodIfItRedeclaresACRUDOne() {
ObjectRepository repository = factory.getRepository(ObjectRepository.class, customImplementation); ObjectRepository repository = factory.getRepository(ObjectRepository.class, customImplementation);
repository.findOne(1); repository.findById(1);
verify(customImplementation, times(1)).findOne(1); verify(customImplementation, times(1)).findById(1);
verify(backingRepo, times(0)).findOne(1); verify(backingRepo, times(0)).findById(1);
} }
@Test // DATACMNS-836 @Test // DATACMNS-836
@ -70,10 +71,10 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests {
Serializable id = 1L; Serializable id = 1L;
RxJava1ConvertingRepository repository = factory.getRepository(RxJava1ConvertingRepository.class); RxJava1ConvertingRepository repository = factory.getRepository(RxJava1ConvertingRepository.class);
repository.exists(id); repository.existsById(id);
repository.exists((Long) id); repository.existsById((Long) id);
verify(backingRepo, times(2)).exists(id); verify(backingRepo, times(2)).existsById(id);
} }
@Test // DATACMNS-836 @Test // DATACMNS-836
@ -83,9 +84,9 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests {
Single<Long> ids = Single.just(1L); Single<Long> ids = Single.just(1L);
RxJava1ConvertingRepository repository = factory.getRepository(RxJava1ConvertingRepository.class); 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 @Test // DATACMNS-988
@ -93,9 +94,9 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests {
Long id = 1L; Long id = 1L;
RxJava2ConvertingRepository repository = factory.getRepository(RxJava2ConvertingRepository.class); 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 @Test // DATACMNS-988
@ -104,36 +105,36 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests {
Serializable id = 1L; Serializable id = 1L;
RxJava2ConvertingRepository repository = factory.getRepository(RxJava2ConvertingRepository.class); 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<Object, Long> { interface RxJava1ConvertingRepository extends Repository<Object, Long> {
Single<Boolean> exists(Single<Long> id); Single<Boolean> existsById(Single<Long> id);
Single<Boolean> exists(Serializable id); Single<Boolean> existsById(Serializable id);
Single<Boolean> exists(Long id); Single<Boolean> existsById(Long id);
} }
interface RxJava2ConvertingRepository extends Repository<Object, Long> { interface RxJava2ConvertingRepository extends Repository<Object, Long> {
Maybe<Boolean> findOne(Serializable id); Maybe<Boolean> findById(Serializable id);
Single<Boolean> exists(Long id); Single<Boolean> existsById(Long id);
Completable delete(Serializable id); Completable deleteById(Serializable id);
} }
interface ObjectRepository interface ObjectRepository
extends Repository<Object, Serializable>, RepositoryFactorySupportUnitTests.ObjectRepositoryCustom { extends Repository<Object, Object>, RepositoryFactorySupportUnitTests.ObjectRepositoryCustom {
} }
interface ObjectRepositoryCustom { interface ObjectRepositoryCustom {
Object findOne(Serializable id); Object findById(Object id);
} }
} }

18
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.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -77,7 +77,7 @@ public class RepositoryFactorySupportUnitTests {
DummyRepositoryFactory factory; DummyRepositoryFactory factory;
@Mock PagingAndSortingRepository<Object, Serializable> backingRepo; @Mock PagingAndSortingRepository<Object, Object> backingRepo;
@Mock ObjectRepositoryCustom customImplementation; @Mock ObjectRepositoryCustom customImplementation;
@Mock MyQueryCreationListener listener; @Mock MyQueryCreationListener listener;
@ -119,10 +119,10 @@ public class RepositoryFactorySupportUnitTests {
public void invokesCustomMethodIfItRedeclaresACRUDOne() { public void invokesCustomMethodIfItRedeclaresACRUDOne() {
ObjectRepository repository = factory.getRepository(ObjectRepository.class, customImplementation); ObjectRepository repository = factory.getRepository(ObjectRepository.class, customImplementation);
repository.findOne(1); repository.findById(1);
verify(customImplementation, times(1)).findOne(1); verify(customImplementation, times(1)).findById(1);
verify(backingRepo, times(0)).findOne(1); verify(backingRepo, times(0)).findById(1);
} }
@Test @Test
@ -316,7 +316,7 @@ public class RepositoryFactorySupportUnitTests {
interface SimpleRepository extends Repository<Object, Serializable> {} interface SimpleRepository extends Repository<Object, Serializable> {}
interface ObjectRepository extends Repository<Object, Serializable>, ObjectRepositoryCustom { interface ObjectRepository extends Repository<Object, Object>, ObjectRepositoryCustom {
Object findByClass(Class<?> clazz); Object findByClass(Class<?> clazz);
@ -335,7 +335,7 @@ public class RepositoryFactorySupportUnitTests {
interface ObjectRepositoryCustom { interface ObjectRepositoryCustom {
Object findOne(Serializable id); Object findById(Object id);
} }
interface PlainQueryCreationListener extends QueryCreationListener<RepositoryQuery> { interface PlainQueryCreationListener extends QueryCreationListener<RepositoryQuery> {
@ -352,7 +352,7 @@ public class RepositoryFactorySupportUnitTests {
interface ReadOnlyRepository<T, ID extends Serializable> extends Repository<T, ID> { interface ReadOnlyRepository<T, ID extends Serializable> extends Repository<T, ID> {
T findOne(ID id); Optional<T> findById(ID id);
Iterable<T> findAll(); Iterable<T> findAll();
@ -360,7 +360,7 @@ public class RepositoryFactorySupportUnitTests {
List<T> findAll(Sort sort); List<T> findAll(Sort sort);
boolean exists(ID id); boolean existsById(ID id);
long count(); long count();
} }

2
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, Long> { public interface ProductRepository extends Repository<Product, Long> {
Product findOne(Long id); Product findById(Long id);
Product save(Product product); Product save(Product product);
} }

19
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.mockito.Mockito.*;
import static org.springframework.data.repository.support.RepositoryInvocationTestUtils.*; import static org.springframework.data.repository.support.RepositoryInvocationTestUtils.*;
import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
@ -62,12 +61,12 @@ public class CrudRepositoryInvokerUnitTests {
@Test // DATACMNS-589, DATAREST-216 @Test // DATACMNS-589, DATAREST-216
public void invokesRedeclaredFindOne() { public void invokesRedeclaredFindOne() {
getInvokerFor(orderRepository, expectInvocationOnType(OrderRepository.class)).invokeFindOne(1L); getInvokerFor(orderRepository, expectInvocationOnType(OrderRepository.class)).invokeFindById(1L);
} }
@Test // DATACMNS-589 @Test // DATACMNS-589
public void invokesRedeclaredDelete() throws Exception { public void invokesRedeclaredDelete() throws Exception {
getInvokerFor(orderRepository, expectInvocationOnType(OrderRepository.class)).invokeDelete(1L); getInvokerFor(orderRepository, expectInvocationOnType(OrderRepository.class)).invokeDeleteById(1L);
} }
@Test // DATACMNS-589 @Test // DATACMNS-589
@ -80,15 +79,15 @@ public class CrudRepositoryInvokerUnitTests {
@Test // DATACMNS-589 @Test // DATACMNS-589
public void invokesFindOneOnCrudRepository() throws Exception { public void invokesFindOneOnCrudRepository() throws Exception {
Method method = CrudRepository.class.getMethod("findOne", Serializable.class); Method method = CrudRepository.class.getMethod("findById", Object.class);
getInvokerFor(personRepository, expectInvocationOf(method)).invokeFindOne(1L); getInvokerFor(personRepository, expectInvocationOf(method)).invokeFindById(1L);
} }
@Test // DATACMNS-589, DATAREST-216 @Test // DATACMNS-589, DATAREST-216
public void invokesDeleteOnCrudRepository() throws Exception { public void invokesDeleteOnCrudRepository() throws Exception {
Method method = CrudRepository.class.getMethod("delete", Serializable.class); Method method = CrudRepository.class.getMethod("deleteById", Object.class);
getInvokerFor(personRepository, expectInvocationOf(method)).invokeDelete(1L); getInvokerFor(personRepository, expectInvocationOf(method)).invokeDeleteById(1L);
} }
@Test // DATACMNS-589 @Test // DATACMNS-589
@ -142,10 +141,10 @@ public class CrudRepositoryInvokerUnitTests {
<S extends Order> S save(S entity); <S extends Order> S save(S entity);
@Override @Override
Optional<Order> findOne(Long id); Optional<Order> findById(Long id);
@Override @Override
void delete(Long id); void deleteById(Long id);
} }
static class Person {} static class Person {}
@ -172,6 +171,6 @@ public class CrudRepositoryInvokerUnitTests {
interface CrudWithRedeclaredDelete extends CrudRepository<Order, Long> { interface CrudWithRedeclaredDelete extends CrudRepository<Order, Long> {
void delete(Long id); void deleteById(Long id);
} }
} }

4
src/test/java/org/springframework/data/repository/support/DefaultRepositoryInvokerFactoryIntegrationTests.java

@ -59,9 +59,9 @@ public class DefaultRepositoryInvokerFactoryIntegrationTests {
// Mockito.reset(productRepository); // Mockito.reset(productRepository);
Product product = new Product(); Product product = new Product();
when(productRepository.findOne(4711L)).thenReturn(product); when(productRepository.findById(4711L)).thenReturn(product);
Optional<Object> invokeFindOne = factory.getInvokerFor(Product.class).invokeFindOne(4711L); Optional<Object> invokeFindOne = factory.getInvokerFor(Product.class).invokeFindById(4711L);
assertThat(invokeFindOne).isEqualTo(Optional.of(product)); assertThat(invokeFindOne).isEqualTo(Optional.of(product));
} }

2
src/test/java/org/springframework/data/repository/support/DomainClassConverterUnitTests.java

@ -121,7 +121,7 @@ public class DomainClassConverterUnitTests {
UserRepository bean = context.getBean(UserRepository.class); UserRepository bean = context.getBean(UserRepository.class);
UserRepository repo = (UserRepository) ((Advised) bean).getTargetSource().getTarget(); UserRepository repo = (UserRepository) ((Advised) bean).getTargetSource().getTarget();
verify(repo, times(1)).findOne(1L); verify(repo, times(1)).findById(1L);
} }
@Test // DATACMNS-133 @Test // DATACMNS-133

38
src/test/java/org/springframework/data/repository/support/ReflectionRepositoryInvokerUnitTests.java

@ -82,22 +82,22 @@ public class ReflectionRepositoryInvokerUnitTests {
public void invokesFindOneCorrectly() throws Exception { public void invokesFindOneCorrectly() throws Exception {
ManualCrudRepository repository = mock(ManualCrudRepository.class); 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)).invokeFindById("1");
getInvokerFor(repository, expectInvocationOf(method)).invokeFindOne(1L); getInvokerFor(repository, expectInvocationOf(method)).invokeFindById(1L);
} }
@Test // DATACMNS-589 @Test // DATACMNS-589
public void invokesDeleteWithDomainCorrectly() throws Exception { public void invokesDeleteWithDomainCorrectly() throws Exception {
RepoWithDomainDeleteAndFindOne repository = mock(RepoWithDomainDeleteAndFindOne.class); 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); 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 @Test // DATACMNS-589
@ -164,9 +164,9 @@ public class ReflectionRepositoryInvokerUnitTests {
public void invokesOverriddenDeleteMethodCorrectly() throws Exception { public void invokesOverriddenDeleteMethodCorrectly() throws Exception {
MyRepo repository = mock(MyRepo.class); 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 @Test(expected = IllegalStateException.class) // DATACMNS-589
@ -175,7 +175,7 @@ public class ReflectionRepositoryInvokerUnitTests {
RepositoryInvoker invoker = getInvokerFor(mock(EmptyRepository.class)); RepositoryInvoker invoker = getInvokerFor(mock(EmptyRepository.class));
assertThat(invoker.hasDeleteMethod()).isFalse(); assertThat(invoker.hasDeleteMethod()).isFalse();
invoker.invokeDelete(1L); invoker.invokeDeleteById(1L);
} }
@Test(expected = IllegalStateException.class) // DATACMNS-589 @Test(expected = IllegalStateException.class) // DATACMNS-589
@ -184,7 +184,7 @@ public class ReflectionRepositoryInvokerUnitTests {
RepositoryInvoker invoker = getInvokerFor(mock(EmptyRepository.class)); RepositoryInvoker invoker = getInvokerFor(mock(EmptyRepository.class));
assertThat(invoker.hasFindOneMethod()).isFalse(); assertThat(invoker.hasFindOneMethod()).isFalse();
invoker.invokeFindOne(1L); invoker.invokeFindById(1L);
} }
@Test(expected = IllegalStateException.class) // DATACMNS-589 @Test(expected = IllegalStateException.class) // DATACMNS-589
@ -245,11 +245,11 @@ public class ReflectionRepositoryInvokerUnitTests {
public void convertsWrapperTypeToJdkOptional() { public void convertsWrapperTypeToJdkOptional() {
GuavaRepository mock = mock(GuavaRepository.class); 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); RepositoryInvoker invoker = getInvokerFor(mock);
Optional<Object> invokeFindOne = invoker.invokeFindOne(1L); Optional<Object> invokeFindOne = invoker.invokeFindById(1L);
assertThat(invokeFindOne).isPresent(); assertThat(invokeFindOne).isPresent();
} }
@ -262,8 +262,8 @@ public class ReflectionRepositoryInvokerUnitTests {
Method method = ManualCrudRepository.class.getMethod("findAll"); Method method = ManualCrudRepository.class.getMethod("findAll");
Optional<Object> result = getInvokerFor(mock).invokeQueryMethod(method, new LinkedMultiValueMap<>(), Pageable.unpaged(), Optional<Object> result = getInvokerFor(mock).invokeQueryMethod(method, new LinkedMultiValueMap<>(),
Sort.unsorted()); Pageable.unpaged(), Sort.unsorted());
assertThat(result).hasValueSatisfying(it -> { assertThat(result).hasValueSatisfying(it -> {
assertThat(it).isInstanceOf(Collection.class); assertThat(it).isInstanceOf(Collection.class);
@ -287,20 +287,20 @@ public class ReflectionRepositoryInvokerUnitTests {
class Domain {} class Domain {}
interface CustomRepo { interface CustomRepo {
void delete(Long id); void deleteById(Long id);
} }
interface EmptyRepository extends Repository<Domain, Long> {} interface EmptyRepository extends Repository<Domain, Long> {}
interface ManualCrudRepository extends Repository<Domain, Long> { interface ManualCrudRepository extends Repository<Domain, Long> {
Domain findOne(Long id); Domain findById(Long id);
Iterable<Domain> findAll(); Iterable<Domain> findAll();
<T extends Domain> T save(T entity); <T extends Domain> T save(T entity);
void delete(Long id); void deleteById(Long id);
} }
interface RepoWithFindAllWithoutParameters extends Repository<Domain, Long> { interface RepoWithFindAllWithoutParameters extends Repository<Domain, Long> {
@ -320,7 +320,7 @@ public class ReflectionRepositoryInvokerUnitTests {
interface RepoWithDomainDeleteAndFindOne extends Repository<Domain, Long> { interface RepoWithDomainDeleteAndFindOne extends Repository<Domain, Long> {
Domain findOne(Long id); Domain findById(Long id);
void delete(Domain entity); void delete(Domain entity);
} }
@ -332,6 +332,6 @@ public class ReflectionRepositoryInvokerUnitTests {
interface GuavaRepository extends Repository<Domain, Long> { interface GuavaRepository extends Repository<Domain, Long> {
com.google.common.base.Optional<Domain> findOne(Long id); com.google.common.base.Optional<Domain> findById(Long id);
} }
} }

Loading…
Cancel
Save