theResourceIds, DeleteConflictList theDeleteConflicts, RequestDetails theRequest) {
+ public DeleteMethodOutcome deletePidList(String theUrl, Collection
theResourceIds, DeleteConflictList theDeleteConflicts, RequestDetails theRequest) {
StopWatch w = new StopWatch();
TransactionDetails transactionDetails = new TransactionDetails();
List deletedResources = new ArrayList<>();
- for (ResourcePersistentId pid : theResourceIds) {
- ResourceTable entity = myEntityManager.find(ResourceTable.class, pid.getIdAsLong());
+ for (P pid : theResourceIds) {
+ JpaPid jpaPid = (JpaPid)pid;
+ ResourceTable entity = myEntityManager.find(ResourceTable.class, jpaPid.getId());
deletedResources.add(entity);
T resourceToDelete = myJpaStorageResourceParser.toResource(myResourceType, entity, null, false);
@@ -878,10 +880,10 @@ public abstract class BaseHapiFhirResourceDao extends B
throw new PreconditionFailedException(Msg.code(969) + "Can not perform version-specific expunge of resource " + theId.toUnqualified().getValue() + " as this is the current version");
}
- return myExpungeService.expunge(getResourceName(), new ResourcePersistentId(entity.getResourceId(), entity.getVersion()), theExpungeOptions, theRequest);
+ return myExpungeService.expunge(getResourceName(), JpaPid.fromIdAndVersion(entity.getResourceId(), entity.getVersion()), theExpungeOptions, theRequest);
}
- return myExpungeService.expunge(getResourceName(), new ResourcePersistentId(entity.getResourceId()), theExpungeOptions, theRequest);
+ return myExpungeService.expunge(getResourceName(), JpaPid.fromId(entity.getResourceId()), theExpungeOptions, theRequest);
}
@Override
@@ -1132,18 +1134,19 @@ public abstract class BaseHapiFhirResourceDao extends B
@Override
@Transactional
- public T readByPid(ResourcePersistentId thePid) {
+ public T readByPid(IResourcePersistentId thePid) {
return readByPid(thePid, false);
}
@Override
@Transactional
- public T readByPid(ResourcePersistentId thePid, boolean theDeletedOk) {
+ public T readByPid(IResourcePersistentId thePid, boolean theDeletedOk) {
StopWatch w = new StopWatch();
+ JpaPid jpaPid = (JpaPid)thePid;
- Optional entity = myResourceTableDao.findById(thePid.getIdAsLong());
+ Optional entity = myResourceTableDao.findById(jpaPid.getId());
if (!entity.isPresent()) {
- throw new ResourceNotFoundException(Msg.code(975) + "No resource found with PID " + thePid);
+ throw new ResourceNotFoundException(Msg.code(975) + "No resource found with PID " + jpaPid);
}
if (isDeleted(entity.get()) && !theDeletedOk) {
throw createResourceGoneException(entity.get());
@@ -1151,7 +1154,7 @@ public abstract class BaseHapiFhirResourceDao extends B
T retVal = myJpaStorageResourceParser.toResource(myResourceType, entity.get(), null, false);
- ourLog.debug("Processed read on {} in {}ms", thePid, w.getMillis());
+ ourLog.debug("Processed read on {} in {}ms", jpaPid, w.getMillis());
return retVal;
}
@@ -1228,10 +1231,11 @@ public abstract class BaseHapiFhirResourceDao extends B
@SuppressWarnings("unchecked")
@Override
- public void reindex(ResourcePersistentId theResourcePersistentId, RequestDetails theRequest, TransactionDetails theTransactionDetails) {
- Optional entityOpt = myResourceTableDao.findById(theResourcePersistentId.getIdAsLong());
+ public void reindex(IResourcePersistentId thePid, RequestDetails theRequest, TransactionDetails theTransactionDetails) {
+ JpaPid jpaPid = (JpaPid)thePid;
+ Optional entityOpt = myResourceTableDao.findById(jpaPid.getId());
if (!entityOpt.isPresent()) {
- ourLog.warn("Unable to find entity with PID: {}", theResourcePersistentId.getId());
+ ourLog.warn("Unable to find entity with PID: {}", jpaPid.getId());
return;
}
@@ -1253,24 +1257,24 @@ public abstract class BaseHapiFhirResourceDao extends B
RequestPartitionId requestPartitionId = myRequestPartitionHelperService.determineReadPartitionForRequestForRead(theRequest, getResourceName(), theId);
BaseHasResource entity;
- ResourcePersistentId pid = myIdHelperService.resolveResourcePersistentIds(requestPartitionId, getResourceName(), theId.getIdPart());
+ JpaPid pid = myIdHelperService.resolveResourcePersistentIds(requestPartitionId, getResourceName(), theId.getIdPart());
Set readPartitions = null;
if (requestPartitionId.isAllPartitions()) {
- entity = myEntityManager.find(ResourceTable.class, pid.getIdAsLong());
+ entity = myEntityManager.find(ResourceTable.class, pid.getId());
} else {
readPartitions = myRequestPartitionHelperService.toReadPartitions(requestPartitionId);
if (readPartitions.size() == 1) {
if (readPartitions.contains(null)) {
- entity = myResourceTableDao.readByPartitionIdNull(pid.getIdAsLong()).orElse(null);
+ entity = myResourceTableDao.readByPartitionIdNull(pid.getId()).orElse(null);
} else {
- entity = myResourceTableDao.readByPartitionId(readPartitions.iterator().next(), pid.getIdAsLong()).orElse(null);
+ entity = myResourceTableDao.readByPartitionId(readPartitions.iterator().next(), pid.getId()).orElse(null);
}
} else {
if (readPartitions.contains(null)) {
List readPartitionsWithoutNull = readPartitions.stream().filter(t -> t != null).collect(Collectors.toList());
- entity = myResourceTableDao.readByPartitionIdsOrNull(readPartitionsWithoutNull, pid.getIdAsLong()).orElse(null);
+ entity = myResourceTableDao.readByPartitionIdsOrNull(readPartitionsWithoutNull, pid.getId()).orElse(null);
} else {
- entity = myResourceTableDao.readByPartitionIds(readPartitions, pid.getIdAsLong()).orElse(null);
+ entity = myResourceTableDao.readByPartitionIds(readPartitions, pid.getId()).orElse(null);
}
}
}
@@ -1320,8 +1324,9 @@ public abstract class BaseHapiFhirResourceDao extends B
}
@Override
- protected IBasePersistedResource readEntityLatestVersion(ResourcePersistentId thePersistentId, RequestDetails theRequestDetails, TransactionDetails theTransactionDetails) {
- return myEntityManager.find(ResourceTable.class, thePersistentId.getIdAsLong());
+ protected IBasePersistedResource readEntityLatestVersion(IResourcePersistentId thePersistentId, RequestDetails theRequestDetails, TransactionDetails theTransactionDetails) {
+ JpaPid jpaPid = (JpaPid)thePersistentId;
+ return myEntityManager.find(ResourceTable.class, jpaPid.getId());
}
@@ -1336,13 +1341,13 @@ public abstract class BaseHapiFhirResourceDao extends B
private ResourceTable readEntityLatestVersion(IIdType theId, @Nonnull RequestPartitionId theRequestPartitionId, TransactionDetails theTransactionDetails) {
validateResourceTypeAndThrowInvalidRequestException(theId);
- ResourcePersistentId persistentId = null;
+ JpaPid persistentId = null;
if (theTransactionDetails != null) {
if (theTransactionDetails.isResolvedResourceIdEmpty(theId.toUnqualifiedVersionless())) {
throw new ResourceNotFoundException(Msg.code(1997) + theId);
}
if (theTransactionDetails.hasResolvedResourceIds()) {
- persistentId = theTransactionDetails.getResolvedResourceId(theId);
+ persistentId = (JpaPid)theTransactionDetails.getResolvedResourceId(theId);
}
}
@@ -1517,7 +1522,7 @@ public abstract class BaseHapiFhirResourceDao extends B
}
@Override
- public List searchForIds(SearchParameterMap theParams, RequestDetails theRequest, @Nullable IBaseResource theConditionalOperationTargetOrNull) {
+ public List searchForIds(SearchParameterMap theParams, RequestDetails theRequest, @Nullable IBaseResource theConditionalOperationTargetOrNull) {
TransactionDetails transactionDetails = new TransactionDetails();
return myTransactionService.execute(theRequest, transactionDetails, tx -> {
@@ -1530,13 +1535,13 @@ public abstract class BaseHapiFhirResourceDao extends B
ISearchBuilder builder = mySearchBuilderFactory.newSearchBuilder(this, getResourceName(), getResourceType());
- List ids = new ArrayList<>();
+ List ids = new ArrayList<>();
String uuid = UUID.randomUUID().toString();
RequestPartitionId requestPartitionId = myRequestPartitionHelperService.determineReadPartitionForRequestForSearchType(theRequest, getResourceName(), theParams, theConditionalOperationTargetOrNull);
SearchRuntimeDetails searchRuntimeDetails = new SearchRuntimeDetails(theRequest, uuid);
- try (IResultIterator iter = builder.createQuery(theParams, searchRuntimeDetails, theRequest, requestPartitionId)) {
+ try (IResultIterator iter = builder.createQuery(theParams, searchRuntimeDetails, theRequest, requestPartitionId)) {
while (iter.hasNext()) {
ids.add(iter.next());
}
@@ -1652,12 +1657,12 @@ public abstract class BaseHapiFhirResourceDao extends B
IIdType resourceId;
RestOperationTypeEnum update = RestOperationTypeEnum.UPDATE;
if (isNotBlank(theMatchUrl)) {
- Set match = myMatchResourceUrlService.processMatchUrl(theMatchUrl, myResourceType, theTransactionDetails, theRequest, theResource);
+ Set match = myMatchResourceUrlService.processMatchUrl(theMatchUrl, myResourceType, theTransactionDetails, theRequest, theResource);
if (match.size() > 1) {
String msg = getContext().getLocalizer().getMessageSanitized(BaseStorageDao.class, "transactionOperationWithMultipleMatchFailure", "UPDATE", theMatchUrl, match.size());
throw new PreconditionFailedException(Msg.code(988) + msg);
} else if (match.size() == 1) {
- ResourcePersistentId pid = match.iterator().next();
+ JpaPid pid = match.iterator().next();
entity = myEntityManager.find(ResourceTable.class, pid.getId());
resourceId = entity.getIdDt();
} else {
@@ -1666,7 +1671,7 @@ public abstract class BaseHapiFhirResourceDao extends B
// Pre-cache the match URL
if (outcome.getPersistentId() != null) {
- myMatchResourceUrlService.matchUrlResolved(theTransactionDetails, getResourceName(), theMatchUrl, outcome.getPersistentId());
+ myMatchResourceUrlService.matchUrlResolved(theTransactionDetails, getResourceName(), theMatchUrl, (JpaPid)outcome.getPersistentId());
}
return outcome;
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java
index 20e882f7f0c..df2a119e3ca 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java
@@ -7,11 +7,10 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.api.model.ExpungeOptions;
import ca.uhn.fhir.jpa.api.model.ExpungeOutcome;
-import ca.uhn.fhir.jpa.dao.data.IResourceSearchViewDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTagDao;
import ca.uhn.fhir.jpa.dao.expunge.ExpungeService;
-import ca.uhn.fhir.jpa.model.config.PartitionSettings;
+import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.search.PersistedJpaBundleProviderFactory;
@@ -20,12 +19,11 @@ import ca.uhn.fhir.jpa.util.QueryChunker;
import ca.uhn.fhir.jpa.util.ResourceCountCache;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
+import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import ca.uhn.fhir.util.StopWatch;
import com.google.common.annotations.VisibleForTesting;
import org.hl7.fhir.instance.model.api.IBaseBundle;
-import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.Propagation;
@@ -165,10 +163,10 @@ public abstract class BaseHapiFhirSystemDao extends B
@Override
@Transactional(propagation = Propagation.MANDATORY)
- public void preFetchResources(List theResolvedIds) {
+ public void preFetchResources(List
theResolvedIds) {
List pids = theResolvedIds
.stream()
- .map(t -> t.getIdAsLong())
+ .map(t -> ((JpaPid) t).getId())
.collect(Collectors.toList());
new QueryChunker().chunk(pids, ids->{
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FulltextSearchSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FulltextSearchSvcImpl.java
index 18ba4b53dd1..3b377e5130d 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FulltextSearchSvcImpl.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FulltextSearchSvcImpl.java
@@ -30,6 +30,7 @@ import ca.uhn.fhir.jpa.dao.search.ExtendedHSearchResourceProjection;
import ca.uhn.fhir.jpa.dao.search.ExtendedHSearchSearchBuilder;
import ca.uhn.fhir.jpa.dao.search.IHSearchSortHelper;
import ca.uhn.fhir.jpa.dao.search.LastNOperation;
+import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.model.search.ExtendedHSearchIndexData;
@@ -43,7 +44,7 @@ import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.Constants;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
+import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
import ca.uhn.fhir.rest.server.util.ResourceSearchParams;
import com.google.common.collect.Ordering;
@@ -156,7 +157,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
// keep this in sync with supportsSomeOf();
private ISearchQueryExecutor doSearch(String theResourceType, SearchParameterMap theParams,
- ResourcePersistentId theReferencingPid, Integer theMaxResultsToFetch) {
+ IResourcePersistentId theReferencingPid, Integer theMaxResultsToFetch) {
int offset = theParams.getOffset() == null ? 0 : theParams.getOffset();
int count = getMaxFetchSize(theParams, theMaxResultsToFetch);
@@ -185,7 +186,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
private SearchQueryOptionsStep, Long, SearchLoadingOptionsStep, ?, ?> getSearchQueryOptionsStep(
- String theResourceType, SearchParameterMap theParams, ResourcePersistentId theReferencingPid) {
+ String theResourceType, SearchParameterMap theParams, IResourcePersistentId theReferencingPid) {
dispatchEvent(IHSearchEventListener.HSearchEventType.SEARCH);
var query= getSearchSession().search(ResourceTable.class)
@@ -213,7 +214,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
private PredicateFinalStep buildWhereClause(SearchPredicateFactory f, String theResourceType,
- SearchParameterMap theParams, ResourcePersistentId theReferencingPid) {
+ SearchParameterMap theParams, IResourcePersistentId theReferencingPid) {
return f.bool(b -> {
ExtendedHSearchClauseBuilder builder = new ExtendedHSearchClauseBuilder(myFhirContext, myModelConfig, b, f);
@@ -261,18 +262,18 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
return Search.session(myEntityManager);
}
- private List convertLongsToResourcePersistentIds(List theLongPids) {
+ private List convertLongsToResourcePersistentIds(List theLongPids) {
return theLongPids.stream()
- .map(ResourcePersistentId::new)
+ .map(JpaPid::fromId)
.collect(Collectors.toList());
}
@Override
- public List everything(String theResourceName, SearchParameterMap theParams, ResourcePersistentId theReferencingPid) {
+ public List everything(String theResourceName, SearchParameterMap theParams, IResourcePersistentId theReferencingPid) {
validateHibernateSearchIsEnabled();
// todo mb what about max results here?
- List retVal = toList(doSearch(null, theParams, theReferencingPid, 10_000), 10_000);
+ List retVal = toList(doSearch(null, theParams, theReferencingPid, 10_000), 10_000);
if (theReferencingPid != null) {
retVal.add(theReferencingPid);
}
@@ -310,7 +311,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
@Transactional()
@Override
- public List search(String theResourceName, SearchParameterMap theParams) {
+ public List search(String theResourceName, SearchParameterMap theParams) {
validateHibernateSearchIsEnabled();
return toList(doSearch(theResourceName, theParams, null, DEFAULT_MAX_NON_PAGED_SIZE), DEFAULT_MAX_NON_PAGED_SIZE);
}
@@ -318,9 +319,9 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
/**
* Adapt our async interface to the legacy concrete List
*/
- private List toList(ISearchQueryExecutor theSearchResultStream, long theMaxSize) {
+ private List toList(ISearchQueryExecutor theSearchResultStream, long theMaxSize) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(theSearchResultStream, 0), false)
- .map(ResourcePersistentId::new)
+ .map(JpaPid::fromId)
.limit(theMaxSize)
.collect(Collectors.toList());
}
@@ -356,7 +357,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
}
@Override
- public List lastN(SearchParameterMap theParams, Integer theMaximumResults) {
+ public List lastN(SearchParameterMap theParams, Integer theMaximumResults) {
ensureElastic();
dispatchEvent(IHSearchEventListener.HSearchEventType.SEARCH);
List pidList = new LastNOperation(getSearchSession(), myFhirContext, myModelConfig, mySearchParamRegistry)
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/HistoryBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/HistoryBuilder.java
index d69e20c82c6..7ca29f6daa1 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/HistoryBuilder.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/HistoryBuilder.java
@@ -27,8 +27,8 @@ import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.api.model.PersistentIdToForcedIdMap;
import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
+import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.param.HistorySearchStyleEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import com.google.common.collect.ImmutableListMultimap;
@@ -128,7 +128,7 @@ public class HistoryBuilder {
List tables = query.getResultList();
if (tables.size() > 0) {
ImmutableListMultimap resourceIdToHistoryEntries = Multimaps.index(tables, ResourceHistoryTable::getResourceId);
- Set pids = resourceIdToHistoryEntries.keySet().stream().map(t-> new ResourcePersistentId(t)).collect(Collectors.toSet());
+ Set pids = resourceIdToHistoryEntries.keySet().stream().map(JpaPid::fromId).collect(Collectors.toSet());
PersistentIdToForcedIdMap pidToForcedId = myIdHelperService.translatePidsToForcedIds(pids);
ourLog.trace("Translated IDs: {}", pidToForcedId.getResourcePersistentIdOptionalMap());
@@ -137,7 +137,7 @@ public class HistoryBuilder {
String resourceId;
- Optional forcedId = pidToForcedId.get(new ResourcePersistentId(nextResourceId));
+ Optional forcedId = pidToForcedId.get(JpaPid.fromId(nextResourceId));
if (forcedId.isPresent()) {
resourceId = forcedId.get();
} else {
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFulltextSearchSvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFulltextSearchSvc.java
index dfa8b1e0971..3b508def2d6 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFulltextSearchSvc.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFulltextSearchSvc.java
@@ -26,7 +26,7 @@ import ca.uhn.fhir.jpa.search.autocomplete.ValueSetAutocompleteOptions;
import ca.uhn.fhir.jpa.search.builder.ISearchQueryExecutor;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
+import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
import org.hl7.fhir.instance.model.api.IBaseResource;
import java.util.Collection;
@@ -43,7 +43,7 @@ public interface IFulltextSearchSvc {
* @param theParams the full query - modified to return only params unused by the index.
* @return the pid list for the matchign resources.
*/
- List search(String theResourceName, SearchParameterMap theParams);
+ List search(String theResourceName, SearchParameterMap theParams);
/**
@@ -63,7 +63,7 @@ public interface IFulltextSearchSvc {
*/
IBaseResource tokenAutocompleteValueSetSearch(ValueSetAutocompleteOptions theOptions);
- List everything(String theResourceName, SearchParameterMap theParams, ResourcePersistentId theReferencingPid);
+ List everything(String theResourceName, SearchParameterMap theParams, T theReferencingPid);
boolean isDisabled();
@@ -81,7 +81,7 @@ public interface IFulltextSearchSvc {
*/
void reindex(ResourceTable theEntity);
- List lastN(SearchParameterMap theParams, Integer theMaximumResults);
+ List lastN(SearchParameterMap theParams, Integer theMaximumResults);
/**
* Returns inlined resource stored along with index mappings for matched identifiers
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoCodeSystem.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoCodeSystem.java
index f8285ba471b..3a4fc8bd720 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoCodeSystem.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoCodeSystem.java
@@ -36,7 +36,7 @@ import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
import ca.uhn.fhir.jpa.util.LogicUtil;
import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
+import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@@ -88,9 +88,9 @@ public class JpaResourceDaoCodeSystem extends BaseHapiF
@Override
public List findCodeSystemIdsContainingSystemAndCode(String theCode, String theSystem, RequestDetails theRequest) {
List valueSetIds;
- List ids = searchForIds(new SearchParameterMap(org.hl7.fhir.r4.model.CodeSystem.SP_CODE, new TokenParam(theSystem, theCode)), theRequest);
+ List ids = searchForIds(new SearchParameterMap(org.hl7.fhir.r4.model.CodeSystem.SP_CODE, new TokenParam(theSystem, theCode)), theRequest);
valueSetIds = new ArrayList<>();
- for (ResourcePersistentId next : ids) {
+ for (IResourcePersistentId next : ids) {
IIdType id = myIdHelperService.translatePidIdToForcedId(myFhirContext, "CodeSystem", next);
valueSetIds.add(id);
}
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoComposition.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoComposition.java
index 4875ed0652e..70f59d42e86 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoComposition.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoComposition.java
@@ -31,7 +31,6 @@ import ca.uhn.fhir.rest.param.StringParam;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
-import org.hl7.fhir.r4.model.Composition;
import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoObservation.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoObservation.java
index c1c767fcad1..bf8b4a9b2b3 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoObservation.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoObservation.java
@@ -24,6 +24,7 @@ import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoObservation;
import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource;
+import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
@@ -34,7 +35,6 @@ import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
import ca.uhn.fhir.rest.param.ReferenceOrListParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
@@ -152,8 +152,8 @@ public class JpaResourceDaoObservation extends BaseHapi
for (IQueryParameterType nextOr : nextPatientList) {
if (nextOr instanceof ReferenceParam) {
ReferenceParam ref = (ReferenceParam) nextOr;
- ResourcePersistentId pid = myIdHelperService.resolveResourcePersistentIds(requestPartitionId, ref.getResourceType(), ref.getIdPart());
- orderedSubjectReferenceMap.put(pid.getIdAsLong(), nextOr);
+ JpaPid pid = myIdHelperService.resolveResourcePersistentIds(requestPartitionId, ref.getResourceType(), ref.getIdPart());
+ orderedSubjectReferenceMap.put(pid.getId(), nextOr);
} else {
throw new IllegalArgumentException(Msg.code(942) + "Invalid token type (expecting ReferenceParam): " + nextOr.getClass());
}
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/TransactionProcessor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/TransactionProcessor.java
index 912f634d8e0..cf400db5c72 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/TransactionProcessor.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/TransactionProcessor.java
@@ -28,16 +28,14 @@ import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
import ca.uhn.fhir.jpa.config.HapiFhirHibernateJpaDialect;
-import ca.uhn.fhir.jpa.dao.index.IdHelperService;
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
+import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken;
-import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc;
import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.util.StopWatch;
@@ -90,7 +88,7 @@ public class TransactionProcessor extends BaseTransactionProcessor {
@Autowired(required = false)
private HapiFhirHibernateJpaDialect myHapiFhirHibernateJpaDialect;
@Autowired
- private IIdHelperService myIdHelperService;
+ private IIdHelperService myIdHelperService;
@Autowired
private PartitionSettings myPartitionSettings;
@Autowired
@@ -98,7 +96,7 @@ public class TransactionProcessor extends BaseTransactionProcessor {
@Autowired
private FhirContext myFhirContext;
@Autowired
- private MatchResourceUrlService myMatchResourceUrlService;
+ private MatchResourceUrlService myMatchResourceUrlService;
@Autowired
private MatchUrlService myMatchUrlService;
@Autowired
@@ -166,12 +164,13 @@ public class TransactionProcessor extends BaseTransactionProcessor {
}
}
}
- List outcome = myIdHelperService.resolveResourcePersistentIdsWithCache(requestPartitionId, idsToPreResolve);
- for (ResourcePersistentId next : outcome) {
+ List outcome = myIdHelperService.resolveResourcePersistentIdsWithCache(requestPartitionId, idsToPreResolve)
+ .stream().collect(Collectors.toList());
+ for (JpaPid next : outcome) {
foundIds.add(next.getAssociatedResourceId().toUnqualifiedVersionless().getValue());
theTransactionDetails.addResolvedResourceId(next.getAssociatedResourceId(), next);
if (myDaoConfig.getResourceClientIdStrategy() != DaoConfig.ClientIdStrategyEnum.ANY || !next.getAssociatedResourceId().isIdPartValidLong()) {
- idsToPreFetch.add(next.getIdAsLong());
+ idsToPreFetch.add(next.getId());
}
}
for (IIdType next : idsToPreResolve) {
@@ -192,18 +191,18 @@ public class TransactionProcessor extends BaseTransactionProcessor {
String requestIfNoneExist = versionAdapter.getEntryIfNoneExist(nextEntry);
String resourceType = myFhirContext.getResourceType(resource);
if ("PUT".equals(verb) && requestUrl != null && requestUrl.contains("?")) {
- ResourcePersistentId cachedId = myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestUrl);
+ JpaPid cachedId = myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestUrl);
if (cachedId != null) {
- idsToPreFetch.add(cachedId.getIdAsLong());
+ idsToPreFetch.add(cachedId.getId());
} else if (SINGLE_PARAMETER_MATCH_URL_PATTERN.matcher(requestUrl).matches()) {
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(resource);
SearchParameterMap matchUrlSearchMap = myMatchUrlService.translateMatchUrl(requestUrl, resourceDefinition);
searchParameterMapsToResolve.add(new MatchUrlToResolve(requestUrl, matchUrlSearchMap, resourceDefinition));
}
} else if ("POST".equals(verb) && requestIfNoneExist != null && requestIfNoneExist.contains("?")) {
- ResourcePersistentId cachedId = myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestIfNoneExist);
+ JpaPid cachedId = myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestIfNoneExist);
if (cachedId != null) {
- idsToPreFetch.add(cachedId.getIdAsLong());
+ idsToPreFetch.add(cachedId.getId());
} else if (SINGLE_PARAMETER_MATCH_URL_PATTERN.matcher(requestIfNoneExist).matches()) {
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(resource);
SearchParameterMap matchUrlSearchMap = myMatchUrlService.translateMatchUrl(requestIfNoneExist, resourceDefinition);
@@ -277,7 +276,7 @@ public class TransactionProcessor extends BaseTransactionProcessor {
}
IFhirSystemDao,?> systemDao = myApplicationContext.getBean(IFhirSystemDao.class);
- systemDao.preFetchResources(ResourcePersistentId.fromLongList(idsToPreFetch));
+ systemDao.preFetchResources(JpaPid.fromLongList(idsToPreFetch));
}
@@ -322,8 +321,8 @@ public class TransactionProcessor extends BaseTransactionProcessor {
private void setSearchToResolvedAndPrefetchFoundResourcePid(TransactionDetails theTransactionDetails, List idsToPreFetch, ResourceIndexedSearchParamToken nextResult, MatchUrlToResolve nextSearchParameterMap) {
ourLog.debug("Matched url {} from database", nextSearchParameterMap.myRequestUrl);
idsToPreFetch.add(nextResult.getResourcePid());
- myMatchResourceUrlService.matchUrlResolved(theTransactionDetails, nextSearchParameterMap.myResourceDefinition.getName(), nextSearchParameterMap.myRequestUrl, new ResourcePersistentId(nextResult.getResourcePid()));
- theTransactionDetails.addResolvedMatchUrl(nextSearchParameterMap.myRequestUrl, new ResourcePersistentId(nextResult.getResourcePid()));
+ myMatchResourceUrlService.matchUrlResolved(theTransactionDetails, nextSearchParameterMap.myResourceDefinition.getName(), nextSearchParameterMap.myRequestUrl, JpaPid.fromId(nextResult.getResourcePid()));
+ theTransactionDetails.addResolvedMatchUrl(nextSearchParameterMap.myRequestUrl, JpaPid.fromId(nextResult.getResourcePid()));
nextSearchParameterMap.setResolved(true);
}
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/expunge/ResourceExpungeService.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/expunge/JpaResourceExpungeService.java
similarity index 85%
rename from hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/expunge/ResourceExpungeService.java
rename to hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/expunge/JpaResourceExpungeService.java
index bdbeb29bcb7..e0dea8e6dc4 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/expunge/ResourceExpungeService.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/expunge/JpaResourceExpungeService.java
@@ -45,13 +45,13 @@ import ca.uhn.fhir.jpa.dao.data.IResourceLinkDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTagDao;
import ca.uhn.fhir.jpa.dao.data.ISearchParamPresentDao;
+import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ForcedId;
import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.util.MemoryCacheService;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.rest.server.util.CompositeInterceptorBroadcaster;
import org.apache.commons.lang3.Validate;
@@ -74,8 +74,8 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@Service
-public class ResourceExpungeService implements IResourceExpungeService {
- private static final Logger ourLog = LoggerFactory.getLogger(ResourceExpungeService.class);
+public class JpaResourceExpungeService implements IResourceExpungeService {
+ private static final Logger ourLog = LoggerFactory.getLogger(JpaResourceExpungeService.class);
@Autowired
private IForcedIdDao myForcedIdDao;
@@ -128,7 +128,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Override
@Transactional
- public List findHistoricalVersionsOfNonDeletedResources(String theResourceName, ResourcePersistentId theResourceId, int theRemainingCount) {
+ public List findHistoricalVersionsOfNonDeletedResources(String theResourceName, JpaPid theJpaPid, int theRemainingCount) {
if (isEmptyQuery(theRemainingCount)) {
return Collections.EMPTY_LIST;
}
@@ -136,11 +136,11 @@ public class ResourceExpungeService implements IResourceExpungeService {
Pageable page = PageRequest.of(0, theRemainingCount);
Slice ids;
- if (theResourceId != null && theResourceId.getId() != null) {
- if (theResourceId.getVersion() != null) {
- ids = toSlice(myResourceHistoryTableDao.findForIdAndVersionAndFetchProvenance(theResourceId.getIdAsLong(), theResourceId.getVersion()));
+ if (theJpaPid != null && theJpaPid.getId() != null) {
+ if (theJpaPid.getVersion() != null) {
+ ids = toSlice(myResourceHistoryTableDao.findForIdAndVersionAndFetchProvenance(theJpaPid.getId(), theJpaPid.getVersion()));
} else {
- ids = myResourceHistoryTableDao.findIdsOfPreviousVersionsOfResourceId(page, theResourceId.getIdAsLong());
+ ids = myResourceHistoryTableDao.findIdsOfPreviousVersionsOfResourceId(page, theJpaPid.getId());
}
} else {
if (theResourceName != null) {
@@ -150,12 +150,12 @@ public class ResourceExpungeService implements IResourceExpungeService {
}
}
- return ResourcePersistentId.fromLongList(ids.getContent());
+ return JpaPid.fromLongList(ids.getContent());
}
@Override
@Transactional
- public List findHistoricalVersionsOfDeletedResources(String theResourceName, ResourcePersistentId theResourceId, int theRemainingCount) {
+ public List findHistoricalVersionsOfDeletedResources(String theResourceName, JpaPid theResourceId, int theRemainingCount) {
if (isEmptyQuery(theRemainingCount)) {
return Collections.EMPTY_LIST;
}
@@ -163,7 +163,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
Pageable page = PageRequest.of(0, theRemainingCount);
Slice ids;
if (theResourceId != null) {
- ids = myResourceTableDao.findIdsOfDeletedResourcesOfType(page, theResourceId.getIdAsLong(), theResourceName);
+ ids = myResourceTableDao.findIdsOfDeletedResourcesOfType(page, theResourceId.getId(), theResourceName);
ourLog.info("Expunging {} deleted resources of type[{}] and ID[{}]", ids.getNumberOfElements(), theResourceName, theResourceId);
} else {
if (theResourceName != null) {
@@ -174,14 +174,14 @@ public class ResourceExpungeService implements IResourceExpungeService {
ourLog.info("Expunging {} deleted resources (all types)", ids.getNumberOfElements());
}
}
- return ResourcePersistentId.fromLongList(ids.getContent());
+ return JpaPid.fromLongList(ids.getContent());
}
@Override
@Transactional
- public void expungeCurrentVersionOfResources(RequestDetails theRequestDetails, List theResourceIds, AtomicInteger theRemainingCount) {
- for (ResourcePersistentId next : theResourceIds) {
- expungeCurrentVersionOfResource(theRequestDetails, next.getIdAsLong(), theRemainingCount);
+ public void expungeCurrentVersionOfResources(RequestDetails theRequestDetails, List theResourceIds, AtomicInteger theRemainingCount) {
+ for (JpaPid next : theResourceIds) {
+ expungeCurrentVersionOfResource(theRequestDetails,(next).getId(), theRemainingCount);
if (expungeLimitReached(theRemainingCount)) {
return;
}
@@ -236,9 +236,9 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Override
@Transactional
- public void expungeHistoricalVersionsOfIds(RequestDetails theRequestDetails, List theResourceIds, AtomicInteger theRemainingCount) {
- for (ResourcePersistentId next : theResourceIds) {
- expungeHistoricalVersionsOfId(theRequestDetails, next.getIdAsLong(), theRemainingCount);
+ public void expungeHistoricalVersionsOfIds(RequestDetails theRequestDetails, List theResourceIds, AtomicInteger theRemainingCount) {
+ for (JpaPid next : theResourceIds) {
+ expungeHistoricalVersionsOfId(theRequestDetails, (next).getId(), theRemainingCount);
if (expungeLimitReached(theRemainingCount)) {
return;
}
@@ -247,9 +247,9 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Override
@Transactional
- public void expungeHistoricalVersions(RequestDetails theRequestDetails, List theHistoricalIds, AtomicInteger theRemainingCount) {
- for (ResourcePersistentId next : theHistoricalIds) {
- expungeHistoricalVersion(theRequestDetails, next.getIdAsLong(), theRemainingCount);
+ public void expungeHistoricalVersions(RequestDetails theRequestDetails, List theHistoricalIds, AtomicInteger theRemainingCount) {
+ for (JpaPid next : theHistoricalIds) {
+ expungeHistoricalVersion(theRequestDetails, (next).getId(), theRemainingCount);
if (expungeLimitReached(theRemainingCount)) {
return;
}
@@ -266,7 +266,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
ourLog.info("Expunging current version of resource {}", resource.getIdDt().getValue());
- deleteAllSearchParams(new ResourcePersistentId(resource.getResourceId()));
+ deleteAllSearchParams(JpaPid.fromId(resource.getResourceId()));
myResourceTagDao.deleteByResourceId(resource.getId());
@@ -282,44 +282,45 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Override
@Transactional
- public void deleteAllSearchParams(ResourcePersistentId theResourceId) {
- ResourceTable resource = myResourceTableDao.findById(theResourceId.getIdAsLong()).orElse(null);
+ public void deleteAllSearchParams(JpaPid theResourceId) {
+ Long theResourceLongId = theResourceId.getId();
+ ResourceTable resource = myResourceTableDao.findById(theResourceLongId).orElse(null);
if (resource == null || resource.isParamsUriPopulated()) {
- myResourceIndexedSearchParamUriDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedSearchParamUriDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsCoordsPopulated()) {
- myResourceIndexedSearchParamCoordsDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedSearchParamCoordsDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsDatePopulated()) {
- myResourceIndexedSearchParamDateDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedSearchParamDateDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsNumberPopulated()) {
- myResourceIndexedSearchParamNumberDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedSearchParamNumberDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsQuantityPopulated()) {
- myResourceIndexedSearchParamQuantityDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedSearchParamQuantityDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsQuantityNormalizedPopulated()) {
- myResourceIndexedSearchParamQuantityNormalizedDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedSearchParamQuantityNormalizedDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsStringPopulated()) {
- myResourceIndexedSearchParamStringDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedSearchParamStringDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsTokenPopulated()) {
- myResourceIndexedSearchParamTokenDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedSearchParamTokenDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsComboStringUniquePresent()) {
- myResourceIndexedCompositeStringUniqueDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedCompositeStringUniqueDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsComboTokensNonUniquePresent()) {
- myResourceIndexedComboTokensNonUniqueDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceIndexedComboTokensNonUniqueDao.deleteByResourceId(theResourceLongId);
}
if (myDaoConfig.getIndexMissingFields() == DaoConfig.IndexEnabledEnum.ENABLED) {
- mySearchParamPresentDao.deleteByResourceId(theResourceId.getIdAsLong());
+ mySearchParamPresentDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isHasLinks()) {
- myResourceLinkDao.deleteByResourceId(theResourceId.getIdAsLong());
+ myResourceLinkDao.deleteByResourceId(theResourceLongId);
}
}
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/IJpaIdHelperService.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/IJpaIdHelperService.java
deleted file mode 100644
index 889dadf1179..00000000000
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/IJpaIdHelperService.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package ca.uhn.fhir.jpa.dao.index;
-
-/*-
- * #%L
- * HAPI FHIR JPA Server
- * %%
- * Copyright (C) 2014 - 2022 Smile CDR, Inc.
- * %%
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * #L%
- */
-
-import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
-import org.hl7.fhir.instance.model.api.IAnyResource;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-import org.hl7.fhir.instance.model.api.IIdType;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.List;
-import java.util.Set;
-
-/**
- * This class is an analog to {@link IIdHelperService} but with additional JPA server methods
- * added.
- *
- * JA 2022-02-17 - I moved these methods out of IdHelperService because I want to reuse
- * IdHelperService in storage-engine-neutral batch tasks such as bulk import. These methods
- * are all just being used by MDM, so they're JPA specific. I believe it should be possible
- * though to just replace all of these calls with equivalents from IdHelperService,
- * at which point this interface and its implementation could just go away.
- *
- * All of the methods here aren't partition aware, so it's not great to use them
- * anyhow. The equivalents in {@link IIdHelperService} are probably a bit more
- * clunky because you have to convert between {@link Long} and
- * {@link ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId} to use them,
- * but they also have caching and partition awareness so the tradeoff for that
- * extra effort is that they are better.
- */
-public interface IJpaIdHelperService extends IIdHelperService {
-
- /**
- * @deprecated This method doesn't take a partition ID as input, so it is unsafe. It
- * should be reworked to include the partition ID before any new use is incorporated
- */
- @Deprecated
- @Nonnull
- List getPidsOrThrowException(List theIds);
-
-
- /**
- * @deprecated This method doesn't take a partition ID as input, so it is unsafe. It
- * should be reworked to include the partition ID before any new use is incorporated
- */
- @Deprecated
- @Nullable
- Long getPidOrNull(IBaseResource theResource);
-
-
- /**
- * @deprecated This method doesn't take a partition ID as input, so it is unsafe. It
- * should be reworked to include the partition ID before any new use is incorporated
- */
- @Deprecated
- @Nonnull
- Long getPidOrThrowException(IIdType theId);
-
- @Nonnull
- ResourcePersistentId getPidOrThrowException(@Nonnull IAnyResource theResource);
-
- IIdType resourceIdFromPidOrThrowException(Long thePid);
-
- /**
- * Given a set of PIDs, return a set of public FHIR Resource IDs.
- * This function will resolve a forced ID if it resolves, and if it fails to resolve to a forced it, will just return the pid
- * Example:
- * Let's say we have Patient/1(pid == 1), Patient/pat1 (pid == 2), Patient/3 (pid == 3), their pids would resolve as follows:
- *
- * [1,2,3] -> ["1","pat1","3"]
- *
- * @param thePids The Set of pids you would like to resolve to external FHIR Resource IDs.
- * @return A Set of strings representing the FHIR IDs of the pids.
- */
- Set translatePidsToFhirResourceIds(Set thePids);
-
-}
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/IdHelperService.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/IdHelperService.java
index acc0c8f4c34..56315718845 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/IdHelperService.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/IdHelperService.java
@@ -30,14 +30,16 @@ import ca.uhn.fhir.jpa.dao.data.IForcedIdDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.model.cross.IResourceLookup;
-import ca.uhn.fhir.jpa.model.cross.ResourceLookup;
+import ca.uhn.fhir.jpa.model.cross.JpaResourceLookup;
+import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ForcedId;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.search.builder.SearchBuilder;
import ca.uhn.fhir.jpa.util.MemoryCacheService;
import ca.uhn.fhir.jpa.util.QueryChunker;
import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
+import ca.uhn.fhir.rest.api.server.storage.BaseResourcePersistentId;
+import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
@@ -92,13 +94,13 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
*
* This service is highly optimized in order to minimize the number of DB calls as much as possible,
* since ID resolution is fundamental to many basic operations. This service returns either
- * {@link IResourceLookup} or {@link ResourcePersistentId} depending on the method being called.
+ * {@link IResourceLookup} or {@link BaseResourcePersistentId} depending on the method being called.
* The former involves an extra database join that the latter does not require, so selecting the
* right method here is important.
*
*/
@Service
-public class IdHelperService implements IIdHelperService {
+public class IdHelperService implements IIdHelperService {
public static final Predicate[] EMPTY_PREDICATE_ARRAY = new Predicate[0];
public static final String RESOURCE_PID = "RESOURCE_PID";
@Autowired
@@ -130,7 +132,7 @@ public class IdHelperService implements IIdHelperService {
*/
@Override
@Nonnull
- public IResourceLookup resolveResourceIdentity(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId) throws ResourceNotFoundException {
+ public IResourceLookup resolveResourceIdentity(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId) throws ResourceNotFoundException {
return resolveResourceIdentity(theRequestPartitionId, theResourceType, theResourceId, false);
}
@@ -143,12 +145,12 @@ public class IdHelperService implements IIdHelperService {
*/
@Override
@Nonnull
- public IResourceLookup resolveResourceIdentity(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId, boolean theExcludeDeleted) throws ResourceNotFoundException {
+ public IResourceLookup resolveResourceIdentity(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId, boolean theExcludeDeleted) throws ResourceNotFoundException {
assert myDontCheckActiveTransactionForUnitTest || TransactionSynchronizationManager.isSynchronizationActive();
assert theRequestPartitionId != null;
IdDt id = new IdDt(theResourceType, theResourceId);
- Map> matches = translateForcedIdToPids(theRequestPartitionId,
+ Map>> matches = translateForcedIdToPids(theRequestPartitionId,
Collections.singletonList(id),
theExcludeDeleted);
@@ -171,25 +173,25 @@ public class IdHelperService implements IIdHelperService {
}
/**
- * Returns a mapping of Id -> ResourcePersistentId.
+ * Returns a mapping of Id -> IResourcePersistentId.
* If any resource is not found, it will throw ResourceNotFound exception (and no map will be returned)
*/
@Override
@Nonnull
- public Map resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId,
+ public Map resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId,
String theResourceType,
List theIds) {
return resolveResourcePersistentIds(theRequestPartitionId, theResourceType, theIds, false);
}
/**
- * Returns a mapping of Id -> ResourcePersistentId.
+ * Returns a mapping of Id -> IResourcePersistentId.
* If any resource is not found, it will throw ResourceNotFound exception (and no map will be returned)
* Optionally filters out deleted resources.
*/
@Override
@Nonnull
- public Map resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId,
+ public Map resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId,
String theResourceType,
List theIds,
boolean theExcludeDeleted) {
@@ -197,13 +199,13 @@ public class IdHelperService implements IIdHelperService {
Validate.notNull(theIds, "theIds cannot be null");
Validate.isTrue(!theIds.isEmpty(), "theIds must not be empty");
- Map retVals = new HashMap<>();
+ Map retVals = new HashMap<>();
for (String id : theIds) {
- ResourcePersistentId retVal;
+ JpaPid retVal;
if (!idRequiresForcedId(id)) {
// is already a PID
- retVal = new ResourcePersistentId(Long.parseLong(id));
+ retVal = JpaPid.fromId(Long.parseLong(id));
retVals.put(id, retVal);
} else {
// is a forced id
@@ -217,7 +219,7 @@ public class IdHelperService implements IIdHelperService {
retVal = myMemoryCacheService.getThenPutAfterCommit(MemoryCacheService.CacheEnum.FORCED_ID_TO_PID, key, t -> {
List ids = Collections.singletonList(new IdType(theResourceType, id));
// fetches from cache using a function that checks cache first...
- List resolvedIds = resolveResourcePersistentIdsWithCache(theRequestPartitionId, ids);
+ List resolvedIds = resolveResourcePersistentIdsWithCache(theRequestPartitionId, ids);
if (resolvedIds.isEmpty()) {
throw new ResourceNotFoundException(Msg.code(1100) + ids.get(0));
}
@@ -238,7 +240,7 @@ public class IdHelperService implements IIdHelperService {
*/
@Override
@Nonnull
- public ResourcePersistentId resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theId) {
+ public JpaPid resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theId) {
return resolveResourcePersistentIds(theRequestPartitionId, theResourceType, theId, false);
}
@@ -249,10 +251,10 @@ public class IdHelperService implements IIdHelperService {
* @throws ResourceNotFoundException If the ID can not be found
*/
@Override
- public ResourcePersistentId resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theId, boolean theExcludeDeleted){
+ public JpaPid resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theId, boolean theExcludeDeleted){
Validate.notNull(theId, "theId must not be null");
- Map retVal = resolveResourcePersistentIds(theRequestPartitionId,
+ Map retVal = resolveResourcePersistentIds(theRequestPartitionId,
theResourceType,
Collections.singletonList(theId),
theExcludeDeleted);
@@ -284,7 +286,7 @@ public class IdHelperService implements IIdHelperService {
*/
@Override
@Nonnull
- public List resolveResourcePersistentIdsWithCache(RequestPartitionId theRequestPartitionId, List theIds) {
+ public List resolveResourcePersistentIdsWithCache(RequestPartitionId theRequestPartitionId, List theIds) {
boolean onlyForcedIds = false;
return resolveResourcePersistentIdsWithCache(theRequestPartitionId, theIds, onlyForcedIds);
}
@@ -299,10 +301,10 @@ public class IdHelperService implements IIdHelperService {
*/
@Override
@Nonnull
- public List resolveResourcePersistentIdsWithCache(RequestPartitionId theRequestPartitionId, List theIds, boolean theOnlyForcedIds) {
+ public List resolveResourcePersistentIdsWithCache(RequestPartitionId theRequestPartitionId, List theIds, boolean theOnlyForcedIds) {
assert myDontCheckActiveTransactionForUnitTest || TransactionSynchronizationManager.isSynchronizationActive();
- List retVal = new ArrayList<>(theIds.size());
+ List retVal = new ArrayList<>(theIds.size());
for (IIdType id : theIds) {
if (!id.hasIdPart()) {
@@ -316,14 +318,16 @@ public class IdHelperService implements IIdHelperService {
if (myDaoConfig.getResourceClientIdStrategy() != DaoConfig.ClientIdStrategyEnum.ANY) {
if (nextId.isIdPartValidLong()) {
if (!theOnlyForcedIds) {
- retVal.add(new ResourcePersistentId(nextId.getIdPartAsLong()).setAssociatedResourceId(nextId));
+ JpaPid jpaPid = JpaPid.fromId(nextId.getIdPartAsLong());
+ jpaPid.setAssociatedResourceId(nextId);
+ retVal.add(jpaPid);
}
continue;
}
}
String key = toForcedIdToPidKey(theRequestPartitionId, nextId.getResourceType(), nextId.getIdPart());
- ResourcePersistentId cachedId = myMemoryCacheService.getIfPresent(MemoryCacheService.CacheEnum.FORCED_ID_TO_PID, key);
+ JpaPid cachedId = myMemoryCacheService.getIfPresent(MemoryCacheService.CacheEnum.FORCED_ID_TO_PID, key);
if (cachedId != null) {
retVal.add(cachedId);
continue;
@@ -337,7 +341,7 @@ public class IdHelperService implements IIdHelperService {
return retVal;
}
- private void doResolvePersistentIds(RequestPartitionId theRequestPartitionId, List theIds, List theOutputListToPopulate) {
+ private void doResolvePersistentIds(RequestPartitionId theRequestPartitionId, List theIds, List theOutputListToPopulate) {
CriteriaBuilder cb = myEntityManager.getCriteriaBuilder();
CriteriaQuery criteriaQuery = cb.createQuery(ForcedId.class);
Root from = criteriaQuery.from(ForcedId.class);
@@ -365,12 +369,12 @@ public class IdHelperService implements IIdHelperService {
for (ForcedId nextId : results) {
// Check if the nextId has a resource ID. It may have a null resource ID if a commit is still pending.
if (nextId.getResourceId() != null) {
- ResourcePersistentId persistentId = new ResourcePersistentId(nextId.getResourceId());
- populateAssociatedResourceId(nextId.getResourceType(), nextId.getForcedId(), persistentId);
- theOutputListToPopulate.add(persistentId);
+ JpaPid jpaPid = JpaPid.fromId(nextId.getResourceId());
+ populateAssociatedResourceId(nextId.getResourceType(), nextId.getForcedId(), jpaPid);
+ theOutputListToPopulate.add(jpaPid);
String key = toForcedIdToPidKey(theRequestPartitionId, nextId.getResourceType(), nextId.getForcedId());
- myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.FORCED_ID_TO_PID, key, persistentId);
+ myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.FORCED_ID_TO_PID, key, jpaPid);
}
}
}
@@ -401,10 +405,10 @@ public class IdHelperService implements IIdHelperService {
return Optional.empty();
}
- private void populateAssociatedResourceId(String nextResourceType, String forcedId, ResourcePersistentId persistentId) {
+ private void populateAssociatedResourceId(String nextResourceType, String forcedId, JpaPid jpaPid) {
IIdType resourceId = myFhirCtx.getVersion().newIdType();
resourceId.setValue(nextResourceType + "/" + forcedId);
- persistentId.setAssociatedResourceId(resourceId);
+ jpaPid.setAssociatedResourceId(resourceId);
}
/**
@@ -412,7 +416,7 @@ public class IdHelperService implements IIdHelperService {
*/
@Nonnull
@Override
- public IIdType translatePidIdToForcedId(FhirContext theCtx, String theResourceType, ResourcePersistentId theId) {
+ public IIdType translatePidIdToForcedId(FhirContext theCtx, String theResourceType, JpaPid theId) {
if (theId.getAssociatedResourceId() != null) {
return theId.getAssociatedResourceId();
}
@@ -430,8 +434,8 @@ public class IdHelperService implements IIdHelperService {
}
@Override
- public Optional translatePidIdToForcedIdWithCache(ResourcePersistentId theId) {
- return myMemoryCacheService.get(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theId.getIdAsLong(), pid -> myForcedIdDao.findByResourcePid(pid).map(ForcedId::asTypedFhirResourceId));
+ public Optional translatePidIdToForcedIdWithCache(JpaPid theId) {
+ return myMemoryCacheService.get(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theId.getId(), pid -> myForcedIdDao.findByResourcePid(pid).map(ForcedId::asTypedFhirResourceId));
}
private ListMultimap organizeIdsByResourceType(Collection theIds) {
@@ -448,7 +452,7 @@ public class IdHelperService implements IIdHelperService {
return typeToIds;
}
- private Map> translateForcedIdToPids(@Nonnull RequestPartitionId theRequestPartitionId, Collection