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