001package ca.uhn.fhir.jpa.dao.data;
002
003import ca.uhn.fhir.jpa.entity.Search;
004import ca.uhn.fhir.jpa.entity.SearchResult;
005import org.springframework.data.domain.Pageable;
006import org.springframework.data.domain.Slice;
007import org.springframework.data.jpa.repository.JpaRepository;
008import org.springframework.data.jpa.repository.Modifying;
009import org.springframework.data.jpa.repository.Query;
010import org.springframework.data.repository.query.Param;
011
012import java.util.List;
013
014/*
015 * #%L
016 * HAPI FHIR JPA Server
017 * %%
018 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
019 * %%
020 * Licensed under the Apache License, Version 2.0 (the "License");
021 * you may not use this file except in compliance with the License.
022 * You may obtain a copy of the License at
023 *
024 *      http://www.apache.org/licenses/LICENSE-2.0
025 *
026 * Unless required by applicable law or agreed to in writing, software
027 * distributed under the License is distributed on an "AS IS" BASIS,
028 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
029 * See the License for the specific language governing permissions and
030 * limitations under the License.
031 * #L%
032 */
033
034public interface ISearchResultDao extends JpaRepository<SearchResult, Long>, IHapiFhirJpaRepository {
035        
036        @Query(value="SELECT r.myResourcePid FROM SearchResult r WHERE r.mySearchPid = :search ORDER BY r.myOrder ASC")
037        Slice<Long> findWithSearchPid(@Param("search") Long theSearchPid, Pageable thePage);
038
039        @Query(value="SELECT r.myResourcePid FROM SearchResult r WHERE r.mySearchPid = :search")
040        List<Long> findWithSearchPidOrderIndependent(@Param("search") Long theSearchPid);
041
042        @Query(value="SELECT r.myId FROM SearchResult r WHERE r.mySearchPid = :search")
043        Slice<Long> findForSearch(Pageable thePage, @Param("search") Long theSearchPid);
044
045        @Modifying
046        @Query("DELETE FROM SearchResult s WHERE s.myId IN :ids")
047        void deleteByIds(@Param("ids") List<Long> theContent);
048
049        @Query("SELECT count(r) FROM SearchResult r WHERE r.mySearchPid = :search")
050        int countForSearch(@Param("search") Long theSearchPid);
051}