Interface CrudRepository<E,​ID>

  • Type Parameters:
    E - The entity type
    ID - The ID type
    All Superinterfaces:
    GenericRepository<E,​ID>
    All Known Subinterfaces:
    PageableRepository<E,​ID>

    @Validated
    public interface CrudRepository<E,​ID>
    extends GenericRepository<E,​ID>
    A repository interface for performing CRUD (Create, Read, Update, Delete). This is a blocking variant and is largely based on the same interface in Spring Data, however includes integrated validation support.
    Since:
    1.0
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      long count()
      Returns the number of entities available.
      void delete​(E entity)
      Deletes a given entity.
      void deleteAll()
      Deletes all entities managed by the repository.
      void deleteAll​(@NotNull java.lang.Iterable<? extends E> entities)
      Deletes the given entities.
      void deleteById​(ID id)
      Deletes the entity with the given id.
      boolean existsById​(ID id)
      Returns whether an entity with the given id exists.
      java.lang.Iterable<E> findAll()
      Returns all instances of the type.
      java.util.Optional<E> findById​(ID id)
      Retrieves an entity by its id.
      <S extends E>
      S
      save​(S entity)
      Saves the given valid entity, returning a possibly new entity representing the saved state.
      <S extends E>
      java.lang.Iterable<S>
      saveAll​(@Valid @NotNull java.lang.Iterable<S> entities)
      Saves all given entities, possibly returning new instances representing the saved state.
      <S extends E>
      S
      update​(S entity)
      This method issues an explicit update for the given entity.
      <S extends E>
      java.lang.Iterable<S>
      updateAll​(@Valid @NotNull java.lang.Iterable<S> entities)
      This method issues an explicit update for the given entities.
    • Method Detail

      • save

        @NonNull
        <S extends E> S save​(@Valid @NotNull @NonNull
                             S entity)
        Saves the given valid entity, returning a possibly new entity representing the saved state. Note that certain implementations may not be able to detect whether a save or update should be performed and may always perform an insert. The update(Object) method can be used in this case to explicitly request an update.
        Type Parameters:
        S - The generic type
        Parameters:
        entity - The entity to save. Must not be null.
        Returns:
        The saved entity will never be null.
        Throws:
        javax.validation.ConstraintViolationException - if the entity is null or invalid.
      • update

        @NonNull
        <S extends E> S update​(@Valid @NotNull @NonNull
                               S entity)
        This method issues an explicit update for the given entity. The method differs from save(Object) in that an update will be generated regardless if the entity has been saved previously or not. If the entity has no assigned ID then an exception will be thrown.
        Type Parameters:
        S - The generic type
        Parameters:
        entity - The entity to save. Must not be null.
        Returns:
        The updated entity will never be null.
        Throws:
        javax.validation.ConstraintViolationException - if the entity is null or invalid.
      • updateAll

        @NonNull
        <S extends E> java.lang.Iterable<S> updateAll​(@Valid @NotNull @NonNull
                                                      @Valid @NotNull java.lang.Iterable<S> entities)
        This method issues an explicit update for the given entities. The method differs from saveAll(Iterable) in that an update will be generated regardless if the entity has been saved previously or not. If the entity has no assigned ID then an exception will be thrown.
        Type Parameters:
        S - The generic type
        Parameters:
        entities - The entities to update. Must not be null.
        Returns:
        The updated entities will never be null.
        Throws:
        javax.validation.ConstraintViolationException - if entities is null or invalid.
      • saveAll

        @NonNull
        <S extends E> java.lang.Iterable<S> saveAll​(@Valid @NotNull @NonNull
                                                    @Valid @NotNull java.lang.Iterable<S> entities)
        Saves all given entities, possibly returning new instances representing the saved state.
        Type Parameters:
        S - The generic type
        Parameters:
        entities - The entities to saved. Must not be null.
        Returns:
        The saved entities objects. will never be null.
        Throws:
        javax.validation.ConstraintViolationException - if the entities are null.
      • findById

        @NonNull
        java.util.Optional<E> findById​(@NotNull @NonNull
                                       ID id)
        Retrieves an entity by its id.
        Parameters:
        id - The ID of the entity to retrieve. Must not be null.
        Returns:
        the entity with the given id or Optional#empty() if none found
        Throws:
        javax.validation.ConstraintViolationException - if the id is null.
      • existsById

        boolean existsById​(@NotNull @NonNull
                           ID id)
        Returns whether an entity with the given id exists.
        Parameters:
        id - must not be null.
        Returns:
        true if an entity with the given id exists, false otherwise.
        Throws:
        javax.validation.ConstraintViolationException - if the id is null.
      • findAll

        @NonNull
        java.lang.Iterable<E> findAll()
        Returns all instances of the type.
        Returns:
        all entities
      • count

        long count()
        Returns the number of entities available.
        Returns:
        the number of entities
      • deleteById

        void deleteById​(@NonNull @NotNull
                        ID id)
        Deletes the entity with the given id.
        Parameters:
        id - must not be null.
        Throws:
        javax.validation.ConstraintViolationException - if the entity is null.
      • delete

        void delete​(@NonNull @NotNull
                    E entity)
        Deletes a given entity.
        Parameters:
        entity - The entity to delete
        Throws:
        javax.validation.ConstraintViolationException - if the entity is null.
      • deleteAll

        void deleteAll​(@NonNull @NotNull
                       @NotNull java.lang.Iterable<? extends E> entities)
        Deletes the given entities.
        Parameters:
        entities - The entities to delete
        Throws:
        javax.validation.ConstraintViolationException - if the entity is null.
      • deleteAll

        void deleteAll()
        Deletes all entities managed by the repository.