View Javadoc
1   package ca.uhn.fhir.jpa.dao.data;
2   
3   import ca.uhn.fhir.jpa.entity.Search;
4   import org.springframework.data.domain.Pageable;
5   import org.springframework.data.domain.Slice;
6   import org.springframework.data.jpa.repository.JpaRepository;
7   import org.springframework.data.jpa.repository.Modifying;
8   import org.springframework.data.jpa.repository.Query;
9   import org.springframework.data.repository.query.Param;
10  
11  import java.util.Collection;
12  import java.util.Date;
13  
14  /*
15   * #%L
16   * HAPI FHIR JPA Server
17   * %%
18   * Copyright (C) 2014 - 2018 University Health Network
19   * %%
20   * Licensed under the Apache License, Version 2.0 (the "License");
21   * you may not use this file except in compliance with the License.
22   * You may obtain a copy of the License at
23   * 
24   * http://www.apache.org/licenses/LICENSE-2.0
25   * 
26   * Unless required by applicable law or agreed to in writing, software
27   * distributed under the License is distributed on an "AS IS" BASIS,
28   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29   * See the License for the specific language governing permissions and
30   * limitations under the License.
31   * #L%
32   */
33  
34  public interface ISearchDao extends JpaRepository<Search, Long> {
35  
36  	@Query("SELECT s FROM Search s WHERE s.myUuid = :uuid")
37  	Search findByUuid(@Param("uuid") String theUuid);
38  
39  	@Query("SELECT s.myId FROM Search s WHERE s.mySearchLastReturned < :cutoff")
40  	Slice<Long> findWhereLastReturnedBefore(@Param("cutoff") Date theCutoff, Pageable thePage);
41  
42  //	@Query("SELECT s FROM Search s WHERE s.myCreated < :cutoff")
43  //	public Collection<Search> findWhereCreatedBefore(@Param("cutoff") Date theCutoff);
44  
45  	@Query("SELECT s FROM Search s WHERE s.myResourceType = :type AND mySearchQueryStringHash = :hash AND s.myCreated > :cutoff AND s.myDeleted = false")
46  	Collection<Search> find(@Param("type") String theResourceType, @Param("hash") int theHashCode, @Param("cutoff") Date theCreatedCutoff);
47  
48  	@Modifying
49  	@Query("UPDATE Search s SET s.mySearchLastReturned = :last WHERE s.myId = :pid")
50  	void updateSearchLastReturned(@Param("pid") long thePid, @Param("last") Date theDate);
51  
52  	@Modifying
53  	@Query("UPDATE Search s SET s.myDeleted = :deleted WHERE s.myId = :pid")
54  	void updateDeleted(@Param("pid") Long thePid, @Param("deleted") boolean theDeleted);
55  
56  	@Modifying
57  	@Query("DELETE FROM Search s WHERE s.myId = :pid")
58  	void deleteByPid(@Param("pid") Long theId);
59  }