Prefer non-lazy outcomes in map

This commit is contained in:
Tadgh 2021-09-14 13:40:53 -04:00
parent 49debec36a
commit 9771210553
3 changed files with 27 additions and 7 deletions

View File

@ -52,13 +52,11 @@ public class LazyDaoMethodOutcome extends DaoMethodOutcome {
private void tryToRunSupplier() {
if (myEntitySupplier != null) {
EntityAndResource entityAndResource = myEntitySupplier.get();
setEntity(entityAndResource.getEntity());
setResource(entityAndResource.getResource());
setId(entityAndResource.getResource().getIdElement());
myEntitySupplierUseCallback.run();
}
}

View File

@ -35,6 +35,7 @@ import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
import ca.uhn.fhir.jpa.api.model.DeleteConflict;
import ca.uhn.fhir.jpa.api.model.DeleteConflictList;
import ca.uhn.fhir.jpa.api.model.DeleteMethodOutcome;
import ca.uhn.fhir.jpa.api.model.LazyDaoMethodOutcome;
import ca.uhn.fhir.jpa.cache.IResourceVersionSvc;
import ca.uhn.fhir.jpa.cache.ResourcePersistentIdMap;
import ca.uhn.fhir.jpa.dao.tx.HapiTransactionService;
@ -280,7 +281,9 @@ public abstract class BaseTransactionProcessor {
idSubstitutions.put(id, newId);
}
}
idToPersistedOutcome.put(newId, outcome);
populateIdToPersistedOutcomeMap(idToPersistedOutcome, newId, outcome);
if (outcome.getCreated()) {
myVersionAdapter.setResponseStatus(newEntry, toStatusString(Constants.STATUS_HTTP_201_CREATED));
} else {
@ -304,6 +307,21 @@ public abstract class BaseTransactionProcessor {
}
/** Method which populates entry in idToPersistedOutcome.
* Will store whatever outcome is sent, unless the key already exists, then we only replace an instance if we find that the instance
* we are replacing with is non-lazy. This allows us to evaluate later more easily, as we _know_ we need access to these.
*/
private void populateIdToPersistedOutcomeMap(Map<IIdType, DaoMethodOutcome> idToPersistedOutcome, IIdType newId, DaoMethodOutcome outcome) {
//Prefer real method outcomes over lazy ones.
if (idToPersistedOutcome.containsKey(newId)) {
if (!(outcome instanceof LazyDaoMethodOutcome)) {
idToPersistedOutcome.put(newId, outcome);
}
} else {
idToPersistedOutcome.put(newId, outcome);
}
}
private Date getLastModified(IBaseResource theRes) {
return theRes.getMeta().getLastUpdated();
}
@ -1092,10 +1110,14 @@ public abstract class BaseTransactionProcessor {
validateNoDuplicates(theRequest, theActionName, conditionalRequestUrls, theIdToPersistedOutcome.values());
}
theTransactionStopWatch.endCurrentTask();
if (conditionalUrlToIdMap.size() > 0) {
theTransactionStopWatch.startTask("Check that all conditionally created/updated entities actually match their conditionals.");
}
if (!myDaoConfig.isMassIngestionMode()) {
validateAllInsertsMatchTheirConditionalUrls(theIdToPersistedOutcome, conditionalUrlToIdMap, theRequest);
}
theTransactionStopWatch.endCurrentTask();
for (IIdType next : theAllIds) {

View File

@ -1824,9 +1824,9 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
p.addIdentifier().setSystem("urn:system").setValue(methodName);
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST).setIfNoneExist("Patient?identifier=urn%3Asystem%7C" + methodName);
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST);
// p = new Patient();
// p.addIdentifier().setSystem("urn:system").setValue(methodName);
// request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST);
try {
mySystemDao.transaction(mySrd, request);