Interface UserRepository

  • All Superinterfaces:
    org.springframework.data.repository.CrudRepository<User,​Long>, org.springframework.data.jpa.repository.JpaRepository<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>
    Class represent repository which is responsible for users db operations
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      Optional<User> findByEmail​(String email)
      Gets user by email
      Optional<User> findByUsername​(String userName)
      Gets user by username
      List<User> getNonAdminUsers()
      Gets all non admin users
      • 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, findAll, findAll, findAllById, flush, getById, getOne, saveAll, saveAllAndFlush, saveAndFlush
      • 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 Detail

      • findByUsername

        Optional<User> findByUsername​(String userName)
        Gets user by username
        Parameters:
        userName - username
        Returns:
        found user
      • findByEmail

        Optional<User> findByEmail​(String email)
        Gets user by email
        Parameters:
        email - email
        Returns:
        found user
      • getNonAdminUsers

        @Query(value="select * from user u where \'ROLE_ADMIN\' not in (select r.name from role r join users_roles ur on r.id = ur.role_id where ur.user_id = u.id) order by username",
               nativeQuery=true)
        List<User> getNonAdminUsers()
        Gets all non admin users
        Returns:
        all non admin users