Interface RepositoryInvoker
- All Superinterfaces:
RepositoryInvocationInformation
- All Known Implementing Classes:
QuerydslRepositoryInvokerAdapter
API to invoke (CRUD) methods on Spring Data repository instances independently of the base interface they expose.
Clients should check the availability of the methods before invoking them by using the methods of
RepositoryInvocationInformation
.- Since:
- 1.10
- Author:
- Oliver Gierke
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Invokes the method equivalent toCrudRepository.deleteById(Object)
.invokeFindAll
(Pageable pageable) Invokes the find-all method of the underlying repository using the method taking aPageable
as parameter if available (i.e. the equivalent toPagingAndSortingRepository.findAll(Pageable)
), using the method taking aSort
if available (i.e. the equivalent toPagingAndSortingRepository.findAll(Sort)
by extracting theSort
contained in the givenPageable
) or the plain equivalent toCrudRepository.findAll()
.invokeFindAll
(Sort sort) Invokes the find-all method of the underlying repository using the method taking aSort
as parameter if available (i.e. the equivalent toPagingAndSortingRepository.findAll(Sort)
) or the plain equivalent toCrudRepository.findAll()
.<T> Optional<T>
invokeFindById
(Object id) Invokes the method equivalent toCrudRepository.findById(Object)
.invokeQueryMethod
(Method method, MultiValueMap<String, ? extends Object> parameters, Pageable pageable, Sort sort) <T> T
invokeSave
(T object) Invokes the method equivalent toCrudRepository.save(Object)
on the repository.Methods inherited from interface org.springframework.data.repository.support.RepositoryInvocationInformation
hasDeleteMethod, hasFindAllMethod, hasFindOneMethod, hasSaveMethod
-
Method Details
-
invokeSave
<T> T invokeSave(T object) Invokes the method equivalent toCrudRepository.save(Object)
on the repository.- Parameters:
object
-- Returns:
- the result of the invocation of the save method
- Throws:
IllegalStateException
- if the repository does not expose a save method.
-
invokeFindById
Invokes the method equivalent toCrudRepository.findById(Object)
.- Parameters:
id
- must not be null.- Returns:
- the entity with the given id.
- Throws:
IllegalStateException
- if the repository does not expose a find-one-method.
-
invokeFindAll
Invokes the find-all method of the underlying repository using the method taking aPageable
as parameter if available (i.e. the equivalent toPagingAndSortingRepository.findAll(Pageable)
), using the method taking aSort
if available (i.e. the equivalent toPagingAndSortingRepository.findAll(Sort)
by extracting theSort
contained in the givenPageable
) or the plain equivalent toCrudRepository.findAll()
.- Parameters:
pageable
- must not be null.- Returns:
- the result of the invocation of the find-all method.
- Throws:
IllegalStateException
- if the repository does not expose a find-all-method.
-
invokeFindAll
Invokes the find-all method of the underlying repository using the method taking aSort
as parameter if available (i.e. the equivalent toPagingAndSortingRepository.findAll(Sort)
) or the plain equivalent toCrudRepository.findAll()
.- Parameters:
sort
- must not be null.- Returns:
- the result of the invocation of the find-all method.
- Throws:
IllegalStateException
- if the repository does not expose a find-all-method.
-
invokeDeleteById
Invokes the method equivalent toCrudRepository.deleteById(Object)
. The given id is assumed to be of a type convertible into the actual identifier type of the backing repository.- Parameters:
id
- must not be null.
-
invokeQueryMethod
Optional<Object> invokeQueryMethod(Method method, MultiValueMap<String, ? extends Object> parameters, Pageable pageable, Sort sort) - Parameters:
method
- must not be null.parameters
- must not be null.pageable
- must not be null.sort
- must not be null.- Returns:
- the result of the invoked query method.
- Since:
- 1.11
-