diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/cache/ResourceVersionSvcDaoImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/cache/ResourceVersionSvcDaoImpl.java index 0f064927c77..44a7c1f1098 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/cache/ResourceVersionSvcDaoImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/cache/ResourceVersionSvcDaoImpl.java @@ -73,7 +73,7 @@ public class ResourceVersionSvcDaoImpl implements IResourceVersionSvc { } List matchingIds = dao.searchForIds(theSearchParamMap, new SystemRequestDetails().setRequestPartitionId(theRequestPartitionId)).stream() - .map(ResourcePersistentId::getIdAsLong) + .map(id -> ((JpaPid) id).getId()) .collect(Collectors.toList()); List allById = new ArrayList<>(); @@ -138,7 +138,7 @@ public class ResourceVersionSvcDaoImpl implements IResourceVersionSvc { } List jpaPids = myIdHelperService.resolveResourcePersistentIdsWithCache(thePartitionId, - new ArrayList<>(theIds)).stream().map(id -> (JpaPid) id).toList(); + new ArrayList<>(theIds)).stream().map(id -> (JpaPid) id).collect(Collectors.toList()); // we'll use this map to fetch pids that require versions HashMap pidsToVersionToResourcePid = new HashMap<>(); @@ -146,7 +146,7 @@ public class ResourceVersionSvcDaoImpl implements IResourceVersionSvc { // fill in our map for (JpaPid pid : jpaPids) { if (pid.getVersion() == null) { - pidsToVersionToResourcePid.put(pid.getIdAsLong(), pid); + pidsToVersionToResourcePid.put(pid.getId(), pid); } Optional idOp = theIds.stream() .filter(i -> i.getIdPart().equals(pid.getAssociatedResourceId().getIdPart())) 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 9ac36e5e3ed..5a83cdcceca 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 @@ -1729,9 +1729,9 @@ public abstract class BaseHapiFhirDao extends BaseStora protected void addPidToResource(IBasePersistedResource theEntity, IBaseResource theResource) { if (theResource instanceof IAnyResource) { - IDao.RESOURCE_PID.put((IAnyResource) theResource, theEntity.getPersistentId().getIdAsLong()); + IDao.RESOURCE_PID.put((IAnyResource) theResource, ((JpaPid) theEntity.getPersistentId()).getId()); } else if (theResource instanceof IResource) { - IDao.RESOURCE_PID.put((IResource) theResource, theEntity.getPersistentId().getIdAsLong()); + IDao.RESOURCE_PID.put((IResource) theResource, ((JpaPid) theEntity.getPersistentId()).getId()); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index 07591ab406b..86e77b937b7 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -301,12 +301,12 @@ public abstract class BaseHapiFhirResourceDao extends B return myTxTemplate.execute(tx -> { IIdType retVal = myIdHelperService.translatePidIdToForcedId(myFhirContext, myResourceName, pid); if (!retVal.hasVersionIdPart()) { - IIdType idWithVersion = myMemoryCacheService.getIfPresent(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getIdAsLong()); + IIdType idWithVersion = myMemoryCacheService.getIfPresent(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getId()); if (idWithVersion == null) { - Long version = myResourceTableDao.findCurrentVersionByPid(pid.getIdAsLong()); + Long version = myResourceTableDao.findCurrentVersionByPid(pid.getId()); if (version != null) { retVal = myFhirContext.getVersion().newIdType().setParts(retVal.getBaseUrl(), retVal.getResourceType(), retVal.getIdPart(), Long.toString(version)); - myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getIdAsLong(), retVal); + myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getId(), retVal); } } else { retVal = idWithVersion; @@ -667,7 +667,7 @@ public abstract class BaseHapiFhirResourceDao extends B TransactionDetails transactionDetails = new TransactionDetails(); List deletedResources = new ArrayList<>(); for (ResourcePersistentId pid : theResourceIds) { - ResourceTable entity = myEntityManager.find(ResourceTable.class, pid.getIdAsLong()); + ResourceTable entity = myEntityManager.find(ResourceTable.class, ((JpaPid) pid).getId()); deletedResources.add(entity); T resourceToDelete = toResource(myResourceType, entity, null, false); @@ -1198,10 +1198,11 @@ public abstract class BaseHapiFhirResourceDao extends B @Transactional public T readByPid(ResourcePersistentId 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()); @@ -1209,7 +1210,7 @@ public abstract class BaseHapiFhirResourceDao extends B T retVal = 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; } @@ -1287,9 +1288,9 @@ public abstract class BaseHapiFhirResourceDao extends B @SuppressWarnings("unchecked") @Override public void reindex(ResourcePersistentId theResourcePersistentId, RequestDetails theRequest, TransactionDetails theTransactionDetails) { - Optional entityOpt = myResourceTableDao.findById(theResourcePersistentId.getIdAsLong()); + Optional entityOpt = myResourceTableDao.findById(((JpaPid) theResourcePersistentId).getId()); if (!entityOpt.isPresent()) { - ourLog.warn("Unable to find entity with PID: {}", theResourcePersistentId.getId()); + ourLog.warn("Unable to find entity with PID: {}", ((JpaPid) theResourcePersistentId).getId()); return; } @@ -1314,21 +1315,21 @@ public abstract class BaseHapiFhirResourceDao extends B JpaPid pid = (JpaPid) 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); } } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDaoObservation.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDaoObservation.java index cb1fb15787b..c69fe2bf58c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDaoObservation.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDaoObservation.java @@ -112,7 +112,7 @@ public abstract class BaseHapiFhirResourceDaoObservation extends B 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/TransactionProcessor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/TransactionProcessor.java index 6c113f43add..35bfedfd4c3 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 @@ -165,12 +165,12 @@ public class TransactionProcessor extends BaseTransactionProcessor { } } List outcome = myIdHelperService.resolveResourcePersistentIdsWithCache(requestPartitionId, idsToPreResolve) - .stream().map(id -> (JpaPid) id).toList(); + .stream().map(id -> (JpaPid) id).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) { @@ -193,7 +193,7 @@ public class TransactionProcessor extends BaseTransactionProcessor { if ("PUT".equals(verb) && requestUrl != null && requestUrl.contains("?")) { JpaPid cachedId = (JpaPid) 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); @@ -202,7 +202,7 @@ public class TransactionProcessor extends BaseTransactionProcessor { } else if ("POST".equals(verb) && requestIfNoneExist != null && requestIfNoneExist.contains("?")) { JpaPid cachedId = (JpaPid) 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); 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/ResourceExpungeService.java index 9b4901c91a1..fe0ed051ffc 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/ResourceExpungeService.java @@ -129,13 +129,14 @@ public class ResourceExpungeService implements IResourceExpungeService { @Transactional public List findHistoricalVersionsOfNonDeletedResources(String theResourceName, ResourcePersistentId theResourceId, int theRemainingCount) { Pageable page = PageRequest.of(0, theRemainingCount); + JpaPid jpaPid = (JpaPid) theResourceId; Slice ids; - if (theResourceId != null && theResourceId.getId() != null) { - if (theResourceId.getVersion() != null) { - ids = toSlice(myResourceHistoryTableDao.findForIdAndVersionAndFetchProvenance(theResourceId.getIdAsLong(), theResourceId.getVersion())); + if (jpaPid != null && jpaPid.getId() != null) { + if (jpaPid.getVersion() != null) { + ids = toSlice(myResourceHistoryTableDao.findForIdAndVersionAndFetchProvenance(jpaPid.getId(), jpaPid.getVersion())); } else { - ids = myResourceHistoryTableDao.findIdsOfPreviousVersionsOfResourceId(page, theResourceId.getIdAsLong()); + ids = myResourceHistoryTableDao.findIdsOfPreviousVersionsOfResourceId(page, jpaPid.getId()); } } else { if (theResourceName != null) { @@ -154,7 +155,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, ((JpaPid) theResourceId).getId(), theResourceName); ourLog.info("Expunging {} deleted resources of type[{}] and ID[{}]", ids.getNumberOfElements(), theResourceName, theResourceId); } else { if (theResourceName != null) { @@ -172,7 +173,7 @@ public class ResourceExpungeService implements IResourceExpungeService { @Transactional public void expungeCurrentVersionOfResources(RequestDetails theRequestDetails, List theResourceIds, AtomicInteger theRemainingCount) { for (ResourcePersistentId next : theResourceIds) { - expungeCurrentVersionOfResource(theRequestDetails, next.getIdAsLong(), theRemainingCount); + expungeCurrentVersionOfResource(theRequestDetails, ((JpaPid) next).getId(), theRemainingCount); if (theRemainingCount.get() <= 0) { return; } @@ -230,7 +231,7 @@ public class ResourceExpungeService implements IResourceExpungeService { @Transactional public void expungeHistoricalVersionsOfIds(RequestDetails theRequestDetails, List theResourceIds, AtomicInteger theRemainingCount) { for (ResourcePersistentId next : theResourceIds) { - expungeHistoricalVersionsOfId(theRequestDetails, next.getIdAsLong(), theRemainingCount); + expungeHistoricalVersionsOfId(theRequestDetails, ((JpaPid) next).getId(), theRemainingCount); if (theRemainingCount.get() <= 0) { return; } @@ -241,7 +242,7 @@ public class ResourceExpungeService implements IResourceExpungeService { @Transactional public void expungeHistoricalVersions(RequestDetails theRequestDetails, List theHistoricalIds, AtomicInteger theRemainingCount) { for (ResourcePersistentId next : theHistoricalIds) { - expungeHistoricalVersion(theRequestDetails, next.getIdAsLong(), theRemainingCount); + expungeHistoricalVersion(theRequestDetails, ((JpaPid) next).getId(), theRemainingCount); if (theRemainingCount.get() <= 0) { return; } @@ -275,43 +276,44 @@ public class ResourceExpungeService implements IResourceExpungeService { @Override @Transactional public void deleteAllSearchParams(ResourcePersistentId theResourceId) { - ResourceTable resource = myResourceTableDao.findById(theResourceId.getIdAsLong()).orElse(null); + Long theResourceLongId = ((JpaPid) 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/IdHelperService.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/IdHelperService.java index 51d20952112..48d4a2a635e 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 @@ -432,7 +432,7 @@ 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)); + return myMemoryCacheService.get(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, ((JpaPid) theId).getId(), pid -> myForcedIdDao.findByResourcePid(pid).map(ForcedId::asTypedFhirResourceId)); } private ListMultimap organizeIdsByResourceType(Collection theIds) { @@ -597,7 +597,7 @@ public class IdHelperService implements IIdHelperService { @Override public PersistentIdToForcedIdMap translatePidsToForcedIds(Set theResourceIds) { assert myDontCheckActiveTransactionForUnitTest || TransactionSynchronizationManager.isSynchronizationActive(); - Set thePids = theResourceIds.stream().map(t -> t.getIdAsLong()).collect(Collectors.toSet()); + Set thePids = theResourceIds.stream().map(t -> ((JpaPid) t).getId()).collect(Collectors.toSet()); Map> retVal = new HashMap<>(myMemoryCacheService.getAllPresent(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, thePids)); List remainingPids = thePids @@ -638,20 +638,21 @@ public class IdHelperService implements IIdHelperService { */ @Override public void addResolvedPidToForcedId(ResourcePersistentId theResourcePersistentId, @Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, @Nullable String theForcedId, @Nullable Date theDeletedAt) { + JpaPid jpaPid = (JpaPid) theResourcePersistentId; if (theForcedId != null) { if (theResourcePersistentId.getAssociatedResourceId() == null) { - populateAssociatedResourceId(theResourceType, theForcedId, (JpaPid) theResourcePersistentId); + populateAssociatedResourceId(theResourceType, theForcedId, jpaPid); } - myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theResourcePersistentId.getIdAsLong(), Optional.of(theResourceType + "/" + theForcedId)); + myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, jpaPid.getId(), Optional.of(theResourceType + "/" + theForcedId)); String key = toForcedIdToPidKey(theRequestPartitionId, theResourceType, theForcedId); myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.FORCED_ID_TO_PID, key, theResourcePersistentId); } else { - myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theResourcePersistentId.getIdAsLong(), Optional.empty()); + myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, jpaPid.getId(), Optional.empty()); } if (!myDaoConfig.isDeleteEnabled()) { - ResourceLookup lookup = new ResourceLookup(theResourceType, theResourcePersistentId.getIdAsLong(), theDeletedAt); + ResourceLookup lookup = new ResourceLookup(theResourceType, jpaPid.getId(), theDeletedAt); String nextKey = theResourcePersistentId.toString(); myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_LOOKUP, nextKey, lookup); } @@ -686,14 +687,17 @@ public class IdHelperService implements IIdHelperService { @Override @Nullable public ResourcePersistentId getPidOrNull(@Nonnull RequestPartitionId theRequestPartitionId, IBaseResource theResource) { - JpaPid retVal = new JpaPid(Long.parseLong(theResource.getUserData(RESOURCE_PID).toString())); - if (retVal.getId() == null) { + Object resourceId = theResource.getUserData(RESOURCE_PID); + JpaPid retVal; + if (resourceId == null) { IIdType id = theResource.getIdElement(); try { retVal = (JpaPid) resolveResourcePersistentIds(theRequestPartitionId, id.getResourceType(), id.getIdPart()); } catch (ResourceNotFoundException e) { return null; } + } else { + retVal = new JpaPid(Long.parseLong(resourceId.toString())); } return retVal; } @@ -718,7 +722,7 @@ public class IdHelperService implements IIdHelperService { @Override public IIdType resourceIdFromPidOrThrowException(ResourcePersistentId thePid, String theResourceType) { - Optional optionalResource = myResourceTableDao.findById(thePid.getIdAsLong()); + Optional optionalResource = myResourceTableDao.findById(((JpaPid) thePid).getId()); if (!optionalResource.isPresent()) { throw new ResourceNotFoundException(Msg.code(2124) + "Requested resource not found"); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/JpaIdHelperService.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/JpaIdHelperService.java index 74fb7c6ce39..27707cb65e9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/JpaIdHelperService.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/JpaIdHelperService.java @@ -59,8 +59,8 @@ public class JpaIdHelperService extends IdHelperService implements IJpaIdHelperS @Nonnull public List getPidsOrThrowException(List theIds) { List resourcePersistentIds = super.resolveResourcePersistentIdsWithCache(RequestPartitionId.allPartitions(), theIds) - .stream().map(id -> (JpaPid) id).toList(); - return resourcePersistentIds.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList()); + .stream().map(id -> (JpaPid) id).collect(Collectors.toList()); + return resourcePersistentIds.stream().map(JpaPid::getId).collect(Collectors.toList()); } @@ -78,7 +78,9 @@ public class JpaIdHelperService extends IdHelperService implements IJpaIdHelperS if (retVal == null) { IIdType id = theResource.getIdElement(); try { - retVal = super.resolveResourcePersistentIds(RequestPartitionId.allPartitions(), id.getResourceType(), id.getIdPart()).getIdAsLong(); + JpaPid jpaPid = (JpaPid) super.resolveResourcePersistentIds( + RequestPartitionId.allPartitions(), id.getResourceType(), id.getIdPart()); + retVal = jpaPid.getId(); } catch (ResourceNotFoundException e) { return null; } @@ -98,8 +100,9 @@ public class JpaIdHelperService extends IdHelperService implements IJpaIdHelperS assert TransactionSynchronizationManager.isSynchronizationActive(); List ids = Collections.singletonList(theId); - List resourcePersistentIds = super.resolveResourcePersistentIdsWithCache(RequestPartitionId.allPartitions(), ids).stream().map(id -> (JpaPid) id).toList();; - return resourcePersistentIds.get(0).getIdAsLong(); + List resourcePersistentIds = super.resolveResourcePersistentIdsWithCache( + RequestPartitionId.allPartitions(), ids).stream().map(id -> (JpaPid) id).collect(Collectors.toList()); + return resourcePersistentIds.get(0).getId(); } @Override diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/mdm/MdmLinkDaoJpaImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/mdm/MdmLinkDaoJpaImpl.java index fc3d2d93a0d..168ba26b155 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/mdm/MdmLinkDaoJpaImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/mdm/MdmLinkDaoJpaImpl.java @@ -67,17 +67,17 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao { @Override public int deleteWithAnyReferenceToPid(ResourcePersistentId thePid) { - return myMdmLinkDao.deleteWithAnyReferenceToPid(thePid.getIdAsLong()); + return myMdmLinkDao.deleteWithAnyReferenceToPid(((JpaPid) thePid).getId()); } @Override public int deleteWithAnyReferenceToPidAndMatchResultNot(ResourcePersistentId thePid, MdmMatchResultEnum theMatchResult) { - return myMdmLinkDao.deleteWithAnyReferenceToPidAndMatchResultNot(thePid.getIdAsLong(), theMatchResult); + return myMdmLinkDao.deleteWithAnyReferenceToPidAndMatchResultNot(((JpaPid) thePid).getId(), theMatchResult); } @Override public List expandPidsFromGroupPidGivenMatchResult(ResourcePersistentId theGroupPid, MdmMatchResultEnum theMdmMatchResultEnum) { - return myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(theGroupPid.getIdAsLong(), theMdmMatchResultEnum) + return myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(((JpaPid) theGroupPid).getId(), theMdmMatchResultEnum) .stream() .map( theMdmPidTuple -> new MdmPidTuple() .setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid())) @@ -87,7 +87,7 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao { @Override public List expandPidsBySourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum) { - return myMdmLinkDao.expandPidsBySourcePidAndMatchResult(theSourcePid.getIdAsLong(), theMdmMatchResultEnum) + return myMdmLinkDao.expandPidsBySourcePidAndMatchResult(((JpaPid) theSourcePid).getId(), theMdmMatchResultEnum) .stream() .map( theMdmPidTuple -> new MdmPidTuple() .setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid())) @@ -97,7 +97,7 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao { @Override public List expandPidsByGoldenResourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum) { - return myMdmLinkDao.expandPidsByGoldenResourcePidAndMatchResult(theSourcePid.getIdAsLong(), theMdmMatchResultEnum) + return myMdmLinkDao.expandPidsByGoldenResourcePidAndMatchResult(((JpaPid) theSourcePid).getId(), theMdmMatchResultEnum) .stream() .map( theMdmPidTuple -> new MdmPidTuple() .setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid())) @@ -123,13 +123,13 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao { @Override public List findAllById(List thePids) { - List theLongPids = thePids.stream().map(theResourcePersistentId -> theResourcePersistentId.getIdAsLong()).collect(Collectors.toList()); + List theLongPids = thePids.stream().map(thePid -> ((JpaPid) thePid).getId()).collect(Collectors.toList()); return myMdmLinkDao.findAllById(theLongPids); } @Override public Optional findById(ResourcePersistentId thePid) { - return myMdmLinkDao.findById(thePid.getIdAsLong()); + return myMdmLinkDao.findById(((JpaPid) thePid).getId()); } public void deleteAll(List theLinks) { @@ -191,11 +191,11 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao { List andPredicates = new ArrayList<>(); if (theGoldenResourceId != null) { - Predicate goldenResourcePredicate = criteriaBuilder.equal(from.get("myGoldenResourcePid").as(Long.class), myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theGoldenResourceId).getIdAsLong()); + Predicate goldenResourcePredicate = criteriaBuilder.equal(from.get("myGoldenResourcePid").as(Long.class), ((JpaPid) myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theGoldenResourceId)).getId()); andPredicates.add(goldenResourcePredicate); } if (theSourceId != null) { - Predicate sourceIdPredicate = criteriaBuilder.equal(from.get("mySourcePid").as(Long.class), myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theSourceId).getIdAsLong()); + Predicate sourceIdPredicate = criteriaBuilder.equal(from.get("mySourcePid").as(Long.class), ((JpaPid) myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theSourceId)).getId()); andPredicates.add(sourceIdPredicate); } if (theMatchResult != null) { @@ -228,12 +228,12 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao { @Override public Optional findBySourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMatch) { - return myMdmLinkDao.findBySourcePidAndMatchResult(theSourcePid.getIdAsLong(), theMatch); + return myMdmLinkDao.findBySourcePidAndMatchResult(((JpaPid) theSourcePid).getId(), theMatch); } @Override public void deleteLinksWithAnyReferenceToPids(List theResourcePersistentIds) { - List goldenResourcePids = theResourcePersistentIds.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList()); + List goldenResourcePids = theResourcePersistentIds.stream().map(pid -> ((JpaPid) pid).getId()).collect(Collectors.toList()); // Split into chunks of 500 so older versions of Oracle don't run into issues (500 = 1000 / 2 since the dao // method uses the list twice in the sql predicate) List> chunks = ListUtils.partition(goldenResourcePids, 500); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/delete/batch2/DeleteExpungeSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/delete/batch2/DeleteExpungeSvcImpl.java index 8338456f9af..19a8d2c12b0 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/delete/batch2/DeleteExpungeSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/delete/batch2/DeleteExpungeSvcImpl.java @@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.delete.batch2; import ca.uhn.fhir.jpa.api.svc.IDeleteExpungeSvc; import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc; +import ca.uhn.fhir.jpa.model.dao.JpaPid; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import org.slf4j.Logger; @@ -70,7 +71,7 @@ public class DeleteExpungeSvcImpl implements IDeleteExpungeSvc { */ private void clearHibernateSearchIndex(List thePersistentIds) { if (myFullTextSearchSvc != null) { - List objectIds = thePersistentIds.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList()); + List objectIds = thePersistentIds.stream().map(id -> ((JpaPid) id).getId()).collect(Collectors.toList()); myFullTextSearchSvc.deleteIndexedDocumentsByTypeAndId(ResourceTable.class, objectIds); ourLog.info("Cleared Hibernate Search indexes."); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java index e3e12eaa6c7..1bef5fbd811 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java @@ -157,9 +157,10 @@ public class MdmLink extends BasePartitionable implements IMdmLink { @Override public IMdmLink setGoldenResourcePersistenceId(ResourcePersistentId theGoldenResourcePid) { - setPersonPid(theGoldenResourcePid.getIdAsLong()); + Long longPid = ((JpaPid) theGoldenResourcePid).getId(); + setPersonPid(longPid); - myGoldenResourcePid = theGoldenResourcePid.getIdAsLong(); + myGoldenResourcePid = longPid; return this; } @@ -170,7 +171,7 @@ public class MdmLink extends BasePartitionable implements IMdmLink { @Override public IMdmLink setSourcePersistenceId(ResourcePersistentId theSourcePid) { - mySourcePid = theSourcePid.getIdAsLong(); + mySourcePid = ((JpaPid) theSourcePid).getId(); return this; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java index 66a4472c75c..f04ba7fff80 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java @@ -528,7 +528,7 @@ public class SearchBuilder implements ISearchBuilder { // add the pids to targetPids for (ResourcePersistentId pid : idToPid.values()) { myAlsoIncludePids.add(pid); - theTargetPids.add(pid.getIdAsLong()); + theTargetPids.add(((JpaPid) pid).getId()); } } @@ -852,7 +852,7 @@ public class SearchBuilder implements ISearchBuilder { if (resourcePidToVersion == null) { resourcePidToVersion = new HashMap<>(); } - resourcePidToVersion.put(next.getIdAsLong(), next.getVersion()); + resourcePidToVersion.put(((JpaPid) next).getId(), next.getVersion()); } } @@ -955,11 +955,11 @@ public class SearchBuilder implements ISearchBuilder { for (ResourceTag tag : tagList) { resourceId = new JpaPid(tag.getResourceId()); - tagCol = tagMap.get(resourceId.getIdAsLong()); + tagCol = tagMap.get(resourceId.getId()); if (tagCol == null) { tagCol = new ArrayList<>(); tagCol.add(tag); - tagMap.put(resourceId.getIdAsLong(), tagCol); + tagMap.put(resourceId.getId(), tagCol); } else { tagCol.add(tag); } @@ -1024,7 +1024,7 @@ public class SearchBuilder implements ISearchBuilder { // Do we use the fulltextsvc via hibernate-search to load resources or be backwards compatible with older ES only impl // to handle lastN? if (myDaoConfig.isAdvancedHSearchIndexing() && myDaoConfig.isStoreResourceInHSearchIndex()) { - List pidList = thePids.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList()); + List pidList = thePids.stream().map(pid -> ((JpaPid) pid).getId()).collect(Collectors.toList()); List resources = myFulltextSearchSvc.getResources(pidList); return resources; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchQueryExecutors.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchQueryExecutors.java index 106bbd39e06..234e78f782e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchQueryExecutors.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchQueryExecutors.java @@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.search.builder; * #L% */ +import ca.uhn.fhir.jpa.model.dao.JpaPid; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import org.apache.commons.lang3.Validate; @@ -119,8 +120,8 @@ public class SearchQueryExecutors { @Override public Long next() { - ResourcePersistentId next = myIterator.next(); - return next==null?null:next.getIdAsLong(); + JpaPid next = (JpaPid) myIterator.next(); + return next == null ? null : next.getId(); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java index 2a3258f7596..472032367a2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java @@ -323,7 +323,7 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc { IIdType csId = myTerminologyVersionAdapterSvc.createOrUpdateCodeSystem(theCodeSystemResource, theRequest); JpaPid codeSystemResourcePid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(RequestPartitionId.allPartitions(), csId.getResourceType(), csId.getIdPart()); - ResourceTable resource = myResourceTableDao.getOne(codeSystemResourcePid.getIdAsLong()); + ResourceTable resource = myResourceTableDao.getOne(codeSystemResourcePid.getId()); ourLog.info("CodeSystem resource has ID: {}", csId.getValue()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/export/svc/JpaBulkExportProcessorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/export/svc/JpaBulkExportProcessorTest.java index ed05675d734..e8d8bbd1066 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/export/svc/JpaBulkExportProcessorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/export/svc/JpaBulkExportProcessorTest.java @@ -265,7 +265,7 @@ public class JpaBulkExportProcessorTest { pids.add(new JpaPid(((IdDt) type).getIdPartAsLong())); } - MdmPidTuple tuple = createTuple(groupId.getIdAsLong(), groupGoldenPid); + MdmPidTuple tuple = createTuple(groupId.getId(), groupGoldenPid); IFhirResourceDao groupDao = mock(IFhirResourceDao.class); parameters.setExpandMdm(theMdm); // set mdm expansion @@ -322,7 +322,7 @@ public class JpaBulkExportProcessorTest { assertTrue(pidIterator.hasNext()); while (pidIterator.hasNext()) { JpaPid pid = (JpaPid) pidIterator.next(); - long idAsLong = pid.getIdAsLong(); + long idAsLong = pid.getId(); boolean existing = pids.contains(new JpaPid(idAsLong)); if (!existing) { assertTrue(theMdm); @@ -353,7 +353,7 @@ public class JpaBulkExportProcessorTest { Arrays.asList(pid, pid2) ); - MdmPidTuple tuple = createTuple(groupId.getIdAsLong(), groupGoldenPid); + MdmPidTuple tuple = createTuple(groupId.getId(), groupGoldenPid); List patientTypes = createPatientTypes(); IFhirResourceDao groupDao = mock(IFhirResourceDao.class); diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java index e7a47323e5f..4a50753cd7a 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java @@ -39,6 +39,7 @@ import ca.uhn.fhir.mdm.util.MdmResourceUtil; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import org.apache.commons.lang3.StringUtils; @@ -363,8 +364,8 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test { Optional matchedLinkForTargetPid = myMdmLinkDaoSvc.getMatchedLinkForSourcePid(runInTransaction(() -> myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), theBaseResource))); if (matchedLinkForTargetPid.isPresent()) { - Long goldenResourcePid = matchedLinkForTargetPid.get().getGoldenResourcePersistenceId().getIdAsLong(); - return (T) relevantDao.readByPid(new JpaPid(goldenResourcePid)); + JpaPid jpaPid = (JpaPid) matchedLinkForTargetPid.get().getGoldenResourcePersistenceId(); + return (T) relevantDao.readByPid(jpaPid); } else { return null; } @@ -372,7 +373,7 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test { protected T getTargetResourceFromMdmLink(IMdmLink theMdmLink, String theResourceType) { IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType); - return (T) resourceDao.readByPid(new JpaPid(theMdmLink.getGoldenResourcePersistenceId().getIdAsLong())); + return (T) resourceDao.readByPid(theMdmLink.getGoldenResourcePersistenceId()); } protected Patient addExternalEID(Patient thePatient, String theEID) { diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvcTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvcTest.java index cd33fb405eb..9d15cabc41d 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvcTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/dao/MdmLinkDaoSvcTest.java @@ -85,8 +85,8 @@ public class MdmLinkDaoSvcTest extends BaseMdmR4Test { lists.stream() .forEach(tuple -> { - assertThat(tuple.getGoldenPid().getIdAsLong(), is(equalTo(golden.getIdElement().getIdPartAsLong()))); - assertThat(tuple.getSourcePid().getIdAsLong(), is(in(expectedExpandedPids))); + assertThat(((JpaPid) tuple.getGoldenPid()).getId(), is(equalTo(golden.getIdElement().getIdPartAsLong()))); + assertThat(((JpaPid)tuple.getSourcePid()).getId(), is(in(expectedExpandedPids))); }); } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java index c8f9d668736..047674c1e73 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java @@ -213,7 +213,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { // Updating a Golden Resource Patient who was created via MDM should fail. IMdmLink mdmLink = runInTransaction(() -> myMdmLinkDaoSvc.getMatchedLinkForSourcePid(myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), patient)).orElseThrow(() -> new IllegalStateException())); - Long sourcePatientPid = mdmLink.getGoldenResourcePersistenceId().getIdAsLong(); + Long sourcePatientPid = ((JpaPid) mdmLink.getGoldenResourcePersistenceId()).getId(); Patient goldenResourcePatient = myPatientDao.readByPid(new JpaPid(sourcePatientPid)); goldenResourcePatient.setGender(Enumerations.AdministrativeGender.MALE); try { diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmGoldenResourceMergerSvcTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmGoldenResourceMergerSvcTest.java index 84054e255de..c0119670f7d 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmGoldenResourceMergerSvcTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmGoldenResourceMergerSvcTest.java @@ -70,10 +70,10 @@ public class MdmGoldenResourceMergerSvcTest extends BaseMdmR4Test { public void before() { myFromGoldenPatient = createGoldenPatient(); IdType fromSourcePatientId = myFromGoldenPatient.getIdElement().toUnqualifiedVersionless(); - myFromGoldenPatientPid = runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), fromSourcePatientId)).getIdAsLong(); + myFromGoldenPatientPid = ((JpaPid) runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), fromSourcePatientId))).getId(); myToGoldenPatient = createGoldenPatient(); IdType toGoldenPatientId = myToGoldenPatient.getIdElement().toUnqualifiedVersionless(); - myToGoldenPatientPid = runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), toGoldenPatientId)).getIdAsLong(); + myToGoldenPatientPid = ((JpaPid) runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), toGoldenPatientId))).getId(); myTargetPatient1 = createPatient(); myTargetPatient2 = createPatient(); diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcTest.java index 8f845455567..ba2a2e92f66 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmLinkSvcTest.java @@ -93,8 +93,8 @@ public class MdmLinkSvcTest extends BaseMdmR4Test { JpaPid goldenPatient1Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient1)); JpaPid goldenPatient2Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient2)); - assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getIdAsLong(), goldenPatient2Pid.getIdAsLong()).isPresent()); - assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getIdAsLong(), goldenPatient1Pid.getIdAsLong()).isPresent()); + assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getId(), goldenPatient2Pid.getId()).isPresent()); + assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getId(), goldenPatient1Pid.getId()).isPresent()); saveNoMatchLink(goldenPatient1Pid, goldenPatient2Pid); @@ -111,8 +111,8 @@ public class MdmLinkSvcTest extends BaseMdmR4Test { JpaPid goldenPatient1Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient1)); JpaPid goldenPatient2Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient2)); - assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getIdAsLong(), goldenPatient2Pid.getIdAsLong()).isPresent()); - assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getIdAsLong(), goldenPatient1Pid.getIdAsLong()).isPresent()); + assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getId(), goldenPatient2Pid.getId()).isPresent()); + assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getId(), goldenPatient1Pid.getId()).isPresent()); saveNoMatchLink(goldenPatient2Pid, goldenPatient1Pid); @@ -175,7 +175,7 @@ public class MdmLinkSvcTest extends BaseMdmR4Test { //assertEquals(patient1.getIdElement().toVersionless().getValue(), sourcePatient.getLinkFirstRep().getTarget().getReference()); List actual = targets .stream() - .map(link -> link.getSourcePersistenceId().getId().toString()) + .map(link -> ((JpaPid) link.getSourcePersistenceId()).getId().toString()) .collect(Collectors.toList()); List expected = Arrays.asList(patient1, patient2) diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/mdm/batch2/clear/MdmClearStepTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/mdm/batch2/clear/MdmClearStepTest.java index 564c1cfac09..01254e9aee5 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/mdm/batch2/clear/MdmClearStepTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/mdm/batch2/clear/MdmClearStepTest.java @@ -6,6 +6,7 @@ import ca.uhn.fhir.batch2.model.JobInstance; import ca.uhn.fhir.jpa.entity.MdmLink; import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test; import ca.uhn.fhir.jpa.mdm.helper.MdmHelperR4; +import ca.uhn.fhir.jpa.model.dao.JpaPid; import ca.uhn.fhir.jpa.partition.SystemRequestDetails; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum; @@ -53,8 +54,8 @@ class MdmClearStepTest extends BaseMdmR4Test { goldenPatient.setId(myGoldenId); myPatientDao.update(goldenPatient); - mySourcePid = myIdHelperService.getPidOrThrowException(sourcePatient).getIdAsLong(); - myGoldenPid = myIdHelperService.getPidOrThrowException(goldenPatient).getIdAsLong(); + mySourcePid = ((JpaPid) myIdHelperService.getPidOrThrowException(sourcePatient)).getId(); + myGoldenPid = ((JpaPid) myIdHelperService.getPidOrThrowException(goldenPatient)).getId(); myLink = buildMdmLink(mySourcePid, myGoldenPid); myMdmLinkDaoSvc.save(myLink); diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/dao/JpaPid.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/dao/JpaPid.java index de119e9cb83..b64179db235 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/dao/JpaPid.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/dao/JpaPid.java @@ -18,7 +18,7 @@ public class JpaPid extends ResourcePersistentId { public static List toLongList(Collection thePids) { List retVal = new ArrayList<>(thePids.size()); for (ResourcePersistentId next : thePids) { - retVal.add(next.getIdAsLong()); + retVal.add(((JpaPid) next).getId()); } return retVal; } diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorService.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorService.java index 5c0a02396e6..f32ecbcf3fd 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorService.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorService.java @@ -401,7 +401,7 @@ public class SearchParamExtractorService { * need to resolve it again */ myResourceLinkResolver.validateTypeOrThrowException(type); - resourceLink = ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, typeString, resolvedTargetId.getIdAsLong(), targetId, transactionDate, targetVersionId); + resourceLink = ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, typeString, ((JpaPid) resolvedTargetId).getId(), targetId, transactionDate, targetVersionId); } else if (theFailOnInvalidReference) { @@ -498,10 +498,10 @@ public class SearchParamExtractorService { private ResourceLink resolveTargetAndCreateResourceLinkOrReturnNull(@Nonnull RequestPartitionId theRequestPartitionId, String theSourceResourceName, PathAndRef thePathAndRef, ResourceTable theEntity, Date theUpdateTime, IIdType theNextId, RequestDetails theRequest, TransactionDetails theTransactionDetails) { assert theRequestPartitionId != null; - ResourcePersistentId resolvedResourceId = theTransactionDetails.getResolvedResourceId(theNextId); + JpaPid resolvedResourceId = (JpaPid) theTransactionDetails.getResolvedResourceId(theNextId); if (resolvedResourceId != null) { String targetResourceType = theNextId.getResourceType(); - Long targetResourcePid = resolvedResourceId.getIdAsLong(); + Long targetResourcePid = resolvedResourceId.getId(); String targetResourceIdPart = theNextId.getIdPart(); Long targetVersion = theNextId.getVersionIdPartAsLong(); return ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, targetResourceType, targetResourcePid, targetResourceIdPart, theUpdateTime, targetVersion); @@ -526,7 +526,7 @@ public class SearchParamExtractorService { } String targetResourceType = targetResource.getResourceType(); - Long targetResourcePid = targetResource.getPersistentId().getIdAsLong(); + Long targetResourcePid = ((JpaPid) targetResource.getPersistentId()).getId(); String targetResourceIdPart = theNextId.getIdPart(); Long targetVersion = theNextId.getVersionIdPartAsLong(); return ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, targetResourceType, targetResourcePid, targetResourceIdPart, theUpdateTime, targetVersion); diff --git a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java index 89d43e2f544..77ffb899c45 100644 --- a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java +++ b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java @@ -211,8 +211,8 @@ public class SearchCoordinatorSvcImplTest extends BaseSearchSvc{ verify(mySearchCacheSvc, atLeastOnce()).save(searchCaptor.capture()); assertEquals(790, allResults.size()); - assertEquals(10, allResults.get(0).getIdAsLong().longValue()); - assertEquals(799, allResults.get(789).getIdAsLong().longValue()); + assertEquals(10, allResults.get(0).getId()); + assertEquals(799, allResults.get(789).getId()); myExpectedNumberOfSearchBuildersCreated = 4; } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/index/IdHelperServiceTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/index/IdHelperServiceTest.java index 073aaba2713..aa8be4ea7b5 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/index/IdHelperServiceTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/index/IdHelperServiceTest.java @@ -26,6 +26,7 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.function.Function; +import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; @@ -154,7 +155,7 @@ public class IdHelperServiceTest { public void testResolveResourceIdentity_defaultFunctionality(){ RequestPartitionId partitionId = RequestPartitionId.fromPartitionIdAndName(1, "partition"); String resourceType = "Patient"; - String resourceForcedId = "AAA"; + String resourceForcedId = "123L"; Object[] forcedIdView = new Object[4]; forcedIdView[0] = resourceType; @@ -168,7 +169,7 @@ public class IdHelperServiceTest { IResourceLookup result = myHelperService.resolveResourceIdentity(partitionId, resourceType, resourceForcedId); assertEquals(forcedIdView[0], result.getResourceType()); - assertEquals(forcedIdView[1], result.getPersistentId().getId()); + assertEquals(forcedIdView[1], ((JpaPid) result.getPersistentId()).getId()); assertEquals(forcedIdView[3], result.getDeleted()); } @@ -185,7 +186,8 @@ public class IdHelperServiceTest { .thenReturn(resourcePersistentId1) .thenReturn(resourcePersistentId2) .thenReturn(resourcePersistentId3); - Map result = myHelperService.resolveResourcePersistentIds(partitionId, resourceType, ids); + Map result = myHelperService.resolveResourcePersistentIds(partitionId, resourceType, ids) + .entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> (JpaPid) entry.getValue())); assertThat(result.keySet(), hasSize(3)); assertEquals(1L, result.get("A").getId()); assertEquals(2L, result.get("B").getId()); @@ -199,6 +201,7 @@ public class IdHelperServiceTest { Long id = 1L; JpaPid jpaPid1 = new JpaPid(id); + when(myDaoConfig.getResourceClientIdStrategy()).thenReturn(DaoConfig.ClientIdStrategyEnum.ANY); when(myMemoryCacheService.getThenPutAfterCommit(any(), any(), any())).thenReturn(jpaPid1); JpaPid result = (JpaPid) myHelperService.resolveResourcePersistentIds(partitionId, resourceType, id.toString()); assertEquals(id, result.getId()); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSearchDaoR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSearchDaoR4Test.java index 6fa07d92c7a..415073a2c5c 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSearchDaoR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSearchDaoR4Test.java @@ -68,7 +68,7 @@ public class FhirSearchDaoR4Test extends BaseJpaR4Test { // verify results Assertions.assertEquals(1, ids.size()); - Assertions.assertEquals(id1, ids.get(0).getIdAsLong()); + Assertions.assertEquals(id1, ids.get(0).getId()); } @Test diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/HookInterceptorR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/HookInterceptorR4Test.java index befa5a0bb37..8287f06756f 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/HookInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/HookInterceptorR4Test.java @@ -4,8 +4,10 @@ import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.dao.IDao; import ca.uhn.fhir.jpa.api.svc.IIdHelperService; +import ca.uhn.fhir.jpa.model.dao.JpaPid; import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test; import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.server.provider.ProviderConstants; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -21,6 +23,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicLong; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -113,7 +116,9 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId(); runInTransaction(() -> { - Long savedPatientPid = myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong(); + List pids = myIdHelperService.resolveResourcePersistentIdsWithCache(null, + Collections.singletonList(savedPatientId)); + Long savedPatientPid = ((JpaPid) pids.get(0)).getId(); assertEquals(savedPatientPid.longValue(), pid.get()); }); } @@ -128,7 +133,7 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { pid.set(resourcePid); }); IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId(); - Long savedPatientPid = runInTransaction(() -> myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong()); + Long savedPatientPid = runInTransaction(() -> ((JpaPid) myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0)).getId()); myClient.delete().resourceById(savedPatientId).execute(); Parameters parameters = new Parameters(); @@ -165,7 +170,7 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { patient.setActive(true); myClient.update().resource(patient).execute(); runInTransaction(() -> { - Long savedPatientPid = myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong(); + Long savedPatientPid = ((JpaPid) myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0)).getId(); assertEquals(savedPatientPid.longValue(), pidOld.get()); assertEquals(savedPatientPid.longValue(), pidNew.get()); }); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImplTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImplTest.java index 34efd900b16..a4ecbbcb476 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImplTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImplTest.java @@ -242,7 +242,7 @@ public class ResourceReindexingSvcImplTest extends BaseJpaTest { when(myDaoRegistry.getResourceDao(eq("Patient"))).thenReturn(myResourceDao); when(myDaoRegistry.getResourceDao(eq(Patient.class))).thenReturn(myResourceDao); when(myResourceDao.readByPid(any(), anyBoolean())).thenAnswer(t->{ - int idx = t.getArgument(0, JpaPid.class).getIdAsLong().intValue(); + int idx = t.getArgument(0, JpaPid.class).getId().intValue(); return resources.get(idx); }); @@ -350,7 +350,7 @@ public class ResourceReindexingSvcImplTest extends BaseJpaTest { when(myDaoRegistry.getResourceDao(eq("Observation"))).thenReturn(myResourceDao); when(myDaoRegistry.getResourceDao(eq(Observation.class))).thenReturn(myResourceDao); when(myResourceDao.readByPid(any(), anyBoolean())).thenAnswer(t->{ - int idx = t.getArgument(0, JpaPid.class).getIdAsLong().intValue(); + int idx = t.getArgument(0, JpaPid.class).getId().intValue(); return resources.get(idx); }); } diff --git a/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/index/ResourceVersionSvcTest.java b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/index/ResourceVersionSvcTest.java index 3e3c73acbab..54d89479d9e 100644 --- a/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/index/ResourceVersionSvcTest.java +++ b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/index/ResourceVersionSvcTest.java @@ -96,7 +96,7 @@ public class ResourceVersionSvcTest { matches.add(getResourceTableRecordForResourceTypeAndPid( pack.MyResourceId.getResourceType(), - pack.MyPid.getIdAsLong(), + ((JpaPid) pack.MyPid).getId(), pack.MyVersion )); } diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmPidTuple.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmPidTuple.java index 3390d7bdea2..25abb05572c 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmPidTuple.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmPidTuple.java @@ -20,6 +20,7 @@ package ca.uhn.fhir.mdm.model; * #L% */ +import ca.uhn.fhir.jpa.model.dao.JpaPid; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; public class MdmPidTuple { @@ -45,11 +46,11 @@ public class MdmPidTuple { } public Long getGoldenPidAsLong() { - return myGoldenPid.getIdAsLong(); + return ((JpaPid) myGoldenPid).getId(); } public Long getSourcePidAsLong() { - return mySourcePid.getIdAsLong(); + return ((JpaPid) myGoldenPid).getId(); } public String getGoldenPidAsString() { diff --git a/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/models/Id.java b/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/models/Id.java index 9fdc07c39dd..9009d11f30f 100644 --- a/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/models/Id.java +++ b/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/models/Id.java @@ -20,6 +20,7 @@ package ca.uhn.fhir.batch2.jobs.models; * #L% */ +import ca.uhn.fhir.jpa.model.dao.JpaPid; import ca.uhn.fhir.model.api.IModelJson; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import com.fasterxml.jackson.annotation.JsonProperty; @@ -77,7 +78,7 @@ public class Id implements IModelJson { public static Id getIdFromPID(ResourcePersistentId thePID, String theResourceType) { Id id = new Id(); - id.setId(thePID.getId().toString()); + id.setId(((JpaPid)thePID).getId().toString()); id.setResourceType(theResourceType); return id; } diff --git a/hapi-fhir-storage-batch2-jobs/src/test/java/ca/uhn/fhir/batch2/jobs/export/ExpandResourcesStepTest.java b/hapi-fhir-storage-batch2-jobs/src/test/java/ca/uhn/fhir/batch2/jobs/export/ExpandResourcesStepTest.java index 745dc723c49..143ff281bfc 100644 --- a/hapi-fhir-storage-batch2-jobs/src/test/java/ca/uhn/fhir/batch2/jobs/export/ExpandResourcesStepTest.java +++ b/hapi-fhir-storage-batch2-jobs/src/test/java/ca/uhn/fhir/batch2/jobs/export/ExpandResourcesStepTest.java @@ -97,7 +97,7 @@ public class ExpandResourcesStepTest { ArrayList resources = new ArrayList<>(); ArrayList ids = new ArrayList<>(); for (int i = 0; i < 100; i++) { - String stringId = "Patient/" + i; + String stringId = String.valueOf(i); Id id = new Id(); id.setResourceType("Patient"); id.setId(stringId); diff --git a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/expunge/ExpungeService.java b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/expunge/ExpungeService.java index a4d64d7bdcb..d17bffdc644 100644 --- a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/expunge/ExpungeService.java +++ b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/expunge/ExpungeService.java @@ -23,6 +23,7 @@ package ca.uhn.fhir.jpa.dao.expunge; import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.jpa.api.model.ExpungeOptions; import ca.uhn.fhir.jpa.api.model.ExpungeOutcome; +import ca.uhn.fhir.jpa.model.dao.JpaPid; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -48,14 +49,15 @@ public class ExpungeService { } public ExpungeOutcome expunge(String theResourceName, ResourcePersistentId theResourceId, ExpungeOptions theExpungeOptions, RequestDetails theRequest) { - ourLog.info("Expunge: ResourceName[{}] Id[{}] Version[{}] Options[{}]", theResourceName, theResourceId != null ? theResourceId.getId() : null, theResourceId != null ? theResourceId.getVersion() : null, theExpungeOptions); - ExpungeOperation expungeOperation = getExpungeOperation(theResourceName, theResourceId, theExpungeOptions, theRequest); + JpaPid jpaPid = (JpaPid) theResourceId; + ourLog.info("Expunge: ResourceName[{}] Id[{}] Version[{}] Options[{}]", theResourceName, jpaPid != null ? jpaPid.getId() : null, jpaPid != null ? jpaPid.getVersion() : null, theExpungeOptions); + ExpungeOperation expungeOperation = getExpungeOperation(theResourceName, jpaPid, theExpungeOptions, theRequest); if (theExpungeOptions.getLimit() < 1) { throw new InvalidRequestException(Msg.code(1087) + "Expunge limit may not be less than 1. Received expunge limit " + theExpungeOptions.getLimit() + "."); } - if (theResourceName == null && (theResourceId == null || (theResourceId.getId() == null && theResourceId.getVersion() == null))) { + if (theResourceName == null && (jpaPid == null || (jpaPid.getId() == null && jpaPid.getVersion() == null))) { if (theExpungeOptions.isExpungeEverything()) { myExpungeEverythingService.expungeEverything(theRequest); return new ExpungeOutcome().setDeletedCount(myExpungeEverythingService.getExpungeDeletedEntityCount()); diff --git a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/index/DaoResourceLinkResolver.java b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/index/DaoResourceLinkResolver.java index ab4b6b3ff06..61ef4384800 100644 --- a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/index/DaoResourceLinkResolver.java +++ b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/index/DaoResourceLinkResolver.java @@ -95,10 +95,10 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver { RuntimeSearchParam searchParam = mySearchParamRegistry.getActiveSearchParam(theSourceResourceName, thePathAndRef.getSearchParamName()); - ResourcePersistentId persistentId = null; + JpaPid persistentId = null; if (theTransactionDetails != null) { - ResourcePersistentId resolvedResourceId = theTransactionDetails.getResolvedResourceId(targetResourceId); - if (resolvedResourceId != null && resolvedResourceId.getIdAsLong() != null && resolvedResourceId.getAssociatedResourceId() != null) { + JpaPid resolvedResourceId = (JpaPid) theTransactionDetails.getResolvedResourceId(targetResourceId); + if (resolvedResourceId != null && resolvedResourceId.getId() != null && resolvedResourceId.getAssociatedResourceId() != null) { persistentId = resolvedResourceId; } } @@ -141,7 +141,8 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver { } if (persistentId == null) { - persistentId = new JpaPid((Long) resolvedResource.getPersistentId().getId()); + persistentId = ((JpaPid) resolvedResource.getPersistentId()); + persistentId = new JpaPid(persistentId.getId()); persistentId.setAssociatedResourceId(targetResourceId); if (theTransactionDetails != null) { theTransactionDetails.addResolvedResourceId(targetResourceId, persistentId); @@ -184,7 +185,8 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver { valueOf = placeholderResourceDao.create(newResource, theRequest).getEntity(); } - JpaPid persistentId = new JpaPid((Long) valueOf.getPersistentId().getId(), 1L); + JpaPid persistentId = (JpaPid) valueOf.getPersistentId(); + persistentId = new JpaPid(persistentId.getId(), 1L); persistentId.setAssociatedResourceId(valueOf.getIdDt()); theTransactionDetails.addResolvedResourceId(persistentId.getAssociatedResourceId(), persistentId); }