Interface ConversationRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Conversation,,UUID> org.springframework.data.jpa.repository.JpaRepository<Conversation,,UUID> org.springframework.data.repository.ListCrudRepository<Conversation,,UUID> org.springframework.data.repository.ListPagingAndSortingRepository<Conversation,,UUID> org.springframework.data.repository.PagingAndSortingRepository<Conversation,,UUID> org.springframework.data.repository.query.QueryByExampleExecutor<Conversation>,org.springframework.data.repository.Repository<Conversation,UUID>
@Repository
public interface ConversationRepository
extends org.springframework.data.jpa.repository.JpaRepository<Conversation,UUID>
-
Field Summary
FieldsModifier and TypeFieldDescriptionMap of field name to column name -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateConversation(UUID conversationId) Activate a conversationlongcountByConversationTypeAndActiveTrue(ConversationType conversationType) Count active conversations by typevoiddeactivateConversation(UUID conversationId) Deactivate a conversationbooleanexistsByIdAndActiveTrue(UUID conversationId) Checks if the conversation exists and is active by its unique conversation IDbooleanexistsDirectConversationBetweenUsers(UUID user1Id, UUID user2Id) Check if a conversation exists between two users (for DIRECT type)Find a conversation by its unique conversation IDorg.springframework.data.domain.Page<Conversation> findByNameContainingIgnoreCase(UUID userId, String term, org.springframework.data.domain.Pageable pageable) Search conversations by search term in the nameorg.springframework.data.domain.Page<Conversation> findConversationsForUser(UUID userId, org.springframework.data.domain.Pageable pageable) Find the requested page from all conversations for a user.findDirectConversationBetweenUsers(UUID user1Id, UUID user2Id) Find direct conversation between two usersvoidupdateLastActivity(UUID conversationId, Instant timestamp) Update last activity timestamp for a conversationMethods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, 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.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
-
Field Details
-
FIELD_COLUMN_NAME_MAP
Map of field name to column name
-
-
Method Details
-
findById
Find a conversation by its unique conversation ID- Specified by:
findByIdin interfaceorg.springframework.data.repository.CrudRepository<Conversation,UUID>
-
existsByIdAndActiveTrue
Checks if the conversation exists and is active by its unique conversation ID -
findConversationsForUser
@Query("SELECT c FROM Conversation c JOIN ConversationParticipant cp ON cp.conversationId = c.id WHERE cp.userId = :userId AND cp.active = true AND c.active = true") org.springframework.data.domain.Page<Conversation> findConversationsForUser(@Param("userId") UUID userId, org.springframework.data.domain.Pageable pageable) Find the requested page from all conversations for a user. -
findDirectConversationBetweenUsers
@Query("SELECT c FROM Conversation c WHERE c.conversationType = \'DIRECT\' AND c.active = true AND ((c.participantOneId = :user1Id AND c.participantTwoId = :user2Id) OR (c.participantOneId = :user2Id AND c.participantTwoId = :user1Id))") Optional<Conversation> findDirectConversationBetweenUsers(@Param("user1Id") UUID user1Id, @Param("user2Id") UUID user2Id) Find direct conversation between two users -
findByNameContainingIgnoreCase
@Query(value="SELECT c.*\nFROM conversations c\nJOIN conversation_participants cp\n ON cp.conversation_id = c.id\n AND cp.user_id = :userId AND cp.is_active = true\nWHERE c.active = true\n AND (\n (c.conversation_type = \'GROUP\' AND LOWER(c.name) LIKE LOWER(\'%\' || :term || \'%\'))\n OR (\n c.conversation_type = \'DIRECT\'\n AND EXISTS (\n SELECT 1 FROM conversation_participants cp2\n JOIN users u on u.id = cp2.user_id\n WHERE cp2.conversation_id = c.id AND cp2.is_active = true\n AND LOWER(u.first_name || \' \' || u.last_name) LIKE LOWER(\'%\' || :term || \'%\')\n )\n )\n )\n", countQuery="SELECT COUNT(c.id)\nFROM conversations c\nJOIN conversation_participants cp\n ON cp.conversation_id = c.id\n AND cp.user_id = :userId AND cp.is_active = true\nWHERE c.active = true\n AND (\n (c.conversation_type = \'GROUP\' AND LOWER(c.name) LIKE LOWER(\'%\' || :term || \'%\'))\n OR (\n c.conversation_type = \'DIRECT\'\n AND EXISTS (\n SELECT 1 FROM conversation_participants cp2\n JOIN users u on u.id = cp2.user_id\n WHERE cp2.conversation_id = c.id AND cp2.is_active = true\n AND LOWER(u.first_name || \' \' || u.last_name) LIKE LOWER(\'%\' || :term || \'%\')\n )\n )\n )\n", nativeQuery=true) org.springframework.data.domain.Page<Conversation> findByNameContainingIgnoreCase(@Param("userId") UUID userId, @Param("term") String term, org.springframework.data.domain.Pageable pageable) Search conversations by search term in the name -
countByConversationTypeAndActiveTrue
Count active conversations by type -
updateLastActivity
@Modifying @Query("UPDATE Conversation c SET c.lastActivity = :timestamp WHERE c.id = :conversationId") void updateLastActivity(@Param("conversationId") UUID conversationId, @Param("timestamp") Instant timestamp) Update last activity timestamp for a conversation -
deactivateConversation
@Modifying @Query("UPDATE Conversation c SET c.active = false WHERE c.id = :conversationId") void deactivateConversation(@Param("conversationId") UUID conversationId) Deactivate a conversation -
activateConversation
@Modifying @Query("UPDATE Conversation c SET c.active = true WHERE c.id = :conversationId") void activateConversation(@Param("conversationId") UUID conversationId) Activate a conversation -
existsDirectConversationBetweenUsers
@Query("SELECT CASE WHEN COUNT(c) > 0 THEN true ELSE false END FROM Conversation c WHERE c.conversationType = \'DIRECT\' AND c.active = true AND ((c.participantOneId = :user1Id AND c.participantTwoId = :user2Id) OR (c.participantOneId = :user2Id AND c.participantTwoId = :user1Id))") boolean existsDirectConversationBetweenUsers(@Param("user1Id") UUID user1Id, @Param("user2Id") UUID user2Id) Check if a conversation exists between two users (for DIRECT type)
-