diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/v2/creator/channel/community/translation/adapter/out/persistence/CreatorCommunityTranslation.kt b/src/main/kotlin/kr/co/vividnext/sodalive/v2/creator/channel/community/translation/adapter/out/persistence/CreatorCommunityTranslation.kt new file mode 100644 index 00000000..9a3da987 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/v2/creator/channel/community/translation/adapter/out/persistence/CreatorCommunityTranslation.kt @@ -0,0 +1,37 @@ +package kr.co.vividnext.sodalive.v2.creator.channel.community.translation.adapter.out.persistence + +import kr.co.vividnext.sodalive.common.BaseEntity +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.Table +import javax.persistence.UniqueConstraint + +@Entity +@Table( + name = "creator_community_translation", + uniqueConstraints = [ + UniqueConstraint( + name = "uk_creator_community_translation_post_locale", + columnNames = ["creator_community_id", "locale"] + ) + ] +) +class CreatorCommunityTranslation( + @Column(name = "creator_community_id", nullable = false) + val creatorCommunityId: Long, + + @Column(nullable = false, length = 10) + val locale: String, + + @Column(nullable = false, columnDefinition = "text") + var content: String, + + @Column(name = "source_revision", nullable = false) + var sourceRevision: Long, + + @Column(name = "source_hash", nullable = false, length = 64) + var sourceHash: String, + + @Column(name = "source_language", nullable = false, length = 10) + var sourceLanguage: String +) : BaseEntity() diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/v2/creator/channel/community/translation/adapter/out/persistence/CreatorCommunityTranslationRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/v2/creator/channel/community/translation/adapter/out/persistence/CreatorCommunityTranslationRepository.kt new file mode 100644 index 00000000..fb603ce8 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/v2/creator/channel/community/translation/adapter/out/persistence/CreatorCommunityTranslationRepository.kt @@ -0,0 +1,26 @@ +package kr.co.vividnext.sodalive.v2.creator.channel.community.translation.adapter.out.persistence + +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Lock +import org.springframework.data.jpa.repository.Query +import org.springframework.data.repository.query.Param +import javax.persistence.LockModeType + +interface CreatorCommunityTranslationRepository : JpaRepository { + fun findByCreatorCommunityIdAndLocale(creatorCommunityId: Long, locale: String): CreatorCommunityTranslation? + + @Lock(LockModeType.PESSIMISTIC_WRITE) + @Query( + "select t from CreatorCommunityTranslation t " + + "where t.creatorCommunityId = :creatorCommunityId and t.locale = :locale" + ) + fun findByCreatorCommunityIdAndLocaleForUpdate( + @Param("creatorCommunityId") creatorCommunityId: Long, + @Param("locale") locale: String + ): CreatorCommunityTranslation? + + fun findByCreatorCommunityIdInAndLocale( + creatorCommunityIds: Collection, + locale: String + ): List +}