package garbagetown.domain.repository.reserve;

import garbagetown.domain.model.Customer;
import garbagetown.domain.model.Reserve;
import garbagetown.domain.model.Tourinfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by garbagetown on 10/27/15.
 */
public interface ReserveRepository extends JpaRepository<Reserve, String> {

    @Query("SELECT r FROM Reserve AS r LEFT JOIN FETCH r.tourinfo AS t LEFT JOIN FETCH t.departure LEFT JOIN FETCH t.arrival WHERE r.customer = :customer ORDER BY t.depDay, r.reserveNo")
    List<Reserve> findAllByCustomer(@Param("customer") Customer customer);

    @Query("SELECT SUM(r.adultCount + r.childCount) FROM Reserve r WHERE r.tourinfo = :tourinfo")
    Long countReservedPersonSumByTourinfo(@Param("tourinfo") Tourinfo tourinfo);
}

@@ -224,24 +224,77 @@
 Repository;%0A
+import org.springframework.data.jpa.repository.Lock;%0A
 import org.s
@@ -392,16 +392,55 @@
 Param;%0A%0A
+import javax.persistence.LockModeType;%0A
 import j
@@ -1020,11 +1020,189 @@
 urinfo);
+%0A%0A    @Query(%22SELECT r FROM Reserve r WHERE reserveNo = :reserveNo%22)%0A    @Lock(LockModeType.PESSIMISTIC_WRITE)%0A    Reserve findOneForUpdate(@Param(%22reserveNo%22) String reserveNo);
 %0A%7D%0A

add findOneForUpdate