View Javadoc
1   package ca.uhn.fhir.jpa.dao;
2   
3   import ca.uhn.fhir.jpa.dao.data.ITermConceptDao;
4   import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
5   import ca.uhn.fhir.jpa.util.ExpungeOptions;
6   import ca.uhn.fhir.jpa.util.ExpungeOutcome;
7   import ca.uhn.fhir.jpa.util.ResourceCountCache;
8   import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
9   import ca.uhn.fhir.rest.api.server.IBundleProvider;
10  import ca.uhn.fhir.rest.api.server.RequestDetails;
11  import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
12  import ca.uhn.fhir.util.StopWatch;
13  import org.hl7.fhir.instance.model.api.IBaseResource;
14  import org.springframework.beans.factory.annotation.Autowired;
15  import org.springframework.beans.factory.annotation.Qualifier;
16  import org.springframework.transaction.PlatformTransactionManager;
17  import org.springframework.transaction.annotation.Propagation;
18  import org.springframework.transaction.annotation.Transactional;
19  
20  import javax.annotation.Nullable;
21  import java.util.Date;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.concurrent.locks.ReentrantLock;
26  
27  /*
28   * #%L
29   * HAPI FHIR JPA Server
30   * %%
31   * Copyright (C) 2014 - 2019 University Health Network
32   * %%
33   * Licensed under the Apache License, Version 2.0 (the "License");
34   * you may not use this file except in compliance with the License.
35   * You may obtain a copy of the License at
36   * 
37   *      http://www.apache.org/licenses/LICENSE-2.0
38   * 
39   * Unless required by applicable law or agreed to in writing, software
40   * distributed under the License is distributed on an "AS IS" BASIS,
41   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42   * See the License for the specific language governing permissions and
43   * limitations under the License.
44   * #L%
45   */
46  
47  public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBaseResource> implements IFhirSystemDao<T, MT> {
48  
49  	private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseHapiFhirSystemDao.class);
50  	@Autowired
51  	@Qualifier("myResourceCountsCache")
52  	public ResourceCountCache myResourceCountsCache;
53  
54  	@Override
55  	@Transactional(propagation = Propagation.NEVER)
56  	public ExpungeOutcome expunge(ExpungeOptions theExpungeOptions) {
57  		return doExpunge(null, null, null, theExpungeOptions);
58  	}
59  
60  	@Transactional(propagation = Propagation.REQUIRED)
61  	@Override
62  	public Map<String, Long> getResourceCounts() {
63  		Map<String, Long> retVal = new HashMap<>();
64  
65  		List<Map<?, ?>> counts = myResourceTableDao.getResourceCounts();
66  		for (Map<?, ?> next : counts) {
67  			retVal.put(next.get("type").toString(), Long.parseLong(next.get("count").toString()));
68  		}
69  
70  		return retVal;
71  	}
72  
73  	@Transactional(propagation = Propagation.SUPPORTS)
74  	@Nullable
75  	@Override
76  	public Map<String, Long> getResourceCountsFromCache() {
77  		return myResourceCountsCache.get();
78  	}
79  
80  	@Override
81  	public IBundleProvider history(Date theSince, Date theUntil, RequestDetails theRequestDetails) {
82  		if (theRequestDetails != null) {
83  			// Notify interceptors
84  			ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails);
85  			notifyInterceptors(RestOperationTypeEnum.HISTORY_SYSTEM, requestDetails);
86  		}
87  
88  		StopWatch w = new StopWatch();
89  		IBundleProvider retVal = super.history(null, null, theSince, theUntil);
90  		ourLog.info("Processed global history in {}ms", w.getMillisAndRestart());
91  		return retVal;
92  	}
93  
94  
95  }