From aa134fc423d454f7d8ee4aa192d2c4a1f3c6cce5 Mon Sep 17 00:00:00 2001 From: "Karl M. Davis" Date: Thu, 1 Jun 2017 03:17:38 -0400 Subject: [PATCH] Hacky but workable fix for race condition surfaced by If-None-Exists creates. Some notes from other attempts I made to fix this in a less hacky way: * Tried to @Autowire myResourceDaos from a setter (rather than using the annotation on a field), and initialize myResourceTypeToDao in that setter, instead. Couldn't get it to work: Spring started throwing odd bean dependency errors. Don't really understand why. * Tried to move the exceptions being thrown on null getDao(Class) results into that method, but that was breaking a test case. Didn't investigate why. --- .../main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 072a6fe34b9..b8db560cabd 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -636,19 +636,21 @@ public abstract class BaseHapiFhirDao implements IDao { @SuppressWarnings("unchecked") public IFhirResourceDao getDao(Class theType) { if (myResourceTypeToDao == null) { - myResourceTypeToDao = new HashMap, IFhirResourceDao>(); + Map, IFhirResourceDao> theResourceTypeToDao = new HashMap, IFhirResourceDao>(); for (IFhirResourceDao next : myResourceDaos) { - myResourceTypeToDao.put(next.getResourceType(), next); + theResourceTypeToDao.put(next.getResourceType(), next); } if (this instanceof IFhirResourceDao) { IFhirResourceDao thiz = (IFhirResourceDao) this; - myResourceTypeToDao.put(thiz.getResourceType(), thiz); + theResourceTypeToDao.put(thiz.getResourceType(), thiz); } + myResourceTypeToDao = theResourceTypeToDao; } - return (IFhirResourceDao) myResourceTypeToDao.get(theType); + IFhirResourceDao dao = (IFhirResourceDao) myResourceTypeToDao.get(theType); + return dao; } @Override