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.
This commit is contained in:
parent
52a5fcce17
commit
aa134fc423
|
@ -636,19 +636,21 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
@SuppressWarnings("unchecked")
|
||||
public <R extends IBaseResource> IFhirResourceDao<R> getDao(Class<R> theType) {
|
||||
if (myResourceTypeToDao == null) {
|
||||
myResourceTypeToDao = new HashMap<Class<? extends IBaseResource>, IFhirResourceDao<?>>();
|
||||
Map<Class<? extends IBaseResource>, IFhirResourceDao<?>> theResourceTypeToDao = new HashMap<Class<? extends IBaseResource>, 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<R>) myResourceTypeToDao.get(theType);
|
||||
IFhirResourceDao<R> dao = (IFhirResourceDao<R>) myResourceTypeToDao.get(theType);
|
||||
return dao;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue