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

    Fields
    Modifier and Type
    Field
    Description
    static final Map<String,String>
    Map of field name to column name
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    activateConversation(UUID conversationId)
    Activate a conversation
    long
    Count active conversations by type
    void
    deactivateConversation(UUID conversationId)
    Deactivate a conversation
    boolean
    existsByIdAndActiveTrue(UUID conversationId)
    Checks if the conversation exists and is active by its unique conversation ID
    boolean
    Check if a conversation exists between two users (for DIRECT type)
    findById(UUID conversationId)
    Find a conversation by its unique conversation ID
    org.springframework.data.domain.Page<Conversation>
    findByNameContainingIgnoreCase(UUID userId, String term, org.springframework.data.domain.Pageable pageable)
    Search conversations by search term in the name
    org.springframework.data.domain.Page<Conversation>
    findConversationsForUser(UUID userId, org.springframework.data.domain.Pageable pageable)
    Find the requested page from all conversations for a user.
    Find direct conversation between two users
    void
    updateLastActivity(UUID conversationId, Instant timestamp)
    Update last activity timestamp for a conversation

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

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, 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.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
  • Field Details

    • FIELD_COLUMN_NAME_MAP

      static final Map<String,String> FIELD_COLUMN_NAME_MAP
      Map of field name to column name
  • Method Details

    • findById

      @NonNull Optional<Conversation> findById(@NonNull UUID conversationId)
      Find a conversation by its unique conversation ID
      Specified by:
      findById in interface org.springframework.data.repository.CrudRepository<Conversation,UUID>
    • existsByIdAndActiveTrue

      boolean existsByIdAndActiveTrue(@NonNull UUID conversationId)
      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

      long countByConversationTypeAndActiveTrue(ConversationType conversationType)
      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)