Interface RxJava3CrudRepository<T,ID>

All Superinterfaces:
Repository<T,ID>

@NoRepositoryBean public interface RxJava3CrudRepository<T,ID> extends Repository<T,ID>
Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms and uses RxJava 3 types. Methods exposed through this interface allow entities to participate in lifecycle events, and optimistic locking if applicable except for some bulk operation methods. Therefore, modules may choose to load an entity before deleting or updating it in order to facilitate events, and any modifying method call may trigger an exception due to failure of optimistic locking.

Save and delete operations with entities that have a version attribute trigger an onError with a OptimisticLockingFailureException when they encounter a different version value in the persistence store than in the entity passed as an argument.

Other delete operations that only receive ids or entities without version attribute do not trigger an error when no matching data is found in the persistence store.

Since:
2.4
Author:
Mark Paluch
See Also:
  • Method Details

    • save

      <S extends T> Single<S> save(S entity)
      Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely.
      Parameters:
      entity - must not be null.
      Returns:
      Single emitting the saved entity.
      Throws:
      IllegalArgumentException - in case the given entity is null.
      OptimisticLockingFailureException - when the entity uses optimistic locking and has a version attribute with a different value from that found in the persistence store. Also thrown if the entity is assumed to be present but does not exist in the database.
    • saveAll

      <S extends T> Flowable<S> saveAll(Iterable<S> entities)
      Saves all given entities.
      Parameters:
      entities - must not be null.
      Returns:
      Flowable emitting the saved entities.
      Throws:
      IllegalArgumentException - in case the given entities or one of its entities is null.
      OptimisticLockingFailureException - when at least one entity uses optimistic locking and has a version attribute with a different value from that found in the persistence store. Also thrown if at least one entity is assumed to be present but does not exist in the database.
    • saveAll

      <S extends T> Flowable<S> saveAll(Flowable<S> entityStream)
      Saves all given entities.
      Parameters:
      entityStream - must not be null.
      Returns:
      Flowable emitting the saved entities.
      Throws:
      IllegalArgumentException - in case the given entityStream is null.
      OptimisticLockingFailureException - when at least one entity uses optimistic locking and has a version attribute with a different value from that found in the persistence store. Also thrown if at least one entity is assumed to be present but does not exist in the database.
    • findById

      Maybe<T> findById(ID id)
      Retrieves an entity by its id.
      Parameters:
      id - must not be null.
      Returns:
      Maybe emitting the entity with the given id or Maybe.empty() if none found.
      Throws:
      IllegalArgumentException - in case the given id is null.
    • findById

      Maybe<T> findById(Single<ID> id)
      Retrieves an entity by its id supplied by a Single.
      Parameters:
      id - must not be null. Uses the first emitted element to perform the find-query.
      Returns:
      Maybe emitting the entity with the given id or Maybe.empty() if none found.
      Throws:
      IllegalArgumentException - in case the given id is null.
    • existsById

      Single<Boolean> existsById(ID id)
      Returns whether an entity with the given id exists.
      Parameters:
      id - must not be null.
      Returns:
      Single emitting true if an entity with the given id exists, false otherwise.
      Throws:
      IllegalArgumentException - in case the given id is null.
    • existsById

      Single<Boolean> existsById(Single<ID> id)
      Returns whether an entity with the given id, supplied by a Single, exists.
      Parameters:
      id - must not be null.
      Returns:
      Single emitting true if an entity with the given id exists, false otherwise.
      Throws:
      IllegalArgumentException - in case the given id is null.
    • findAll

      Flowable<T> findAll()
      Returns all instances of the type.
      Returns:
      Flowable emitting all entities.
    • findAllById

      Flowable<T> findAllById(Iterable<ID> ids)
      Returns all instances of the type T with the given IDs.

      If some or all ids are not found, no entities are returned for these IDs.

      Note that the order of elements in the result is not guaranteed.

      Parameters:
      ids - must not be null nor contain any null values.
      Returns:
      Flowable emitting the found entities. The size can be equal or less than the number of given ids.
      Throws:
      IllegalArgumentException - in case the given ids or one of its items is null.
    • findAllById

      Flowable<T> findAllById(Flowable<ID> idStream)
      Returns all instances of the type T with the given IDs supplied by a Flowable.

      If some or all ids are not found, no entities are returned for these IDs.

      Note that the order of elements in the result is not guaranteed.

      Parameters:
      idStream - must not be null.
      Returns:
      Flowable emitting the found entities.
      Throws:
      IllegalArgumentException - in case the given idStream is null.
    • count

      Single<Long> count()
      Returns the number of entities available.
      Returns:
      Single emitting the number of entities.
    • deleteById

      Completable deleteById(ID id)
      Deletes the entity with the given id.

      If the entity is not found in the persistence store it is silently ignored.

      Parameters:
      id - must not be null.
      Returns:
      Completable signaling when operation has completed.
      Throws:
      IllegalArgumentException - in case the given id is null.
    • delete

      Completable delete(T entity)
      Deletes a given entity.
      Parameters:
      entity - must not be null.
      Returns:
      Completable signaling when operation has completed.
      Throws:
      IllegalArgumentException - in case the given entity is null.
      OptimisticLockingFailureException - when the entity uses optimistic locking and has a version attribute with a different value from that found in the persistence store. Also thrown if the entity is assumed to be present but does not exist in the database.
    • deleteAllById

      Completable deleteAllById(Iterable<? extends ID> ids)
      Deletes all instances of the type T with the given IDs.

      Entities that aren't found in the persistence store are silently ignored.

      Parameters:
      ids - must not be null.
      Returns:
      Completable signaling when operation has completed.
      Throws:
      IllegalArgumentException - in case the given ids or one of its elements is null. null.
      Since:
      2.5
    • deleteAll

      Completable deleteAll(Iterable<? extends T> entities)
      Deletes the given entities.
      Parameters:
      entities - must not be null.
      Returns:
      Completable signaling when operation has completed.
      Throws:
      IllegalArgumentException - in case the given entities or one of its entities is null.
      OptimisticLockingFailureException - when at least one entity uses optimistic locking and has a version attribute with a different value from that found in the persistence store. Also thrown if at least one entity is assumed to be present but does not exist in the database.
    • deleteAll

      Completable deleteAll(Flowable<? extends T> entityStream)
      Deletes the given entities supplied by a Flowable.
      Parameters:
      entityStream - must not be null.
      Returns:
      Completable signaling when operation has completed.
      Throws:
      IllegalArgumentException - in case the given entityStream is null.
      OptimisticLockingFailureException - when at least one entity uses optimistic locking and has a version attribute with a different value from that found in the persistence store. Also thrown if at least one entity is assumed to be present but does not exist in the database.
    • deleteAll

      Completable deleteAll()
      Deletes all entities managed by the repository.
      Returns:
      Completable signaling when operation has completed.