View Javadoc
1   package ca.uhn.fhir.jpa.dao.data;
2   
3   import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
4   import ca.uhn.fhir.jpa.entity.ResourceTable;
5   import org.springframework.data.domain.Pageable;
6   import org.springframework.data.domain.Slice;
7   import org.springframework.data.jpa.repository.JpaRepository;
8   import org.springframework.data.jpa.repository.Modifying;
9   import org.springframework.data.jpa.repository.Query;
10  import org.springframework.data.repository.query.Param;
11  
12  import java.util.List;
13  import java.util.Map;
14  
15  /*
16   * #%L
17   * HAPI FHIR JPA Server
18   * %%
19   * Copyright (C) 2014 - 2018 University Health Network
20   * %%
21   * Licensed under the Apache License, Version 2.0 (the "License");
22   * you may not use this file except in compliance with the License.
23   * You may obtain a copy of the License at
24   * 
25   * http://www.apache.org/licenses/LICENSE-2.0
26   * 
27   * Unless required by applicable law or agreed to in writing, software
28   * distributed under the License is distributed on an "AS IS" BASIS,
29   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30   * See the License for the specific language governing permissions and
31   * limitations under the License.
32   * #L%
33   */
34  
35  public interface IResourceTableDao extends JpaRepository<ResourceTable, Long> {
36  
37  	@Query("SELECT t.myId FROM ResourceTable t WHERE t.myDeleted IS NOT NULL")
38  	Slice<Long> findIdsOfDeletedResources(Pageable thePageable);
39  
40  	@Query("SELECT t.myId FROM ResourceTable t WHERE t.myResourceType = :restype AND t.myDeleted IS NOT NULL")
41  	Slice<Long> findIdsOfDeletedResourcesOfType(Pageable thePageable, @Param("restype") String theResourceName);
42  
43  	@Query("SELECT t.myId FROM ResourceTable t WHERE t.myId = :resid AND t.myResourceType = :restype AND t.myDeleted IS NOT NULL")
44  	Slice<Long> findIdsOfDeletedResourcesOfType(Pageable thePageable, @Param("resid") Long theResourceId, @Param("restype") String theResourceName);
45  
46  	@Query("SELECT t.myId FROM ResourceTable t WHERE t.myIndexStatus IS NULL")
47  	Slice<Long> findIdsOfResourcesRequiringReindexing(Pageable thePageable);
48  
49  	@Query("SELECT t.myResourceType as type, COUNT(*) as count FROM ResourceTable t GROUP BY t.myResourceType")
50  	List<Map<?, ?>> getResourceCounts();
51  
52  	@Modifying
53  	@Query("UPDATE ResourceTable r SET r.myIndexStatus = null WHERE r.myResourceType = :restype")
54  	int markResourcesOfTypeAsRequiringReindexing(@Param("restype") String theResourceType);
55  
56  	@Modifying
57  	@Query("UPDATE ResourceTable r SET r.myIndexStatus = " + BaseHapiFhirDao.INDEX_STATUS_INDEXING_FAILED + " WHERE r.myId = :resid")
58  	void updateStatusToErrored(@Param("resid") Long theId);
59  }