package com.ym.dao;

import com.ym.pojo.Room;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * Created by weiqinxiao on 2019/2/25.
 */
@Repository
public interface RoomDao extends JpaRepository<Room, Long> {
    Room findByRid(String rid);

    @Query(value = "select * from rongyun_room where rid=?1 FOR UPDATE", nativeQuery = true)
    Room findByLockRid(String rid);

    @Modifying
    int deleteByRid(String rid);

    boolean existsByRid(String rid);

    @Modifying
    @Query(value = "update rongyun_room set display=?2 where rid=?1", nativeQuery = true)
    int updateDisplayByRid(String rid, String display);

    @Modifying
    @Query(value = "update rongyun_room set whiteboard_name_index=?2 where rid=?1", nativeQuery = true)
    int updateWhiteboardNameIndexByRid(String rid, int whiteboardNameIndex);
}