package com.mydreamjob.messaging; import org.springframework.data.jpa.repository.*; import org.springframework.data.repository.query.Param; public interface ChatAttachmentRepository extends JpaRepository { @Modifying @Query("delete from ChatAttachment a where a.messageId = :id") void purge(@Param("id") Long messageId); @Modifying @Query("delete from ChatAttachment a where a.messageId in (select m.id from Message m where m.senderUserId = :id)") void purgeForSender(@Param("id") Long userId); @Modifying(clearAutomatically=true,flushAutomatically=true) @Query("update Message m set m.attachmentFilename=null, m.attachmentContentType=null, " + "m.attachmentSize=null, m.attachmentSha256=null, m.attachmentWidth=null, m.attachmentHeight=null, " + "m.version=m.version+1 where m.senderUserId=:id and m.messageType in ('IMAGE','FILE') and m.attachmentSize is not null") void clearMetadataForSender(@Param("id") Long userId); }