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 TypeMethodDescriptionvoidvoidvoidvoidbooleanexistsByUserIdIs(Long userId) This method checks whether a user exists, given the user id.findByEmail(String email) Retrieves an Optional User instance based on the provided email.findByUsername(String username) Retrieves an Optional User instance based on the provided username.findByUsernameContaining(String inputString) findUserByUserId(Long userId) 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, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor
count, delete, exists, findAll, findAll, findAll, findBy, findOneMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods 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
Retrieves an Optional User instance based on the provided username.- Parameters:
username- the username to search for- Returns:
- an Optional User instance
-
findByEmail
Retrieves an Optional User instance based on the provided email.- Parameters:
email- The email to search for- Returns:
- An Optional User instance
-
findUserByUserId
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
-
existsByUserIdIs
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.
-