001/*- 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.config; 021 022import ca.uhn.fhir.context.FhirContext; 023import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; 024import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; 025import ca.uhn.fhir.jpa.api.dao.DaoRegistry; 026import ca.uhn.fhir.jpa.api.dao.IDao; 027import ca.uhn.fhir.jpa.api.svc.IIdHelperService; 028import ca.uhn.fhir.jpa.api.svc.ISearchCoordinatorSvc; 029import ca.uhn.fhir.jpa.dao.ISearchBuilder; 030import ca.uhn.fhir.jpa.dao.SearchBuilderFactory; 031import ca.uhn.fhir.jpa.dao.data.IResourceSearchViewDao; 032import ca.uhn.fhir.jpa.dao.data.IResourceTagDao; 033import ca.uhn.fhir.jpa.dao.tx.HapiTransactionService; 034import ca.uhn.fhir.jpa.model.config.PartitionSettings; 035import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc; 036import ca.uhn.fhir.jpa.search.ExceptionService; 037import ca.uhn.fhir.jpa.search.ISynchronousSearchSvc; 038import ca.uhn.fhir.jpa.search.PersistedJpaBundleProviderFactory; 039import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl; 040import ca.uhn.fhir.jpa.search.SearchStrategyFactory; 041import ca.uhn.fhir.jpa.search.builder.SearchBuilder; 042import ca.uhn.fhir.jpa.search.builder.sql.SqlObjectFactory; 043import ca.uhn.fhir.jpa.search.builder.tasks.SearchContinuationTask; 044import ca.uhn.fhir.jpa.search.builder.tasks.SearchTask; 045import ca.uhn.fhir.jpa.search.builder.tasks.SearchTaskParameters; 046import ca.uhn.fhir.jpa.search.cache.ISearchCacheSvc; 047import ca.uhn.fhir.jpa.search.cache.ISearchResultCacheSvc; 048import ca.uhn.fhir.rest.server.IPagingProvider; 049import ca.uhn.fhir.rest.server.util.ISearchParamRegistry; 050import org.hl7.fhir.instance.model.api.IBaseResource; 051import org.springframework.beans.factory.BeanFactory; 052import org.springframework.beans.factory.annotation.Autowired; 053import org.springframework.context.annotation.Bean; 054import org.springframework.context.annotation.Configuration; 055import org.springframework.context.annotation.Scope; 056import org.springframework.transaction.PlatformTransactionManager; 057 058@Configuration 059public class SearchConfig { 060 public static final String SEARCH_TASK = "searchTask"; 061 public static final String CONTINUE_TASK = "continueTask"; 062 063 @Autowired 064 private JpaStorageSettings myStorageSettings; 065 066 @Autowired 067 private HapiFhirLocalContainerEntityManagerFactoryBean myEntityManagerFactory; 068 069 @Autowired 070 private SqlObjectFactory mySqlBuilderFactory; 071 072 @Autowired 073 private HibernatePropertiesProvider myDialectProvider; 074 075 @Autowired 076 private ISearchParamRegistry mySearchParamRegistry; 077 078 @Autowired 079 private PartitionSettings myPartitionSettings; 080 081 @Autowired 082 protected IInterceptorBroadcaster myInterceptorBroadcaster; 083 084 @Autowired 085 protected IResourceTagDao myResourceTagDao; 086 087 @Autowired 088 private DaoRegistry myDaoRegistry; 089 090 @Autowired 091 private IResourceSearchViewDao myResourceSearchViewDao; 092 093 @Autowired 094 private FhirContext myContext; 095 096 @Autowired 097 private IIdHelperService myIdHelperService; 098 099 @Autowired 100 private PlatformTransactionManager myManagedTxManager; 101 102 @Autowired 103 private SearchStrategyFactory mySearchStrategyFactory; 104 105 @Autowired 106 private SearchBuilderFactory mySearchBuilderFactory; 107 108 @Autowired 109 private ISearchResultCacheSvc mySearchResultCacheSvc; 110 111 @Autowired 112 private ISearchCacheSvc mySearchCacheSvc; 113 114 @Autowired 115 private IPagingProvider myPagingProvider; 116 117 @Autowired 118 private BeanFactory myBeanFactory; 119 120 @Autowired 121 private ISynchronousSearchSvc mySynchronousSearchSvc; 122 123 @Autowired 124 private PersistedJpaBundleProviderFactory myPersistedJpaBundleProviderFactory; 125 126 @Autowired 127 private IRequestPartitionHelperSvc myRequestPartitionHelperService; 128 129 @Autowired 130 private HapiTransactionService myHapiTransactionService; 131 132 @Bean 133 public ISearchCoordinatorSvc searchCoordinatorSvc() { 134 return new SearchCoordinatorSvcImpl( 135 myContext, 136 myStorageSettings, 137 myInterceptorBroadcaster, 138 myHapiTransactionService, 139 mySearchCacheSvc, 140 mySearchResultCacheSvc, 141 myDaoRegistry, 142 mySearchBuilderFactory, 143 mySynchronousSearchSvc, 144 myPersistedJpaBundleProviderFactory, 145 mySearchParamRegistry, 146 mySearchStrategyFactory, 147 exceptionService(), 148 myBeanFactory); 149 } 150 151 @Bean 152 public ExceptionService exceptionService() { 153 return new ExceptionService(myContext); 154 } 155 156 @Bean(name = ISearchBuilder.SEARCH_BUILDER_BEAN_NAME) 157 @Scope("prototype") 158 public ISearchBuilder newSearchBuilder( 159 IDao theDao, String theResourceName, Class<? extends IBaseResource> theResourceType) { 160 return new SearchBuilder( 161 theDao, 162 theResourceName, 163 myStorageSettings, 164 myEntityManagerFactory, 165 mySqlBuilderFactory, 166 myDialectProvider, 167 mySearchParamRegistry, 168 myPartitionSettings, 169 myInterceptorBroadcaster, 170 myResourceTagDao, 171 myDaoRegistry, 172 myResourceSearchViewDao, 173 myContext, 174 myIdHelperService, 175 theResourceType); 176 } 177 178 @Bean(name = SEARCH_TASK) 179 @Scope("prototype") 180 public SearchTask createSearchTask(SearchTaskParameters theParams) { 181 return new SearchTask( 182 theParams, 183 myHapiTransactionService, 184 myContext, 185 myInterceptorBroadcaster, 186 mySearchBuilderFactory, 187 mySearchResultCacheSvc, 188 myStorageSettings, 189 mySearchCacheSvc, 190 myPagingProvider); 191 } 192 193 @Bean(name = CONTINUE_TASK) 194 @Scope("prototype") 195 public SearchContinuationTask createSearchContinuationTask(SearchTaskParameters theParams) { 196 return new SearchContinuationTask( 197 theParams, 198 myHapiTransactionService, 199 myContext, 200 myInterceptorBroadcaster, 201 mySearchBuilderFactory, 202 mySearchResultCacheSvc, 203 myStorageSettings, 204 mySearchCacheSvc, 205 myPagingProvider, 206 exceptionService() // singleton 207 ); 208 } 209}