package com.td.boss.game.combosses.repository;

import com.td.boss.common.repository.*;
import com.td.boss.game.combosses.pojo.ComBosses;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.persistence.LockModeType;
import java.util.Optional;

@Repository
public interface ComBossesRepository extends CommonRepository<ComBosses, Integer> {

    /**
     * 添加jpa行锁，获取boss当前信息
     * @param id
     * @return
     */
    @Lock(value = LockModeType.PESSIMISTIC_WRITE)
    @Query("select a from ComBosses a where a.id = :id")
    Optional<ComBosses> findComBossesWithPessimisticLock(Integer id);
}
