View Javadoc
1   package ca.uhn.fhir.jpa.dao.data;
2   
3   import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
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.Query;
8   import org.springframework.data.jpa.repository.Temporal;
9   import org.springframework.data.repository.query.Param;
10  
11  import javax.persistence.TemporalType;
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 IResourceHistoryTableDao extends JpaRepository<ResourceHistoryTable, Long> {
35  
36  	@Query("SELECT COUNT(*) FROM ResourceHistoryTable t WHERE t.myUpdated >= :cutoff")
37  	int countForAllResourceTypes(
38  		@Temporal(value = TemporalType.TIMESTAMP) @Param("cutoff") Date theCutoff
39  	);
40  
41  	@Query("SELECT COUNT(*) FROM ResourceHistoryTable t")
42  	int countForAllResourceTypes(
43  	);
44  
45  	@Query("SELECT COUNT(*) FROM ResourceHistoryTable t WHERE t.myResourceId = :id AND t.myUpdated >= :cutoff")
46  	int countForResourceInstance(
47  		@Param("id") Long theId,
48  		@Temporal(value = TemporalType.TIMESTAMP) @Param("cutoff") Date theCutoff
49  	);
50  
51  	@Query("SELECT COUNT(*) FROM ResourceHistoryTable t WHERE t.myResourceId = :id")
52  	int countForResourceInstance(
53  		@Param("id") Long theId
54  	);
55  
56  	@Query("SELECT COUNT(*) FROM ResourceHistoryTable t WHERE t.myResourceType = :type AND t.myUpdated >= :cutoff")
57  	int countForResourceType(
58  		@Param("type") String theType,
59  		@Temporal(value = TemporalType.TIMESTAMP) @Param("cutoff") Date theCutoff
60  	);
61  
62  	@Query("SELECT COUNT(*) FROM ResourceHistoryTable t WHERE t.myResourceType = :type")
63  	int countForResourceType(
64  		@Param("type") String theType
65  	);
66  
67  	@Query("SELECT t FROM ResourceHistoryTable t WHERE t.myResourceId = :id AND t.myResourceVersion = :version")
68  	ResourceHistoryTable findForIdAndVersion(@Param("id") long theId, @Param("version") long theVersion);
69  
70  	@Query("SELECT t.myId FROM ResourceHistoryTable t WHERE t.myResourceId = :resId AND t.myResourceVersion != :dontWantVersion")
71  	Slice<Long> findForResourceId(Pageable thePage, @Param("resId") Long theId, @Param("dontWantVersion") Long theDontWantVersion);
72  
73  	@Query("" +
74  		"SELECT v.myId FROM ResourceHistoryTable v " +
75  		"LEFT OUTER JOIN ResourceTable t ON (v.myResourceId = t.myId) " +
76  		"WHERE v.myResourceVersion != t.myVersion AND " +
77  		"t.myResourceType = :restype")
78  	Slice<Long> findIdsOfPreviousVersionsOfResources(Pageable thePage, @Param("restype") String theResourceName);
79  
80  	@Query("" +
81  		"SELECT v.myId FROM ResourceHistoryTable v " +
82  		"LEFT OUTER JOIN ResourceTable t ON (v.myResourceId = t.myId) " +
83  		"WHERE v.myResourceVersion != t.myVersion")
84  	Slice<Long> findIdsOfPreviousVersionsOfResources(Pageable thePage);
85  }