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.
This commit is contained in:
Oliver Gierke
2017-04-28 15:28:28 +02:00
parent 382c912111
commit 727ab8384c
55 changed files with 324 additions and 397 deletions

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.domain;
import java.io.Serializable;
import java.time.temporal.TemporalAccessor;
import java.util.Optional;
@@ -27,7 +26,7 @@ import java.util.Optional;
* @param <ID> the type of the audited type's identifier
* @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.

View File

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

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.querydsl;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Optional;
@@ -112,22 +111,22 @@ public class QuerydslRepositoryInvokerAdapter implements RepositoryInvoker {
return delegate.hasSaveMethod();
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.repository.support.RepositoryInvoker#invokeDelete(java.io.Serializable)
* @see org.springframework.data.repository.support.RepositoryInvoker#invokeDeleteById(java.lang.Object)
*/
@Override
public void invokeDelete(Serializable id) {
delegate.invokeDelete(id);
public void invokeDeleteById(Object id) {
delegate.invokeDeleteById(id);
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.repository.support.RepositoryInvoker#invokeFindOne(java.io.Serializable)
* @see org.springframework.data.repository.support.RepositoryInvoker#invokeFindById(java.lang.Object)
*/
@Override
public <T> Optional<T> invokeFindOne(Serializable id) {
return delegate.invokeFindOne(id);
public <T> Optional<T> invokeFindById(Object id) {
return delegate.invokeFindById(id);
}
/*

View File

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

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.repository;
import java.io.Serializable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@@ -31,7 +29,7 @@ import org.springframework.data.domain.Sort;
* @see Page
*/
@NoRepositoryBean
public interface PagingAndSortingRepository<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.

View File

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

View File

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

View File

@@ -65,7 +65,7 @@ public interface CrudMethods {
/**
* Returns the find one method of the repository. Usually signature compatible to
* {@link CrudRepository#findOne(java.io.Serializable)}
* {@link CrudRepository#findById(Object)}
*
* @return the find one method of the repository or {@literal null} if not available.
* @see #hasFindOneMethod()

View File

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

View File

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

View File

@@ -15,11 +15,12 @@
*/
package org.springframework.data.repository.core.support;
import java.io.Serializable;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.Optional;
import org.springframework.data.repository.core.EntityInformation;
import org.springframework.util.Assert;
/**
* Base class for implementations of {@link EntityInformation}. Considers an entity to be new whenever
@@ -28,20 +29,10 @@ import org.springframework.util.Assert;
* @author Oliver Gierke
* @author Nick Williams
*/
public abstract class AbstractEntityInformation<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!");
this.domainClass = domainClass;
}
private final @NonNull Class<T> domainClass;
/*
* (non-Javadoc)

View File

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

View File

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

View File

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

View File

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

View File

@@ -15,11 +15,12 @@
*/
package org.springframework.data.repository.core.support;
import java.io.Serializable;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.Optional;
import org.springframework.data.repository.core.EntityInformation;
import org.springframework.util.Assert;
/**
* Useful base class to implement custom {@link EntityInformation}s and delegate execution of standard methods from
@@ -27,21 +28,10 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
*/
public class DelegatingEntityInformation<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!");
this.delegate = delegate;
}
private final @NonNull EntityInformation<T, ID> delegate;
/*
* (non-Javadoc)

View File

@@ -18,10 +18,10 @@ package org.springframework.data.repository.core.support;
import lombok.RequiredArgsConstructor;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Stream;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
@@ -90,7 +90,7 @@ public class EventPublishingRepositoryProxyPostProcessor implements RepositoryPr
Object result = invocation.proceed();
if (!invocation.getMethod().getName().equals("save")) {
if (!Stream.of("save", "saveAll").anyMatch(it -> invocation.getMethod().getName().equals(it))) {
return result;
}

View File

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

View File

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

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.repository.core.support;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Optional;
@@ -32,7 +31,7 @@ import org.springframework.util.ReflectionUtils;
* @author Oliver Gierke
* @author Christoph Strobl
*/
public class ReflectionEntityInformation<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;

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.repository.core.support;
import java.io.Serializable;
import java.util.List;
import java.util.Optional;
@@ -50,7 +49,7 @@ import org.springframework.util.Assert;
* @author Oliver Gierke
* @author Thomas Darimont
*/
public abstract class RepositoryFactoryBeanSupport<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,
BeanFactoryAware, ApplicationEventPublisherAware {

View File

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

View File

@@ -19,7 +19,6 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -291,7 +290,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
* @param domainClass
* @return
*/
public abstract <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.

View File

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

View File

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

View File

@@ -15,15 +15,13 @@
*/
package org.springframework.data.repository.reactive;
import java.io.Serializable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.reactivestreams.Publisher;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
* Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms
* and uses Project Reactor types which are built on top of Reactive Streams.
@@ -34,7 +32,7 @@ import reactor.core.publisher.Mono;
* @see Flux
*/
@NoRepositoryBean
public interface ReactiveCrudRepository<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
@@ -52,7 +50,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @return the saved entities.
* @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.
@@ -61,7 +59,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @return the saved entities.
* @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.
@@ -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.
* @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}.
@@ -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.
* @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.
@@ -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.
* @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.
@@ -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
* @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.
@@ -112,7 +110,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @param ids must not be {@literal null}.
* @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.
@@ -120,7 +118,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @param idStream must not be {@literal null}.
* @return the found entities.
*/
Flux<T> findAll(Publisher<ID> idStream);
Flux<T> findAllById(Publisher<ID> idStream);
/**
* 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}.
* @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.
@@ -151,7 +149,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @param entities must not be {@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.
@@ -159,7 +157,7 @@ public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repo
* @param entityStream must not be {@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.

View File

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

View File

@@ -15,15 +15,13 @@
*/
package org.springframework.data.repository.reactive;
import java.io.Serializable;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
import rx.Completable;
import rx.Observable;
import rx.Single;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
/**
* Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms
* and uses RxJava 1 types.
@@ -34,7 +32,7 @@ import rx.Single;
* @see Observable
*/
@NoRepositoryBean
public interface RxJava1CrudRepository<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
@@ -52,7 +50,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @return the saved entities.
* @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.
@@ -61,7 +59,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @return the saved entities.
* @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.
@@ -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.
* @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}.
@@ -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.
* @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.
@@ -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.
* @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.
@@ -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.
* @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.
@@ -112,7 +110,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @param ids must not be {@literal null}.
* @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.
@@ -120,7 +118,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @param idStream must not be {@literal null}.
* @return the found entities.
*/
Observable<T> findAll(Observable<ID> idStream);
Observable<T> findAllById(Observable<ID> idStream);
/**
* 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}.
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}.
*/
Completable delete(ID id);
Completable deleteById(ID id);
/**
* Deletes a given entity.
@@ -151,7 +149,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @param entities must not be {@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.
@@ -159,7 +157,7 @@ public interface RxJava1CrudRepository<T, ID extends Serializable> extends Repos
* @param entityStream must not be {@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.

View File

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

View File

@@ -20,8 +20,6 @@ import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
import java.io.Serializable;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
@@ -37,7 +35,7 @@ import org.springframework.data.repository.Repository;
* @see Completable
*/
@NoRepositoryBean
public interface RxJava2CrudRepository<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
@@ -55,7 +53,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @return the saved entities.
* @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.
@@ -64,7 +62,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @return the saved entities.
* @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.
@@ -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.
* @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}.
@@ -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.
* @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.
@@ -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.
* @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.
@@ -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.
* @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.
@@ -115,7 +113,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @param ids must not be {@literal null}.
* @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.
@@ -123,7 +121,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @param idStream must not be {@literal null}.
* @return the found entities.
*/
Flowable<T> findAll(Flowable<ID> idStream);
Flowable<T> findAllById(Flowable<ID> idStream);
/**
* 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}.
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}.
*/
Completable delete(ID id);
Completable deleteById(ID id);
/**
* Deletes a given entity.
@@ -154,7 +152,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @param entities must not be {@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.
@@ -162,7 +160,7 @@ public interface RxJava2CrudRepository<T, ID extends Serializable> extends Repos
* @param entityStream must not be {@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.

View File

@@ -17,8 +17,6 @@ package org.springframework.data.repository.reactive;
import io.reactivex.Flowable;
import java.io.Serializable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;
@@ -33,7 +31,7 @@ import org.springframework.data.repository.NoRepositoryBean;
* @see RxJava2CrudRepository
*/
@NoRepositoryBean
public interface RxJava2SortingRepository<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.

View File

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

View File

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

View File

@@ -154,7 +154,7 @@ public class DomainClassConverter<T extends ConversionService & ConverterRegistr
RepositoryInvoker invoker = repositoryInvokerFactory.getInvokerFor(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);
}
/*

View File

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

View File

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

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.repository.support;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -49,12 +48,12 @@ public class Repositories implements Iterable<Class<?>> {
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 final Optional<BeanFactory> beanFactory;
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.
@@ -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
* 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);
Class<?> userType = ClassUtils.getUserClass(domainClass);
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(userType);
RepositoryFactoryInformation<Object, Object> repositoryInfo = repositoryFactoryInfos.get(userType);
if (repositoryInfo != null) {
return repositoryInfo;
@@ -173,7 +172,7 @@ public class Repositories implements Iterable<Class<?>> {
* @return
*/
@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);
@@ -191,7 +190,7 @@ public class Repositories implements Iterable<Class<?>> {
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()
: Optional.of(information.getRepositoryInformation());
}
@@ -264,12 +263,12 @@ public class Repositories implements Iterable<Class<?>> {
*
* @author Thomas Darimont
*/
private static enum EmptyRepositoryFactoryInformation implements RepositoryFactoryInformation<Object, Serializable> {
private static enum EmptyRepositoryFactoryInformation implements RepositoryFactoryInformation<Object, Object> {
INSTANCE;
@Override
public EntityInformation<Object, Serializable> getEntityInformation() {
public EntityInformation<Object, Object> getEntityInformation() {
return null;
}

View File

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