/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.dao import net.piedpiper.bremer.entity.TagEntity import net.piedpiper.bremer.utils.DaoUtils import org.apache.ibatis.annotations.* import org.springframework.stereotype.Repository @Repository("bremer.dao.TagDao") @Mapper interface TagDao { @ResultMap("net.piedpiper.bremer.TagEntity") @Select("SELECT * FROM tag WHERE slug = #{slug}") fun findOneBySlug(@Param("slug") slug: String): TagEntity? @ResultMap("net.piedpiper.bremer.TagEntity") @Select("SELECT * FROM tag WHERE slug = #{slug} FOR UPDATE") fun findOneBySlugWithLock(@Param("slug") slug: String): TagEntity? @ResultMap("net.piedpiper.bremer.TagEntity") @Select("SELECT * FROM tag") fun findAll(): List<TagEntity> @ResultMap("net.piedpiper.bremer.TagEntity") @Select("SELECT * FROM tag WHERE name LIKE CONCAT('%', #{nameLike}, '%') LIMIT #{limit}") fun findAllByNameLikeLimit( @Param("nameLike") nameLike: String, @Param("limit") limit: Int ): List<TagEntity> @InsertProvider(type = Sql::class, method = "insertOne") @Options(useGeneratedKeys = true, keyProperty = "id") fun insertOne(@Param("entity") entity: TagEntity): Boolean @UpdateProvider(type = Sql::class, method = "updateOne") fun updateOne(@Param("entity") entity: TagEntity) @Delete("DELETE FROM tag WHERE id = #{id}") fun deleteById(@Param("id") id: Long): Boolean class Sql { companion object { @JvmStatic @Options(useGeneratedKeys = true, keyColumn = "id") fun insertOne(@Param("entity") entity: TagEntity): String = DaoUtils.insertOne(entity) @JvmStatic fun updateOne(@Param("entity") entity: TagEntity): String = DaoUtils.updateOne(entity) } } }