001/*-
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2023 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.batch2;
021
022import ca.uhn.fhir.batch2.api.IJobPersistence;
023import ca.uhn.fhir.batch2.config.BaseBatch2Config;
024import ca.uhn.fhir.jpa.bulk.export.job.BulkExportJobConfig;
025import ca.uhn.fhir.jpa.dao.data.IBatch2JobInstanceRepository;
026import ca.uhn.fhir.jpa.dao.data.IBatch2WorkChunkRepository;
027import ca.uhn.fhir.jpa.dao.tx.IHapiTransactionService;
028import org.springframework.context.annotation.Bean;
029import org.springframework.context.annotation.Configuration;
030import org.springframework.context.annotation.Import;
031import org.springframework.context.annotation.Primary;
032
033import javax.persistence.EntityManager;
034
035@Configuration
036@Import({BulkExportJobConfig.class})
037public class JpaBatch2Config extends BaseBatch2Config {
038
039        @Bean
040        public IJobPersistence batch2JobInstancePersister(
041                        IBatch2JobInstanceRepository theJobInstanceRepository,
042                        IBatch2WorkChunkRepository theWorkChunkRepository,
043                        IHapiTransactionService theTransactionService,
044                        EntityManager theEntityManager) {
045                return new JpaJobPersistenceImpl(
046                                theJobInstanceRepository, theWorkChunkRepository, theTransactionService, theEntityManager);
047        }
048
049        @Primary
050        @Bean
051        public IJobPersistence batch2JobInstancePersisterWrapper(
052                        IBatch2JobInstanceRepository theJobInstanceRepository,
053                        IBatch2WorkChunkRepository theWorkChunkRepository,
054                        IHapiTransactionService theTransactionService,
055                        EntityManager theEntityManager) {
056                IJobPersistence retVal = batch2JobInstancePersister(
057                                theJobInstanceRepository, theWorkChunkRepository, theTransactionService, theEntityManager);
058                // Avoid H2 synchronization issues caused by
059                // https://github.com/h2database/h2database/issues/1808
060                // TODO: Update 2023-03-14 - The bug above appears to be fixed. I'm going to try
061                // disabing this and see if we can get away without it. If so, we can delete
062                // this entirely
063                //              if (HapiSystemProperties.isUnitTestModeEnabled()) {
064                //                      retVal = ProxyUtil.synchronizedProxy(IJobPersistence.class, retVal);
065                //              }
066                return retVal;
067        }
068}