Combine postconstruct methods (#4330)

* Combine postconstruct methods

* Add changelog
This commit is contained in:
James Agnew 2022-12-11 13:02:04 -05:00 committed by GitHub
parent 3b987d6961
commit 7747ebae41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 14 deletions

View File

@ -0,0 +1,6 @@
---
type: fix
issue: 4330
title: "When running HAPI FHIR-based applications from within IntelliJ, an arbitrary ordering
of PostConstruct methods in BaseHapiFhirResourceDao could cause a crash. This has been
fixed."

View File

@ -729,13 +729,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
}
}
@PostConstruct
public void detectSearchDaoDisabled() {
if (mySearchDao != null && mySearchDao.isDisabled()) {
mySearchDao = null;
}
}
private <MT extends IBaseMetaType> void doMetaAdd(MT theMetaAdd, BaseHasResource theEntity, RequestDetails theRequestDetails, TransactionDetails theTransactionDetails) {
IBaseResource oldVersion = myJpaStorageResourceParser.toResource(theEntity, false);
@ -1098,18 +1091,19 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
public void start() {
assert getConfig() != null;
RuntimeResourceDefinition def = getContext().getResourceDefinition(myResourceType);
myResourceName = def.getName();
if (mySearchDao != null && mySearchDao.isDisabled()) {
mySearchDao = null;
}
ourLog.debug("Starting resource DAO for type: {}", getResourceName());
myInstanceValidator = getApplicationContext().getBean(IInstanceValidatorModule.class);
myTxTemplate = new TransactionTemplate(myPlatformTransactionManager);
super.start();
}
@PostConstruct
public void postConstruct() {
RuntimeResourceDefinition def = getContext().getResourceDefinition(myResourceType);
myResourceName = def.getName();
}
/**
* Subclasses may override to provide behaviour. Invoked within a delete
* transaction with the resource that is about to be deleted.

View File

@ -36,6 +36,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationContext;
import javax.persistence.EntityManager;
import java.util.List;
@ -65,6 +66,9 @@ class BaseHapiFhirResourceDaoTest {
@Mock
private UrlPartitioner myUrlPartitioner;
@Mock
private ApplicationContext myApplicationContext;
@Mock
private ISearchParamRegistry mySearchParamRegistry;
@ -92,7 +96,7 @@ class BaseHapiFhirResourceDaoTest {
*/
private void setup(Class clazz) {
mySvc.setResourceType(clazz);
mySvc.postConstruct();
mySvc.start();
}
@Test

View File

@ -39,6 +39,7 @@ public class JpaResourceDaoSearchParameterTest {
myDao = new JpaResourceDaoSearchParameter<>();
myDao.setContext(myCtx);
myDao.setResourceType(SearchParameter.class);
myDao.setDaoConfigForUnitTest(new DaoConfig());
myDao.setApplicationContext(myApplicationContext);
myDao.setVersionCanonicalizerForUnitTest(versionCanonicalizer);