Interface UserRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<User,Long>, org.springframework.data.jpa.repository.JpaRepository<User,Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<User>, org.springframework.data.repository.ListCrudRepository<User,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<User,Long>, org.springframework.data.repository.PagingAndSortingRepository<User,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<User>, org.springframework.data.repository.Repository<User,Long>

@Repository public interface UserRepository extends org.springframework.data.jpa.repository.JpaRepository<User,Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<User>
This repository provides CRUD operations for the User entity. It extends JpaRepository and JpaSpecificationExecutor interfaces. JpaRepository provides basic CRUD operations while JpaSpecificationExecutor provides search functionality using specifications.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    void
     
    void
     
    boolean
    This method checks whether a user exists, given the user id.
    Retrieves an Optional User instance based on the provided email.
    Retrieves an Optional User instance based on the provided username.
     
    Retrieves an Optional User instance based on the provided user id.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor

    count, delete, exists, findAll, findAll, findAll, findBy, findOne

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • createTriggerForDeletingMember

      @Modifying @Transactional @Query(value="CREATE TRIGGER delete_fridge_member BEFORE DELETE ON users FOR EACH ROW BEGIN DELETE FROM fridge_members WHERE fridge_members.user_id = OLD.user_id; END; ", nativeQuery=true) @Profile("!test") void createTriggerForDeletingMember()
    • dropMemberTrigger

      @Modifying @Transactional @Query(value="DROP TRIGGER IF EXISTS delete_fridge_member", nativeQuery=true) @Profile("!test") void dropMemberTrigger()
    • createTriggerForNullingUserStat

      @Modifying @Transactional @Query(value="CREATE TRIGGER delete_user_stat BEFORE DELETE ON users FOR EACH ROW BEGIN UPDATE stats SET user_id = null WHERE user_id = OLD.user_id; END; ", nativeQuery=true) @Profile("!test") void createTriggerForNullingUserStat()
    • dropUserStatTrigger

      @Modifying @Transactional @Query(value="DROP TRIGGER IF EXISTS delete_user_stat", nativeQuery=true) @Profile("!test") void dropUserStatTrigger()
    • findByUsername

      Optional<User> findByUsername(String username)
      Retrieves an Optional User instance based on the provided username.
      Parameters:
      username - the username to search for
      Returns:
      an Optional User instance
    • findByEmail

      Optional<User> findByEmail(String email)
      Retrieves an Optional User instance based on the provided email.
      Parameters:
      email - The email to search for
      Returns:
      An Optional User instance
    • findUserByUserId

      Optional<User> findUserByUserId(Long userId)
      Retrieves an Optional User instance based on the provided user id.
      Parameters:
      userId - The user ID to search for
      Returns:
      An Optional User instance
    • findByUsernameContaining

      @Query("SELECT u FROM User u WHERE LOWER(u.username) LIKE %:inputString%") List<User> findByUsernameContaining(@Param("inputString") String inputString)
    • existsByUserIdIs

      boolean existsByUserIdIs(Long userId)
      This method checks whether a user exists, given the user id.
      Parameters:
      userId - ID of the user, given as a Long object.
      Returns:
      Status of whether user exists.